ABAP Select data from SAP table IMMPURORDPRICE into internal table
Get Example source ABAP code based on a different SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP IMMPURORDPRICE table and store it within an internal table, including using the newer @DATA inline declaration methods. It also shows you various ways to process this data using ABAP work area, inline declaration or field symbols including executing all the relevant CONVERSION_EXIT routines specific to IMMPURORDPRICE. See here for more generic Select statement tips.
Sometimes data within SAP is stored within the database table in a different format to what it is displayed to the user. These input/output conversation FM routines are what translates the data between the two formats.
There is also a full declaration of the IMMPURORDPRICE table where each field has a char/string type for you to simply copy and paste. This allows you to use processing that is only available to these field types such as the CONCATENATE statement.
DATA: IT_IMMPURORDPRICE TYPE STANDARD TABLE OF IMMPURORDPRICE, WA_IMMPURORDPRICE TYPE IMMPURORDPRICE, GD_STR TYPE STRING. DATA: lo_typedescr type REF TO cl_abap_typedescr. DATA: lv_fieldname type fieldname. FIELD-SYMBOLS: <FIELD> TYPE any. FIELD-SYMBOLS: <IMMPURORDPRICE> TYPE IMMPURORDPRICE. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_IMMPURORDPRICE. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM IMMPURORDPRICE INTO TABLE IT_IMMPURORDPRICE. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM IMMPURORDPRICE * INTO TABLE @DATA(IT_IMMPURORDPRICE2). *--Further methods of using ABAP code to select data from SAP database tables *You can also declare the header/work area using the in-line DATA declaration method READ TABLE IT_IMMPURORDPRICE INDEX 1 INTO DATA(WA_IMMPURORDPRICE2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_IMMPURORDPRICE ASSIGNING <IMMPURORDPRICE>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<IMMPURORDPRICE>-MANDT = 1.
<IMMPURORDPRICE>-PURCHASEORDER = 1.
<IMMPURORDPRICE>-PRICINGDOCUMENT = 1.
<IMMPURORDPRICE>-PRICINGDOCUMENTITEM = 1.
<IMMPURORDPRICE>-PRICINGPROCEDURESTEP = 1.
ENDLOOP. LOOP AT IT_IMMPURORDPRICE INTO WA_IMMPURORDPRICE. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_IMMPURORDPRICE-PRICINGPROCEDURECOUNTER, sy-vline,
WA_IMMPURORDPRICE-CONDITIONAPPLICATION, sy-vline,
WA_IMMPURORDPRICE-CONDITIONTYPE, sy-vline,
WA_IMMPURORDPRICE-PRICINGDATETIME, sy-vline,
WA_IMMPURORDPRICE-CONDITIONCALCULATIONTYPE, sy-vline,
WA_IMMPURORDPRICE-CONDITIONBASEVALUE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IMMPURORDPRICE you want to display... WRITE:/ sy-uline. * Aternatively use generic code to Write field values (and NAME) to screen report DO. ASSIGN COMPONENT sy-index OF STRUCTURE wa_IMMPURORDPRICE TO <field>. IF sy-subrc <> 0. EXIT. ENDIF. WRITE:/ 'Field Value', <field>, sy-vline. gd_str = <field> . lo_typedescr ?= CL_ABAP_DATADESCR=>DESCRIBE_BY_DATA( <field> ). lv_fieldname = lo_typedescr->GET_RELATIVE_NAME( ). WRITE:/ 'Field Name', lv_fieldname. ENDDO. *Redo loop but convert all fields from internal to out value LOOP AT IT_IMMPURORDPRICE INTO WA_IMMPURORDPRICE. *Write horizonal line to screen report. WRITE:/ sy-uline. *Convert all fields to display/output versions using conversion routines PERFORM convert_all_field_values CHANGING wa_EKKO. ENDLOOP. *&---------------------------------------------------------------------* *& Form convert_all_field_values *&---------------------------------------------------------------------* FORM convert_all_field_values CHANGING p_EKKO LIKE wa_EKKO. DATA: ld_input(1000) TYPE c, ld_output(1000) TYPE C.
*Conversion exit ALPHA, internal->external for field PURCHASEORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-PURCHASEORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-PURCHASEORDER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EXCRT, internal->external for field PRICEDETNEXCHANGERATE CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-PRICEDETNEXCHANGERATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-PRICEDETNEXCHANGERATE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CONDITIONQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-CONDITIONQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-CONDITIONQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field GLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-GLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-GLACCOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ACCRUALSGLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-ACCRUALSGLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-ACCRUALSGLACCOUNT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field FREIGHTSUPPLIER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-FREIGHTSUPPLIER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-FREIGHTSUPPLIER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field CONDITIONSCALEBASISUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-CONDITIONSCALEBASISUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-CONDITIONSCALEBASISUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CUSTOMERREBATERECIPIENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDPRICE-CUSTOMERREBATERECIPIENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDPRICE-CUSTOMERREBATERECIPIENT.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_IMMPURORDPRICE_STR,
MANDT TYPE STRING,
PURCHASEORDER TYPE STRING,
PRICINGDOCUMENT TYPE STRING,
PRICINGDOCUMENTITEM TYPE STRING,
PRICINGPROCEDURESTEP TYPE STRING,
PRICINGPROCEDURECOUNTER TYPE STRING,
CONDITIONAPPLICATION TYPE STRING,
CONDITIONTYPE TYPE STRING,
PRICINGDATETIME TYPE STRING,
CONDITIONCALCULATIONTYPE TYPE STRING,
CONDITIONBASEVALUE TYPE STRING,
CONDITIONRATEVALUE TYPE STRING,
CONDITIONCURRENCY TYPE STRING,
PRICEDETNEXCHANGERATE TYPE STRING,
CONDITIONQUANTITY TYPE STRING,
CONDITIONQUANTITYUNIT TYPE STRING,
CONDITIONTOBASEQTYNMRTR TYPE STRING,
CONDITIONTOBASEQTYDNMNTR TYPE STRING,
CONDITIONCATEGORY TYPE STRING,
CONDITIONISFORSTATISTICS TYPE STRING,
PRICINGSCALETYPE TYPE STRING,
ISRELEVANTFORACCRUAL TYPE STRING,
CNDNISRELEVANTFORINVOICELIST TYPE STRING,
CONDITIONORIGIN TYPE STRING,
ISGROUPCONDITION TYPE STRING,
ACCESSNUMBEROFACCESSSEQUENCE TYPE STRING,
CONDITIONRECORD TYPE STRING,
CONDITIONSEQUENTIALNUMBER TYPE STRING,
ACCOUNTKEYFORGLACCOUNT TYPE STRING,
GLACCOUNT TYPE STRING,
TAXCODE TYPE STRING,
ACCTKEYFORACCRUALSGLACCOUNT TYPE STRING,
ACCRUALSGLACCOUNT TYPE STRING,
WITHHOLDINGTAXCODE TYPE STRING,
FREIGHTSUPPLIER TYPE STRING,
CNDNROUNDINGOFFDIFFAMOUNT TYPE STRING,
CONDITIONAMOUNT TYPE STRING,
TRANSACTIONCURRENCY TYPE STRING,
CONDITIONCONTROL TYPE STRING,
CONDITIONINACTIVEREASON TYPE STRING,
CONDITIONCLASS TYPE STRING,
PRCGPROCEDURECOUNTERFORHEADER TYPE STRING,
FACTORFORCONDITIONBASISVALUE TYPE STRING,
STRUCTURECONDITION TYPE STRING,
PERIODFACTORFORCNDNBASISVALUE TYPE STRING,
PRICINGSCALEBASIS TYPE STRING,
CONDITIONSCALEBASISVALUE TYPE STRING,
CONDITIONSCALEBASISUNIT TYPE STRING,
CONDITIONSCALEBASISCURRENCY TYPE STRING,
CONDITIONALTERNATIVECURRENCY TYPE STRING,
CONDITIONAMOUNTINLOCALCRCY TYPE STRING,
CNDNISRELEVANTFORINTCOBILLING TYPE STRING,
CONDITIONISMANUALLYCHANGED TYPE STRING,
BILLINGPRICESOURCE TYPE STRING,
TAXJURISDICTIONLEVEL TYPE STRING,
CONDITIONBYTESEQUENCE TYPE STRING,
CNDNISRELEVANTFORLIMITVALUE TYPE STRING,
CONDITIONBASISLIMITEXCEEDED TYPE STRING,
CONDITIONAMOUNTLIMITEXCEEDED TYPE STRING,
CUMULATEDCONDITIONBASISVALUE TYPE STRING,
CUSTOMERREBATERECIPIENT TYPE STRING,
CONDITIONISFORCONFIGURATION TYPE STRING,
VARIANTCONDITION TYPE STRING,
CONDITIONACCTASSGMTRELEVANCE TYPE STRING,
CONDITIONMATRIXMAINTRELEVANCE TYPE STRING,
CONFIGBLPARAMETERSANDFORMULAS TYPE STRING,
CONDITIONADJUSTEDQUANTITY TYPE STRING,
CNDNVALUEZEROPROCGCODE TYPE STRING,END OF T_EKKO_STR. DATA: WA_IMMPURORDPRICE_STR type T_EKKO_STR. DATA: ld_text TYPE string. LOOP AT IT_EKKO INTO WA_EKKO. MOVE-CORRESPONDING wa_EKKO TO WA_EKKO_STR. CONCATENATE: sy-vline
WA_IMMPURORDPRICE_STR-MANDT sy-vline
WA_IMMPURORDPRICE_STR-PURCHASEORDER sy-vline
WA_IMMPURORDPRICE_STR-PRICINGDOCUMENT sy-vline
WA_IMMPURORDPRICE_STR-PRICINGDOCUMENTITEM sy-vline
WA_IMMPURORDPRICE_STR-PRICINGPROCEDURESTEP sy-vline
WA_IMMPURORDPRICE_STR-PRICINGPROCEDURECOUNTER sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONAPPLICATION sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONTYPE sy-vline
WA_IMMPURORDPRICE_STR-PRICINGDATETIME sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONCALCULATIONTYPE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONBASEVALUE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONRATEVALUE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONCURRENCY sy-vline
WA_IMMPURORDPRICE_STR-PRICEDETNEXCHANGERATE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONQUANTITY sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONQUANTITYUNIT sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONTOBASEQTYNMRTR sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONTOBASEQTYDNMNTR sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONCATEGORY sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONISFORSTATISTICS sy-vline
WA_IMMPURORDPRICE_STR-PRICINGSCALETYPE sy-vline
WA_IMMPURORDPRICE_STR-ISRELEVANTFORACCRUAL sy-vline
WA_IMMPURORDPRICE_STR-CNDNISRELEVANTFORINVOICELIST sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONORIGIN sy-vline
WA_IMMPURORDPRICE_STR-ISGROUPCONDITION sy-vline
WA_IMMPURORDPRICE_STR-ACCESSNUMBEROFACCESSSEQUENCE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONRECORD sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONSEQUENTIALNUMBER sy-vline
WA_IMMPURORDPRICE_STR-ACCOUNTKEYFORGLACCOUNT sy-vline
WA_IMMPURORDPRICE_STR-GLACCOUNT sy-vline
WA_IMMPURORDPRICE_STR-TAXCODE sy-vline
WA_IMMPURORDPRICE_STR-ACCTKEYFORACCRUALSGLACCOUNT sy-vline
WA_IMMPURORDPRICE_STR-ACCRUALSGLACCOUNT sy-vline
WA_IMMPURORDPRICE_STR-WITHHOLDINGTAXCODE sy-vline
WA_IMMPURORDPRICE_STR-FREIGHTSUPPLIER sy-vline
WA_IMMPURORDPRICE_STR-CNDNROUNDINGOFFDIFFAMOUNT sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONAMOUNT sy-vline
WA_IMMPURORDPRICE_STR-TRANSACTIONCURRENCY sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONCONTROL sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONINACTIVEREASON sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONCLASS sy-vline
WA_IMMPURORDPRICE_STR-PRCGPROCEDURECOUNTERFORHEADER sy-vline
WA_IMMPURORDPRICE_STR-FACTORFORCONDITIONBASISVALUE sy-vline
WA_IMMPURORDPRICE_STR-STRUCTURECONDITION sy-vline
WA_IMMPURORDPRICE_STR-PERIODFACTORFORCNDNBASISVALUE sy-vline
WA_IMMPURORDPRICE_STR-PRICINGSCALEBASIS sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONSCALEBASISVALUE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONSCALEBASISUNIT sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONSCALEBASISCURRENCY sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONALTERNATIVECURRENCY sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONAMOUNTINLOCALCRCY sy-vline
WA_IMMPURORDPRICE_STR-CNDNISRELEVANTFORINTCOBILLING sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONISMANUALLYCHANGED sy-vline
WA_IMMPURORDPRICE_STR-BILLINGPRICESOURCE sy-vline
WA_IMMPURORDPRICE_STR-TAXJURISDICTIONLEVEL sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONBYTESEQUENCE sy-vline
WA_IMMPURORDPRICE_STR-CNDNISRELEVANTFORLIMITVALUE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONBASISLIMITEXCEEDED sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONAMOUNTLIMITEXCEEDED sy-vline
WA_IMMPURORDPRICE_STR-CUMULATEDCONDITIONBASISVALUE sy-vline
WA_IMMPURORDPRICE_STR-CUSTOMERREBATERECIPIENT sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONISFORCONFIGURATION sy-vline
WA_IMMPURORDPRICE_STR-VARIANTCONDITION sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONACCTASSGMTRELEVANCE sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONMATRIXMAINTRELEVANCE sy-vline
WA_IMMPURORDPRICE_STR-CONFIGBLPARAMETERSANDFORMULAS sy-vline
WA_IMMPURORDPRICE_STR-CONDITIONADJUSTEDQUANTITY sy-vline
WA_IMMPURORDPRICE_STR-CNDNVALUEZEROPROCGCODE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.