ABAP Select data from SAP table PMY_RPCT2AL0 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 PMY_RPCT2AL0 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 PMY_RPCT2AL0. 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 PMY_RPCT2AL0 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_PMY_RPCT2AL0 TYPE STANDARD TABLE OF PMY_RPCT2AL0,
      WA_PMY_RPCT2AL0 TYPE PMY_RPCT2AL0,
      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: <PMY_RPCT2AL0> TYPE PMY_RPCT2AL0.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PMY_RPCT2AL0
*  INTO TABLE @DATA(IT_PMY_RPCT2AL02).
*--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_PMY_RPCT2AL0 INDEX 1 INTO DATA(WA_PMY_RPCT2AL02).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PMY_RPCT2AL0 ASSIGNING <PMY_RPCT2AL0>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PMY_RPCT2AL0>-PERNR = 1.
<PMY_RPCT2AL0>-ER_NAME = 1.
<PMY_RPCT2AL0>-ER_ADD1 = 1.
<PMY_RPCT2AL0>-ER_ADD2 = 1.
<PMY_RPCT2AL0>-ER_ADD3 = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PMY_RPCT2AL0-ER_ADD4, sy-vline,
WA_PMY_RPCT2AL0-TNOER, sy-vline,
WA_PMY_RPCT2AL0-ER_TELEL, sy-vline,
WA_PMY_RPCT2AL0-EE_NAME1, sy-vline,
WA_PMY_RPCT2AL0-EE_NAME2, sy-vline,
WA_PMY_RPCT2AL0-HIRE_DAT_DD, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PMY_RPCT2AL0 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_PMY_RPCT2AL0 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_PMY_RPCT2AL0 INTO WA_PMY_RPCT2AL0. *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_PMY_RPCT2AL0_STR,
PERNR TYPE STRING,
ER_NAME TYPE STRING,
ER_ADD1 TYPE STRING,
ER_ADD2 TYPE STRING,
ER_ADD3 TYPE STRING,
ER_ADD4 TYPE STRING,
TNOER TYPE STRING,
ER_TELEL TYPE STRING,
EE_NAME1 TYPE STRING,
EE_NAME2 TYPE STRING,
HIRE_DAT_DD TYPE STRING,
HIRE_DAT_MM TYPE STRING,
HIRE_DAT_YY TYPE STRING,
COM_DAT_DD TYPE STRING,
COM_DAT_MM TYPE STRING,
COM_DAT_YY TYPE STRING,
DOB_DD TYPE STRING,
DOB_MM TYPE STRING,
DOB_YY TYPE STRING,
PENS_TYPE_M TYPE STRING,
PENS_TYPE_V TYPE STRING,
ICNUM TYPE STRING,
TNOEE_PRE TYPE STRING,
TNOEE_POS TYPE STRING,
MARST TYPE STRING,
CHILD_NO TYPE STRING,
CHILD_AMT TYPE STRING,
SPO_NAME1 TYPE STRING,
SPO_NAME2 TYPE STRING,
SPO_IC_NO TYPE STRING,
SPO_IT_PRE TYPE STRING,
SPO_IT_POS TYPE STRING,
E_TELEL TYPE STRING,
EE_ADD1 TYPE STRING,
EE_ADD2 TYPE STRING,
EE_ADD3 TYPE STRING,
EE_ADD4 TYPE STRING,
EE_ADD5 TYPE STRING,
AGENT_FLAG TYPE STRING,
B_NAM TYPE STRING,
B_ICNUM TYPE STRING,
B_ADD1 TYPE STRING,
B_ADD2 TYPE STRING,
B_ADD3 TYPE STRING,
B_ADD4 TYPE STRING,
B_ADD5 TYPE STRING,
B_TELEL TYPE STRING,
BEGDA1 TYPE STRING,
ENDDA1 TYPE STRING,
W10 TYPE STRING,
BEGDA2 TYPE STRING,
ENDDA2 TYPE STRING,
W11 TYPE STRING,
BEGDA3 TYPE STRING,
ENDDA3 TYPE STRING,
W12 TYPE STRING,
BEGDA4 TYPE STRING,
ENDDA4 TYPE STRING,
W13 TYPE STRING,
BEGDA5 TYPE STRING,
ENDDA5 TYPE STRING,
W14 TYPE STRING,
BEGDA6 TYPE STRING,
ENDDA6 TYPE STRING,
W15 TYPE STRING,
BEGDA7 TYPE STRING,
ENDDA7 TYPE STRING,
W16 TYPE STRING,
BEGDA8 TYPE STRING,
ENDDA8 TYPE STRING,
W19 TYPE STRING,
BEGDA9 TYPE STRING,
ENDDA9 TYPE STRING,
W17 TYPE STRING,
BEGDA10 TYPE STRING,
ENDDA10 TYPE STRING,
WAK TYPE STRING,
BEGDA11 TYPE STRING,
ENDDA11 TYPE STRING,
W30 TYPE STRING,
BEGDA12 TYPE STRING,
ENDDA12 TYPE STRING,
W25 TYPE STRING,
STOCK_NUM TYPE STRING,
STOCK_BAL TYPE STRING,
GIVE_DD TYPE STRING,
GIVE_MM TYPE STRING,
GIVE_YY TYPE STRING,
EXE_DD TYPE STRING,
EXE_MM TYPE STRING,
EXE_YY TYPE STRING,
STOCK_DD TYPE STRING,
STOCK_MM TYPE STRING,
STOCK_YY TYPE STRING,
BEN_AMT TYPE STRING,
TABLE_C TYPE STRING,
TOTAL_AMT TYPE STRING,
WSW TYPE STRING,
WTD TYPE STRING,
WZT TYPE STRING,
WE0 TYPE STRING,
USER_NAME TYPE STRING,
USER_POS TYPE STRING,
RUN_DD TYPE STRING,
RUN_MM TYPE STRING,
RUN_YY TYPE STRING,END OF T_EKKO_STR. DATA: WA_PMY_RPCT2AL0_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_PMY_RPCT2AL0_STR-PERNR sy-vline
WA_PMY_RPCT2AL0_STR-ER_NAME sy-vline
WA_PMY_RPCT2AL0_STR-ER_ADD1 sy-vline
WA_PMY_RPCT2AL0_STR-ER_ADD2 sy-vline
WA_PMY_RPCT2AL0_STR-ER_ADD3 sy-vline
WA_PMY_RPCT2AL0_STR-ER_ADD4 sy-vline
WA_PMY_RPCT2AL0_STR-TNOER sy-vline
WA_PMY_RPCT2AL0_STR-ER_TELEL sy-vline
WA_PMY_RPCT2AL0_STR-EE_NAME1 sy-vline
WA_PMY_RPCT2AL0_STR-EE_NAME2 sy-vline
WA_PMY_RPCT2AL0_STR-HIRE_DAT_DD sy-vline
WA_PMY_RPCT2AL0_STR-HIRE_DAT_MM sy-vline
WA_PMY_RPCT2AL0_STR-HIRE_DAT_YY sy-vline
WA_PMY_RPCT2AL0_STR-COM_DAT_DD sy-vline
WA_PMY_RPCT2AL0_STR-COM_DAT_MM sy-vline
WA_PMY_RPCT2AL0_STR-COM_DAT_YY sy-vline
WA_PMY_RPCT2AL0_STR-DOB_DD sy-vline
WA_PMY_RPCT2AL0_STR-DOB_MM sy-vline
WA_PMY_RPCT2AL0_STR-DOB_YY sy-vline
WA_PMY_RPCT2AL0_STR-PENS_TYPE_M sy-vline
WA_PMY_RPCT2AL0_STR-PENS_TYPE_V sy-vline
WA_PMY_RPCT2AL0_STR-ICNUM sy-vline
WA_PMY_RPCT2AL0_STR-TNOEE_PRE sy-vline
WA_PMY_RPCT2AL0_STR-TNOEE_POS sy-vline
WA_PMY_RPCT2AL0_STR-MARST sy-vline
WA_PMY_RPCT2AL0_STR-CHILD_NO sy-vline
WA_PMY_RPCT2AL0_STR-CHILD_AMT sy-vline
WA_PMY_RPCT2AL0_STR-SPO_NAME1 sy-vline
WA_PMY_RPCT2AL0_STR-SPO_NAME2 sy-vline
WA_PMY_RPCT2AL0_STR-SPO_IC_NO sy-vline
WA_PMY_RPCT2AL0_STR-SPO_IT_PRE sy-vline
WA_PMY_RPCT2AL0_STR-SPO_IT_POS sy-vline
WA_PMY_RPCT2AL0_STR-E_TELEL sy-vline
WA_PMY_RPCT2AL0_STR-EE_ADD1 sy-vline
WA_PMY_RPCT2AL0_STR-EE_ADD2 sy-vline
WA_PMY_RPCT2AL0_STR-EE_ADD3 sy-vline
WA_PMY_RPCT2AL0_STR-EE_ADD4 sy-vline
WA_PMY_RPCT2AL0_STR-EE_ADD5 sy-vline
WA_PMY_RPCT2AL0_STR-AGENT_FLAG sy-vline
WA_PMY_RPCT2AL0_STR-B_NAM sy-vline
WA_PMY_RPCT2AL0_STR-B_ICNUM sy-vline
WA_PMY_RPCT2AL0_STR-B_ADD1 sy-vline
WA_PMY_RPCT2AL0_STR-B_ADD2 sy-vline
WA_PMY_RPCT2AL0_STR-B_ADD3 sy-vline
WA_PMY_RPCT2AL0_STR-B_ADD4 sy-vline
WA_PMY_RPCT2AL0_STR-B_ADD5 sy-vline
WA_PMY_RPCT2AL0_STR-B_TELEL sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA1 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA1 sy-vline
WA_PMY_RPCT2AL0_STR-W10 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA2 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA2 sy-vline
WA_PMY_RPCT2AL0_STR-W11 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA3 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA3 sy-vline
WA_PMY_RPCT2AL0_STR-W12 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA4 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA4 sy-vline
WA_PMY_RPCT2AL0_STR-W13 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA5 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA5 sy-vline
WA_PMY_RPCT2AL0_STR-W14 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA6 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA6 sy-vline
WA_PMY_RPCT2AL0_STR-W15 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA7 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA7 sy-vline
WA_PMY_RPCT2AL0_STR-W16 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA8 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA8 sy-vline
WA_PMY_RPCT2AL0_STR-W19 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA9 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA9 sy-vline
WA_PMY_RPCT2AL0_STR-W17 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA10 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA10 sy-vline
WA_PMY_RPCT2AL0_STR-WAK sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA11 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA11 sy-vline
WA_PMY_RPCT2AL0_STR-W30 sy-vline
WA_PMY_RPCT2AL0_STR-BEGDA12 sy-vline
WA_PMY_RPCT2AL0_STR-ENDDA12 sy-vline
WA_PMY_RPCT2AL0_STR-W25 sy-vline
WA_PMY_RPCT2AL0_STR-STOCK_NUM sy-vline
WA_PMY_RPCT2AL0_STR-STOCK_BAL sy-vline
WA_PMY_RPCT2AL0_STR-GIVE_DD sy-vline
WA_PMY_RPCT2AL0_STR-GIVE_MM sy-vline
WA_PMY_RPCT2AL0_STR-GIVE_YY sy-vline
WA_PMY_RPCT2AL0_STR-EXE_DD sy-vline
WA_PMY_RPCT2AL0_STR-EXE_MM sy-vline
WA_PMY_RPCT2AL0_STR-EXE_YY sy-vline
WA_PMY_RPCT2AL0_STR-STOCK_DD sy-vline
WA_PMY_RPCT2AL0_STR-STOCK_MM sy-vline
WA_PMY_RPCT2AL0_STR-STOCK_YY sy-vline
WA_PMY_RPCT2AL0_STR-BEN_AMT sy-vline
WA_PMY_RPCT2AL0_STR-TABLE_C sy-vline
WA_PMY_RPCT2AL0_STR-TOTAL_AMT sy-vline
WA_PMY_RPCT2AL0_STR-WSW sy-vline
WA_PMY_RPCT2AL0_STR-WTD sy-vline
WA_PMY_RPCT2AL0_STR-WZT sy-vline
WA_PMY_RPCT2AL0_STR-WE0 sy-vline
WA_PMY_RPCT2AL0_STR-USER_NAME sy-vline
WA_PMY_RPCT2AL0_STR-USER_POS sy-vline
WA_PMY_RPCT2AL0_STR-RUN_DD sy-vline
WA_PMY_RPCT2AL0_STR-RUN_MM sy-vline
WA_PMY_RPCT2AL0_STR-RUN_YY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.