ABAP Select data from SAP table P05_SIM_TEXTS 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 P05_SIM_TEXTS 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 P05_SIM_TEXTS. 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 P05_SIM_TEXTS 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_P05_SIM_TEXTS TYPE STANDARD TABLE OF P05_SIM_TEXTS, WA_P05_SIM_TEXTS TYPE P05_SIM_TEXTS, 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: <P05_SIM_TEXTS> TYPE P05_SIM_TEXTS. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_P05_SIM_TEXTS. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM P05_SIM_TEXTS INTO TABLE IT_P05_SIM_TEXTS. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM P05_SIM_TEXTS * INTO TABLE @DATA(IT_P05_SIM_TEXTS2). *--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_P05_SIM_TEXTS INDEX 1 INTO DATA(WA_P05_SIM_TEXTS2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_P05_SIM_TEXTS ASSIGNING <P05_SIM_TEXTS>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<P05_SIM_TEXTS>-SCHKZ = 1.
<P05_SIM_TEXTS>-REPER = 1.
<P05_SIM_TEXTS>-KDZW1 = 1.
<P05_SIM_TEXTS>-KDWW1 = 1.
<P05_SIM_TEXTS>-KDWAO = 1.
ENDLOOP. LOOP AT IT_P05_SIM_TEXTS INTO WA_P05_SIM_TEXTS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_P05_SIM_TEXTS-KDZKS, sy-vline,
WA_P05_SIM_TEXTS-PKLAS, sy-vline,
WA_P05_SIM_TEXTS-BDRPR, sy-vline,
WA_P05_SIM_TEXTS-BDRWG, sy-vline,
WA_P05_SIM_TEXTS-NOMPR, sy-vline,
WA_P05_SIM_TEXTS-WGBNP, sy-vline.
ENDLOOP. *Add any further fields from structure WA_P05_SIM_TEXTS 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_P05_SIM_TEXTS 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_P05_SIM_TEXTS INTO WA_P05_SIM_TEXTS. *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_P05_SIM_TEXTS_STR,
SCHKZ TYPE STRING,
REPER TYPE STRING,
KDZW1 TYPE STRING,
KDWW1 TYPE STRING,
KDWAO TYPE STRING,
KDZKS TYPE STRING,
PKLAS TYPE STRING,
BDRPR TYPE STRING,
BDRWG TYPE STRING,
NOMPR TYPE STRING,
WGBNP TYPE STRING,
INHPR TYPE STRING,
EXSV1 TYPE STRING,
EXSV2 TYPE STRING,
EXSV3 TYPE STRING,
EXSV4 TYPE STRING,
EXSV5 TYPE STRING,
EXSV6 TYPE STRING,
EXSV7 TYPE STRING,
AUSNA TYPE STRING,
KDLHF TYPE STRING,
TABEL TYPE STRING,
TIJDV TYPE STRING,
JRLOT TYPE STRING,
ONKST TYPE STRING,
WERKS TYPE STRING,
GSBER TYPE STRING,
BTRTL TYPE STRING,
PERSG TYPE STRING,
PERSK TYPE STRING,
T5N1N_EXSV1 TYPE STRING,
T5N1N_EXSV2 TYPE STRING,
T5N1N_EXSV3 TYPE STRING,
T5N1N_EXSV4 TYPE STRING,
T5N1N_EXSV5 TYPE STRING,
T5N1N_EXSV6 TYPE STRING,
T5N1N_EXSV7 TYPE STRING,
INKKD TYPE STRING,
SPEC1 TYPE STRING,
SPEC2 TYPE STRING,
SPEC3 TYPE STRING,
SPEC4 TYPE STRING,
SPEC5 TYPE STRING,END OF T_EKKO_STR. DATA: WA_P05_SIM_TEXTS_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_P05_SIM_TEXTS_STR-SCHKZ sy-vline
WA_P05_SIM_TEXTS_STR-REPER sy-vline
WA_P05_SIM_TEXTS_STR-KDZW1 sy-vline
WA_P05_SIM_TEXTS_STR-KDWW1 sy-vline
WA_P05_SIM_TEXTS_STR-KDWAO sy-vline
WA_P05_SIM_TEXTS_STR-KDZKS sy-vline
WA_P05_SIM_TEXTS_STR-PKLAS sy-vline
WA_P05_SIM_TEXTS_STR-BDRPR sy-vline
WA_P05_SIM_TEXTS_STR-BDRWG sy-vline
WA_P05_SIM_TEXTS_STR-NOMPR sy-vline
WA_P05_SIM_TEXTS_STR-WGBNP sy-vline
WA_P05_SIM_TEXTS_STR-INHPR sy-vline
WA_P05_SIM_TEXTS_STR-EXSV1 sy-vline
WA_P05_SIM_TEXTS_STR-EXSV2 sy-vline
WA_P05_SIM_TEXTS_STR-EXSV3 sy-vline
WA_P05_SIM_TEXTS_STR-EXSV4 sy-vline
WA_P05_SIM_TEXTS_STR-EXSV5 sy-vline
WA_P05_SIM_TEXTS_STR-EXSV6 sy-vline
WA_P05_SIM_TEXTS_STR-EXSV7 sy-vline
WA_P05_SIM_TEXTS_STR-AUSNA sy-vline
WA_P05_SIM_TEXTS_STR-KDLHF sy-vline
WA_P05_SIM_TEXTS_STR-TABEL sy-vline
WA_P05_SIM_TEXTS_STR-TIJDV sy-vline
WA_P05_SIM_TEXTS_STR-JRLOT sy-vline
WA_P05_SIM_TEXTS_STR-ONKST sy-vline
WA_P05_SIM_TEXTS_STR-WERKS sy-vline
WA_P05_SIM_TEXTS_STR-GSBER sy-vline
WA_P05_SIM_TEXTS_STR-BTRTL sy-vline
WA_P05_SIM_TEXTS_STR-PERSG sy-vline
WA_P05_SIM_TEXTS_STR-PERSK sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV1 sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV2 sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV3 sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV4 sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV5 sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV6 sy-vline
WA_P05_SIM_TEXTS_STR-T5N1N_EXSV7 sy-vline
WA_P05_SIM_TEXTS_STR-INKKD sy-vline
WA_P05_SIM_TEXTS_STR-SPEC1 sy-vline
WA_P05_SIM_TEXTS_STR-SPEC2 sy-vline
WA_P05_SIM_TEXTS_STR-SPEC3 sy-vline
WA_P05_SIM_TEXTS_STR-SPEC4 sy-vline
WA_P05_SIM_TEXTS_STR-SPEC5 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.