ABAP Select data from SAP table ICSDIAGNOSIS 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 ICSDIAGNOSIS 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 ICSDIAGNOSIS. 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 ICSDIAGNOSIS 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_ICSDIAGNOSIS TYPE STANDARD TABLE OF ICSDIAGNOSIS,
      WA_ICSDIAGNOSIS TYPE ICSDIAGNOSIS,
      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: <ICSDIAGNOSIS> TYPE ICSDIAGNOSIS.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ICSDIAGNOSIS
*  INTO TABLE @DATA(IT_ICSDIAGNOSIS2).
*--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_ICSDIAGNOSIS INDEX 1 INTO DATA(WA_ICSDIAGNOSIS2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ICSDIAGNOSIS ASSIGNING <ICSDIAGNOSIS>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ICSDIAGNOSIS>-CLIENT = 1.
<ICSDIAGNOSIS>-ACTIVE = 1.
<ICSDIAGNOSIS>-CLAIM = 1.
<ICSDIAGNOSIS>-PATIENT = 1.
<ICSDIAGNOSIS>-SUBOBJCAT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ICSDIAGNOSIS-SUBOBJECT, sy-vline,
WA_ICSDIAGNOSIS-DIAGNO, sy-vline,
WA_ICSDIAGNOSIS-CHANGETIME, sy-vline,
WA_ICSDIAGNOSIS-CHANGEDBY, sy-vline,
WA_ICSDIAGNOSIS-DELETED, sy-vline,
WA_ICSDIAGNOSIS-CATAID1, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ICSDIAGNOSIS 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_ICSDIAGNOSIS 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_ICSDIAGNOSIS INTO WA_ICSDIAGNOSIS. *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 ALPHA, internal->external for field CLAIM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_ICSDIAGNOSIS-CLAIM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICSDIAGNOSIS-CLAIM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit TSTAM, internal->external for field CHANGETIME CALL FUNCTION 'CONVERSION_EXIT_TSTAM_OUTPUT' EXPORTING input = WA_ICSDIAGNOSIS-CHANGETIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICSDIAGNOSIS-CHANGETIME.
WRITE:/ 'New Value:', ld_input.

*Conversion exit DIAID, internal->external for field DIAGID1 CALL FUNCTION 'CONVERSION_EXIT_DIAID_OUTPUT' EXPORTING input = WA_ICSDIAGNOSIS-DIAGID1 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICSDIAGNOSIS-DIAGID1.
WRITE:/ 'New Value:', ld_input.

*Conversion exit DIAID, internal->external for field DIAGID2 CALL FUNCTION 'CONVERSION_EXIT_DIAID_OUTPUT' EXPORTING input = WA_ICSDIAGNOSIS-DIAGID2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICSDIAGNOSIS-DIAGID2.
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_ICSDIAGNOSIS_STR,
CLIENT TYPE STRING,
ACTIVE TYPE STRING,
CLAIM TYPE STRING,
PATIENT TYPE STRING,
SUBOBJCAT TYPE STRING,
SUBOBJECT TYPE STRING,
DIAGNO TYPE STRING,
CHANGETIME TYPE STRING,
CHANGEDBY TYPE STRING,
DELETED TYPE STRING,
CATAID1 TYPE STRING,
DIAGID1 TYPE STRING,
CATAID2 TYPE STRING,
DIAGID2 TYPE STRING,
DIAGNOPARENT TYPE STRING,
DESCRIPTION TYPE STRING,
ENDDATE TYPE STRING,
DIAGSRCCAT TYPE STRING,
DIAGSRCID TYPE STRING,
DIAGTYPE TYPE STRING,
LOCALIZATION TYPE STRING,
SEVERITYCODE TYPE STRING,
MORPHOLOGY TYPE STRING,
EXCORIATION TYPE STRING,
GUARANTEE TYPE STRING,
DEPARTMENT TYPE STRING,
DIAGORDER TYPE STRING,
LOCALIZATION2 TYPE STRING,
USED4CALC TYPE STRING,
ASSIGN_GUID TYPE STRING,
_DATAAGING TYPE STRING,END OF T_EKKO_STR. DATA: WA_ICSDIAGNOSIS_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_ICSDIAGNOSIS_STR-CLIENT sy-vline
WA_ICSDIAGNOSIS_STR-ACTIVE sy-vline
WA_ICSDIAGNOSIS_STR-CLAIM sy-vline
WA_ICSDIAGNOSIS_STR-PATIENT sy-vline
WA_ICSDIAGNOSIS_STR-SUBOBJCAT sy-vline
WA_ICSDIAGNOSIS_STR-SUBOBJECT sy-vline
WA_ICSDIAGNOSIS_STR-DIAGNO sy-vline
WA_ICSDIAGNOSIS_STR-CHANGETIME sy-vline
WA_ICSDIAGNOSIS_STR-CHANGEDBY sy-vline
WA_ICSDIAGNOSIS_STR-DELETED sy-vline
WA_ICSDIAGNOSIS_STR-CATAID1 sy-vline
WA_ICSDIAGNOSIS_STR-DIAGID1 sy-vline
WA_ICSDIAGNOSIS_STR-CATAID2 sy-vline
WA_ICSDIAGNOSIS_STR-DIAGID2 sy-vline
WA_ICSDIAGNOSIS_STR-DIAGNOPARENT sy-vline
WA_ICSDIAGNOSIS_STR-DESCRIPTION sy-vline
WA_ICSDIAGNOSIS_STR-ENDDATE sy-vline
WA_ICSDIAGNOSIS_STR-DIAGSRCCAT sy-vline
WA_ICSDIAGNOSIS_STR-DIAGSRCID sy-vline
WA_ICSDIAGNOSIS_STR-DIAGTYPE sy-vline
WA_ICSDIAGNOSIS_STR-LOCALIZATION sy-vline
WA_ICSDIAGNOSIS_STR-SEVERITYCODE sy-vline
WA_ICSDIAGNOSIS_STR-MORPHOLOGY sy-vline
WA_ICSDIAGNOSIS_STR-EXCORIATION sy-vline
WA_ICSDIAGNOSIS_STR-GUARANTEE sy-vline
WA_ICSDIAGNOSIS_STR-DEPARTMENT sy-vline
WA_ICSDIAGNOSIS_STR-DIAGORDER sy-vline
WA_ICSDIAGNOSIS_STR-LOCALIZATION2 sy-vline
WA_ICSDIAGNOSIS_STR-USED4CALC sy-vline
WA_ICSDIAGNOSIS_STR-ASSIGN_GUID sy-vline
WA_ICSDIAGNOSIS_STR-_DATAAGING sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.