ABAP Select data from SAP table ESH_S_OM_ACC_DATA_OTYP 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 ESH_S_OM_ACC_DATA_OTYP 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 ESH_S_OM_ACC_DATA_OTYP. 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 ESH_S_OM_ACC_DATA_OTYP 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_ESH_S_OM_ACC_DATA_OTYP TYPE STANDARD TABLE OF ESH_S_OM_ACC_DATA_OTYP,
      WA_ESH_S_OM_ACC_DATA_OTYP TYPE ESH_S_OM_ACC_DATA_OTYP,
      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: <ESH_S_OM_ACC_DATA_OTYP> TYPE ESH_S_OM_ACC_DATA_OTYP.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ESH_S_OM_ACC_DATA_OTYP
*  INTO TABLE @DATA(IT_ESH_S_OM_ACC_DATA_OTYP2).
*--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_ESH_S_OM_ACC_DATA_OTYP INDEX 1 INTO DATA(WA_ESH_S_OM_ACC_DATA_OTYP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ESH_S_OM_ACC_DATA_OTYP ASSIGNING <ESH_S_OM_ACC_DATA_OTYP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ESH_S_OM_ACC_DATA_OTYP>-AOTYP = 1.
<ESH_S_OM_ACC_DATA_OTYP>-AOTYPT = 1.
<ESH_S_OM_ACC_DATA_OTYP>-AOTYPC = 1.
<ESH_S_OM_ACC_DATA_OTYP>-AOTYPD = 1.
<ESH_S_OM_ACC_DATA_OTYP>-AOTYPK = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ESH_S_OM_ACC_DATA_OTYP-AOTYPU, sy-vline,
WA_ESH_S_OM_ACC_DATA_OTYP-AOTYPUT, sy-vline,
WA_ESH_S_OM_ACC_DATA_OTYP-AOTYPUF, sy-vline,
WA_ESH_S_OM_ACC_DATA_OTYP-AOTYPN, sy-vline,
WA_ESH_S_OM_ACC_DATA_OTYP-AOTYPNT, sy-vline,
WA_ESH_S_OM_ACC_DATA_OTYP-AOTYPNRO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ESH_S_OM_ACC_DATA_OTYP 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_ESH_S_OM_ACC_DATA_OTYP 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_ESH_S_OM_ACC_DATA_OTYP INTO WA_ESH_S_OM_ACC_DATA_OTYP. *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_ESH_S_OM_ACC_DATA_OTYP_STR,
AOTYP TYPE STRING,
AOTYPT TYPE STRING,
AOTYPC TYPE STRING,
AOTYPD TYPE STRING,
AOTYPK TYPE STRING,
AOTYPU TYPE STRING,
AOTYPUT TYPE STRING,
AOTYPUF TYPE STRING,
AOTYPN TYPE STRING,
AOTYPNT TYPE STRING,
AOTYPNRO TYPE STRING,
AOTYPNF TYPE STRING,
AOTYPNRF TYPE STRING,
AOTYPNRFU TYPE STRING,
AOTYPNRFB TYPE STRING,
AOTYPNQ TYPE STRING,
AOTYPNQT TYPE STRING,
AOTYPNQF TYPE STRING,
AOTYPNQFB TYPE STRING,
AOTYPNQFC TYPE STRING,
AOTYPNA TYPE STRING,
AOTYPNAT TYPE STRING,
AOTYPNAF TYPE STRING,
AOTYPNGF TYPE STRING,
AOTYPNGFT TYPE STRING,
AOTYPNGFF TYPE STRING,
AOTYPNGFD TYPE STRING,
AOTYPNRG TYPE STRING,
AOTYPNRGT TYPE STRING,
AOTYPNRGF TYPE STRING,
AOTYPNRGD TYPE STRING,
AOTYPNRGU TYPE STRING,
AOTYPNQG TYPE STRING,
AOTYPNQGT TYPE STRING,
AOTYPNQGF TYPE STRING,
AOTYPNQGD TYPE STRING,
AOTYPNQD TYPE STRING,
AOTYPNQDM TYPE STRING,
AOTYPUG TYPE STRING,
AOTYPUGT TYPE STRING,
AOTYPUGF TYPE STRING,
AOTYPNRR TYPE STRING,
AOTYPNRRT TYPE STRING,
AOTYPNRRF TYPE STRING,
AOTYPNRRV TYPE STRING,
AOTYPNRP TYPE STRING,
AOTYPNRPT TYPE STRING,
AOTYPNRPF TYPE STRING,
AOTYPNRPV TYPE STRING,
AOTYPNBN TYPE STRING,
AOTYPNBNT TYPE STRING,
AOTYPNBNF TYPE STRING,
AOTYPNCC TYPE STRING,
AOTYPNCCR TYPE STRING,
AOTYPNCCL TYPE STRING,
AOTYPNL TYPE STRING,
AOTYPP_NRF TYPE STRING,
AOTYPPS_NRF TYPE STRING,
AOTYPP_NQF TYPE STRING,
AOTYPPS_NQF TYPE STRING,
AOTYPP_NAF TYPE STRING,
AOTYPPS_NAF TYPE STRING,
AOTYPP_UF TYPE STRING,
AOTYPPS_UF TYPE STRING,
ASWASGN_OTYP TYPE STRING,
ASWASGN_OTYPN TYPE STRING,
ASWASGN_OTYPNF TYPE STRING,
ASWASGN_OTYPNRF TYPE STRING,
ASWASGN_OTYPNQF TYPE STRING,
ASWASGN_OTYPNA TYPE STRING,
ASWASGN_OTYPNAF TYPE STRING,
ASWASGN_OTYPNCC TYPE STRING,
ASWASGN_OTYPNGF TYPE STRING,
ASWASGN_OTYPNRG TYPE STRING,
ASWASGN_OTYPNQG TYPE STRING,END OF T_EKKO_STR. DATA: WA_ESH_S_OM_ACC_DATA_OTYP_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_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYP sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPC sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPD sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPK sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPU sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPUT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPUF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPN sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRO sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRFU sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRFB sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQ sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQFB sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQFC sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNA sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNAT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNAF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNGF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNGFT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNGFF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNGFD sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRG sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRGT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRGF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRGD sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRGU sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQG sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQGT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQGF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQGD sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQD sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNQDM sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPUG sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPUGT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPUGF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRR sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRRT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRRF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRRV sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRP sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRPT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRPF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNRPV sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNBN sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNBNT sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNBNF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNCC sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNCCR sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNCCL sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPNL sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPP_NRF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPPS_NRF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPP_NQF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPPS_NQF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPP_NAF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPPS_NAF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPP_UF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-AOTYPPS_UF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYP sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPN sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNRF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNQF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNA sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNAF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNCC sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNGF sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNRG sy-vline
WA_ESH_S_OM_ACC_DATA_OTYP_STR-ASWASGN_OTYPNQG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.