ABAP Select data from SAP table PS0572 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 PS0572 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 PS0572. 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 PS0572 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_PS0572 TYPE STANDARD TABLE OF PS0572,
      WA_PS0572 TYPE PS0572,
      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: <PS0572> TYPE PS0572.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PS0572
*  INTO TABLE @DATA(IT_PS05722).
*--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_PS0572 INDEX 1 INTO DATA(WA_PS05722).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PS0572 ASSIGNING <PS0572>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0572>-COVPA = 1.
<PS0572>-ABST1 = 1.
<PS0572>-EVAL1 = 1.
<PS0572>-EXTE1 = 1.
<PS0572>-REDU1 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PS0572-ABST2, sy-vline,
WA_PS0572-EVAL2, sy-vline,
WA_PS0572-EXTE2, sy-vline,
WA_PS0572-REDU2, sy-vline,
WA_PS0572-ABST3, sy-vline,
WA_PS0572-EVAL3, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0572 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_PS0572 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_PS0572 INTO WA_PS0572. *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_PS0572_STR,
COVPA TYPE STRING,
ABST1 TYPE STRING,
EVAL1 TYPE STRING,
EXTE1 TYPE STRING,
REDU1 TYPE STRING,
ABST2 TYPE STRING,
EVAL2 TYPE STRING,
EXTE2 TYPE STRING,
REDU2 TYPE STRING,
ABST3 TYPE STRING,
EVAL3 TYPE STRING,
EXTE3 TYPE STRING,
REDU3 TYPE STRING,
ABST4 TYPE STRING,
EVAL4 TYPE STRING,
EXTE4 TYPE STRING,
REDU4 TYPE STRING,
ABST5 TYPE STRING,
EVAL5 TYPE STRING,
EXTE5 TYPE STRING,
REDU5 TYPE STRING,
ABST6 TYPE STRING,
EVAL6 TYPE STRING,
EXTE6 TYPE STRING,
REDU6 TYPE STRING,
ABST7 TYPE STRING,
EVAL7 TYPE STRING,
EXTE7 TYPE STRING,
REDU7 TYPE STRING,
ABST8 TYPE STRING,
EVAL8 TYPE STRING,
EXTE8 TYPE STRING,
REDU8 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0572_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_PS0572_STR-COVPA sy-vline
WA_PS0572_STR-ABST1 sy-vline
WA_PS0572_STR-EVAL1 sy-vline
WA_PS0572_STR-EXTE1 sy-vline
WA_PS0572_STR-REDU1 sy-vline
WA_PS0572_STR-ABST2 sy-vline
WA_PS0572_STR-EVAL2 sy-vline
WA_PS0572_STR-EXTE2 sy-vline
WA_PS0572_STR-REDU2 sy-vline
WA_PS0572_STR-ABST3 sy-vline
WA_PS0572_STR-EVAL3 sy-vline
WA_PS0572_STR-EXTE3 sy-vline
WA_PS0572_STR-REDU3 sy-vline
WA_PS0572_STR-ABST4 sy-vline
WA_PS0572_STR-EVAL4 sy-vline
WA_PS0572_STR-EXTE4 sy-vline
WA_PS0572_STR-REDU4 sy-vline
WA_PS0572_STR-ABST5 sy-vline
WA_PS0572_STR-EVAL5 sy-vline
WA_PS0572_STR-EXTE5 sy-vline
WA_PS0572_STR-REDU5 sy-vline
WA_PS0572_STR-ABST6 sy-vline
WA_PS0572_STR-EVAL6 sy-vline
WA_PS0572_STR-EXTE6 sy-vline
WA_PS0572_STR-REDU6 sy-vline
WA_PS0572_STR-ABST7 sy-vline
WA_PS0572_STR-EVAL7 sy-vline
WA_PS0572_STR-EXTE7 sy-vline
WA_PS0572_STR-REDU7 sy-vline
WA_PS0572_STR-ABST8 sy-vline
WA_PS0572_STR-EVAL8 sy-vline
WA_PS0572_STR-EXTE8 sy-vline
WA_PS0572_STR-REDU8 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.