ABAP Select data from SAP table TDS_ME_PO_ITEM 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 TDS_ME_PO_ITEM 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 TDS_ME_PO_ITEM. 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 TDS_ME_PO_ITEM 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_TDS_ME_PO_ITEM TYPE STANDARD TABLE OF TDS_ME_PO_ITEM,
      WA_TDS_ME_PO_ITEM TYPE TDS_ME_PO_ITEM,
      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: <TDS_ME_PO_ITEM> TYPE TDS_ME_PO_ITEM.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM TDS_ME_PO_ITEM
*  INTO TABLE @DATA(IT_TDS_ME_PO_ITEM2).
*--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_TDS_ME_PO_ITEM INDEX 1 INTO DATA(WA_TDS_ME_PO_ITEM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_TDS_ME_PO_ITEM ASSIGNING <TDS_ME_PO_ITEM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<TDS_ME_PO_ITEM>-MANDT = 1.
<TDS_ME_PO_ITEM>-EBELN = 1.
<TDS_ME_PO_ITEM>-EBELP = 1.
<TDS_ME_PO_ITEM>-PSTYP = 1.
<TDS_ME_PO_ITEM>-TXZ01 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_TDS_ME_PO_ITEM-MATNR, sy-vline,
WA_TDS_ME_PO_ITEM-MATKL, sy-vline,
WA_TDS_ME_PO_ITEM-WERKS, sy-vline,
WA_TDS_ME_PO_ITEM-INFNR, sy-vline,
WA_TDS_ME_PO_ITEM-IDNLF, sy-vline,
WA_TDS_ME_PO_ITEM-MEINS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_TDS_ME_PO_ITEM 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_TDS_ME_PO_ITEM 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_TDS_ME_PO_ITEM INTO WA_TDS_ME_PO_ITEM. *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 EBELN CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_TDS_ME_PO_ITEM-EBELN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_ME_PO_ITEM-EBELN.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

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

*Conversion exit EAN11, internal->external for field EAN11 CALL FUNCTION 'CONVERSION_EXIT_EAN11_OUTPUT' EXPORTING input = WA_TDS_ME_PO_ITEM-EAN11 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_ME_PO_ITEM-EAN11.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit AU132, internal->external for field WMWST CALL FUNCTION 'CONVERSION_EXIT_AU132_OUTPUT' EXPORTING input = WA_TDS_ME_PO_ITEM-WMWST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_TDS_ME_PO_ITEM-WMWST.
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_TDS_ME_PO_ITEM_STR,
MANDT TYPE STRING,
EBELN TYPE STRING,
EBELP TYPE STRING,
PSTYP TYPE STRING,
TXZ01 TYPE STRING,
MATNR TYPE STRING,
MATKL TYPE STRING,
WERKS TYPE STRING,
INFNR TYPE STRING,
IDNLF TYPE STRING,
MEINS TYPE STRING,
ORDER_UNIT_TECH TYPE STRING,
MENGE TYPE STRING,
NETPR TYPE STRING,
BPRME TYPE STRING,
ORDER_PRICE_UNIT_TECH TYPE STRING,
NETWR TYPE STRING,
WAERS TYPE STRING,
LMEIN TYPE STRING,
BASE_UNIT_TECH TYPE STRING,
BPUMN TYPE STRING,
BPUMZ TYPE STRING,
UMREZ TYPE STRING,
UMREN TYPE STRING,
EINDT TYPE STRING,
MMPUR_SERVPROC_PERIOD_START TYPE STRING,
MMPUR_SERVPROC_PERIOD_END TYPE STRING,
ADRNR TYPE STRING,
ADDRESS_LINE_1 TYPE STRING,
ADDRESS_LINE_2 TYPE STRING,
ADDRESS_LINE_3 TYPE STRING,
ADDRESS_LINE_4 TYPE STRING,
ADDRESS_LINE_5 TYPE STRING,
ADDRESS_LINE_6 TYPE STRING,
ADDRESS_LINE_7 TYPE STRING,
ADDRESS_LINE_8 TYPE STRING,
KONNR TYPE STRING,
KTPNR TYPE STRING,
SERVICEPERFORMER TYPE STRING,
SERVICEPERFORMERNAME TYPE STRING,
INCOV TYPE STRING,
BEZEI_V TYPE STRING,
INCO1 TYPE STRING,
BEZEI TYPE STRING,
INCO2_L TYPE STRING,
INCO3_L TYPE STRING,
PRODUCTTYPE TYPE STRING,
PEINH TYPE STRING,
PRSDR TYPE STRING,
LOEKZ TYPE STRING,
RETPO TYPE STRING,
ELIKZ TYPE STRING,
ISVCO TYPE STRING,
STAWN TYPE STRING,
EMATN TYPE STRING,
EAN11 TYPE STRING,
STORAGELOCATIONNAME TYPE STRING,
STORAGELOCATION TYPE STRING,
J_1BNBM TYPE STRING,
MWSKZ TYPE STRING,
DUMMY_EKPO_INCL_EEW_TR TYPE STRING,
DUMMY_EKPO_INCL_EEW_PS TYPE STRING,
SPE_CRM_REF_SO TYPE STRING,
SPE_CRM_REF_ITEM TYPE STRING,
EVERS TYPE STRING,
EVTXT TYPE STRING,
WMWST TYPE STRING,END OF T_EKKO_STR. DATA: WA_TDS_ME_PO_ITEM_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_TDS_ME_PO_ITEM_STR-MANDT sy-vline
WA_TDS_ME_PO_ITEM_STR-EBELN sy-vline
WA_TDS_ME_PO_ITEM_STR-EBELP sy-vline
WA_TDS_ME_PO_ITEM_STR-PSTYP sy-vline
WA_TDS_ME_PO_ITEM_STR-TXZ01 sy-vline
WA_TDS_ME_PO_ITEM_STR-MATNR sy-vline
WA_TDS_ME_PO_ITEM_STR-MATKL sy-vline
WA_TDS_ME_PO_ITEM_STR-WERKS sy-vline
WA_TDS_ME_PO_ITEM_STR-INFNR sy-vline
WA_TDS_ME_PO_ITEM_STR-IDNLF sy-vline
WA_TDS_ME_PO_ITEM_STR-MEINS sy-vline
WA_TDS_ME_PO_ITEM_STR-ORDER_UNIT_TECH sy-vline
WA_TDS_ME_PO_ITEM_STR-MENGE sy-vline
WA_TDS_ME_PO_ITEM_STR-NETPR sy-vline
WA_TDS_ME_PO_ITEM_STR-BPRME sy-vline
WA_TDS_ME_PO_ITEM_STR-ORDER_PRICE_UNIT_TECH sy-vline
WA_TDS_ME_PO_ITEM_STR-NETWR sy-vline
WA_TDS_ME_PO_ITEM_STR-WAERS sy-vline
WA_TDS_ME_PO_ITEM_STR-LMEIN sy-vline
WA_TDS_ME_PO_ITEM_STR-BASE_UNIT_TECH sy-vline
WA_TDS_ME_PO_ITEM_STR-BPUMN sy-vline
WA_TDS_ME_PO_ITEM_STR-BPUMZ sy-vline
WA_TDS_ME_PO_ITEM_STR-UMREZ sy-vline
WA_TDS_ME_PO_ITEM_STR-UMREN sy-vline
WA_TDS_ME_PO_ITEM_STR-EINDT sy-vline
WA_TDS_ME_PO_ITEM_STR-MMPUR_SERVPROC_PERIOD_START sy-vline
WA_TDS_ME_PO_ITEM_STR-MMPUR_SERVPROC_PERIOD_END sy-vline
WA_TDS_ME_PO_ITEM_STR-ADRNR sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_1 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_2 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_3 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_4 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_5 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_6 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_7 sy-vline
WA_TDS_ME_PO_ITEM_STR-ADDRESS_LINE_8 sy-vline
WA_TDS_ME_PO_ITEM_STR-KONNR sy-vline
WA_TDS_ME_PO_ITEM_STR-KTPNR sy-vline
WA_TDS_ME_PO_ITEM_STR-SERVICEPERFORMER sy-vline
WA_TDS_ME_PO_ITEM_STR-SERVICEPERFORMERNAME sy-vline
WA_TDS_ME_PO_ITEM_STR-INCOV sy-vline
WA_TDS_ME_PO_ITEM_STR-BEZEI_V sy-vline
WA_TDS_ME_PO_ITEM_STR-INCO1 sy-vline
WA_TDS_ME_PO_ITEM_STR-BEZEI sy-vline
WA_TDS_ME_PO_ITEM_STR-INCO2_L sy-vline
WA_TDS_ME_PO_ITEM_STR-INCO3_L sy-vline
WA_TDS_ME_PO_ITEM_STR-PRODUCTTYPE sy-vline
WA_TDS_ME_PO_ITEM_STR-PEINH sy-vline
WA_TDS_ME_PO_ITEM_STR-PRSDR sy-vline
WA_TDS_ME_PO_ITEM_STR-LOEKZ sy-vline
WA_TDS_ME_PO_ITEM_STR-RETPO sy-vline
WA_TDS_ME_PO_ITEM_STR-ELIKZ sy-vline
WA_TDS_ME_PO_ITEM_STR-ISVCO sy-vline
WA_TDS_ME_PO_ITEM_STR-STAWN sy-vline
WA_TDS_ME_PO_ITEM_STR-EMATN sy-vline
WA_TDS_ME_PO_ITEM_STR-EAN11 sy-vline
WA_TDS_ME_PO_ITEM_STR-STORAGELOCATIONNAME sy-vline
WA_TDS_ME_PO_ITEM_STR-STORAGELOCATION sy-vline
WA_TDS_ME_PO_ITEM_STR-J_1BNBM sy-vline
WA_TDS_ME_PO_ITEM_STR-MWSKZ sy-vline
WA_TDS_ME_PO_ITEM_STR-DUMMY_EKPO_INCL_EEW_TR sy-vline
WA_TDS_ME_PO_ITEM_STR-DUMMY_EKPO_INCL_EEW_PS sy-vline
WA_TDS_ME_PO_ITEM_STR-SPE_CRM_REF_SO sy-vline
WA_TDS_ME_PO_ITEM_STR-SPE_CRM_REF_ITEM sy-vline
WA_TDS_ME_PO_ITEM_STR-EVERS sy-vline
WA_TDS_ME_PO_ITEM_STR-EVTXT sy-vline
WA_TDS_ME_PO_ITEM_STR-WMWST sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.