ABAP Select data from SAP table PS0633 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 PS0633 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 PS0633. 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 PS0633 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_PS0633 TYPE STANDARD TABLE OF PS0633, WA_PS0633 TYPE PS0633, 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: <PS0633> TYPE PS0633. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PS0633. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PS0633 INTO TABLE IT_PS0633. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PS0633 * INTO TABLE @DATA(IT_PS06332). *--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_PS0633 INDEX 1 INTO DATA(WA_PS06332). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PS0633 ASSIGNING <PS0633>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0633>-CASEN = 1.
<PS0633>-ANONY = 1.
<PS0633>-STATS = 1.
<PS0633>-BASEI = 1.
<PS0633>-COUNI = 1.
ENDLOOP. LOOP AT IT_PS0633 INTO WA_PS0633. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PS0633-MEDII, sy-vline,
WA_PS0633-COMPI, sy-vline,
WA_PS0633-INVEI, sy-vline,
WA_PS0633-DECII, sy-vline,
WA_PS0633-BAS01, sy-vline,
WA_PS0633-BAS02, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0633 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_PS0633 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_PS0633 INTO WA_PS0633. *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.
*Conversion exit ALPHA, internal->external for field CADDR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PS0633-CADDR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS0633-CADDR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MADDR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PS0633-MADDR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS0633-MADDR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field IADDR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PS0633-IADDR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS0633-IADDR.
WRITE:/ 'New Value:', ld_input.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_PS0633_STR,
CASEN TYPE STRING,
ANONY TYPE STRING,
STATS TYPE STRING,
BASEI TYPE STRING,
COUNI TYPE STRING,
MEDII TYPE STRING,
COMPI TYPE STRING,
INVEI TYPE STRING,
DECII TYPE STRING,
BAS01 TYPE STRING,
BAS02 TYPE STRING,
BAS03 TYPE STRING,
BAS04 TYPE STRING,
BAS05 TYPE STRING,
BAS06 TYPE STRING,
BAS07 TYPE STRING,
BAS08 TYPE STRING,
BAS09 TYPE STRING,
BAS10 TYPE STRING,
ISU01 TYPE STRING,
ISU02 TYPE STRING,
ISU03 TYPE STRING,
ISU04 TYPE STRING,
ISU05 TYPE STRING,
ISU06 TYPE STRING,
ISU07 TYPE STRING,
ISU08 TYPE STRING,
ISU09 TYPE STRING,
ISU10 TYPE STRING,
CADDR TYPE STRING,
CCNTD TYPE STRING,
CIINT TYPE STRING,
CFINT TYPE STRING,
CNOFI TYPE STRING,
CRECV TYPE STRING,
MADDR TYPE STRING,
MASGN TYPE STRING,
MCMPL TYPE STRING,
MRSOL TYPE STRING,
MRSLD TYPE STRING,
MCOST TYPE STRING,
MTYPE TYPE STRING,
WAERS TYPE STRING,
FDOCN TYPE STRING,
FACKD TYPE STRING,
FACCD TYPE STRING,
FMIXD TYPE STRING,
FFILE TYPE STRING,
FRECV TYPE STRING,
FRMND TYPE STRING,
FCONSOLID TYPE STRING,
REF_CASEN TYPE STRING,
IADDR TYPE STRING,
IASGN TYPE STRING,
ISTAT TYPE STRING,
IPAID TYPE STRING,
IROID TYPE STRING,
IHEAR TYPE STRING,
IFRDH TYPE STRING,
IFADR TYPE STRING,
IFADI TYPE STRING,
IAPPL TYPE STRING,
IDECI TYPE STRING,
IDECR TYPE STRING,
ICIVL TYPE STRING,
INARC TYPE STRING,
DCLSR TYPE STRING,
DACTN TYPE STRING,
DHIRE TYPE STRING,
DPROM TYPE STRING,
DDSCP TYPE STRING,
DXRAS TYPE STRING,
DXRIN TYPE STRING,
DXRVL TYPE STRING,
DXRMV TYPE STRING,
DXOTH TYPE STRING,
DXNOR TYPE STRING,
DXBCK TYPE STRING,
DBCKP TYPE STRING,
DXATT TYPE STRING,
DATTN TYPE STRING,
DXAWR TYPE STRING,
DAWRD TYPE STRING,
DXSUM TYPE STRING,
DLSUM TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0633_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_PS0633_STR-CASEN sy-vline
WA_PS0633_STR-ANONY sy-vline
WA_PS0633_STR-STATS sy-vline
WA_PS0633_STR-BASEI sy-vline
WA_PS0633_STR-COUNI sy-vline
WA_PS0633_STR-MEDII sy-vline
WA_PS0633_STR-COMPI sy-vline
WA_PS0633_STR-INVEI sy-vline
WA_PS0633_STR-DECII sy-vline
WA_PS0633_STR-BAS01 sy-vline
WA_PS0633_STR-BAS02 sy-vline
WA_PS0633_STR-BAS03 sy-vline
WA_PS0633_STR-BAS04 sy-vline
WA_PS0633_STR-BAS05 sy-vline
WA_PS0633_STR-BAS06 sy-vline
WA_PS0633_STR-BAS07 sy-vline
WA_PS0633_STR-BAS08 sy-vline
WA_PS0633_STR-BAS09 sy-vline
WA_PS0633_STR-BAS10 sy-vline
WA_PS0633_STR-ISU01 sy-vline
WA_PS0633_STR-ISU02 sy-vline
WA_PS0633_STR-ISU03 sy-vline
WA_PS0633_STR-ISU04 sy-vline
WA_PS0633_STR-ISU05 sy-vline
WA_PS0633_STR-ISU06 sy-vline
WA_PS0633_STR-ISU07 sy-vline
WA_PS0633_STR-ISU08 sy-vline
WA_PS0633_STR-ISU09 sy-vline
WA_PS0633_STR-ISU10 sy-vline
WA_PS0633_STR-CADDR sy-vline
WA_PS0633_STR-CCNTD sy-vline
WA_PS0633_STR-CIINT sy-vline
WA_PS0633_STR-CFINT sy-vline
WA_PS0633_STR-CNOFI sy-vline
WA_PS0633_STR-CRECV sy-vline
WA_PS0633_STR-MADDR sy-vline
WA_PS0633_STR-MASGN sy-vline
WA_PS0633_STR-MCMPL sy-vline
WA_PS0633_STR-MRSOL sy-vline
WA_PS0633_STR-MRSLD sy-vline
WA_PS0633_STR-MCOST sy-vline
WA_PS0633_STR-MTYPE sy-vline
WA_PS0633_STR-WAERS sy-vline
WA_PS0633_STR-FDOCN sy-vline
WA_PS0633_STR-FACKD sy-vline
WA_PS0633_STR-FACCD sy-vline
WA_PS0633_STR-FMIXD sy-vline
WA_PS0633_STR-FFILE sy-vline
WA_PS0633_STR-FRECV sy-vline
WA_PS0633_STR-FRMND sy-vline
WA_PS0633_STR-FCONSOLID sy-vline
WA_PS0633_STR-REF_CASEN sy-vline
WA_PS0633_STR-IADDR sy-vline
WA_PS0633_STR-IASGN sy-vline
WA_PS0633_STR-ISTAT sy-vline
WA_PS0633_STR-IPAID sy-vline
WA_PS0633_STR-IROID sy-vline
WA_PS0633_STR-IHEAR sy-vline
WA_PS0633_STR-IFRDH sy-vline
WA_PS0633_STR-IFADR sy-vline
WA_PS0633_STR-IFADI sy-vline
WA_PS0633_STR-IAPPL sy-vline
WA_PS0633_STR-IDECI sy-vline
WA_PS0633_STR-IDECR sy-vline
WA_PS0633_STR-ICIVL sy-vline
WA_PS0633_STR-INARC sy-vline
WA_PS0633_STR-DCLSR sy-vline
WA_PS0633_STR-DACTN sy-vline
WA_PS0633_STR-DHIRE sy-vline
WA_PS0633_STR-DPROM sy-vline
WA_PS0633_STR-DDSCP sy-vline
WA_PS0633_STR-DXRAS sy-vline
WA_PS0633_STR-DXRIN sy-vline
WA_PS0633_STR-DXRVL sy-vline
WA_PS0633_STR-DXRMV sy-vline
WA_PS0633_STR-DXOTH sy-vline
WA_PS0633_STR-DXNOR sy-vline
WA_PS0633_STR-DXBCK sy-vline
WA_PS0633_STR-DBCKP sy-vline
WA_PS0633_STR-DXATT sy-vline
WA_PS0633_STR-DATTN sy-vline
WA_PS0633_STR-DXAWR sy-vline
WA_PS0633_STR-DAWRD sy-vline
WA_PS0633_STR-DXSUM sy-vline
WA_PS0633_STR-DLSUM sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.