ABAP Select data from SAP table PS3375 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 PS3375 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 PS3375. 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 PS3375 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_PS3375 TYPE STANDARD TABLE OF PS3375,
      WA_PS3375 TYPE PS3375,
      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: <PS3375> TYPE PS3375.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PS3375
*  INTO TABLE @DATA(IT_PS33752).
*--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_PS3375 INDEX 1 INTO DATA(WA_PS33752).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PS3375 ASSIGNING <PS3375>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PS3375>-OFGRP = 1.
<PS3375>-DEC_MONTH = 1.
<PS3375>-DEC_YEAR = 1.
<PS3375>-FLAG_MM = 1.
<PS3375>-FLAG_SM = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PS3375-CANA01, sy-vline,
WA_PS3375-BEGD01, sy-vline,
WA_PS3375-BEGT01, sy-vline,
WA_PS3375-ENDD01, sy-vline,
WA_PS3375-ENDT01, sy-vline,
WA_PS3375-EERE01, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PS3375 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_PS3375 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_PS3375 INTO WA_PS3375. *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 GJAHR, internal->external for field DEC_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_PS3375-DEC_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PS3375-DEC_YEAR.
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_PS3375_STR,
OFGRP TYPE STRING,
DEC_MONTH TYPE STRING,
DEC_YEAR TYPE STRING,
FLAG_MM TYPE STRING,
FLAG_SM TYPE STRING,
CANA01 TYPE STRING,
BEGD01 TYPE STRING,
BEGT01 TYPE STRING,
ENDD01 TYPE STRING,
ENDT01 TYPE STRING,
EERE01 TYPE STRING,
CANA02 TYPE STRING,
BEGD02 TYPE STRING,
BEGT02 TYPE STRING,
ENDD02 TYPE STRING,
ENDT02 TYPE STRING,
EERE02 TYPE STRING,
CANA03 TYPE STRING,
BEGD03 TYPE STRING,
BEGT03 TYPE STRING,
ENDD03 TYPE STRING,
ENDT03 TYPE STRING,
EERE03 TYPE STRING,
CANA04 TYPE STRING,
BEGD04 TYPE STRING,
BEGT04 TYPE STRING,
ENDD04 TYPE STRING,
ENDT04 TYPE STRING,
EERE04 TYPE STRING,
CANA05 TYPE STRING,
BEGD05 TYPE STRING,
BEGT05 TYPE STRING,
ENDD05 TYPE STRING,
ENDT05 TYPE STRING,
EERE05 TYPE STRING,
CANA06 TYPE STRING,
BEGD06 TYPE STRING,
BEGT06 TYPE STRING,
ENDD06 TYPE STRING,
ENDT06 TYPE STRING,
EERE06 TYPE STRING,
CANA07 TYPE STRING,
BEGD07 TYPE STRING,
BEGT07 TYPE STRING,
ENDD07 TYPE STRING,
ENDT07 TYPE STRING,
EERE07 TYPE STRING,
CANA08 TYPE STRING,
BEGD08 TYPE STRING,
BEGT08 TYPE STRING,
ENDD08 TYPE STRING,
ENDT08 TYPE STRING,
EERE08 TYPE STRING,
CANA09 TYPE STRING,
BEGD09 TYPE STRING,
BEGT09 TYPE STRING,
ENDD09 TYPE STRING,
ENDT09 TYPE STRING,
EERE09 TYPE STRING,
CANA10 TYPE STRING,
BEGD10 TYPE STRING,
BEGT10 TYPE STRING,
ENDD10 TYPE STRING,
ENDT10 TYPE STRING,
EERE10 TYPE STRING,
SUBDT TYPE STRING,
SUBID TYPE STRING,
SUBST TYPE STRING,
VERST TYPE STRING,
APPST TYPE STRING,
ASSNO TYPE STRING,END OF T_EKKO_STR. DATA: WA_PS3375_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_PS3375_STR-OFGRP sy-vline
WA_PS3375_STR-DEC_MONTH sy-vline
WA_PS3375_STR-DEC_YEAR sy-vline
WA_PS3375_STR-FLAG_MM sy-vline
WA_PS3375_STR-FLAG_SM sy-vline
WA_PS3375_STR-CANA01 sy-vline
WA_PS3375_STR-BEGD01 sy-vline
WA_PS3375_STR-BEGT01 sy-vline
WA_PS3375_STR-ENDD01 sy-vline
WA_PS3375_STR-ENDT01 sy-vline
WA_PS3375_STR-EERE01 sy-vline
WA_PS3375_STR-CANA02 sy-vline
WA_PS3375_STR-BEGD02 sy-vline
WA_PS3375_STR-BEGT02 sy-vline
WA_PS3375_STR-ENDD02 sy-vline
WA_PS3375_STR-ENDT02 sy-vline
WA_PS3375_STR-EERE02 sy-vline
WA_PS3375_STR-CANA03 sy-vline
WA_PS3375_STR-BEGD03 sy-vline
WA_PS3375_STR-BEGT03 sy-vline
WA_PS3375_STR-ENDD03 sy-vline
WA_PS3375_STR-ENDT03 sy-vline
WA_PS3375_STR-EERE03 sy-vline
WA_PS3375_STR-CANA04 sy-vline
WA_PS3375_STR-BEGD04 sy-vline
WA_PS3375_STR-BEGT04 sy-vline
WA_PS3375_STR-ENDD04 sy-vline
WA_PS3375_STR-ENDT04 sy-vline
WA_PS3375_STR-EERE04 sy-vline
WA_PS3375_STR-CANA05 sy-vline
WA_PS3375_STR-BEGD05 sy-vline
WA_PS3375_STR-BEGT05 sy-vline
WA_PS3375_STR-ENDD05 sy-vline
WA_PS3375_STR-ENDT05 sy-vline
WA_PS3375_STR-EERE05 sy-vline
WA_PS3375_STR-CANA06 sy-vline
WA_PS3375_STR-BEGD06 sy-vline
WA_PS3375_STR-BEGT06 sy-vline
WA_PS3375_STR-ENDD06 sy-vline
WA_PS3375_STR-ENDT06 sy-vline
WA_PS3375_STR-EERE06 sy-vline
WA_PS3375_STR-CANA07 sy-vline
WA_PS3375_STR-BEGD07 sy-vline
WA_PS3375_STR-BEGT07 sy-vline
WA_PS3375_STR-ENDD07 sy-vline
WA_PS3375_STR-ENDT07 sy-vline
WA_PS3375_STR-EERE07 sy-vline
WA_PS3375_STR-CANA08 sy-vline
WA_PS3375_STR-BEGD08 sy-vline
WA_PS3375_STR-BEGT08 sy-vline
WA_PS3375_STR-ENDD08 sy-vline
WA_PS3375_STR-ENDT08 sy-vline
WA_PS3375_STR-EERE08 sy-vline
WA_PS3375_STR-CANA09 sy-vline
WA_PS3375_STR-BEGD09 sy-vline
WA_PS3375_STR-BEGT09 sy-vline
WA_PS3375_STR-ENDD09 sy-vline
WA_PS3375_STR-ENDT09 sy-vline
WA_PS3375_STR-EERE09 sy-vline
WA_PS3375_STR-CANA10 sy-vline
WA_PS3375_STR-BEGD10 sy-vline
WA_PS3375_STR-BEGT10 sy-vline
WA_PS3375_STR-ENDD10 sy-vline
WA_PS3375_STR-ENDT10 sy-vline
WA_PS3375_STR-EERE10 sy-vline
WA_PS3375_STR-SUBDT sy-vline
WA_PS3375_STR-SUBID sy-vline
WA_PS3375_STR-SUBST sy-vline
WA_PS3375_STR-VERST sy-vline
WA_PS3375_STR-APPST sy-vline
WA_PS3375_STR-ASSNO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.