ABAP Select data from SAP table IMAINTORDCONF 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 IMAINTORDCONF 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 IMAINTORDCONF. 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 IMAINTORDCONF 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_IMAINTORDCONF TYPE STANDARD TABLE OF IMAINTORDCONF,
      WA_IMAINTORDCONF TYPE IMAINTORDCONF,
      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: <IMAINTORDCONF> TYPE IMAINTORDCONF.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IMAINTORDCONF
*  INTO TABLE @DATA(IT_IMAINTORDCONF2).
*--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_IMAINTORDCONF INDEX 1 INTO DATA(WA_IMAINTORDCONF2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IMAINTORDCONF ASSIGNING <IMAINTORDCONF>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IMAINTORDCONF>-MANDT = 1.
<IMAINTORDCONF>-MAINTORDERCONF = 1.
<IMAINTORDCONF>-MAINTORDERCONFCNTRVALUE = 1.
<IMAINTORDCONF>-MAINTORDERCONFIRMATIONENTRYDTE = 1.
<IMAINTORDCONF>-MAINTORDEROPERATIONCOUNTER = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IMAINTORDCONF-ENTEREDBYUSER, sy-vline,
WA_IMAINTORDCONF-LASTCHANGEDATE, sy-vline,
WA_IMAINTORDCONF-LASTCHANGEDBYUSER, sy-vline,
WA_IMAINTORDCONF-POSTINGDATE, sy-vline,
WA_IMAINTORDCONF-WORKCENTERINTERNALID, sy-vline,
WA_IMAINTORDCONF-CONFIRMATIONTEXT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IMAINTORDCONF 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_IMAINTORDCONF 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_IMAINTORDCONF INTO WA_IMAINTORDCONF. *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 ISOLA, internal->external for field LANGUAGE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-LANGUAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-LANGUAGE.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field ACTUALWORKQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-ACTUALWORKQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-ACTUALWORKQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field ACTUALDURATIONUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-ACTUALDURATIONUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-ACTUALDURATIONUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field CONFIRMATIONUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-CONFIRMATIONUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-CONFIRMATIONUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field MAINTENANCEORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-MAINTENANCEORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-MAINTENANCEORDER.
WRITE:/ 'New Value:', ld_input.

*Conversion exit NUMCV, internal->external for field MAINTENANCEORDEROPERATION CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-MAINTENANCEORDEROPERATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-MAINTENANCEORDEROPERATION.
WRITE:/ 'New Value:', ld_input.

*Conversion exit NUMCV, internal->external for field MAINTENANCEORDERSUBOPERATION CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-MAINTENANCEORDERSUBOPERATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-MAINTENANCEORDERSUBOPERATION.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field REMAININGWORKQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-REMAININGWORKQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-REMAININGWORKQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field ACTUALWORKEXTERNALQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-ACTUALWORKEXTERNALQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-ACTUALWORKEXTERNALQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field REMAININGWORKEXTQUANTITYUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-REMAININGWORKEXTQUANTITYUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-REMAININGWORKEXTQUANTITYUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field MATERIALDOCUMENT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMAINTORDCONF-MATERIALDOCUMENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDCONF-MATERIALDOCUMENT.
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_IMAINTORDCONF_STR,
MANDT TYPE STRING,
MAINTORDERCONF TYPE STRING,
MAINTORDERCONFCNTRVALUE TYPE STRING,
MAINTORDERCONFIRMATIONENTRYDTE TYPE STRING,
MAINTORDEROPERATIONCOUNTER TYPE STRING,
ENTEREDBYUSER TYPE STRING,
LASTCHANGEDATE TYPE STRING,
LASTCHANGEDBYUSER TYPE STRING,
POSTINGDATE TYPE STRING,
WORKCENTERINTERNALID TYPE STRING,
CONFIRMATIONTEXT TYPE STRING,
LANGUAGE TYPE STRING,
LONGTEXTEXISTS TYPE STRING,
ACTUALWORKQUANTITY TYPE STRING,
ACTUALWORKQUANTITYUNIT TYPE STRING,
ACTIVITYTYPE TYPE STRING,
ACTUALDURATION TYPE STRING,
ACTUALDURATIONUNIT TYPE STRING,
EMPLOYEEWAGETYPE TYPE STRING,
CONFIRMATIONYIELDQUANTITY TYPE STRING,
CONFIRMATIONSCRAPQUANTITY TYPE STRING,
CONFIRMATIONUNIT TYPE STRING,
VARIANCEREASONCODE TYPE STRING,
PERSONNELNUMBER TYPE STRING,
OPERATIONCONFIRMEDSTARTDATE TYPE STRING,
OPERATIONCONFIRMEDSTARTTIME TYPE STRING,
OPERATIONCONFIRMEDENDDATE TYPE STRING,
OPERATIONCONFIRMEDENDTIME TYPE STRING,
ACTYCONFFCSTDENDDATE TYPE STRING,
ACTYCONFFCSTDENDTIME TYPE STRING,
ISFINALCONFIRMATION TYPE STRING,
OPENRESERVATIONSISCLEARED TYPE STRING,
MAINTENANCEORDER TYPE STRING,
MAINTENANCEORDEROPERATION TYPE STRING,
MAINTENANCEORDERSUBOPERATION TYPE STRING,
REMAININGWORKQUANTITY TYPE STRING,
REMAININGWORKQUANTITYUNIT TYPE STRING,
NOFURTHERWORKQUANTITYISEXPD TYPE STRING,
ISREVERSED TYPE STRING,
ISREVERSAL TYPE STRING,
CONFIRMATIONREWORKQUANTITY TYPE STRING,
MAINTORDERCONFIRMATIONENTRYTME TYPE STRING,
ACCOUNTINGINDICATORCODE TYPE STRING,
ENTEREDBYEXTERNALUSER TYPE STRING,
CONFIRMATIONEXTERNALENTRYDATE TYPE STRING,
CONFIRMATIONEXTERNALENTRYTIME TYPE STRING,
ACTUALWORKEXTERNALQUANTITYUNIT TYPE STRING,
REMAININGWORKEXTQUANTITYUNIT TYPE STRING,
PLANT TYPE STRING,
FACTORYCALENDAR TYPE STRING,
MAINTORDEROPERATIONINTERNALID TYPE STRING,
CAPACITYINTERNALID TYPE STRING,
EMPLOYEEWAGEGROUP TYPE STRING,
NMBROFMAINTTECHNICIANCAPSPLITS TYPE STRING,
MATERIALDOCUMENT TYPE STRING,END OF T_EKKO_STR. DATA: WA_IMAINTORDCONF_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_IMAINTORDCONF_STR-MANDT sy-vline
WA_IMAINTORDCONF_STR-MAINTORDERCONF sy-vline
WA_IMAINTORDCONF_STR-MAINTORDERCONFCNTRVALUE sy-vline
WA_IMAINTORDCONF_STR-MAINTORDERCONFIRMATIONENTRYDTE sy-vline
WA_IMAINTORDCONF_STR-MAINTORDEROPERATIONCOUNTER sy-vline
WA_IMAINTORDCONF_STR-ENTEREDBYUSER sy-vline
WA_IMAINTORDCONF_STR-LASTCHANGEDATE sy-vline
WA_IMAINTORDCONF_STR-LASTCHANGEDBYUSER sy-vline
WA_IMAINTORDCONF_STR-POSTINGDATE sy-vline
WA_IMAINTORDCONF_STR-WORKCENTERINTERNALID sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONTEXT sy-vline
WA_IMAINTORDCONF_STR-LANGUAGE sy-vline
WA_IMAINTORDCONF_STR-LONGTEXTEXISTS sy-vline
WA_IMAINTORDCONF_STR-ACTUALWORKQUANTITY sy-vline
WA_IMAINTORDCONF_STR-ACTUALWORKQUANTITYUNIT sy-vline
WA_IMAINTORDCONF_STR-ACTIVITYTYPE sy-vline
WA_IMAINTORDCONF_STR-ACTUALDURATION sy-vline
WA_IMAINTORDCONF_STR-ACTUALDURATIONUNIT sy-vline
WA_IMAINTORDCONF_STR-EMPLOYEEWAGETYPE sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONYIELDQUANTITY sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONSCRAPQUANTITY sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONUNIT sy-vline
WA_IMAINTORDCONF_STR-VARIANCEREASONCODE sy-vline
WA_IMAINTORDCONF_STR-PERSONNELNUMBER sy-vline
WA_IMAINTORDCONF_STR-OPERATIONCONFIRMEDSTARTDATE sy-vline
WA_IMAINTORDCONF_STR-OPERATIONCONFIRMEDSTARTTIME sy-vline
WA_IMAINTORDCONF_STR-OPERATIONCONFIRMEDENDDATE sy-vline
WA_IMAINTORDCONF_STR-OPERATIONCONFIRMEDENDTIME sy-vline
WA_IMAINTORDCONF_STR-ACTYCONFFCSTDENDDATE sy-vline
WA_IMAINTORDCONF_STR-ACTYCONFFCSTDENDTIME sy-vline
WA_IMAINTORDCONF_STR-ISFINALCONFIRMATION sy-vline
WA_IMAINTORDCONF_STR-OPENRESERVATIONSISCLEARED sy-vline
WA_IMAINTORDCONF_STR-MAINTENANCEORDER sy-vline
WA_IMAINTORDCONF_STR-MAINTENANCEORDEROPERATION sy-vline
WA_IMAINTORDCONF_STR-MAINTENANCEORDERSUBOPERATION sy-vline
WA_IMAINTORDCONF_STR-REMAININGWORKQUANTITY sy-vline
WA_IMAINTORDCONF_STR-REMAININGWORKQUANTITYUNIT sy-vline
WA_IMAINTORDCONF_STR-NOFURTHERWORKQUANTITYISEXPD sy-vline
WA_IMAINTORDCONF_STR-ISREVERSED sy-vline
WA_IMAINTORDCONF_STR-ISREVERSAL sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONREWORKQUANTITY sy-vline
WA_IMAINTORDCONF_STR-MAINTORDERCONFIRMATIONENTRYTME sy-vline
WA_IMAINTORDCONF_STR-ACCOUNTINGINDICATORCODE sy-vline
WA_IMAINTORDCONF_STR-ENTEREDBYEXTERNALUSER sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONEXTERNALENTRYDATE sy-vline
WA_IMAINTORDCONF_STR-CONFIRMATIONEXTERNALENTRYTIME sy-vline
WA_IMAINTORDCONF_STR-ACTUALWORKEXTERNALQUANTITYUNIT sy-vline
WA_IMAINTORDCONF_STR-REMAININGWORKEXTQUANTITYUNIT sy-vline
WA_IMAINTORDCONF_STR-PLANT sy-vline
WA_IMAINTORDCONF_STR-FACTORYCALENDAR sy-vline
WA_IMAINTORDCONF_STR-MAINTORDEROPERATIONINTERNALID sy-vline
WA_IMAINTORDCONF_STR-CAPACITYINTERNALID sy-vline
WA_IMAINTORDCONF_STR-EMPLOYEEWAGEGROUP sy-vline
WA_IMAINTORDCONF_STR-NMBROFMAINTTECHNICIANCAPSPLITS sy-vline
WA_IMAINTORDCONF_STR-MATERIALDOCUMENT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.