ABAP Select data from SAP table IMMPURORDITEMPRC 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 IMMPURORDITEMPRC 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 IMMPURORDITEMPRC. 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 IMMPURORDITEMPRC 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_IMMPURORDITEMPRC TYPE STANDARD TABLE OF IMMPURORDITEMPRC,
      WA_IMMPURORDITEMPRC TYPE IMMPURORDITEMPRC,
      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: <IMMPURORDITEMPRC> TYPE IMMPURORDITEMPRC.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_IMMPURORDITEMPRC.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM IMMPURORDITEMPRC
  INTO TABLE IT_IMMPURORDITEMPRC.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IMMPURORDITEMPRC
*  INTO TABLE @DATA(IT_IMMPURORDITEMPRC2).
*--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_IMMPURORDITEMPRC INDEX 1 INTO DATA(WA_IMMPURORDITEMPRC2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IMMPURORDITEMPRC ASSIGNING <IMMPURORDITEMPRC>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IMMPURORDITEMPRC>-MANDT = 1.
<IMMPURORDITEMPRC>-PURCHASEORDER = 1.
<IMMPURORDITEMPRC>-PURCHASEORDERITEM = 1.
<IMMPURORDITEMPRC>-PRICINGDOCUMENT = 1.
<IMMPURORDITEMPRC>-PRICINGDOCUMENTITEM = 1.
ENDLOOP.

LOOP AT IT_IMMPURORDITEMPRC INTO WA_IMMPURORDITEMPRC.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IMMPURORDITEMPRC-PRICINGPROCEDURESTEP, sy-vline,
WA_IMMPURORDITEMPRC-PRICINGPROCEDURECOUNTER, sy-vline,
WA_IMMPURORDITEMPRC-CONDITIONAPPLICATION, sy-vline,
WA_IMMPURORDITEMPRC-CONDITIONTYPE, sy-vline,
WA_IMMPURORDITEMPRC-PRICINGDATETIME, sy-vline,
WA_IMMPURORDITEMPRC-CONDITIONCALCULATIONTYPE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IMMPURORDITEMPRC 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_IMMPURORDITEMPRC 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_IMMPURORDITEMPRC INTO WA_IMMPURORDITEMPRC. *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_IMMPURORDITEMPRC-PURCHASEORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-PURCHASEORDER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit EXCRT, internal->external for field PRICEDETNEXCHANGERATE CALL FUNCTION 'CONVERSION_EXIT_EXCRT_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-PRICEDETNEXCHANGERATE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-PRICEDETNEXCHANGERATE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field CONDITIONQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-CONDITIONQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-CONDITIONQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field GLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-GLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-GLACCOUNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field ACCRUALSGLACCOUNT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-ACCRUALSGLACCOUNT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-ACCRUALSGLACCOUNT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field FREIGHTSUPPLIER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-FREIGHTSUPPLIER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-FREIGHTSUPPLIER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field CONDITIONSCALEBASISUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-CONDITIONSCALEBASISUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-CONDITIONSCALEBASISUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field CUSTOMERREBATERECIPIENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMMPURORDITEMPRC-CUSTOMERREBATERECIPIENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMMPURORDITEMPRC-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_IMMPURORDITEMPRC_STR,
MANDT TYPE STRING,
PURCHASEORDER TYPE STRING,
PURCHASEORDERITEM 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_IMMPURORDITEMPRC_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_IMMPURORDITEMPRC_STR-MANDT sy-vline
WA_IMMPURORDITEMPRC_STR-PURCHASEORDER sy-vline
WA_IMMPURORDITEMPRC_STR-PURCHASEORDERITEM sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGDOCUMENT sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGDOCUMENTITEM sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGPROCEDURESTEP sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGPROCEDURECOUNTER sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONAPPLICATION sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONTYPE sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGDATETIME sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONCALCULATIONTYPE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONBASEVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONRATEVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONCURRENCY sy-vline
WA_IMMPURORDITEMPRC_STR-PRICEDETNEXCHANGERATE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONQUANTITY sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONQUANTITYUNIT sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONTOBASEQTYNMRTR sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONTOBASEQTYDNMNTR sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONCATEGORY sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONISFORSTATISTICS sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGSCALETYPE sy-vline
WA_IMMPURORDITEMPRC_STR-ISRELEVANTFORACCRUAL sy-vline
WA_IMMPURORDITEMPRC_STR-CNDNISRELEVANTFORINVOICELIST sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONORIGIN sy-vline
WA_IMMPURORDITEMPRC_STR-ISGROUPCONDITION sy-vline
WA_IMMPURORDITEMPRC_STR-ACCESSNUMBEROFACCESSSEQUENCE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONRECORD sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONSEQUENTIALNUMBER sy-vline
WA_IMMPURORDITEMPRC_STR-ACCOUNTKEYFORGLACCOUNT sy-vline
WA_IMMPURORDITEMPRC_STR-GLACCOUNT sy-vline
WA_IMMPURORDITEMPRC_STR-TAXCODE sy-vline
WA_IMMPURORDITEMPRC_STR-ACCTKEYFORACCRUALSGLACCOUNT sy-vline
WA_IMMPURORDITEMPRC_STR-ACCRUALSGLACCOUNT sy-vline
WA_IMMPURORDITEMPRC_STR-WITHHOLDINGTAXCODE sy-vline
WA_IMMPURORDITEMPRC_STR-FREIGHTSUPPLIER sy-vline
WA_IMMPURORDITEMPRC_STR-CNDNROUNDINGOFFDIFFAMOUNT sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONAMOUNT sy-vline
WA_IMMPURORDITEMPRC_STR-TRANSACTIONCURRENCY sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONCONTROL sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONINACTIVEREASON sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONCLASS sy-vline
WA_IMMPURORDITEMPRC_STR-PRCGPROCEDURECOUNTERFORHEADER sy-vline
WA_IMMPURORDITEMPRC_STR-FACTORFORCONDITIONBASISVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-STRUCTURECONDITION sy-vline
WA_IMMPURORDITEMPRC_STR-PERIODFACTORFORCNDNBASISVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-PRICINGSCALEBASIS sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONSCALEBASISVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONSCALEBASISUNIT sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONSCALEBASISCURRENCY sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONALTERNATIVECURRENCY sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONAMOUNTINLOCALCRCY sy-vline
WA_IMMPURORDITEMPRC_STR-CNDNISRELEVANTFORINTCOBILLING sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONISMANUALLYCHANGED sy-vline
WA_IMMPURORDITEMPRC_STR-BILLINGPRICESOURCE sy-vline
WA_IMMPURORDITEMPRC_STR-TAXJURISDICTIONLEVEL sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONBYTESEQUENCE sy-vline
WA_IMMPURORDITEMPRC_STR-CNDNISRELEVANTFORLIMITVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONBASISLIMITEXCEEDED sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONAMOUNTLIMITEXCEEDED sy-vline
WA_IMMPURORDITEMPRC_STR-CUMULATEDCONDITIONBASISVALUE sy-vline
WA_IMMPURORDITEMPRC_STR-CUSTOMERREBATERECIPIENT sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONISFORCONFIGURATION sy-vline
WA_IMMPURORDITEMPRC_STR-VARIANTCONDITION sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONACCTASSGMTRELEVANCE sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONMATRIXMAINTRELEVANCE sy-vline
WA_IMMPURORDITEMPRC_STR-CONFIGBLPARAMETERSANDFORMULAS sy-vline
WA_IMMPURORDITEMPRC_STR-CONDITIONADJUSTEDQUANTITY sy-vline
WA_IMMPURORDITEMPRC_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.