ABAP Select data from SAP table IMDEFCCONFACTTP 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 IMDEFCCONFACTTP 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 IMDEFCCONFACTTP. 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 IMDEFCCONFACTTP 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_IMDEFCCONFACTTP TYPE STANDARD TABLE OF IMDEFCCONFACTTP,
      WA_IMDEFCCONFACTTP TYPE IMDEFCCONFACTTP,
      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: <IMDEFCCONFACTTP> TYPE IMDEFCCONFACTTP.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IMDEFCCONFACTTP
*  INTO TABLE @DATA(IT_IMDEFCCONFACTTP2).
*--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_IMDEFCCONFACTTP INDEX 1 INTO DATA(WA_IMDEFCCONFACTTP2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IMDEFCCONFACTTP ASSIGNING <IMDEFCCONFACTTP>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IMDEFCCONFACTTP>-MANDT = 1.
<IMDEFCCONFACTTP>-MDCHGPROCESSSTEPUUID = 1.
<IMDEFCCONFACTTP>-MDCHGPROCESSSTEPADAPTERCONFIGN = 1.
<IMDEFCCONFACTTP>-MDCHGPROCACTVTCONFIGN = 1.
<IMDEFCCONFACTTP>-MDCHGPROCESSSTPOWNCONFIGNISRQD = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IMDEFCCONFACTTP-MDCHGPROCACTVTTARGETNEW, sy-vline,
WA_IMDEFCCONFACTTP-MDCHGPROCACTVTCHGREQTYPENEW, sy-vline,
WA_IMDEFCCONFACTTP-MDCHGPROCACTVTNMBROFRECDNEW, sy-vline,
WA_IMDEFCCONFACTTP-MDCHGPROCACTVTTARGETNEWERR, sy-vline,
WA_IMDEFCCONFACTTP-MDCHGPROCACTVTCHGREQNEWERR, sy-vline,
WA_IMDEFCCONFACTTP-MDCHGPROCACTVTNMBROFRECDNEWERR, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IMDEFCCONFACTTP 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_IMDEFCCONFACTTP 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_IMDEFCCONFACTTP INTO WA_IMDEFCCONFACTTP. *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_IMDEFCCONFACTTP_STR,
MANDT TYPE STRING,
MDCHGPROCESSSTEPUUID TYPE STRING,
MDCHGPROCESSSTEPADAPTERCONFIGN TYPE STRING,
MDCHGPROCACTVTCONFIGN TYPE STRING,
MDCHGPROCESSSTPOWNCONFIGNISRQD TYPE STRING,
MDCHGPROCACTVTTARGETNEW TYPE STRING,
MDCHGPROCACTVTCHGREQTYPENEW TYPE STRING,
MDCHGPROCACTVTNMBROFRECDNEW TYPE STRING,
MDCHGPROCACTVTTARGETNEWERR TYPE STRING,
MDCHGPROCACTVTCHGREQNEWERR TYPE STRING,
MDCHGPROCACTVTNMBROFRECDNEWERR TYPE STRING,
MDCHGPROCACTVTTARGETUPDT TYPE STRING,
MDCHGPROCACTVTCHGREQUPDT TYPE STRING,
MDCHGPROCACTVTMAXNMBRRECDUPDT TYPE STRING,
MDCHGPROCACTVTTARGETUPDTERR TYPE STRING,
MDCHGPROCACTVTCHGREQUPDTERR TYPE STRING,
MDCHGPROCACTVTNMBRRECDUPDTERR TYPE STRING,
MDCHGPROCACTVTTARGETGRP TYPE STRING,
MDCHGPROCACTVTCHGREQGRP TYPE STRING,
MDCHGPROCACTVTNMBROFRECDGRP TYPE STRING,
MDCHGPROCACTVTTGTGRPERR TYPE STRING,
MDCHGPROCACTVTCHGREQGRPERR TYPE STRING,
MDCHGPROCACTVTNMBRRECDGRPERR TYPE STRING,
MDCHGPROCACTVTISDATARPLCTNRQD TYPE STRING,
MDCHGPROCACTVTISMDGOVVALDTNRQD TYPE STRING,
MDCHGPROCACTVTISBRFPLUSCHKRQD TYPE STRING,
MDCHGPROCQLTYRULECHKISRQD TYPE STRING,
MDCHGPROCACTVTRETENTIONTMEMINS TYPE STRING,
MDCHGPROCACTVTRETENTIONTMEDAYS TYPE STRING,
MDCHGPROCACTVTRETENTIONTMEHRS TYPE STRING,END OF T_EKKO_STR. DATA: WA_IMDEFCCONFACTTP_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_IMDEFCCONFACTTP_STR-MANDT sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCESSSTEPUUID sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCESSSTEPADAPTERCONFIGN sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCONFIGN sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCESSSTPOWNCONFIGNISRQD sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTTARGETNEW sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCHGREQTYPENEW sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTNMBROFRECDNEW sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTTARGETNEWERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCHGREQNEWERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTNMBROFRECDNEWERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTTARGETUPDT sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCHGREQUPDT sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTMAXNMBRRECDUPDT sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTTARGETUPDTERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCHGREQUPDTERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTNMBRRECDUPDTERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTTARGETGRP sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCHGREQGRP sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTNMBROFRECDGRP sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTTGTGRPERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTCHGREQGRPERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTNMBRRECDGRPERR sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTISDATARPLCTNRQD sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTISMDGOVVALDTNRQD sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTISBRFPLUSCHKRQD sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCQLTYRULECHKISRQD sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTRETENTIONTMEMINS sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTRETENTIONTMEDAYS sy-vline
WA_IMDEFCCONFACTTP_STR-MDCHGPROCACTVTRETENTIONTMEHRS sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.