ABAP Select data from SAP table PS0359 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 PS0359 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 PS0359. 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 PS0359 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_PS0359 TYPE STANDARD TABLE OF PS0359,
      WA_PS0359 TYPE PS0359,
      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: <PS0359> TYPE PS0359.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PS0359
*  INTO TABLE @DATA(IT_PS03592).
*--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_PS0359 INDEX 1 INTO DATA(WA_PS03592).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PS0359 ASSIGNING <PS0359>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0359>-TXTBL = 1.
<PS0359>-TXBAS = 1.
<PS0359>-P45ID = 1.
<PS0359>-P45DT = 1.
<PS0359>-TFAYR = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PS0359-TFAWK, sy-vline,
WA_PS0359-P45TF, sy-vline,
WA_PS0359-TFADT, sy-vline,
WA_PS0359-TXRFS, sy-vline,
WA_PS0359-ERNIE, sy-vline,
WA_PS0359-ERNDT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0359 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_PS0359 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_PS0359 INTO WA_PS0359. *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_PS0359_STR,
TXTBL TYPE STRING,
TXBAS TYPE STRING,
P45ID TYPE STRING,
P45DT TYPE STRING,
TFAYR TYPE STRING,
TFAWK TYPE STRING,
P45TF TYPE STRING,
TFADT TYPE STRING,
TXRFS TYPE STRING,
ERNIE TYPE STRING,
ERNDT TYPE STRING,
WAERS TYPE STRING,
CUTOF TYPE STRING,
EXIND TYPE STRING,
SEQNO TYPE STRING,
LYEXMP TYPE STRING,
USCAPP TYPE STRING,
URAT1 TYPE STRING,
URAT2 TYPE STRING,
URAT3 TYPE STRING,
USBAS TYPE STRING,
UTRY1 TYPE STRING,
UTRY2 TYPE STRING,
UTRM1 TYPE STRING,
UTRM2 TYPE STRING,
UTRW1 TYPE STRING,
UTRW2 TYPE STRING,
UDEFA TYPE STRING,
UWIHF TYPE STRING,
LPTAX TYPE STRING,
URAT4 TYPE STRING,
URAT5 TYPE STRING,
UTRY3 TYPE STRING,
UTRM3 TYPE STRING,
UTRW3 TYPE STRING,
UTRY4 TYPE STRING,
UTRM4 TYPE STRING,
UTRW4 TYPE STRING,
UNW53 TYPE STRING,
RPNNO TYPE STRING,
RPNID TYPE STRING,
EMPID TYPE STRING,
EXORD TYPE STRING,
SOURCE TYPE STRING,
TRAT1 TYPE STRING,
TRAT2 TYPE STRING,
P45PY TYPE STRING,
P45TX TYPE STRING,
P45UY TYPE STRING,
P45UD TYPE STRING,
EELSD TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0359_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_PS0359_STR-TXTBL sy-vline
WA_PS0359_STR-TXBAS sy-vline
WA_PS0359_STR-P45ID sy-vline
WA_PS0359_STR-P45DT sy-vline
WA_PS0359_STR-TFAYR sy-vline
WA_PS0359_STR-TFAWK sy-vline
WA_PS0359_STR-P45TF sy-vline
WA_PS0359_STR-TFADT sy-vline
WA_PS0359_STR-TXRFS sy-vline
WA_PS0359_STR-ERNIE sy-vline
WA_PS0359_STR-ERNDT sy-vline
WA_PS0359_STR-WAERS sy-vline
WA_PS0359_STR-CUTOF sy-vline
WA_PS0359_STR-EXIND sy-vline
WA_PS0359_STR-SEQNO sy-vline
WA_PS0359_STR-LYEXMP sy-vline
WA_PS0359_STR-USCAPP sy-vline
WA_PS0359_STR-URAT1 sy-vline
WA_PS0359_STR-URAT2 sy-vline
WA_PS0359_STR-URAT3 sy-vline
WA_PS0359_STR-USBAS sy-vline
WA_PS0359_STR-UTRY1 sy-vline
WA_PS0359_STR-UTRY2 sy-vline
WA_PS0359_STR-UTRM1 sy-vline
WA_PS0359_STR-UTRM2 sy-vline
WA_PS0359_STR-UTRW1 sy-vline
WA_PS0359_STR-UTRW2 sy-vline
WA_PS0359_STR-UDEFA sy-vline
WA_PS0359_STR-UWIHF sy-vline
WA_PS0359_STR-LPTAX sy-vline
WA_PS0359_STR-URAT4 sy-vline
WA_PS0359_STR-URAT5 sy-vline
WA_PS0359_STR-UTRY3 sy-vline
WA_PS0359_STR-UTRM3 sy-vline
WA_PS0359_STR-UTRW3 sy-vline
WA_PS0359_STR-UTRY4 sy-vline
WA_PS0359_STR-UTRM4 sy-vline
WA_PS0359_STR-UTRW4 sy-vline
WA_PS0359_STR-UNW53 sy-vline
WA_PS0359_STR-RPNNO sy-vline
WA_PS0359_STR-RPNID sy-vline
WA_PS0359_STR-EMPID sy-vline
WA_PS0359_STR-EXORD sy-vline
WA_PS0359_STR-SOURCE sy-vline
WA_PS0359_STR-TRAT1 sy-vline
WA_PS0359_STR-TRAT2 sy-vline
WA_PS0359_STR-P45PY sy-vline
WA_PS0359_STR-P45TX sy-vline
WA_PS0359_STR-P45UY sy-vline
WA_PS0359_STR-P45UD sy-vline
WA_PS0359_STR-EELSD sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.