ABAP Select data from SAP table DNOD_NOTIF_S 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 DNOD_NOTIF_S 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 DNOD_NOTIF_S. 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 DNOD_NOTIF_S 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_DNOD_NOTIF_S TYPE STANDARD TABLE OF DNOD_NOTIF_S,
      WA_DNOD_NOTIF_S TYPE DNOD_NOTIF_S,
      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: <DNOD_NOTIF_S> TYPE DNOD_NOTIF_S.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM DNOD_NOTIF_S
*  INTO TABLE @DATA(IT_DNOD_NOTIF_S2).
*--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_DNOD_NOTIF_S INDEX 1 INTO DATA(WA_DNOD_NOTIF_S2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_DNOD_NOTIF_S ASSIGNING <DNOD_NOTIF_S>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<DNOD_NOTIF_S>-CLIENT = 1.
<DNOD_NOTIF_S>-GUIDS = 1.
<DNOD_NOTIF_S>-GUIDH = 1.
<DNOD_NOTIF_S>-DELETED = 1.
<DNOD_NOTIF_S>-INSTN = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_DNOD_NOTIF_S-MNUMM, sy-vline,
WA_DNOD_NOTIF_S-MSTAT, sy-vline,
WA_DNOD_NOTIF_S-COMP, sy-vline,
WA_DNOD_NOTIF_S-OSSYS, sy-vline,
WA_DNOD_NOTIF_S-DBSYS, sy-vline,
WA_DNOD_NOTIF_S-FRONT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_DNOD_NOTIF_S 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_DNOD_NOTIF_S 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_DNOD_NOTIF_S INTO WA_DNOD_NOTIF_S. *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 TSTPS, internal->external for field SAP_TSTMP CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-SAP_TSTMP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-SAP_TSTMP.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field S2SAP_TSTMP CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-S2SAP_TSTMP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-S2SAP_TSTMP.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field REL_SAP_TSTMP CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-REL_SAP_TSTMP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-REL_SAP_TSTMP.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field S2SAP_FIRST CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-S2SAP_FIRST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-S2SAP_FIRST.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field S2SAP_LAST CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-S2SAP_LAST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-S2SAP_LAST.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field SFRSAP_FIRST CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-SFRSAP_FIRST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-SFRSAP_FIRST.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTPS, internal->external for field SFRSAP_LAST CALL FUNCTION 'CONVERSION_EXIT_TSTPS_OUTPUT' EXPORTING input = WA_DNOD_NOTIF_S-SFRSAP_LAST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_DNOD_NOTIF_S-SFRSAP_LAST.
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_DNOD_NOTIF_S_STR,
CLIENT TYPE STRING,
GUIDS TYPE STRING,
GUIDH TYPE STRING,
DELETED TYPE STRING,
INSTN TYPE STRING,
MNUMM TYPE STRING,
MSTAT TYPE STRING,
COMP TYPE STRING,
OSSYS TYPE STRING,
DBSYS TYPE STRING,
FRONT TYPE STRING,
SWCOMP TYPE STRING,
SWREL TYPE STRING,
SWPTCH TYPE STRING,
ADD_SWCOMP TYPE STRING,
SYSTYPE TYPE STRING,
SYSID TYPE STRING,
MANDT TYPE STRING,
SAP_TSTMP TYPE STRING,
S2SAP_TSTMP TYPE STRING,
REL_SAP_TSTMP TYPE STRING,
SOLNUMB TYPE STRING,
BUSPROCOBJ1 TYPE STRING,
BUSPROCOBJ2 TYPE STRING,
BUSPROCOBJ3 TYPE STRING,
BUSPROCOBJ4 TYPE STRING,
BUSPROCOBJ5 TYPE STRING,
SWCOMPONENT1 TYPE STRING,
SWCOMPONENT2 TYPE STRING,
SWCOMPONENT3 TYPE STRING,
SWCOMPONENT4 TYPE STRING,
SWCOMPONENT5 TYPE STRING,
PROJECTNUMB TYPE STRING,
ROLLOUTPHASE TYPE STRING,
SESSINO_SRC TYPE STRING,
SESSITYPE_SRC TYPE STRING,
SESSINO_TRG TYPE STRING,
SESSITYPE_TRG TYPE STRING,
S2SAP_FIRST TYPE STRING,
S2SAP_LAST TYPE STRING,
SFRSAP_FIRST TYPE STRING,
SFRSAP_LAST TYPE STRING,
TIME_AT_SDESK TYPE STRING,
TIME_AT_SAP TYPE STRING,
STEP1 TYPE STRING,
STEP2 TYPE STRING,
STEP3 TYPE STRING,
STEP4 TYPE STRING,
STEP5 TYPE STRING,
SYSNO TYPE STRING,END OF T_EKKO_STR. DATA: WA_DNOD_NOTIF_S_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_DNOD_NOTIF_S_STR-CLIENT sy-vline
WA_DNOD_NOTIF_S_STR-GUIDS sy-vline
WA_DNOD_NOTIF_S_STR-GUIDH sy-vline
WA_DNOD_NOTIF_S_STR-DELETED sy-vline
WA_DNOD_NOTIF_S_STR-INSTN sy-vline
WA_DNOD_NOTIF_S_STR-MNUMM sy-vline
WA_DNOD_NOTIF_S_STR-MSTAT sy-vline
WA_DNOD_NOTIF_S_STR-COMP sy-vline
WA_DNOD_NOTIF_S_STR-OSSYS sy-vline
WA_DNOD_NOTIF_S_STR-DBSYS sy-vline
WA_DNOD_NOTIF_S_STR-FRONT sy-vline
WA_DNOD_NOTIF_S_STR-SWCOMP sy-vline
WA_DNOD_NOTIF_S_STR-SWREL sy-vline
WA_DNOD_NOTIF_S_STR-SWPTCH sy-vline
WA_DNOD_NOTIF_S_STR-ADD_SWCOMP sy-vline
WA_DNOD_NOTIF_S_STR-SYSTYPE sy-vline
WA_DNOD_NOTIF_S_STR-SYSID sy-vline
WA_DNOD_NOTIF_S_STR-MANDT sy-vline
WA_DNOD_NOTIF_S_STR-SAP_TSTMP sy-vline
WA_DNOD_NOTIF_S_STR-S2SAP_TSTMP sy-vline
WA_DNOD_NOTIF_S_STR-REL_SAP_TSTMP sy-vline
WA_DNOD_NOTIF_S_STR-SOLNUMB sy-vline
WA_DNOD_NOTIF_S_STR-BUSPROCOBJ1 sy-vline
WA_DNOD_NOTIF_S_STR-BUSPROCOBJ2 sy-vline
WA_DNOD_NOTIF_S_STR-BUSPROCOBJ3 sy-vline
WA_DNOD_NOTIF_S_STR-BUSPROCOBJ4 sy-vline
WA_DNOD_NOTIF_S_STR-BUSPROCOBJ5 sy-vline
WA_DNOD_NOTIF_S_STR-SWCOMPONENT1 sy-vline
WA_DNOD_NOTIF_S_STR-SWCOMPONENT2 sy-vline
WA_DNOD_NOTIF_S_STR-SWCOMPONENT3 sy-vline
WA_DNOD_NOTIF_S_STR-SWCOMPONENT4 sy-vline
WA_DNOD_NOTIF_S_STR-SWCOMPONENT5 sy-vline
WA_DNOD_NOTIF_S_STR-PROJECTNUMB sy-vline
WA_DNOD_NOTIF_S_STR-ROLLOUTPHASE sy-vline
WA_DNOD_NOTIF_S_STR-SESSINO_SRC sy-vline
WA_DNOD_NOTIF_S_STR-SESSITYPE_SRC sy-vline
WA_DNOD_NOTIF_S_STR-SESSINO_TRG sy-vline
WA_DNOD_NOTIF_S_STR-SESSITYPE_TRG sy-vline
WA_DNOD_NOTIF_S_STR-S2SAP_FIRST sy-vline
WA_DNOD_NOTIF_S_STR-S2SAP_LAST sy-vline
WA_DNOD_NOTIF_S_STR-SFRSAP_FIRST sy-vline
WA_DNOD_NOTIF_S_STR-SFRSAP_LAST sy-vline
WA_DNOD_NOTIF_S_STR-TIME_AT_SDESK sy-vline
WA_DNOD_NOTIF_S_STR-TIME_AT_SAP sy-vline
WA_DNOD_NOTIF_S_STR-STEP1 sy-vline
WA_DNOD_NOTIF_S_STR-STEP2 sy-vline
WA_DNOD_NOTIF_S_STR-STEP3 sy-vline
WA_DNOD_NOTIF_S_STR-STEP4 sy-vline
WA_DNOD_NOTIF_S_STR-STEP5 sy-vline
WA_DNOD_NOTIF_S_STR-SYSNO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.