ABAP Select data from SAP table PS0276 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 PS0276 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 PS0276. 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 PS0276 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_PS0276 TYPE STANDARD TABLE OF PS0276, WA_PS0276 TYPE PS0276, 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: <PS0276> TYPE PS0276. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PS0276. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PS0276 INTO TABLE IT_PS0276. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PS0276 * INTO TABLE @DATA(IT_PS02762). *--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_PS0276 INDEX 1 INTO DATA(WA_PS02762). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PS0276 ASSIGNING <PS0276>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0276>-VSRT = 1.
<PS0276>-BMODT = 1.
<PS0276>-VSCOV1 = 1.
<PS0276>-VSCAL1 = 1.
<PS0276>-EECOV1 = 1.
ENDLOOP. LOOP AT IT_PS0276 INTO WA_PS0276. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PS0276-SPCOV1, sy-vline,
WA_PS0276-VLOCK1, sy-vline,
WA_PS0276-VSAMT1, sy-vline,
WA_PS0276-CURRK1, sy-vline,
WA_PS0276-VSCOV2, sy-vline,
WA_PS0276-VSCAL2, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0276 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_PS0276 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_PS0276 INTO WA_PS0276. *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_PS0276_STR,
VSRT TYPE STRING,
BMODT TYPE STRING,
VSCOV1 TYPE STRING,
VSCAL1 TYPE STRING,
EECOV1 TYPE STRING,
SPCOV1 TYPE STRING,
VLOCK1 TYPE STRING,
VSAMT1 TYPE STRING,
CURRK1 TYPE STRING,
VSCOV2 TYPE STRING,
VSCAL2 TYPE STRING,
EECOV2 TYPE STRING,
SPCOV2 TYPE STRING,
VLOCK2 TYPE STRING,
VSAMT2 TYPE STRING,
CURRK2 TYPE STRING,
VSCOV3 TYPE STRING,
VSCAL3 TYPE STRING,
EECOV3 TYPE STRING,
SPCOV3 TYPE STRING,
VLOCK3 TYPE STRING,
VSAMT3 TYPE STRING,
CURRK3 TYPE STRING,
VSCOV4 TYPE STRING,
VSCAL4 TYPE STRING,
EECOV4 TYPE STRING,
SPCOV4 TYPE STRING,
VLOCK4 TYPE STRING,
VSAMT4 TYPE STRING,
CURRK4 TYPE STRING,
VSCOV5 TYPE STRING,
VSCAL5 TYPE STRING,
EECOV5 TYPE STRING,
SPCOV5 TYPE STRING,
VLOCK5 TYPE STRING,
VSAMT5 TYPE STRING,
CURRK5 TYPE STRING,
VSCOV6 TYPE STRING,
VSCAL6 TYPE STRING,
EECOV6 TYPE STRING,
SPCOV6 TYPE STRING,
VLOCK6 TYPE STRING,
VSAMT6 TYPE STRING,
CURRK6 TYPE STRING,
VSCOV7 TYPE STRING,
VSCAL7 TYPE STRING,
EECOV7 TYPE STRING,
SPCOV7 TYPE STRING,
VLOCK7 TYPE STRING,
VSAMT7 TYPE STRING,
CURRK7 TYPE STRING,
VSCOV8 TYPE STRING,
VSCAL8 TYPE STRING,
EECOV8 TYPE STRING,
SPCOV8 TYPE STRING,
VLOCK8 TYPE STRING,
VSAMT8 TYPE STRING,
CURRK8 TYPE STRING,
VSCOV9 TYPE STRING,
VSCAL9 TYPE STRING,
EECOV9 TYPE STRING,
SPCOV9 TYPE STRING,
VLOCK9 TYPE STRING,
VSAMT9 TYPE STRING,
CURRK9 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0276_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_PS0276_STR-VSRT sy-vline
WA_PS0276_STR-BMODT sy-vline
WA_PS0276_STR-VSCOV1 sy-vline
WA_PS0276_STR-VSCAL1 sy-vline
WA_PS0276_STR-EECOV1 sy-vline
WA_PS0276_STR-SPCOV1 sy-vline
WA_PS0276_STR-VLOCK1 sy-vline
WA_PS0276_STR-VSAMT1 sy-vline
WA_PS0276_STR-CURRK1 sy-vline
WA_PS0276_STR-VSCOV2 sy-vline
WA_PS0276_STR-VSCAL2 sy-vline
WA_PS0276_STR-EECOV2 sy-vline
WA_PS0276_STR-SPCOV2 sy-vline
WA_PS0276_STR-VLOCK2 sy-vline
WA_PS0276_STR-VSAMT2 sy-vline
WA_PS0276_STR-CURRK2 sy-vline
WA_PS0276_STR-VSCOV3 sy-vline
WA_PS0276_STR-VSCAL3 sy-vline
WA_PS0276_STR-EECOV3 sy-vline
WA_PS0276_STR-SPCOV3 sy-vline
WA_PS0276_STR-VLOCK3 sy-vline
WA_PS0276_STR-VSAMT3 sy-vline
WA_PS0276_STR-CURRK3 sy-vline
WA_PS0276_STR-VSCOV4 sy-vline
WA_PS0276_STR-VSCAL4 sy-vline
WA_PS0276_STR-EECOV4 sy-vline
WA_PS0276_STR-SPCOV4 sy-vline
WA_PS0276_STR-VLOCK4 sy-vline
WA_PS0276_STR-VSAMT4 sy-vline
WA_PS0276_STR-CURRK4 sy-vline
WA_PS0276_STR-VSCOV5 sy-vline
WA_PS0276_STR-VSCAL5 sy-vline
WA_PS0276_STR-EECOV5 sy-vline
WA_PS0276_STR-SPCOV5 sy-vline
WA_PS0276_STR-VLOCK5 sy-vline
WA_PS0276_STR-VSAMT5 sy-vline
WA_PS0276_STR-CURRK5 sy-vline
WA_PS0276_STR-VSCOV6 sy-vline
WA_PS0276_STR-VSCAL6 sy-vline
WA_PS0276_STR-EECOV6 sy-vline
WA_PS0276_STR-SPCOV6 sy-vline
WA_PS0276_STR-VLOCK6 sy-vline
WA_PS0276_STR-VSAMT6 sy-vline
WA_PS0276_STR-CURRK6 sy-vline
WA_PS0276_STR-VSCOV7 sy-vline
WA_PS0276_STR-VSCAL7 sy-vline
WA_PS0276_STR-EECOV7 sy-vline
WA_PS0276_STR-SPCOV7 sy-vline
WA_PS0276_STR-VLOCK7 sy-vline
WA_PS0276_STR-VSAMT7 sy-vline
WA_PS0276_STR-CURRK7 sy-vline
WA_PS0276_STR-VSCOV8 sy-vline
WA_PS0276_STR-VSCAL8 sy-vline
WA_PS0276_STR-EECOV8 sy-vline
WA_PS0276_STR-SPCOV8 sy-vline
WA_PS0276_STR-VLOCK8 sy-vline
WA_PS0276_STR-VSAMT8 sy-vline
WA_PS0276_STR-CURRK8 sy-vline
WA_PS0276_STR-VSCOV9 sy-vline
WA_PS0276_STR-VSCAL9 sy-vline
WA_PS0276_STR-EECOV9 sy-vline
WA_PS0276_STR-SPCOV9 sy-vline
WA_PS0276_STR-VLOCK9 sy-vline
WA_PS0276_STR-VSAMT9 sy-vline
WA_PS0276_STR-CURRK9 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.