ABAP Select data from SAP table /SAPAPO/MM_ITM_DATA_STR 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 /SAPAPO/MM_ITM_DATA_STR 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 /SAPAPO/MM_ITM_DATA_STR. 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 /SAPAPO/MM_ITM_DATA_STR 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_/SAPAPO/MM_ITM_DATA_STR TYPE STANDARD TABLE OF /SAPAPO/MM_ITM_DATA_STR,
      WA_/SAPAPO/MM_ITM_DATA_STR TYPE /SAPAPO/MM_ITM_DATA_STR,
      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: </SAPAPO/MM_ITM_DATA_STR> TYPE /SAPAPO/MM_ITM_DATA_STR.

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

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /SAPAPO/MM_ITM_DATA_STR
  INTO TABLE IT_/SAPAPO/MM_ITM_DATA_STR.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /SAPAPO/MM_ITM_DATA_STR
*  INTO TABLE @DATA(IT_/SAPAPO/MM_ITM_DATA_STR2).
*--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_/SAPAPO/MM_ITM_DATA_STR INDEX 1 INTO DATA(WA_/SAPAPO/MM_ITM_DATA_STR2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/SAPAPO/MM_ITM_DATA_STR ASSIGNING </SAPAPO/MM_ITM_DATA_STR>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/MM_ITM_DATA_STR>-S_MM_DOC = 1.
</SAPAPO/MM_ITM_DATA_STR>-MANDT = 1.
</SAPAPO/MM_ITM_DATA_STR>-GUID = 1.
</SAPAPO/MM_ITM_DATA_STR>-EKGRP = 1.
</SAPAPO/MM_ITM_DATA_STR>-KUNNR = 1.
ENDLOOP.

LOOP AT IT_/SAPAPO/MM_ITM_DATA_STR INTO WA_/SAPAPO/MM_ITM_DATA_STR.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/SAPAPO/MM_ITM_DATA_STR-LPRIO, sy-vline,
WA_/SAPAPO/MM_ITM_DATA_STR-VKORG, sy-vline,
WA_/SAPAPO/MM_ITM_DATA_STR-VTWEG, sy-vline,
WA_/SAPAPO/MM_ITM_DATA_STR-SPART, sy-vline,
WA_/SAPAPO/MM_ITM_DATA_STR-EKORG, sy-vline,
WA_/SAPAPO/MM_ITM_DATA_STR-KOSCH, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/MM_ITM_DATA_STR 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_/SAPAPO/MM_ITM_DATA_STR 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_/SAPAPO/MM_ITM_DATA_STR INTO WA_/SAPAPO/MM_ITM_DATA_STR. *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 REQPRF CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SAPAPO/MM_ITM_DATA_STR-REQPRF IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/MM_ITM_DATA_STR-REQPRF.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field VRKME CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPAPO/MM_ITM_DATA_STR-VRKME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/MM_ITM_DATA_STR-VRKME.
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_/SAPAPO/MM_ITM_DATA_STR_STR,
S_MM_DOC TYPE STRING,
MANDT TYPE STRING,
GUID TYPE STRING,
EKGRP TYPE STRING,
KUNNR TYPE STRING,
LPRIO TYPE STRING,
VKORG TYPE STRING,
VTWEG TYPE STRING,
SPART TYPE STRING,
EKORG TYPE STRING,
KOSCH TYPE STRING,
ORDID TYPE STRING,
POSITION_NO TYPE STRING,
EXT_LOCTO TYPE STRING,
LOCTO TYPE STRING,
LOCFR TYPE STRING,
MATID TYPE STRING,
SUBST TYPE STRING,
CREATED_AT TYPE STRING,
CREATED_BY TYPE STRING,
CHANGED_AT TYPE STRING,
CHANGED_BY TYPE STRING,
PARENT TYPE STRING,
ORDERED_PROD TYPE STRING,
PARTNER_PROD TYPE STRING,
ITM_TYPE TYPE STRING,
SUBST_REASON TYPE STRING,
STORE_LOC TYPE STRING,
ACCID TYPE STRING,
CHMOD TYPE STRING,
ATPCAT TYPE STRING,
DLVGRP TYPE STRING,
REQPRF TYPE STRING,
RESMOD TYPE STRING,
VRKME TYPE STRING,
COPAC TYPE STRING,
BSART TYPE STRING,
PSTYP TYPE STRING,
NO_SUBST TYPE STRING,
SCHED_BWLPROCESS TYPE STRING,
UEBPO TYPE STRING,
BOP_PROCESS TYPE STRING,
PRREG TYPE STRING,
PRIO_REQ TYPE STRING,
ADVCODE TYPE STRING,
VSTEL TYPE STRING,
VSBED TYPE STRING,
FIXMG TYPE STRING,
VEN_NAME1 TYPE STRING,
VEN_NAME2 TYPE STRING,
VEN_CITY1 TYPE STRING,
VEN_COUNTRY TYPE STRING,
SCHED_HNDLG TYPE STRING,
ROUTE TYPE STRING,
S_ATPPARAM TYPE STRING,
T_MM_SCHED TYPE STRING,
T_MM_FIELD TYPE STRING,
T_QTVB TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/MM_ITM_DATA_STR_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_/SAPAPO/MM_ITM_DATA_STR_STR-S_MM_DOC sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-MANDT sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-GUID sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-EKGRP sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-KUNNR sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-LPRIO sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VKORG sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VTWEG sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-SPART sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-EKORG sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-KOSCH sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ORDID sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-POSITION_NO sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-EXT_LOCTO sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-LOCTO sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-LOCFR sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-MATID sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-SUBST sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-CREATED_AT sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-CREATED_BY sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-CHANGED_AT sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-CHANGED_BY sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-PARENT sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ORDERED_PROD sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-PARTNER_PROD sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ITM_TYPE sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-SUBST_REASON sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-STORE_LOC sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ACCID sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-CHMOD sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ATPCAT sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-DLVGRP sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-REQPRF sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-RESMOD sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VRKME sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-COPAC sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-BSART sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-PSTYP sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-NO_SUBST sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-SCHED_BWLPROCESS sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-UEBPO sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-BOP_PROCESS sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-PRREG sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-PRIO_REQ sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ADVCODE sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VSTEL sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VSBED sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-FIXMG sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VEN_NAME1 sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VEN_NAME2 sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VEN_CITY1 sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-VEN_COUNTRY sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-SCHED_HNDLG sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-ROUTE sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-S_ATPPARAM sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-T_MM_SCHED sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-T_MM_FIELD sy-vline
WA_/SAPAPO/MM_ITM_DATA_STR_STR-T_QTVB sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.