ABAP Select data from SAP table E1PLL40 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 E1PLL40 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 E1PLL40. 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 E1PLL40 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_E1PLL40 TYPE STANDARD TABLE OF E1PLL40,
      WA_E1PLL40 TYPE E1PLL40,
      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: <E1PLL40> TYPE E1PLL40.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM E1PLL40
*  INTO TABLE @DATA(IT_E1PLL402).
*--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_E1PLL40 INDEX 1 INTO DATA(WA_E1PLL402).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_E1PLL40 ASSIGNING <E1PLL40>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<E1PLL40>-MSGFN = 1.
<E1PLL40>-PERNR = 1.
<E1PLL40>-GRUNR = 1.
<E1PLL40>-PABRJ = 1.
<E1PLL40>-PABRP = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_E1PLL40-STATU, sy-vline,
WA_E1PLL40-BUDAT, sy-vline,
WA_E1PLL40-RUCKR, sy-vline,
WA_E1PLL40-RUCKZ, sy-vline,
WA_E1PLL40-LSTYP, sy-vline,
WA_E1PLL40-SUBTY, sy-vline.
ENDLOOP. *Add any further fields from structure WA_E1PLL40 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_E1PLL40 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_E1PLL40 INTO WA_E1PLL40. *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_E1PLL40_STR,
MSGFN TYPE STRING,
PERNR TYPE STRING,
GRUNR TYPE STRING,
PABRJ TYPE STRING,
PABRP TYPE STRING,
STATU TYPE STRING,
BUDAT TYPE STRING,
RUCKR TYPE STRING,
RUCKZ TYPE STRING,
LSTYP TYPE STRING,
SUBTY TYPE STRING,
RUECK TYPE STRING,
RMZHL TYPE STRING,
AUFNR TYPE STRING,
FOLGE TYPE STRING,
VORNR TYPE STRING,
UVORN TYPE STRING,
LOARR TYPE STRING,
SBUKR TYPE STRING,
SWERK TYPE STRING,
SGSBR TYPE STRING,
SKOST TYPE STRING,
EBUKR TYPE STRING,
EWERK TYPE STRING,
EGSBR TYPE STRING,
EKOST TYPE STRING,
EKKRS TYPE STRING,
MEINH TYPE STRING,
LMNGR TYPE STRING,
XMNGR TYPE STRING,
GRUND TYPE STRING,
BMSCH TYPE STRING,
BEG01 TYPE STRING,
END01 TYPE STRING,
VGW01 TYPE STRING,
VGE01 TYPE STRING,
RUW01 TYPE STRING,
RUE01 TYPE STRING,
SOW01 TYPE STRING,
SOE01 TYPE STRING,
BEG02 TYPE STRING,
END02 TYPE STRING,
VGW02 TYPE STRING,
VGE02 TYPE STRING,
RUW02 TYPE STRING,
RUE02 TYPE STRING,
SOW02 TYPE STRING,
SOE02 TYPE STRING,
BEG03 TYPE STRING,
END03 TYPE STRING,
VGW03 TYPE STRING,
VGE03 TYPE STRING,
RUW03 TYPE STRING,
RUE03 TYPE STRING,
SOW03 TYPE STRING,
SOE03 TYPE STRING,
BEG04 TYPE STRING,
END04 TYPE STRING,
VGW04 TYPE STRING,
VGE04 TYPE STRING,
RUW04 TYPE STRING,
RUE04 TYPE STRING,
SOW04 TYPE STRING,
SOE04 TYPE STRING,
BEG05 TYPE STRING,
END05 TYPE STRING,
VGW05 TYPE STRING,
VGE05 TYPE STRING,
RUW05 TYPE STRING,
RUE05 TYPE STRING,
SOW05 TYPE STRING,
SOE05 TYPE STRING,
BEG06 TYPE STRING,
END06 TYPE STRING,
VGW06 TYPE STRING,
VGE06 TYPE STRING,
RUW06 TYPE STRING,
RUE06 TYPE STRING,
SOW06 TYPE STRING,
SOE06 TYPE STRING,
SPERR TYPE STRING,
USER1 TYPE STRING,
USER2 TYPE STRING,
LOGRR TYPE STRING,
TRFST TYPE STRING,
PRFOR TYPE STRING,END OF T_EKKO_STR. DATA: WA_E1PLL40_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_E1PLL40_STR-MSGFN sy-vline
WA_E1PLL40_STR-PERNR sy-vline
WA_E1PLL40_STR-GRUNR sy-vline
WA_E1PLL40_STR-PABRJ sy-vline
WA_E1PLL40_STR-PABRP sy-vline
WA_E1PLL40_STR-STATU sy-vline
WA_E1PLL40_STR-BUDAT sy-vline
WA_E1PLL40_STR-RUCKR sy-vline
WA_E1PLL40_STR-RUCKZ sy-vline
WA_E1PLL40_STR-LSTYP sy-vline
WA_E1PLL40_STR-SUBTY sy-vline
WA_E1PLL40_STR-RUECK sy-vline
WA_E1PLL40_STR-RMZHL sy-vline
WA_E1PLL40_STR-AUFNR sy-vline
WA_E1PLL40_STR-FOLGE sy-vline
WA_E1PLL40_STR-VORNR sy-vline
WA_E1PLL40_STR-UVORN sy-vline
WA_E1PLL40_STR-LOARR sy-vline
WA_E1PLL40_STR-SBUKR sy-vline
WA_E1PLL40_STR-SWERK sy-vline
WA_E1PLL40_STR-SGSBR sy-vline
WA_E1PLL40_STR-SKOST sy-vline
WA_E1PLL40_STR-EBUKR sy-vline
WA_E1PLL40_STR-EWERK sy-vline
WA_E1PLL40_STR-EGSBR sy-vline
WA_E1PLL40_STR-EKOST sy-vline
WA_E1PLL40_STR-EKKRS sy-vline
WA_E1PLL40_STR-MEINH sy-vline
WA_E1PLL40_STR-LMNGR sy-vline
WA_E1PLL40_STR-XMNGR sy-vline
WA_E1PLL40_STR-GRUND sy-vline
WA_E1PLL40_STR-BMSCH sy-vline
WA_E1PLL40_STR-BEG01 sy-vline
WA_E1PLL40_STR-END01 sy-vline
WA_E1PLL40_STR-VGW01 sy-vline
WA_E1PLL40_STR-VGE01 sy-vline
WA_E1PLL40_STR-RUW01 sy-vline
WA_E1PLL40_STR-RUE01 sy-vline
WA_E1PLL40_STR-SOW01 sy-vline
WA_E1PLL40_STR-SOE01 sy-vline
WA_E1PLL40_STR-BEG02 sy-vline
WA_E1PLL40_STR-END02 sy-vline
WA_E1PLL40_STR-VGW02 sy-vline
WA_E1PLL40_STR-VGE02 sy-vline
WA_E1PLL40_STR-RUW02 sy-vline
WA_E1PLL40_STR-RUE02 sy-vline
WA_E1PLL40_STR-SOW02 sy-vline
WA_E1PLL40_STR-SOE02 sy-vline
WA_E1PLL40_STR-BEG03 sy-vline
WA_E1PLL40_STR-END03 sy-vline
WA_E1PLL40_STR-VGW03 sy-vline
WA_E1PLL40_STR-VGE03 sy-vline
WA_E1PLL40_STR-RUW03 sy-vline
WA_E1PLL40_STR-RUE03 sy-vline
WA_E1PLL40_STR-SOW03 sy-vline
WA_E1PLL40_STR-SOE03 sy-vline
WA_E1PLL40_STR-BEG04 sy-vline
WA_E1PLL40_STR-END04 sy-vline
WA_E1PLL40_STR-VGW04 sy-vline
WA_E1PLL40_STR-VGE04 sy-vline
WA_E1PLL40_STR-RUW04 sy-vline
WA_E1PLL40_STR-RUE04 sy-vline
WA_E1PLL40_STR-SOW04 sy-vline
WA_E1PLL40_STR-SOE04 sy-vline
WA_E1PLL40_STR-BEG05 sy-vline
WA_E1PLL40_STR-END05 sy-vline
WA_E1PLL40_STR-VGW05 sy-vline
WA_E1PLL40_STR-VGE05 sy-vline
WA_E1PLL40_STR-RUW05 sy-vline
WA_E1PLL40_STR-RUE05 sy-vline
WA_E1PLL40_STR-SOW05 sy-vline
WA_E1PLL40_STR-SOE05 sy-vline
WA_E1PLL40_STR-BEG06 sy-vline
WA_E1PLL40_STR-END06 sy-vline
WA_E1PLL40_STR-VGW06 sy-vline
WA_E1PLL40_STR-VGE06 sy-vline
WA_E1PLL40_STR-RUW06 sy-vline
WA_E1PLL40_STR-RUE06 sy-vline
WA_E1PLL40_STR-SOW06 sy-vline
WA_E1PLL40_STR-SOE06 sy-vline
WA_E1PLL40_STR-SPERR sy-vline
WA_E1PLL40_STR-USER1 sy-vline
WA_E1PLL40_STR-USER2 sy-vline
WA_E1PLL40_STR-LOGRR sy-vline
WA_E1PLL40_STR-TRFST sy-vline
WA_E1PLL40_STR-PRFOR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.