ABAP Select data from SAP table PS0590 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 PS0590 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 PS0590. 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 PS0590 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_PS0590 TYPE STANDARD TABLE OF PS0590, WA_PS0590 TYPE PS0590, 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: <PS0590> TYPE PS0590. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PS0590. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PS0590 INTO TABLE IT_PS0590. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PS0590 * INTO TABLE @DATA(IT_PS05902). *--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_PS0590 INDEX 1 INTO DATA(WA_PS05902). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PS0590 ASSIGNING <PS0590>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0590>-WAEHI = 1.
<PS0590>-AST01 = 1.
<PS0590>-ASC01 = 1.
<PS0590>-AMT01 = 1.
<PS0590>-PRC01 = 1.
ENDLOOP. LOOP AT IT_PS0590 INTO WA_PS0590. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PS0590-AST02, sy-vline,
WA_PS0590-ASC02, sy-vline,
WA_PS0590-AMT02, sy-vline,
WA_PS0590-PRC02, sy-vline,
WA_PS0590-AST03, sy-vline,
WA_PS0590-ASC03, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0590 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_PS0590 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_PS0590 INTO WA_PS0590. *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_PS0590_STR,
WAEHI TYPE STRING,
AST01 TYPE STRING,
ASC01 TYPE STRING,
AMT01 TYPE STRING,
PRC01 TYPE STRING,
AST02 TYPE STRING,
ASC02 TYPE STRING,
AMT02 TYPE STRING,
PRC02 TYPE STRING,
AST03 TYPE STRING,
ASC03 TYPE STRING,
AMT03 TYPE STRING,
PRC03 TYPE STRING,
AST04 TYPE STRING,
ASC04 TYPE STRING,
AMT04 TYPE STRING,
PRC04 TYPE STRING,
AST05 TYPE STRING,
ASC05 TYPE STRING,
AMT05 TYPE STRING,
PRC05 TYPE STRING,
AST06 TYPE STRING,
ASC06 TYPE STRING,
AMT06 TYPE STRING,
PRC06 TYPE STRING,
AST07 TYPE STRING,
ASC07 TYPE STRING,
AMT07 TYPE STRING,
PRC07 TYPE STRING,
AST08 TYPE STRING,
ASC08 TYPE STRING,
AMT08 TYPE STRING,
PRC08 TYPE STRING,
AST09 TYPE STRING,
ASC09 TYPE STRING,
AMT09 TYPE STRING,
PRC09 TYPE STRING,
AST10 TYPE STRING,
ASC10 TYPE STRING,
AMT10 TYPE STRING,
PRC10 TYPE STRING,
AST11 TYPE STRING,
ASC11 TYPE STRING,
AMT11 TYPE STRING,
PRC11 TYPE STRING,
AST12 TYPE STRING,
ASC12 TYPE STRING,
AMT12 TYPE STRING,
PRC12 TYPE STRING,
AST13 TYPE STRING,
ASC13 TYPE STRING,
AMT13 TYPE STRING,
PRC13 TYPE STRING,
AST14 TYPE STRING,
ASC14 TYPE STRING,
AMT14 TYPE STRING,
PRC14 TYPE STRING,
AST15 TYPE STRING,
ASC15 TYPE STRING,
AMT15 TYPE STRING,
PRC15 TYPE STRING,
TOTAM TYPE STRING,
CLTOT TYPE STRING,
TOTSF TYPE STRING,
SFSCL TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0590_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_PS0590_STR-WAEHI sy-vline
WA_PS0590_STR-AST01 sy-vline
WA_PS0590_STR-ASC01 sy-vline
WA_PS0590_STR-AMT01 sy-vline
WA_PS0590_STR-PRC01 sy-vline
WA_PS0590_STR-AST02 sy-vline
WA_PS0590_STR-ASC02 sy-vline
WA_PS0590_STR-AMT02 sy-vline
WA_PS0590_STR-PRC02 sy-vline
WA_PS0590_STR-AST03 sy-vline
WA_PS0590_STR-ASC03 sy-vline
WA_PS0590_STR-AMT03 sy-vline
WA_PS0590_STR-PRC03 sy-vline
WA_PS0590_STR-AST04 sy-vline
WA_PS0590_STR-ASC04 sy-vline
WA_PS0590_STR-AMT04 sy-vline
WA_PS0590_STR-PRC04 sy-vline
WA_PS0590_STR-AST05 sy-vline
WA_PS0590_STR-ASC05 sy-vline
WA_PS0590_STR-AMT05 sy-vline
WA_PS0590_STR-PRC05 sy-vline
WA_PS0590_STR-AST06 sy-vline
WA_PS0590_STR-ASC06 sy-vline
WA_PS0590_STR-AMT06 sy-vline
WA_PS0590_STR-PRC06 sy-vline
WA_PS0590_STR-AST07 sy-vline
WA_PS0590_STR-ASC07 sy-vline
WA_PS0590_STR-AMT07 sy-vline
WA_PS0590_STR-PRC07 sy-vline
WA_PS0590_STR-AST08 sy-vline
WA_PS0590_STR-ASC08 sy-vline
WA_PS0590_STR-AMT08 sy-vline
WA_PS0590_STR-PRC08 sy-vline
WA_PS0590_STR-AST09 sy-vline
WA_PS0590_STR-ASC09 sy-vline
WA_PS0590_STR-AMT09 sy-vline
WA_PS0590_STR-PRC09 sy-vline
WA_PS0590_STR-AST10 sy-vline
WA_PS0590_STR-ASC10 sy-vline
WA_PS0590_STR-AMT10 sy-vline
WA_PS0590_STR-PRC10 sy-vline
WA_PS0590_STR-AST11 sy-vline
WA_PS0590_STR-ASC11 sy-vline
WA_PS0590_STR-AMT11 sy-vline
WA_PS0590_STR-PRC11 sy-vline
WA_PS0590_STR-AST12 sy-vline
WA_PS0590_STR-ASC12 sy-vline
WA_PS0590_STR-AMT12 sy-vline
WA_PS0590_STR-PRC12 sy-vline
WA_PS0590_STR-AST13 sy-vline
WA_PS0590_STR-ASC13 sy-vline
WA_PS0590_STR-AMT13 sy-vline
WA_PS0590_STR-PRC13 sy-vline
WA_PS0590_STR-AST14 sy-vline
WA_PS0590_STR-ASC14 sy-vline
WA_PS0590_STR-AMT14 sy-vline
WA_PS0590_STR-PRC14 sy-vline
WA_PS0590_STR-AST15 sy-vline
WA_PS0590_STR-ASC15 sy-vline
WA_PS0590_STR-AMT15 sy-vline
WA_PS0590_STR-PRC15 sy-vline
WA_PS0590_STR-TOTAM sy-vline
WA_PS0590_STR-CLTOT sy-vline
WA_PS0590_STR-TOTSF sy-vline
WA_PS0590_STR-SFSCL sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.