ABAP Select data from SAP table RDGCHKM 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 RDGCHKM 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 RDGCHKM. 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 RDGCHKM 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_RDGCHKM TYPE STANDARD TABLE OF RDGCHKM,
      WA_RDGCHKM TYPE RDGCHKM,
      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: <RDGCHKM> TYPE RDGCHKM.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM RDGCHKM
*  INTO TABLE @DATA(IT_RDGCHKM2).
*--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_RDGCHKM INDEX 1 INTO DATA(WA_RDGCHKM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_RDGCHKM ASSIGNING <RDGCHKM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<RDGCHKM>-TSNUM = 1.
<RDGCHKM>-TSTYP = 1.
<RDGCHKM>-TSRFO = 1.
<RDGCHKM>-LAUFK = 1.
<RDGCHKM>-DGCHKS = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_RDGCHKM-DGCHKM, sy-vline,
WA_RDGCHKM-DGCKORD, sy-vline,
WA_RDGCHKM-DGMOT, sy-vline,
WA_RDGCHKM-RVLID, sy-vline,
WA_RDGCHKM-DGCTRY, sy-vline,
WA_RDGCHKM-DGREGIO, sy-vline.
ENDLOOP. *Add any further fields from structure WA_RDGCHKM 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_RDGCHKM 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_RDGCHKM INTO WA_RDGCHKM. *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_RDGCHKM_STR,
TSNUM TYPE STRING,
TSTYP TYPE STRING,
TSRFO TYPE STRING,
LAUFK TYPE STRING,
DGCHKS TYPE STRING,
DGCHKM TYPE STRING,
DGCKORD TYPE STRING,
DGMOT TYPE STRING,
RVLID TYPE STRING,
DGCTRY TYPE STRING,
DGREGIO TYPE STRING,
DGCTRYR TYPE STRING,
DGREACT TYPE STRING,
DGMSGID TYPE STRING,
DGMSGNR TYPE STRING,
MSGV1 TYPE STRING,
MSGV2 TYPE STRING,
MSGV3 TYPE STRING,
MSGV4 TYPE STRING,
DGDNSTS TYPE STRING,
DGSBAT TYPE STRING,
DGSDIA TYPE STRING,
DGCHKF TYPE STRING,
DGCHKMD TYPE STRING,
DGMOTD TYPE STRING,
DGFTDAT TYPE STRING,
DGCKMCAT TYPE STRING,END OF T_EKKO_STR. DATA: WA_RDGCHKM_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_RDGCHKM_STR-TSNUM sy-vline
WA_RDGCHKM_STR-TSTYP sy-vline
WA_RDGCHKM_STR-TSRFO sy-vline
WA_RDGCHKM_STR-LAUFK sy-vline
WA_RDGCHKM_STR-DGCHKS sy-vline
WA_RDGCHKM_STR-DGCHKM sy-vline
WA_RDGCHKM_STR-DGCKORD sy-vline
WA_RDGCHKM_STR-DGMOT sy-vline
WA_RDGCHKM_STR-RVLID sy-vline
WA_RDGCHKM_STR-DGCTRY sy-vline
WA_RDGCHKM_STR-DGREGIO sy-vline
WA_RDGCHKM_STR-DGCTRYR sy-vline
WA_RDGCHKM_STR-DGREACT sy-vline
WA_RDGCHKM_STR-DGMSGID sy-vline
WA_RDGCHKM_STR-DGMSGNR sy-vline
WA_RDGCHKM_STR-MSGV1 sy-vline
WA_RDGCHKM_STR-MSGV2 sy-vline
WA_RDGCHKM_STR-MSGV3 sy-vline
WA_RDGCHKM_STR-MSGV4 sy-vline
WA_RDGCHKM_STR-DGDNSTS sy-vline
WA_RDGCHKM_STR-DGSBAT sy-vline
WA_RDGCHKM_STR-DGSDIA sy-vline
WA_RDGCHKM_STR-DGCHKF sy-vline
WA_RDGCHKM_STR-DGCHKMD sy-vline
WA_RDGCHKM_STR-DGMOTD sy-vline
WA_RDGCHKM_STR-DGFTDAT sy-vline
WA_RDGCHKM_STR-DGCKMCAT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.