ABAP Select data from SAP table ICL_TICL003_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 ICL_TICL003_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 ICL_TICL003_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 ICL_TICL003_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_ICL_TICL003_S TYPE STANDARD TABLE OF ICL_TICL003_S,
      WA_ICL_TICL003_S TYPE ICL_TICL003_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: <ICL_TICL003_S> TYPE ICL_TICL003_S.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM ICL_TICL003_S
*  INTO TABLE @DATA(IT_ICL_TICL003_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_ICL_TICL003_S INDEX 1 INTO DATA(WA_ICL_TICL003_S2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_ICL_TICL003_S ASSIGNING <ICL_TICL003_S>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<ICL_TICL003_S>-CLIENT = 1.
<ICL_TICL003_S>-CLTYPE = 1.
<ICL_TICL003_S>-GENERAT = 1.
<ICL_TICL003_S>-VERSION = 1.
<ICL_TICL003_S>-ACTIVE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_ICL_TICL003_S-CHANGEDBY, sy-vline,
WA_ICL_TICL003_S-CHANGETIME, sy-vline,
WA_ICL_TICL003_S-INACTIVETIME, sy-vline,
WA_ICL_TICL003_S-EFFFROMTIME, sy-vline,
WA_ICL_TICL003_S-EFFTOTIME, sy-vline,
WA_ICL_TICL003_S-TERMTIME, sy-vline.
ENDLOOP. *Add any further fields from structure WA_ICL_TICL003_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_ICL_TICL003_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_ICL_TICL003_S INTO WA_ICL_TICL003_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 TSTAM, internal->external for field CHANGETIME CALL FUNCTION 'CONVERSION_EXIT_TSTAM_OUTPUT' EXPORTING input = WA_ICL_TICL003_S-CHANGETIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICL_TICL003_S-CHANGETIME.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit TSTAM, internal->external for field TERMTIME CALL FUNCTION 'CONVERSION_EXIT_TSTAM_OUTPUT' EXPORTING input = WA_ICL_TICL003_S-TERMTIME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_ICL_TICL003_S-TERMTIME.
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_ICL_TICL003_S_STR,
CLIENT TYPE STRING,
CLTYPE TYPE STRING,
GENERAT TYPE STRING,
VERSION TYPE STRING,
ACTIVE TYPE STRING,
CHANGEDBY TYPE STRING,
CHANGETIME TYPE STRING,
INACTIVETIME TYPE STRING,
EFFFROMTIME TYPE STRING,
EFFTOTIME TYPE STRING,
TERMTIME TYPE STRING,
DELETED TYPE STRING,
OVERSION TYPE STRING,
OSYSID TYPE STRING,
OMANDT TYPE STRING,
BVERSION TYPE STRING,
CURR TYPE STRING,
COMPLEX TYPE STRING,
DEFLTPOST TYPE STRING,
GFUNCTION TYPE STRING,
CDSPEC_CLAIM TYPE STRING,
XDUBLCHECK TYPE STRING,
LOSDATDEV TYPE STRING,
XNOPREMCHK TYPE STRING,
XPREMINCCI TYPE STRING,
MAXOSPRMA TYPE STRING,
MAXOSPRMD TYPE STRING,
POLBTOLH TYPE STRING,
POLETOLH TYPE STRING,
COVBTOLH TYPE STRING,
COVETOLH TYPE STRING,
DEDUCAMTTOL TYPE STRING,
DEDUCPERTOL TYPE STRING,
STATCLAIMVR TYPE STRING,
STATSUBCLVR TYPE STRING,
STATPAYVR TYPE STRING,
STATLITHVR TYPE STRING,
STATLITIVR TYPE STRING,
STATNEG TYPE STRING,
NOCLXSUBCL TYPE STRING,
NOCLNSUBCL TYPE STRING,
XREOPENNOCLM TYPE STRING,
INVOICE_GET_PROC TYPE STRING,
PROCESS TYPE STRING,
CCTYPE TYPE STRING,
INVTYPE_REQ TYPE STRING,
SCHEDCAT TYPE STRING,
DATELOSSCHK TYPE STRING,
POLNEWIMP TYPE STRING,
POLNUMCHK TYPE STRING,
REQFLDCHECK TYPE STRING,
CLAI_ATTRIB TYPE STRING,
RCOVERCHECK TYPE STRING,
COVERREJR TYPE STRING,
CLAIMACLOSE TYPE STRING,
XF4PRODCOVTYPES TYPE STRING,
SPLIT_REQUIRED TYPE STRING,
XCCALC_SUPP_PS TYPE STRING,
ROLE TYPE STRING,
INIT_SEND_DAYS TYPE STRING,
INIT_SEND_EXPR TYPE STRING,
DFLT_SRCH_MNTH TYPE STRING,
RE_SRCH_MNTHS TYPE STRING,
RE_SRCH_EXPR TYPE STRING,END OF T_EKKO_STR. DATA: WA_ICL_TICL003_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_ICL_TICL003_S_STR-CLIENT sy-vline
WA_ICL_TICL003_S_STR-CLTYPE sy-vline
WA_ICL_TICL003_S_STR-GENERAT sy-vline
WA_ICL_TICL003_S_STR-VERSION sy-vline
WA_ICL_TICL003_S_STR-ACTIVE sy-vline
WA_ICL_TICL003_S_STR-CHANGEDBY sy-vline
WA_ICL_TICL003_S_STR-CHANGETIME sy-vline
WA_ICL_TICL003_S_STR-INACTIVETIME sy-vline
WA_ICL_TICL003_S_STR-EFFFROMTIME sy-vline
WA_ICL_TICL003_S_STR-EFFTOTIME sy-vline
WA_ICL_TICL003_S_STR-TERMTIME sy-vline
WA_ICL_TICL003_S_STR-DELETED sy-vline
WA_ICL_TICL003_S_STR-OVERSION sy-vline
WA_ICL_TICL003_S_STR-OSYSID sy-vline
WA_ICL_TICL003_S_STR-OMANDT sy-vline
WA_ICL_TICL003_S_STR-BVERSION sy-vline
WA_ICL_TICL003_S_STR-CURR sy-vline
WA_ICL_TICL003_S_STR-COMPLEX sy-vline
WA_ICL_TICL003_S_STR-DEFLTPOST sy-vline
WA_ICL_TICL003_S_STR-GFUNCTION sy-vline
WA_ICL_TICL003_S_STR-CDSPEC_CLAIM sy-vline
WA_ICL_TICL003_S_STR-XDUBLCHECK sy-vline
WA_ICL_TICL003_S_STR-LOSDATDEV sy-vline
WA_ICL_TICL003_S_STR-XNOPREMCHK sy-vline
WA_ICL_TICL003_S_STR-XPREMINCCI sy-vline
WA_ICL_TICL003_S_STR-MAXOSPRMA sy-vline
WA_ICL_TICL003_S_STR-MAXOSPRMD sy-vline
WA_ICL_TICL003_S_STR-POLBTOLH sy-vline
WA_ICL_TICL003_S_STR-POLETOLH sy-vline
WA_ICL_TICL003_S_STR-COVBTOLH sy-vline
WA_ICL_TICL003_S_STR-COVETOLH sy-vline
WA_ICL_TICL003_S_STR-DEDUCAMTTOL sy-vline
WA_ICL_TICL003_S_STR-DEDUCPERTOL sy-vline
WA_ICL_TICL003_S_STR-STATCLAIMVR sy-vline
WA_ICL_TICL003_S_STR-STATSUBCLVR sy-vline
WA_ICL_TICL003_S_STR-STATPAYVR sy-vline
WA_ICL_TICL003_S_STR-STATLITHVR sy-vline
WA_ICL_TICL003_S_STR-STATLITIVR sy-vline
WA_ICL_TICL003_S_STR-STATNEG sy-vline
WA_ICL_TICL003_S_STR-NOCLXSUBCL sy-vline
WA_ICL_TICL003_S_STR-NOCLNSUBCL sy-vline
WA_ICL_TICL003_S_STR-XREOPENNOCLM sy-vline
WA_ICL_TICL003_S_STR-INVOICE_GET_PROC sy-vline
WA_ICL_TICL003_S_STR-PROCESS sy-vline
WA_ICL_TICL003_S_STR-CCTYPE sy-vline
WA_ICL_TICL003_S_STR-INVTYPE_REQ sy-vline
WA_ICL_TICL003_S_STR-SCHEDCAT sy-vline
WA_ICL_TICL003_S_STR-DATELOSSCHK sy-vline
WA_ICL_TICL003_S_STR-POLNEWIMP sy-vline
WA_ICL_TICL003_S_STR-POLNUMCHK sy-vline
WA_ICL_TICL003_S_STR-REQFLDCHECK sy-vline
WA_ICL_TICL003_S_STR-CLAI_ATTRIB sy-vline
WA_ICL_TICL003_S_STR-RCOVERCHECK sy-vline
WA_ICL_TICL003_S_STR-COVERREJR sy-vline
WA_ICL_TICL003_S_STR-CLAIMACLOSE sy-vline
WA_ICL_TICL003_S_STR-XF4PRODCOVTYPES sy-vline
WA_ICL_TICL003_S_STR-SPLIT_REQUIRED sy-vline
WA_ICL_TICL003_S_STR-XCCALC_SUPP_PS sy-vline
WA_ICL_TICL003_S_STR-ROLE sy-vline
WA_ICL_TICL003_S_STR-INIT_SEND_DAYS sy-vline
WA_ICL_TICL003_S_STR-INIT_SEND_EXPR sy-vline
WA_ICL_TICL003_S_STR-DFLT_SRCH_MNTH sy-vline
WA_ICL_TICL003_S_STR-RE_SRCH_MNTHS sy-vline
WA_ICL_TICL003_S_STR-RE_SRCH_EXPR sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.