ABAP Select data from SAP table PSG_RPCTGMLR0_DTAB 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 PSG_RPCTGMLR0_DTAB 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 PSG_RPCTGMLR0_DTAB. 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 PSG_RPCTGMLR0_DTAB 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_PSG_RPCTGMLR0_DTAB TYPE STANDARD TABLE OF PSG_RPCTGMLR0_DTAB,
      WA_PSG_RPCTGMLR0_DTAB TYPE PSG_RPCTGMLR0_DTAB,
      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: <PSG_RPCTGMLR0_DTAB> TYPE PSG_RPCTGMLR0_DTAB.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PSG_RPCTGMLR0_DTAB
*  INTO TABLE @DATA(IT_PSG_RPCTGMLR0_DTAB2).
*--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_PSG_RPCTGMLR0_DTAB INDEX 1 INTO DATA(WA_PSG_RPCTGMLR0_DTAB2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PSG_RPCTGMLR0_DTAB ASSIGNING <PSG_RPCTGMLR0_DTAB>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PSG_RPCTGMLR0_DTAB>-CPF_REFNO = 1.
<PSG_RPCTGMLR0_DTAB>-OFF_TEL = 1.
<PSG_RPCTGMLR0_DTAB>-EMAIL = 1.
<PSG_RPCTGMLR0_DTAB>-FAX_NO = 1.
<PSG_RPCTGMLR0_DTAB>-BANK_NAME = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PSG_RPCTGMLR0_DTAB-BANK_PART, sy-vline,
WA_PSG_RPCTGMLR0_DTAB-FOR_COMP_ADD, sy-vline,
WA_PSG_RPCTGMLR0_DTAB-NAME, sy-vline,
WA_PSG_RPCTGMLR0_DTAB-NRIC_NO, sy-vline,
WA_PSG_RPCTGMLR0_DTAB-HOME_TEL, sy-vline,
WA_PSG_RPCTGMLR0_DTAB-HP_NO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PSG_RPCTGMLR0_DTAB 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_PSG_RPCTGMLR0_DTAB 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_PSG_RPCTGMLR0_DTAB INTO WA_PSG_RPCTGMLR0_DTAB. *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 SXIDN, internal->external for field EMAIL CALL FUNCTION 'CONVERSION_EXIT_SXIDN_OUTPUT' EXPORTING input = WA_PSG_RPCTGMLR0_DTAB-EMAIL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PSG_RPCTGMLR0_DTAB-EMAIL.
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_PSG_RPCTGMLR0_DTAB_STR,
CPF_REFNO TYPE STRING,
OFF_TEL TYPE STRING,
EMAIL TYPE STRING,
FAX_NO TYPE STRING,
BANK_NAME TYPE STRING,
BANK_PART TYPE STRING,
FOR_COMP_ADD TYPE STRING,
NAME TYPE STRING,
NRIC_NO TYPE STRING,
HOME_TEL TYPE STRING,
HP_NO TYPE STRING,
DESIG TYPE STRING,
ST_DAT_EMP TYPE STRING,
HUSBAND_NAME TYPE STRING,
HUSBAND_NRIC_NO TYPE STRING,
CITIZEN_SG TYPE STRING,
NON_CITIZEN_SG TYPE STRING,
HUS_CITIZEN_SG TYPE STRING,
HUS_NON_CITIZEN_SG TYPE STRING,
GROSS_SAL TYPE STRING,
GPML_ALLOWANCE TYPE STRING,
NON_GPML_ALLOWANCE TYPE STRING,
ECPF TYPE STRING,
SERIAL_NO TYPE STRING,
CLD_BDATE TYPE STRING,
CLD_BCERT_NO TYPE STRING,
HOSPITAL_NAME TYPE STRING,
CUT_LINES TYPE STRING,
CUT_LINES1 TYPE STRING,
CUT_LINES2 TYPE STRING,
TOT_WDAYS TYPE STRING,
WDAYS TYPE STRING,
ML_BEGDA1 TYPE STRING,
ML_BEGDA2 TYPE STRING,
ML_BEGDA3 TYPE STRING,
ML_BEGDA4 TYPE STRING,
ML_BEGDA5 TYPE STRING,
ML_BEGDA6 TYPE STRING,
ML_BEGDA7 TYPE STRING,
ML_BEGDA8 TYPE STRING,
ML_ENDDA1 TYPE STRING,
ML_ENDDA2 TYPE STRING,
ML_ENDDA3 TYPE STRING,
ML_ENDDA4 TYPE STRING,
ML_ENDDA5 TYPE STRING,
ML_ENDDA6 TYPE STRING,
ML_ENDDA7 TYPE STRING,
ML_ENDDA8 TYPE STRING,
CONT TYPE STRING,
NON_CONT TYPE STRING,
CONF_NO TYPE STRING,
SUPERSCRIPT2 TYPE STRING,
CHILD_NO TYPE STRING,
SUPERSCRIPT TYPE STRING,
ER_NAME TYPE STRING,
ER_NRIC TYPE STRING,
SIGN TYPE STRING,
DATE TYPE STRING,
BEGDA TYPE STRING,
ENDDA TYPE STRING,END OF T_EKKO_STR. DATA: WA_PSG_RPCTGMLR0_DTAB_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_PSG_RPCTGMLR0_DTAB_STR-CPF_REFNO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-OFF_TEL sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-EMAIL sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-FAX_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-BANK_NAME sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-BANK_PART sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-FOR_COMP_ADD sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-NAME sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-NRIC_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HOME_TEL sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HP_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-DESIG sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ST_DAT_EMP sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HUSBAND_NAME sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HUSBAND_NRIC_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CITIZEN_SG sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-NON_CITIZEN_SG sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HUS_CITIZEN_SG sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HUS_NON_CITIZEN_SG sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-GROSS_SAL sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-GPML_ALLOWANCE sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-NON_GPML_ALLOWANCE sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ECPF sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-SERIAL_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CLD_BDATE sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CLD_BCERT_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-HOSPITAL_NAME sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CUT_LINES sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CUT_LINES1 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CUT_LINES2 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-TOT_WDAYS sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-WDAYS sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA1 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA2 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA3 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA4 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA5 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA6 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA7 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_BEGDA8 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA1 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA2 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA3 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA4 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA5 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA6 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA7 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ML_ENDDA8 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CONT sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-NON_CONT sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CONF_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-SUPERSCRIPT2 sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-CHILD_NO sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-SUPERSCRIPT sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ER_NAME sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ER_NRIC sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-SIGN sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-DATE sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-BEGDA sy-vline
WA_PSG_RPCTGMLR0_DTAB_STR-ENDDA sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.