ABAP Select data from SAP table /SAPAPO/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_STR TYPE STANDARD TABLE OF /SAPAPO/OE_ORDER_DISPLAY_STR, WA_/SAPAPO/OE_ORDER_DISPLAY_STR TYPE /SAPAPO/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_STR> TYPE /SAPAPO/OE_ORDER_DISPLAY_STR. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SAPAPO/OE_ORDER_DISPLAY_STR. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SAPAPO/OE_ORDER_DISPLAY_STR INTO TABLE IT_/SAPAPO/OE_ORDER_DISPLAY_STR. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SAPAPO/OE_ORDER_DISPLAY_STR * INTO TABLE @DATA(IT_/SAPAPO/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_STR INDEX 1 INTO DATA(WA_/SAPAPO/OE_ORDER_DISPLAY_STR2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SAPAPO/OE_ORDER_DISPLAY_STR ASSIGNING </SAPAPO/OE_ORDER_DISPLAY_STR>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SAPAPO/OE_ORDER_DISPLAY_STR>-PROCESSED = 1.
</SAPAPO/OE_ORDER_DISPLAY_STR>-ORDID = 1.
</SAPAPO/OE_ORDER_DISPLAY_STR>-ORDNO = 1.
</SAPAPO/OE_ORDER_DISPLAY_STR>-EXTID = 1.
</SAPAPO/OE_ORDER_DISPLAY_STR>-CATNA = 1.
ENDLOOP. LOOP AT IT_/SAPAPO/OE_ORDER_DISPLAY_STR INTO WA_/SAPAPO/OE_ORDER_DISPLAY_STR. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SAPAPO/OE_ORDER_DISPLAY_STR-CTEXT, sy-vline,
WA_/SAPAPO/OE_ORDER_DISPLAY_STR-MATNR, sy-vline,
WA_/SAPAPO/OE_ORDER_DISPLAY_STR-MAKTX, sy-vline,
WA_/SAPAPO/OE_ORDER_DISPLAY_STR-FASTD, sy-vline,
WA_/SAPAPO/OE_ORDER_DISPLAY_STR-FASTT, sy-vline,
WA_/SAPAPO/OE_ORDER_DISPLAY_STR-B_OUTD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SAPAPO/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_STR INTO WA_/SAPAPO/OE_ORDER_DISPLAY_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 MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SAPAPO/OE_ORDER_DISPLAY_STR-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/OE_ORDER_DISPLAY_STR-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEOUT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SAPAPO/OE_ORDER_DISPLAY_STR-MEOUT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/OE_ORDER_DISPLAY_STR-MEOUT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field CORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SAPAPO/OE_ORDER_DISPLAY_STR-CORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SAPAPO/OE_ORDER_DISPLAY_STR-CORDER.
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/OE_ORDER_DISPLAY_STR_STR,
PROCESSED TYPE STRING,
ORDID TYPE STRING,
ORDNO TYPE STRING,
EXTID TYPE STRING,
CATNA TYPE STRING,
CTEXT TYPE STRING,
MATNR TYPE STRING,
MAKTX TYPE STRING,
FASTD TYPE STRING,
FASTT TYPE STRING,
B_OUTD TYPE STRING,
B_OUTT TYPE STRING,
LAEND TYPE STRING,
LAENT TYPE STRING,
AVDATE TYPE STRING,
AVTIME TYPE STRING,
DELST TYPE STRING,
DELAV TYPE STRING,
TZONE TYPE STRING,
QOUTW TYPE STRING,
QOUTG TYPE STRING,
QOUTO TYPE STRING,
QOUTC TYPE STRING,
QOUTP TYPE STRING,
MEOUT TYPE STRING,
ATPSTAT TYPE STRING,
CV_EX TYPE STRING,
FXOUT TYPE STRING,
FXINP TYPE STRING,
FXTRM TYPE STRING,
S_UNP TYPE STRING,
S_REL TYPE STRING,
S_STA TYPE STRING,
S_PCF TYPE STRING,
S_FCF TYPE STRING,
LOCNO TYPE STRING,
LOCTXT TYPE STRING,
ACTSEQ TYPE STRING,
LASTPT TYPE STRING,
PLPPS TYPE STRING,
EXDAT TYPE STRING,
EXTIM TYPE STRING,
PPENA TYPE STRING,
VALFRD TYPE STRING,
VALFRT TYPE STRING,
VALTOD TYPE STRING,
VALTOT TYPE STRING,
MINLS TYPE STRING,
MAXLS TYPE STRING,
ASSCR TYPE STRING,
PLS_ICO TYPE STRING,
PLS_TXT TYPE STRING,
CORDER TYPE STRING,
CORPOS TYPE STRING,
ATWRT01 TYPE STRING,
ATWRT02 TYPE STRING,
ATWRT03 TYPE STRING,
ATWRT04 TYPE STRING,
ATWRT05 TYPE STRING,
ATWRT06 TYPE STRING,
ATWRT07 TYPE STRING,
ATWRT08 TYPE STRING,
ATWRT09 TYPE STRING,
ATWRT10 TYPE STRING,
CT TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SAPAPO/OE_ORDER_DISPLAY_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/OE_ORDER_DISPLAY_STR_STR-PROCESSED sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ORDID sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ORDNO sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-EXTID sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-CATNA sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-CTEXT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-MATNR sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-MAKTX sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-FASTD sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-FASTT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-B_OUTD sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-B_OUTT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-LAEND sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-LAENT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-AVDATE sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-AVTIME sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-DELST sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-DELAV sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-TZONE sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-QOUTW sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-QOUTG sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-QOUTO sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-QOUTC sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-QOUTP sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-MEOUT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATPSTAT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-CV_EX sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-FXOUT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-FXINP sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-FXTRM sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-S_UNP sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-S_REL sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-S_STA sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-S_PCF sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-S_FCF sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-LOCNO sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-LOCTXT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ACTSEQ sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-LASTPT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-PLPPS sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-EXDAT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-EXTIM sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-PPENA sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-VALFRD sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-VALFRT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-VALTOD sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-VALTOT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-MINLS sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-MAXLS sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ASSCR sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-PLS_ICO sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-PLS_TXT sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-CORDER sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-CORPOS sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT01 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT02 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT03 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT04 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT05 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT06 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT07 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT08 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT09 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-ATWRT10 sy-vline
WA_/SAPAPO/OE_ORDER_DISPLAY_STR_STR-CT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.