ABAP Select data from SAP table /AIFX/TREE_DATA_OMVOH_ST 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 /AIFX/TREE_DATA_OMVOH_ST 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 /AIFX/TREE_DATA_OMVOH_ST. 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 /AIFX/TREE_DATA_OMVOH_ST 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_/AIFX/TREE_DATA_OMVOH_ST TYPE STANDARD TABLE OF /AIFX/TREE_DATA_OMVOH_ST, WA_/AIFX/TREE_DATA_OMVOH_ST TYPE /AIFX/TREE_DATA_OMVOH_ST, 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: </AIFX/TREE_DATA_OMVOH_ST> TYPE /AIFX/TREE_DATA_OMVOH_ST. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/AIFX/TREE_DATA_OMVOH_ST. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /AIFX/TREE_DATA_OMVOH_ST INTO TABLE IT_/AIFX/TREE_DATA_OMVOH_ST. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /AIFX/TREE_DATA_OMVOH_ST * INTO TABLE @DATA(IT_/AIFX/TREE_DATA_OMVOH_ST2). *--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_/AIFX/TREE_DATA_OMVOH_ST INDEX 1 INTO DATA(WA_/AIFX/TREE_DATA_OMVOH_ST2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/AIFX/TREE_DATA_OMVOH_ST ASSIGNING </AIFX/TREE_DATA_OMVOH_ST>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</AIFX/TREE_DATA_OMVOH_ST>-NR = 1.
</AIFX/TREE_DATA_OMVOH_ST>-PARENT = 1.
</AIFX/TREE_DATA_OMVOH_ST>-ROW_DATA = 1.
</AIFX/TREE_DATA_OMVOH_ST>-EXPANDED = 1.
</AIFX/TREE_DATA_OMVOH_ST>-IS_LEAF = 1.
ENDLOOP. LOOP AT IT_/AIFX/TREE_DATA_OMVOH_ST INTO WA_/AIFX/TREE_DATA_OMVOH_ST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/AIFX/TREE_DATA_OMVOH_ST-NODE_TEXT, sy-vline,
WA_/AIFX/TREE_DATA_OMVOH_ST-STATUS_ICON, sy-vline,
WA_/AIFX/TREE_DATA_OMVOH_ST-SEQ_NUMBER, sy-vline,
WA_/AIFX/TREE_DATA_OMVOH_ST-COUNTER, sy-vline,
WA_/AIFX/TREE_DATA_OMVOH_ST-MSGGUID, sy-vline,
WA_/AIFX/TREE_DATA_OMVOH_ST-NUMBEROFABORTS, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/AIFX/TREE_DATA_OMVOH_ST 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_/AIFX/TREE_DATA_OMVOH_ST 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_/AIFX/TREE_DATA_OMVOH_ST INTO WA_/AIFX/TREE_DATA_OMVOH_ST. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_/AIFX/TREE_DATA_OMVOH_ST_STR,
NR TYPE STRING,
PARENT TYPE STRING,
ROW_DATA TYPE STRING,
EXPANDED TYPE STRING,
IS_LEAF TYPE STRING,
NODE_TEXT TYPE STRING,
STATUS_ICON TYPE STRING,
SEQ_NUMBER TYPE STRING,
COUNTER TYPE STRING,
MSGGUID TYPE STRING,
NUMBEROFABORTS TYPE STRING,
NUMBEROFERRORS TYPE STRING,
NUMBEROFWARNINGS TYPE STRING,
NUMBEROFSUCCESS TYPE STRING,
NUMBEROFINFOS TYPE STRING,
PI_MSG_ID TYPE STRING,
REMARKS TYPE STRING,
COL1 TYPE STRING,
COL2 TYPE STRING,
COL3 TYPE STRING,
COL4 TYPE STRING,
COL5 TYPE STRING,
COL6 TYPE STRING,
COL7 TYPE STRING,
COL8 TYPE STRING,
COL9 TYPE STRING,
COL10 TYPE STRING,
COL11 TYPE STRING,
COL12 TYPE STRING,
COL13 TYPE STRING,
COL14 TYPE STRING,
COL15 TYPE STRING,
COL16 TYPE STRING,
COL17 TYPE STRING,
COL18 TYPE STRING,
COL19 TYPE STRING,
COL20 TYPE STRING,
COL21 TYPE STRING,
COL22 TYPE STRING,
COL23 TYPE STRING,
COL24 TYPE STRING,
COL25 TYPE STRING,
COL26 TYPE STRING,
COL27 TYPE STRING,
COL28 TYPE STRING,
COL29 TYPE STRING,
COL30 TYPE STRING,
MSG_IDX_DATA TYPE STRING,
TOOLTIP TYPE STRING,END OF T_EKKO_STR. DATA: WA_/AIFX/TREE_DATA_OMVOH_ST_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_/AIFX/TREE_DATA_OMVOH_ST_STR-NR sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-PARENT sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-ROW_DATA sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-EXPANDED sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-IS_LEAF sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-NODE_TEXT sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-STATUS_ICON sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-SEQ_NUMBER sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COUNTER sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-MSGGUID sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-NUMBEROFABORTS sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-NUMBEROFERRORS sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-NUMBEROFWARNINGS sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-NUMBEROFSUCCESS sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-NUMBEROFINFOS sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-PI_MSG_ID sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-REMARKS sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL1 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL2 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL3 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL4 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL5 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL6 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL7 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL8 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL9 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL10 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL11 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL12 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL13 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL14 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL15 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL16 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL17 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL18 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL19 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL20 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL21 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL22 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL23 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL24 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL25 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL26 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL27 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL28 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL29 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-COL30 sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-MSG_IDX_DATA sy-vline
WA_/AIFX/TREE_DATA_OMVOH_ST_STR-TOOLTIP sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.