ABAP Select data from SAP table IPRDPLANT 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 IPRDPLANT 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 IPRDPLANT. 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 IPRDPLANT 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_IPRDPLANT TYPE STANDARD TABLE OF IPRDPLANT,
      WA_IPRDPLANT TYPE IPRDPLANT,
      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: <IPRDPLANT> TYPE IPRDPLANT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IPRDPLANT
*  INTO TABLE @DATA(IT_IPRDPLANT2).
*--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_IPRDPLANT INDEX 1 INTO DATA(WA_IPRDPLANT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IPRDPLANT ASSIGNING <IPRDPLANT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IPRDPLANT>-MANDT = 1.
<IPRDPLANT>-PRODUCT = 1.
<IPRDPLANT>-PLANT = 1.
<IPRDPLANT>-PURCHASINGGROUP = 1.
<IPRDPLANT>-COUNTRYOFORIGIN = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IPRDPLANT-REGIONOFORIGIN, sy-vline,
WA_IPRDPLANT-PRODUCTIONINVTRYMANAGEDLOC, sy-vline,
WA_IPRDPLANT-PROFILECODE, sy-vline,
WA_IPRDPLANT-PROFILEVALIDITYSTARTDATE, sy-vline,
WA_IPRDPLANT-AVAILABILITYCHECKTYPE, sy-vline,
WA_IPRDPLANT-FISCALYEARVARIANT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IPRDPLANT 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_IPRDPLANT 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_IPRDPLANT INTO WA_IPRDPLANT. *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 MATN1, internal->external for field PRODUCT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPRDPLANT-PRODUCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPRDPLANT-PRODUCT.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit MATN1, internal->external for field PRODUCTISCONFIGURABLE CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPRDPLANT-PRODUCTISCONFIGURABLE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPRDPLANT-PRODUCTISCONFIGURABLE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field CONFIGURABLEPRODUCT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPRDPLANT-CONFIGURABLEPRODUCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPRDPLANT-CONFIGURABLEPRODUCT.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit MATN1, internal->external for field CONSUMPTIONREFERENCEPRODUCT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPRDPLANT-CONSUMPTIONREFERENCEPRODUCT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPRDPLANT-CONSUMPTIONREFERENCEPRODUCT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit MATN1, internal->external for field ORIGINALBATCHREFERENCEMATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_IPRDPLANT-ORIGINALBATCHREFERENCEMATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPRDPLANT-ORIGINALBATCHREFERENCEMATERIAL.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field BASEUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IPRDPLANT-BASEUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IPRDPLANT-BASEUNIT.
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_IPRDPLANT_STR,
MANDT TYPE STRING,
PRODUCT TYPE STRING,
PLANT TYPE STRING,
PURCHASINGGROUP TYPE STRING,
COUNTRYOFORIGIN TYPE STRING,
REGIONOFORIGIN TYPE STRING,
PRODUCTIONINVTRYMANAGEDLOC TYPE STRING,
PROFILECODE TYPE STRING,
PROFILEVALIDITYSTARTDATE TYPE STRING,
AVAILABILITYCHECKTYPE TYPE STRING,
FISCALYEARVARIANT TYPE STRING,
PERIODTYPE TYPE STRING,
PROFITCENTER TYPE STRING,
COMMODITY TYPE STRING,
GOODSRECEIPTDURATION TYPE STRING,
MAINTENANCESTATUSNAME TYPE STRING,
ISMARKEDFORDELETION TYPE STRING,
MRPTYPE TYPE STRING,
MRPRESPONSIBLE TYPE STRING,
ABCINDICATOR TYPE STRING,
MINIMUMLOTSIZEQUANTITY TYPE STRING,
MAXIMUMLOTSIZEQUANTITY TYPE STRING,
FIXEDLOTSIZEQUANTITY TYPE STRING,
CONSUMPTIONTAXCTRLCODE TYPE STRING,
ISCOPRODUCT TYPE STRING,
PRODUCTISCONFIGURABLE TYPE STRING,
CONFIGURABLEPRODUCT TYPE STRING,
STOCKDETERMINATIONGROUP TYPE STRING,
STOCKINTRANSFERQUANTITY TYPE STRING,
STOCKINTRANSITQUANTITY TYPE STRING,
HASPOSTTOINSPECTIONSTOCK TYPE STRING,
ISBATCHMANAGEMENTREQUIRED TYPE STRING,
SERIALNUMBERPROFILE TYPE STRING,
ISNEGATIVESTOCKALLOWED TYPE STRING,
GOODSRECEIPTBLOCKEDSTOCKQTY TYPE STRING,
HASCONSIGNMENTCTRL TYPE STRING,
FISCALYEARCURRENTPERIOD TYPE STRING,
FISCALMONTHCURRENTPERIOD TYPE STRING,
ISPURGACROSSPURGGROUP TYPE STRING,
ISINTERNALBATCHMANAGED TYPE STRING,
PRODUCTCFOPCATEGORY TYPE STRING,
PRODUCTISEXCISETAXRELEVANT TYPE STRING,
UNDERDELIVTOLERANCELIMIT TYPE STRING,
OVERDELIVTOLERANCELIMIT TYPE STRING,
PROCUREMENTTYPE TYPE STRING,
SPECIALPROCUREMENTTYPE TYPE STRING,
PRODUCTIONSCHEDULINGPROFILE TYPE STRING,
PRODUCTIONSUPERVISOR TYPE STRING,
SAFETYSTOCKQUANTITY TYPE STRING,
GOODSISSUEUNIT TYPE STRING,
SOURCEOFSUPPLYCATEGORY TYPE STRING,
CONSUMPTIONREFERENCEPRODUCT TYPE STRING,
CONSUMPTIONREFERENCEPLANT TYPE STRING,
CONSUMPTIONREFUSAGEENDDATE TYPE STRING,
CONSUMPTIONQTYMULTIPLIER TYPE STRING,
PRODUCTUNITGROUP TYPE STRING,
DISTRCNTRDISTRIBUTIONPROFILE TYPE STRING,
CONSIGNMENTCONTROL TYPE STRING,
GOODISSUEPROCESSINGDAYS TYPE STRING,
PLANNEDDELIVERYDURATIONINDAYS TYPE STRING,
ISACTIVEENTITY TYPE STRING,
PRODUCTISCRITICALPRT TYPE STRING,
PRODUCTLOGISTICSHANDLINGGROUP TYPE STRING,
MATERIALFREIGHTGROUP TYPE STRING,
ORIGINALBATCHREFERENCEMATERIAL TYPE STRING,
ORIGLBATCHMANAGEMENTISREQUIRED TYPE STRING,
PRODUCTCONFIGURATION TYPE STRING,
BASEUNIT TYPE STRING,END OF T_EKKO_STR. DATA: WA_IPRDPLANT_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_IPRDPLANT_STR-MANDT sy-vline
WA_IPRDPLANT_STR-PRODUCT sy-vline
WA_IPRDPLANT_STR-PLANT sy-vline
WA_IPRDPLANT_STR-PURCHASINGGROUP sy-vline
WA_IPRDPLANT_STR-COUNTRYOFORIGIN sy-vline
WA_IPRDPLANT_STR-REGIONOFORIGIN sy-vline
WA_IPRDPLANT_STR-PRODUCTIONINVTRYMANAGEDLOC sy-vline
WA_IPRDPLANT_STR-PROFILECODE sy-vline
WA_IPRDPLANT_STR-PROFILEVALIDITYSTARTDATE sy-vline
WA_IPRDPLANT_STR-AVAILABILITYCHECKTYPE sy-vline
WA_IPRDPLANT_STR-FISCALYEARVARIANT sy-vline
WA_IPRDPLANT_STR-PERIODTYPE sy-vline
WA_IPRDPLANT_STR-PROFITCENTER sy-vline
WA_IPRDPLANT_STR-COMMODITY sy-vline
WA_IPRDPLANT_STR-GOODSRECEIPTDURATION sy-vline
WA_IPRDPLANT_STR-MAINTENANCESTATUSNAME sy-vline
WA_IPRDPLANT_STR-ISMARKEDFORDELETION sy-vline
WA_IPRDPLANT_STR-MRPTYPE sy-vline
WA_IPRDPLANT_STR-MRPRESPONSIBLE sy-vline
WA_IPRDPLANT_STR-ABCINDICATOR sy-vline
WA_IPRDPLANT_STR-MINIMUMLOTSIZEQUANTITY sy-vline
WA_IPRDPLANT_STR-MAXIMUMLOTSIZEQUANTITY sy-vline
WA_IPRDPLANT_STR-FIXEDLOTSIZEQUANTITY sy-vline
WA_IPRDPLANT_STR-CONSUMPTIONTAXCTRLCODE sy-vline
WA_IPRDPLANT_STR-ISCOPRODUCT sy-vline
WA_IPRDPLANT_STR-PRODUCTISCONFIGURABLE sy-vline
WA_IPRDPLANT_STR-CONFIGURABLEPRODUCT sy-vline
WA_IPRDPLANT_STR-STOCKDETERMINATIONGROUP sy-vline
WA_IPRDPLANT_STR-STOCKINTRANSFERQUANTITY sy-vline
WA_IPRDPLANT_STR-STOCKINTRANSITQUANTITY sy-vline
WA_IPRDPLANT_STR-HASPOSTTOINSPECTIONSTOCK sy-vline
WA_IPRDPLANT_STR-ISBATCHMANAGEMENTREQUIRED sy-vline
WA_IPRDPLANT_STR-SERIALNUMBERPROFILE sy-vline
WA_IPRDPLANT_STR-ISNEGATIVESTOCKALLOWED sy-vline
WA_IPRDPLANT_STR-GOODSRECEIPTBLOCKEDSTOCKQTY sy-vline
WA_IPRDPLANT_STR-HASCONSIGNMENTCTRL sy-vline
WA_IPRDPLANT_STR-FISCALYEARCURRENTPERIOD sy-vline
WA_IPRDPLANT_STR-FISCALMONTHCURRENTPERIOD sy-vline
WA_IPRDPLANT_STR-ISPURGACROSSPURGGROUP sy-vline
WA_IPRDPLANT_STR-ISINTERNALBATCHMANAGED sy-vline
WA_IPRDPLANT_STR-PRODUCTCFOPCATEGORY sy-vline
WA_IPRDPLANT_STR-PRODUCTISEXCISETAXRELEVANT sy-vline
WA_IPRDPLANT_STR-UNDERDELIVTOLERANCELIMIT sy-vline
WA_IPRDPLANT_STR-OVERDELIVTOLERANCELIMIT sy-vline
WA_IPRDPLANT_STR-PROCUREMENTTYPE sy-vline
WA_IPRDPLANT_STR-SPECIALPROCUREMENTTYPE sy-vline
WA_IPRDPLANT_STR-PRODUCTIONSCHEDULINGPROFILE sy-vline
WA_IPRDPLANT_STR-PRODUCTIONSUPERVISOR sy-vline
WA_IPRDPLANT_STR-SAFETYSTOCKQUANTITY sy-vline
WA_IPRDPLANT_STR-GOODSISSUEUNIT sy-vline
WA_IPRDPLANT_STR-SOURCEOFSUPPLYCATEGORY sy-vline
WA_IPRDPLANT_STR-CONSUMPTIONREFERENCEPRODUCT sy-vline
WA_IPRDPLANT_STR-CONSUMPTIONREFERENCEPLANT sy-vline
WA_IPRDPLANT_STR-CONSUMPTIONREFUSAGEENDDATE sy-vline
WA_IPRDPLANT_STR-CONSUMPTIONQTYMULTIPLIER sy-vline
WA_IPRDPLANT_STR-PRODUCTUNITGROUP sy-vline
WA_IPRDPLANT_STR-DISTRCNTRDISTRIBUTIONPROFILE sy-vline
WA_IPRDPLANT_STR-CONSIGNMENTCONTROL sy-vline
WA_IPRDPLANT_STR-GOODISSUEPROCESSINGDAYS sy-vline
WA_IPRDPLANT_STR-PLANNEDDELIVERYDURATIONINDAYS sy-vline
WA_IPRDPLANT_STR-ISACTIVEENTITY sy-vline
WA_IPRDPLANT_STR-PRODUCTISCRITICALPRT sy-vline
WA_IPRDPLANT_STR-PRODUCTLOGISTICSHANDLINGGROUP sy-vline
WA_IPRDPLANT_STR-MATERIALFREIGHTGROUP sy-vline
WA_IPRDPLANT_STR-ORIGINALBATCHREFERENCEMATERIAL sy-vline
WA_IPRDPLANT_STR-ORIGLBATCHMANAGEMENTISREQUIRED sy-vline
WA_IPRDPLANT_STR-PRODUCTCONFIGURATION sy-vline
WA_IPRDPLANT_STR-BASEUNIT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.