SAP S202Z ABAP Select data from SAP table
Below is a number of ABAP code snippets to demonstrate how to select data from SAP S202Z 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 S202Z. 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 S202Z 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_S202Z TYPE STANDARD TABLE OF S202Z,
WA_S202Z TYPE S202Z,
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: <S202Z> TYPE S202Z.
*Process all fields in table header/work area as string values
PERFORM process_as_string_field_values CHANGING wa_S202Z.
SELECT *
*restrict ABAP select to first 10 rows
UP TO 10 ROWS
FROM S202Z
INTO TABLE IT_S202Z.
*Select data and declare internal table using in-line method @DATA
*SELECT *
* FROM S202Z
* INTO TABLE @DATA(IT_S202Z2).
*--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_S202Z INDEX 1 INTO DATA(WA_S202Z2).
*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_S202Z ASSIGNING <S202Z>.
*To update a field value using a field symbol simply change the value via the field symbol pointer<S202Z>-UMSKAL = 1.
<S202Z>-UMSKAL_PRZ = 1.
<S202Z>-UMSKAO = 1.
<S202Z>-UMSKAO_PRZ = 1.
<S202Z>-UBMGVP_PRZ = 1.
ENDLOOP. LOOP AT IT_S202Z INTO WA_S202Z. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_S202Z-UBMGVO_PRZ, sy-vline,
WA_S202Z-PRSNLS_PRZ, sy-vline,
WA_S202Z-PRSNLO_PRZ, sy-vline,
WA_S202Z-UMSMAM, sy-vline,
WA_S202Z-UMSMAO, sy-vline,
WA_S202Z-BKIMVP_PRZ, sy-vline.
ENDLOOP. *Add any further fields from structure WA_S202Z 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_S202Z 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_S202Z INTO WA_S202Z. *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_S202Z_STR,
UMSKAL TYPE STRING,
UMSKAL_PRZ TYPE STRING,
UMSKAO TYPE STRING,
UMSKAO_PRZ TYPE STRING,
UBMGVP_PRZ TYPE STRING,
UBMGVO_PRZ TYPE STRING,
PRSNLS_PRZ TYPE STRING,
PRSNLO_PRZ TYPE STRING,
UMSMAM TYPE STRING,
UMSMAO TYPE STRING,
BKIMVP_PRZ TYPE STRING,
BKIMVO_PRZ TYPE STRING,
RTEGVP_PRZ TYPE STRING,
RTEGVO_PRZ TYPE STRING,
ROHERT TYPE STRING,
ROHERT_PRZ TYPE STRING,END OF T_EKKO_STR. DATA: WA_S202Z_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_S202Z_STR-UMSKAL sy-vline
WA_S202Z_STR-UMSKAL_PRZ sy-vline
WA_S202Z_STR-UMSKAO sy-vline
WA_S202Z_STR-UMSKAO_PRZ sy-vline
WA_S202Z_STR-UBMGVP_PRZ sy-vline
WA_S202Z_STR-UBMGVO_PRZ sy-vline
WA_S202Z_STR-PRSNLS_PRZ sy-vline
WA_S202Z_STR-PRSNLO_PRZ sy-vline
WA_S202Z_STR-UMSMAM sy-vline
WA_S202Z_STR-UMSMAO sy-vline
WA_S202Z_STR-BKIMVP_PRZ sy-vline
WA_S202Z_STR-BKIMVO_PRZ sy-vline
WA_S202Z_STR-RTEGVP_PRZ sy-vline
WA_S202Z_STR-RTEGVO_PRZ sy-vline
WA_S202Z_STR-ROHERT sy-vline
WA_S202Z_STR-ROHERT_PRZ sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.
Search for further information about these or an SAP related objects