ABAP Select data from SAP table IMAINTORDINSPLOT 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 IMAINTORDINSPLOT 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 IMAINTORDINSPLOT. 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 IMAINTORDINSPLOT 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_IMAINTORDINSPLOT TYPE STANDARD TABLE OF IMAINTORDINSPLOT,
      WA_IMAINTORDINSPLOT TYPE IMAINTORDINSPLOT,
      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: <IMAINTORDINSPLOT> TYPE IMAINTORDINSPLOT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM IMAINTORDINSPLOT
*  INTO TABLE @DATA(IT_IMAINTORDINSPLOT2).
*--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_IMAINTORDINSPLOT INDEX 1 INTO DATA(WA_IMAINTORDINSPLOT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_IMAINTORDINSPLOT ASSIGNING <IMAINTORDINSPLOT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<IMAINTORDINSPLOT>-MANDT = 1.
<IMAINTORDINSPLOT>-MAINTENANCEORDER = 1.
<IMAINTORDINSPLOT>-INSPECTIONLOT = 1.
<IMAINTORDINSPLOT>-PLANT = 1.
<IMAINTORDINSPLOT>-INSPECTIONLOTTYPE = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_IMAINTORDINSPLOT-INSPECTIONLOTORIGIN, sy-vline,
WA_IMAINTORDINSPLOT-STATUSOBJECT, sy-vline,
WA_IMAINTORDINSPLOT-STATUSOBJECTCATEGORY, sy-vline,
WA_IMAINTORDINSPLOT-STATUSPROFILE, sy-vline,
WA_IMAINTORDINSPLOT-GOODSRECEIPTISMOVEDTOBLKDSTOCK, sy-vline,
WA_IMAINTORDINSPLOT-INSPECTIONLOTISSKIPPED, sy-vline.
ENDLOOP. *Add any further fields from structure WA_IMAINTORDINSPLOT 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_IMAINTORDINSPLOT 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_IMAINTORDINSPLOT INTO WA_IMAINTORDINSPLOT. *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 MAINTENANCEORDER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_IMAINTORDINSPLOT-MAINTENANCEORDER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDINSPLOT-MAINTENANCEORDER.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

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

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

*Conversion exit ISOLA, internal->external for field LANGUAGE CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_IMAINTORDINSPLOT-LANGUAGE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDINSPLOT-LANGUAGE.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit TPLNR, internal->external for field FUNCTIONALLOCATION CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT' EXPORTING input = WA_IMAINTORDINSPLOT-FUNCTIONALLOCATION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_IMAINTORDINSPLOT-FUNCTIONALLOCATION.
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_IMAINTORDINSPLOT_STR,
MANDT TYPE STRING,
MAINTENANCEORDER TYPE STRING,
INSPECTIONLOT TYPE STRING,
PLANT TYPE STRING,
INSPECTIONLOTTYPE TYPE STRING,
INSPECTIONLOTORIGIN TYPE STRING,
STATUSOBJECT TYPE STRING,
STATUSOBJECTCATEGORY TYPE STRING,
STATUSPROFILE TYPE STRING,
GOODSRECEIPTISMOVEDTOBLKDSTOCK TYPE STRING,
INSPECTIONLOTISSKIPPED TYPE STRING,
INSPLOTCREATEDONLOCALDATE TYPE STRING,
INSPLOTCREATEDONLOCALTIME TYPE STRING,
INSPECTIONLOTCREATEDBY TYPE STRING,
INSPECTIONLOTCREATEDON TYPE STRING,
INSPECTIONLOTCREATEDONTIME TYPE STRING,
INSPECTIONLOTCHANGEDBY TYPE STRING,
INSPECTIONLOTCHANGEDATE TYPE STRING,
INSPECTIONLOTCHANGETIME TYPE STRING,
CHANGEDDATETIME TYPE STRING,
INSPECTIONLOTSTARTDATE TYPE STRING,
INSPECTIONLOTSTARTTIME TYPE STRING,
INSPECTIONLOTENDDATE TYPE STRING,
INSPECTIONLOTENDTIME TYPE STRING,
BILLOFOPERATIONSTYPE TYPE STRING,
BILLOFOPERATIONSGROUP TYPE STRING,
BILLOFOPERATIONSUSAGE TYPE STRING,
BILLOFOPERATIONSVARIANT TYPE STRING,
BILLOFOPERATIONSCHANGESTATEID TYPE STRING,
INSPLOTSELBILLOFOPERATIONSUSGE TYPE STRING,
INSPLOTSELECTIONVALIDFROMDATE TYPE STRING,
MANUFACTURINGORDER TYPE STRING,
ORDERINTERNALBILLOFOPERATIONS TYPE STRING,
INSPLOTSELECTIONCUSTOMER TYPE STRING,
CUSTOMER TYPE STRING,
INSPLOTSELECTIONSUPPLIER TYPE STRING,
SUPPLIER TYPE STRING,
LANGUAGE TYPE STRING,
INSPECTIONLOTTEXT TYPE STRING,
INSPECTIONLOTOBJECTTEXT TYPE STRING,
INSPLOTNMBRADDLRECORDEDCHARC TYPE STRING,
INSPLOTNMBROPENSHORTTERMCHARC TYPE STRING,
INSPLOTNMBROPENLONGTERMCHARC TYPE STRING,
INSPLOTUSAGEDECISIONTOOL TYPE STRING,
INSPECTIONLOTHASUSAGEDECISION TYPE STRING,
MAINTBUSINESSSUBOBJECTTYPE TYPE STRING,
MAINTENANCEBUSINESSSUBOBJECT TYPE STRING,
MAINTCHECKLISTTEMPLATETYPE TYPE STRING,
MAINTENANCECHECKLISTTEMPLATE TYPE STRING,
EQUIPMENT TYPE STRING,
FUNCTIONALLOCATION TYPE STRING,
MAINTCHKLSTADDLINFORMATIONTEXT TYPE STRING,
MAINCHECKLISTISDEACTIVATED TYPE STRING,
MAINTENANCEBUSINESSOBJECTTYPE TYPE STRING,
MAINTENANCECHECKLISTTYPE TYPE STRING,END OF T_EKKO_STR. DATA: WA_IMAINTORDINSPLOT_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_IMAINTORDINSPLOT_STR-MANDT sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTENANCEORDER sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOT sy-vline
WA_IMAINTORDINSPLOT_STR-PLANT sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTTYPE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTORIGIN sy-vline
WA_IMAINTORDINSPLOT_STR-STATUSOBJECT sy-vline
WA_IMAINTORDINSPLOT_STR-STATUSOBJECTCATEGORY sy-vline
WA_IMAINTORDINSPLOT_STR-STATUSPROFILE sy-vline
WA_IMAINTORDINSPLOT_STR-GOODSRECEIPTISMOVEDTOBLKDSTOCK sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTISSKIPPED sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTCREATEDONLOCALDATE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTCREATEDONLOCALTIME sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTCREATEDBY sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTCREATEDON sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTCREATEDONTIME sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTCHANGEDBY sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTCHANGEDATE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTCHANGETIME sy-vline
WA_IMAINTORDINSPLOT_STR-CHANGEDDATETIME sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTSTARTDATE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTSTARTTIME sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTENDDATE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTENDTIME sy-vline
WA_IMAINTORDINSPLOT_STR-BILLOFOPERATIONSTYPE sy-vline
WA_IMAINTORDINSPLOT_STR-BILLOFOPERATIONSGROUP sy-vline
WA_IMAINTORDINSPLOT_STR-BILLOFOPERATIONSUSAGE sy-vline
WA_IMAINTORDINSPLOT_STR-BILLOFOPERATIONSVARIANT sy-vline
WA_IMAINTORDINSPLOT_STR-BILLOFOPERATIONSCHANGESTATEID sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTSELBILLOFOPERATIONSUSGE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTSELECTIONVALIDFROMDATE sy-vline
WA_IMAINTORDINSPLOT_STR-MANUFACTURINGORDER sy-vline
WA_IMAINTORDINSPLOT_STR-ORDERINTERNALBILLOFOPERATIONS sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTSELECTIONCUSTOMER sy-vline
WA_IMAINTORDINSPLOT_STR-CUSTOMER sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTSELECTIONSUPPLIER sy-vline
WA_IMAINTORDINSPLOT_STR-SUPPLIER sy-vline
WA_IMAINTORDINSPLOT_STR-LANGUAGE sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTTEXT sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTOBJECTTEXT sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTNMBRADDLRECORDEDCHARC sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTNMBROPENSHORTTERMCHARC sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTNMBROPENLONGTERMCHARC sy-vline
WA_IMAINTORDINSPLOT_STR-INSPLOTUSAGEDECISIONTOOL sy-vline
WA_IMAINTORDINSPLOT_STR-INSPECTIONLOTHASUSAGEDECISION sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTBUSINESSSUBOBJECTTYPE sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTENANCEBUSINESSSUBOBJECT sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTCHECKLISTTEMPLATETYPE sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTENANCECHECKLISTTEMPLATE sy-vline
WA_IMAINTORDINSPLOT_STR-EQUIPMENT sy-vline
WA_IMAINTORDINSPLOT_STR-FUNCTIONALLOCATION sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTCHKLSTADDLINFORMATIONTEXT sy-vline
WA_IMAINTORDINSPLOT_STR-MAINCHECKLISTISDEACTIVATED sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTENANCEBUSINESSOBJECTTYPE sy-vline
WA_IMAINTORDINSPLOT_STR-MAINTENANCECHECKLISTTYPE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.