ABAP Select data from SAP table PS0305 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 PS0305 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 PS0305. 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 PS0305 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_PS0305 TYPE STANDARD TABLE OF PS0305,
      WA_PS0305 TYPE PS0305,
      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: <PS0305> TYPE PS0305.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PS0305
*  INTO TABLE @DATA(IT_PS03052).
*--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_PS0305 INDEX 1 INTO DATA(WA_PS03052).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PS0305 ASSIGNING <PS0305>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS0305>-PREMP = 1.
<PS0305>-CFDDL = 1.
<PS0305>-CAUSA = 1.
<PS0305>-ITWAE = 1.
<PS0305>-WTP01 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PS0305-AMT01, sy-vline,
WA_PS0305-NUM01, sy-vline,
WA_PS0305-RTE01, sy-vline,
WA_PS0305-WTP02, sy-vline,
WA_PS0305-AMT02, sy-vline,
WA_PS0305-NUM02, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS0305 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_PS0305 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_PS0305 INTO WA_PS0305. *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_PS0305_STR,
PREMP TYPE STRING,
CFDDL TYPE STRING,
CAUSA TYPE STRING,
ITWAE TYPE STRING,
WTP01 TYPE STRING,
AMT01 TYPE STRING,
NUM01 TYPE STRING,
RTE01 TYPE STRING,
WTP02 TYPE STRING,
AMT02 TYPE STRING,
NUM02 TYPE STRING,
RTE02 TYPE STRING,
WTP03 TYPE STRING,
AMT03 TYPE STRING,
NUM03 TYPE STRING,
RTE03 TYPE STRING,
WTP04 TYPE STRING,
AMT04 TYPE STRING,
NUM04 TYPE STRING,
RTE04 TYPE STRING,
WTP05 TYPE STRING,
AMT05 TYPE STRING,
NUM05 TYPE STRING,
RTE05 TYPE STRING,
WTP06 TYPE STRING,
AMT06 TYPE STRING,
NUM06 TYPE STRING,
RTE06 TYPE STRING,
WTP07 TYPE STRING,
AMT07 TYPE STRING,
NUM07 TYPE STRING,
RTE07 TYPE STRING,
WTP08 TYPE STRING,
AMT08 TYPE STRING,
NUM08 TYPE STRING,
RTE08 TYPE STRING,
WTP09 TYPE STRING,
AMT09 TYPE STRING,
NUM09 TYPE STRING,
RTE09 TYPE STRING,
WTP10 TYPE STRING,
AMT10 TYPE STRING,
NUM10 TYPE STRING,
RTE10 TYPE STRING,
WTP11 TYPE STRING,
AMT11 TYPE STRING,
NUM11 TYPE STRING,
RTE11 TYPE STRING,
WTP12 TYPE STRING,
AMT12 TYPE STRING,
NUM12 TYPE STRING,
RTE12 TYPE STRING,
WTP13 TYPE STRING,
AMT13 TYPE STRING,
NUM13 TYPE STRING,
RTE13 TYPE STRING,
WTP14 TYPE STRING,
AMT14 TYPE STRING,
NUM14 TYPE STRING,
RTE14 TYPE STRING,
WTP15 TYPE STRING,
AMT15 TYPE STRING,
NUM15 TYPE STRING,
RTE15 TYPE STRING,
WTP16 TYPE STRING,
AMT16 TYPE STRING,
NUM16 TYPE STRING,
RTE16 TYPE STRING,
WTP17 TYPE STRING,
AMT17 TYPE STRING,
NUM17 TYPE STRING,
RTE17 TYPE STRING,
WTP18 TYPE STRING,
AMT18 TYPE STRING,
NUM18 TYPE STRING,
RTE18 TYPE STRING,
WTP19 TYPE STRING,
AMT19 TYPE STRING,
NUM19 TYPE STRING,
RTE19 TYPE STRING,
WTP20 TYPE STRING,
AMT20 TYPE STRING,
NUM20 TYPE STRING,
RTE20 TYPE STRING,
WTP21 TYPE STRING,
AMT21 TYPE STRING,
NUM21 TYPE STRING,
RTE21 TYPE STRING,
WTP22 TYPE STRING,
AMT22 TYPE STRING,
NUM22 TYPE STRING,
RTE22 TYPE STRING,
WTP23 TYPE STRING,
AMT23 TYPE STRING,
NUM23 TYPE STRING,
RTE23 TYPE STRING,
WTP24 TYPE STRING,
AMT24 TYPE STRING,
NUM24 TYPE STRING,
RTE24 TYPE STRING,
WTP25 TYPE STRING,
AMT25 TYPE STRING,
NUM25 TYPE STRING,
RTE25 TYPE STRING,
WTP26 TYPE STRING,
AMT26 TYPE STRING,
NUM26 TYPE STRING,
RTE26 TYPE STRING,
WTP27 TYPE STRING,
AMT27 TYPE STRING,
NUM27 TYPE STRING,
RTE27 TYPE STRING,
WTP28 TYPE STRING,
AMT28 TYPE STRING,
NUM28 TYPE STRING,
RTE28 TYPE STRING,
WTP29 TYPE STRING,
AMT29 TYPE STRING,
NUM29 TYPE STRING,
RTE29 TYPE STRING,
WTP30 TYPE STRING,
AMT30 TYPE STRING,
NUM30 TYPE STRING,
RTE30 TYPE STRING,
WTP31 TYPE STRING,
AMT31 TYPE STRING,
NUM31 TYPE STRING,
RTE31 TYPE STRING,
WTP32 TYPE STRING,
AMT32 TYPE STRING,
NUM32 TYPE STRING,
RTE32 TYPE STRING,
WTP33 TYPE STRING,
AMT33 TYPE STRING,
NUM33 TYPE STRING,
RTE33 TYPE STRING,
WTP34 TYPE STRING,
AMT34 TYPE STRING,
NUM34 TYPE STRING,
RTE34 TYPE STRING,
WTP35 TYPE STRING,
AMT35 TYPE STRING,
NUM35 TYPE STRING,
RTE35 TYPE STRING,
WTP36 TYPE STRING,
AMT36 TYPE STRING,
NUM36 TYPE STRING,
RTE36 TYPE STRING,
WTP37 TYPE STRING,
AMT37 TYPE STRING,
NUM37 TYPE STRING,
RTE37 TYPE STRING,
WTP38 TYPE STRING,
AMT38 TYPE STRING,
NUM38 TYPE STRING,
RTE38 TYPE STRING,
WTP39 TYPE STRING,
AMT39 TYPE STRING,
NUM39 TYPE STRING,
RTE39 TYPE STRING,
WTP40 TYPE STRING,
AMT40 TYPE STRING,
NUM40 TYPE STRING,
RTE40 TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS0305_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_PS0305_STR-PREMP sy-vline
WA_PS0305_STR-CFDDL sy-vline
WA_PS0305_STR-CAUSA sy-vline
WA_PS0305_STR-ITWAE sy-vline
WA_PS0305_STR-WTP01 sy-vline
WA_PS0305_STR-AMT01 sy-vline
WA_PS0305_STR-NUM01 sy-vline
WA_PS0305_STR-RTE01 sy-vline
WA_PS0305_STR-WTP02 sy-vline
WA_PS0305_STR-AMT02 sy-vline
WA_PS0305_STR-NUM02 sy-vline
WA_PS0305_STR-RTE02 sy-vline
WA_PS0305_STR-WTP03 sy-vline
WA_PS0305_STR-AMT03 sy-vline
WA_PS0305_STR-NUM03 sy-vline
WA_PS0305_STR-RTE03 sy-vline
WA_PS0305_STR-WTP04 sy-vline
WA_PS0305_STR-AMT04 sy-vline
WA_PS0305_STR-NUM04 sy-vline
WA_PS0305_STR-RTE04 sy-vline
WA_PS0305_STR-WTP05 sy-vline
WA_PS0305_STR-AMT05 sy-vline
WA_PS0305_STR-NUM05 sy-vline
WA_PS0305_STR-RTE05 sy-vline
WA_PS0305_STR-WTP06 sy-vline
WA_PS0305_STR-AMT06 sy-vline
WA_PS0305_STR-NUM06 sy-vline
WA_PS0305_STR-RTE06 sy-vline
WA_PS0305_STR-WTP07 sy-vline
WA_PS0305_STR-AMT07 sy-vline
WA_PS0305_STR-NUM07 sy-vline
WA_PS0305_STR-RTE07 sy-vline
WA_PS0305_STR-WTP08 sy-vline
WA_PS0305_STR-AMT08 sy-vline
WA_PS0305_STR-NUM08 sy-vline
WA_PS0305_STR-RTE08 sy-vline
WA_PS0305_STR-WTP09 sy-vline
WA_PS0305_STR-AMT09 sy-vline
WA_PS0305_STR-NUM09 sy-vline
WA_PS0305_STR-RTE09 sy-vline
WA_PS0305_STR-WTP10 sy-vline
WA_PS0305_STR-AMT10 sy-vline
WA_PS0305_STR-NUM10 sy-vline
WA_PS0305_STR-RTE10 sy-vline
WA_PS0305_STR-WTP11 sy-vline
WA_PS0305_STR-AMT11 sy-vline
WA_PS0305_STR-NUM11 sy-vline
WA_PS0305_STR-RTE11 sy-vline
WA_PS0305_STR-WTP12 sy-vline
WA_PS0305_STR-AMT12 sy-vline
WA_PS0305_STR-NUM12 sy-vline
WA_PS0305_STR-RTE12 sy-vline
WA_PS0305_STR-WTP13 sy-vline
WA_PS0305_STR-AMT13 sy-vline
WA_PS0305_STR-NUM13 sy-vline
WA_PS0305_STR-RTE13 sy-vline
WA_PS0305_STR-WTP14 sy-vline
WA_PS0305_STR-AMT14 sy-vline
WA_PS0305_STR-NUM14 sy-vline
WA_PS0305_STR-RTE14 sy-vline
WA_PS0305_STR-WTP15 sy-vline
WA_PS0305_STR-AMT15 sy-vline
WA_PS0305_STR-NUM15 sy-vline
WA_PS0305_STR-RTE15 sy-vline
WA_PS0305_STR-WTP16 sy-vline
WA_PS0305_STR-AMT16 sy-vline
WA_PS0305_STR-NUM16 sy-vline
WA_PS0305_STR-RTE16 sy-vline
WA_PS0305_STR-WTP17 sy-vline
WA_PS0305_STR-AMT17 sy-vline
WA_PS0305_STR-NUM17 sy-vline
WA_PS0305_STR-RTE17 sy-vline
WA_PS0305_STR-WTP18 sy-vline
WA_PS0305_STR-AMT18 sy-vline
WA_PS0305_STR-NUM18 sy-vline
WA_PS0305_STR-RTE18 sy-vline
WA_PS0305_STR-WTP19 sy-vline
WA_PS0305_STR-AMT19 sy-vline
WA_PS0305_STR-NUM19 sy-vline
WA_PS0305_STR-RTE19 sy-vline
WA_PS0305_STR-WTP20 sy-vline
WA_PS0305_STR-AMT20 sy-vline
WA_PS0305_STR-NUM20 sy-vline
WA_PS0305_STR-RTE20 sy-vline
WA_PS0305_STR-WTP21 sy-vline
WA_PS0305_STR-AMT21 sy-vline
WA_PS0305_STR-NUM21 sy-vline
WA_PS0305_STR-RTE21 sy-vline
WA_PS0305_STR-WTP22 sy-vline
WA_PS0305_STR-AMT22 sy-vline
WA_PS0305_STR-NUM22 sy-vline
WA_PS0305_STR-RTE22 sy-vline
WA_PS0305_STR-WTP23 sy-vline
WA_PS0305_STR-AMT23 sy-vline
WA_PS0305_STR-NUM23 sy-vline
WA_PS0305_STR-RTE23 sy-vline
WA_PS0305_STR-WTP24 sy-vline
WA_PS0305_STR-AMT24 sy-vline
WA_PS0305_STR-NUM24 sy-vline
WA_PS0305_STR-RTE24 sy-vline
WA_PS0305_STR-WTP25 sy-vline
WA_PS0305_STR-AMT25 sy-vline
WA_PS0305_STR-NUM25 sy-vline
WA_PS0305_STR-RTE25 sy-vline
WA_PS0305_STR-WTP26 sy-vline
WA_PS0305_STR-AMT26 sy-vline
WA_PS0305_STR-NUM26 sy-vline
WA_PS0305_STR-RTE26 sy-vline
WA_PS0305_STR-WTP27 sy-vline
WA_PS0305_STR-AMT27 sy-vline
WA_PS0305_STR-NUM27 sy-vline
WA_PS0305_STR-RTE27 sy-vline
WA_PS0305_STR-WTP28 sy-vline
WA_PS0305_STR-AMT28 sy-vline
WA_PS0305_STR-NUM28 sy-vline
WA_PS0305_STR-RTE28 sy-vline
WA_PS0305_STR-WTP29 sy-vline
WA_PS0305_STR-AMT29 sy-vline
WA_PS0305_STR-NUM29 sy-vline
WA_PS0305_STR-RTE29 sy-vline
WA_PS0305_STR-WTP30 sy-vline
WA_PS0305_STR-AMT30 sy-vline
WA_PS0305_STR-NUM30 sy-vline
WA_PS0305_STR-RTE30 sy-vline
WA_PS0305_STR-WTP31 sy-vline
WA_PS0305_STR-AMT31 sy-vline
WA_PS0305_STR-NUM31 sy-vline
WA_PS0305_STR-RTE31 sy-vline
WA_PS0305_STR-WTP32 sy-vline
WA_PS0305_STR-AMT32 sy-vline
WA_PS0305_STR-NUM32 sy-vline
WA_PS0305_STR-RTE32 sy-vline
WA_PS0305_STR-WTP33 sy-vline
WA_PS0305_STR-AMT33 sy-vline
WA_PS0305_STR-NUM33 sy-vline
WA_PS0305_STR-RTE33 sy-vline
WA_PS0305_STR-WTP34 sy-vline
WA_PS0305_STR-AMT34 sy-vline
WA_PS0305_STR-NUM34 sy-vline
WA_PS0305_STR-RTE34 sy-vline
WA_PS0305_STR-WTP35 sy-vline
WA_PS0305_STR-AMT35 sy-vline
WA_PS0305_STR-NUM35 sy-vline
WA_PS0305_STR-RTE35 sy-vline
WA_PS0305_STR-WTP36 sy-vline
WA_PS0305_STR-AMT36 sy-vline
WA_PS0305_STR-NUM36 sy-vline
WA_PS0305_STR-RTE36 sy-vline
WA_PS0305_STR-WTP37 sy-vline
WA_PS0305_STR-AMT37 sy-vline
WA_PS0305_STR-NUM37 sy-vline
WA_PS0305_STR-RTE37 sy-vline
WA_PS0305_STR-WTP38 sy-vline
WA_PS0305_STR-AMT38 sy-vline
WA_PS0305_STR-NUM38 sy-vline
WA_PS0305_STR-RTE38 sy-vline
WA_PS0305_STR-WTP39 sy-vline
WA_PS0305_STR-AMT39 sy-vline
WA_PS0305_STR-NUM39 sy-vline
WA_PS0305_STR-RTE39 sy-vline
WA_PS0305_STR-WTP40 sy-vline
WA_PS0305_STR-AMT40 sy-vline
WA_PS0305_STR-NUM40 sy-vline
WA_PS0305_STR-RTE40 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.