ABAP Select data from SAP table PINSPRSLTSTAT 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 PINSPRSLTSTAT 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 PINSPRSLTSTAT. 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 PINSPRSLTSTAT 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_PINSPRSLTSTAT TYPE STANDARD TABLE OF PINSPRSLTSTAT,
      WA_PINSPRSLTSTAT TYPE PINSPRSLTSTAT,
      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: <PINSPRSLTSTAT> TYPE PINSPRSLTSTAT.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM PINSPRSLTSTAT
*  INTO TABLE @DATA(IT_PINSPRSLTSTAT2).
*--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_PINSPRSLTSTAT INDEX 1 INTO DATA(WA_PINSPRSLTSTAT2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_PINSPRSLTSTAT ASSIGNING <PINSPRSLTSTAT>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<PINSPRSLTSTAT>-MANDT = 1.
<PINSPRSLTSTAT>-INSPECTIONLOT = 1.
<PINSPRSLTSTAT>-INSPPLANOPERATIONINTERNALID = 1.
<PINSPRSLTSTAT>-INSPECTIONCHARACTERISTIC = 1.
<PINSPRSLTSTAT>-INSPECTIONOPERATION = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_PINSPRSLTSTAT-INSPECTIONSPECIFICATIONPLANT, sy-vline,
WA_PINSPRSLTSTAT-INSPECTIONSPECIFICATION, sy-vline,
WA_PINSPRSLTSTAT-INSPECTIONSPECIFICATIONVERSION, sy-vline,
WA_PINSPRSLTSTAT-INSPECTIONLOTORIGIN, sy-vline,
WA_PINSPRSLTSTAT-INSPECTIONLOTTYPE, sy-vline,
WA_PINSPRSLTSTAT-INSPLOTSELECTIONSUPPLIER, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PINSPRSLTSTAT 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_PINSPRSLTSTAT 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_PINSPRSLTSTAT INTO WA_PINSPRSLTSTAT. *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 INSPECTIONLOT CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PINSPRSLTSTAT-INSPECTIONLOT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PINSPRSLTSTAT-INSPECTIONLOT.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

*Conversion exit MATN1, internal->external for field INSPLOTSELECTIONMATERIAL CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_PINSPRSLTSTAT-INSPLOTSELECTIONMATERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PINSPRSLTSTAT-INSPLOTSELECTIONMATERIAL.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

*Conversion exit CUNIT, internal->external for field INSPCHARACTERISTICSAMPLEUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PINSPRSLTSTAT-INSPCHARACTERISTICSAMPLEUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PINSPRSLTSTAT-INSPCHARACTERISTICSAMPLEUNIT.
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_PINSPRSLTSTAT_STR,
MANDT TYPE STRING,
INSPECTIONLOT TYPE STRING,
INSPPLANOPERATIONINTERNALID TYPE STRING,
INSPECTIONCHARACTERISTIC TYPE STRING,
INSPECTIONOPERATION TYPE STRING,
INSPECTIONSPECIFICATIONPLANT TYPE STRING,
INSPECTIONSPECIFICATION TYPE STRING,
INSPECTIONSPECIFICATIONVERSION TYPE STRING,
INSPECTIONLOTORIGIN TYPE STRING,
INSPECTIONLOTTYPE TYPE STRING,
INSPLOTSELECTIONSUPPLIER TYPE STRING,
INSPLOTSELECTIONCUSTOMER TYPE STRING,
INSPLOTSELECTIONMANUFACTURER TYPE STRING,
BATCH TYPE STRING,
PLANT TYPE STRING,
INSPLOTSELECTIONMATERIAL TYPE STRING,
CREATIONDATE TYPE STRING,
BILLOFOPERATIONSTYPE TYPE STRING,
BILLOFOPERATIONSGROUP TYPE STRING,
BILLOFOPERATIONSVARIANT TYPE STRING,
BOOOPERATIONINTERNALID TYPE STRING,
QUALITYCONTROLCHART TYPE STRING,
INSPECTIONRESULTSTATUS TYPE STRING,
INSPECTIONVALUATIONRESULT TYPE STRING,
INSPECTIONSPECIFICATIONUNIT TYPE STRING,
INSPCHARCISNOTPLANNED TYPE STRING,
INSPSPECTARGETVALUE TYPE STRING,
INSPSPECUPPERLIMIT TYPE STRING,
INSPSPECLOWERLIMIT TYPE STRING,
INSPECTIONRESULTMEANVALUE TYPE STRING,
INSPECTIONRESULTHASMEANVALUE TYPE STRING,
INSPECTIONRESULTMAXIMUMVALUE TYPE STRING,
INSPECTIONRESULTMINIMUMVALUE TYPE STRING,
INSPRESULTVALIDVALUESNUMBER TYPE STRING,
INSPRSLTNONCONFORMINGVALSNMBR TYPE STRING,
INSPRSLTABOVETOLERANCEVALSNMBR TYPE STRING,
INSPRSLTBELOWTOLERANCEVALSNMBR TYPE STRING,
INSPECTIONRESULTTEXT TYPE STRING,
INSPECTOR TYPE STRING,
INSPECTIONRESULTATTRIBUTE TYPE STRING,
INSPRESULTVARIANCE TYPE STRING,
INSPRSLTWEIGHTEDVARIANCEVALUE TYPE STRING,
INSPCHARCOUNT TYPE STRING,
INSPRESULTTOTALVARIANCE TYPE STRING,
INSPRSLTABOVETOLERANCEFRACTION TYPE STRING,
INSPRSLTBELOWTOLERANCEFRACTION TYPE STRING,
INSPECTIONSPECIFICATIONTEXT TYPE STRING,
INSPSPECSAMPLEQUANTITYFACTOR TYPE STRING,
INSPCHARACTERISTICSAMPLEUNIT TYPE STRING,
INSPCHARACTERISTICSAMPLESIZE TYPE STRING,
BOOCHARACTERISTICVERSION TYPE STRING,
INSPSPECCHARACTERISTICTYPE TYPE STRING,END OF T_EKKO_STR. DATA: WA_PINSPRSLTSTAT_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_PINSPRSLTSTAT_STR-MANDT sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONLOT sy-vline
WA_PINSPRSLTSTAT_STR-INSPPLANOPERATIONINTERNALID sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONCHARACTERISTIC sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONOPERATION sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONSPECIFICATIONPLANT sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONSPECIFICATION sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONSPECIFICATIONVERSION sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONLOTORIGIN sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONLOTTYPE sy-vline
WA_PINSPRSLTSTAT_STR-INSPLOTSELECTIONSUPPLIER sy-vline
WA_PINSPRSLTSTAT_STR-INSPLOTSELECTIONCUSTOMER sy-vline
WA_PINSPRSLTSTAT_STR-INSPLOTSELECTIONMANUFACTURER sy-vline
WA_PINSPRSLTSTAT_STR-BATCH sy-vline
WA_PINSPRSLTSTAT_STR-PLANT sy-vline
WA_PINSPRSLTSTAT_STR-INSPLOTSELECTIONMATERIAL sy-vline
WA_PINSPRSLTSTAT_STR-CREATIONDATE sy-vline
WA_PINSPRSLTSTAT_STR-BILLOFOPERATIONSTYPE sy-vline
WA_PINSPRSLTSTAT_STR-BILLOFOPERATIONSGROUP sy-vline
WA_PINSPRSLTSTAT_STR-BILLOFOPERATIONSVARIANT sy-vline
WA_PINSPRSLTSTAT_STR-BOOOPERATIONINTERNALID sy-vline
WA_PINSPRSLTSTAT_STR-QUALITYCONTROLCHART sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTSTATUS sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONVALUATIONRESULT sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONSPECIFICATIONUNIT sy-vline
WA_PINSPRSLTSTAT_STR-INSPCHARCISNOTPLANNED sy-vline
WA_PINSPRSLTSTAT_STR-INSPSPECTARGETVALUE sy-vline
WA_PINSPRSLTSTAT_STR-INSPSPECUPPERLIMIT sy-vline
WA_PINSPRSLTSTAT_STR-INSPSPECLOWERLIMIT sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTMEANVALUE sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTHASMEANVALUE sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTMAXIMUMVALUE sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTMINIMUMVALUE sy-vline
WA_PINSPRSLTSTAT_STR-INSPRESULTVALIDVALUESNUMBER sy-vline
WA_PINSPRSLTSTAT_STR-INSPRSLTNONCONFORMINGVALSNMBR sy-vline
WA_PINSPRSLTSTAT_STR-INSPRSLTABOVETOLERANCEVALSNMBR sy-vline
WA_PINSPRSLTSTAT_STR-INSPRSLTBELOWTOLERANCEVALSNMBR sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTTEXT sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTOR sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONRESULTATTRIBUTE sy-vline
WA_PINSPRSLTSTAT_STR-INSPRESULTVARIANCE sy-vline
WA_PINSPRSLTSTAT_STR-INSPRSLTWEIGHTEDVARIANCEVALUE sy-vline
WA_PINSPRSLTSTAT_STR-INSPCHARCOUNT sy-vline
WA_PINSPRSLTSTAT_STR-INSPRESULTTOTALVARIANCE sy-vline
WA_PINSPRSLTSTAT_STR-INSPRSLTABOVETOLERANCEFRACTION sy-vline
WA_PINSPRSLTSTAT_STR-INSPRSLTBELOWTOLERANCEFRACTION sy-vline
WA_PINSPRSLTSTAT_STR-INSPECTIONSPECIFICATIONTEXT sy-vline
WA_PINSPRSLTSTAT_STR-INSPSPECSAMPLEQUANTITYFACTOR sy-vline
WA_PINSPRSLTSTAT_STR-INSPCHARACTERISTICSAMPLEUNIT sy-vline
WA_PINSPRSLTSTAT_STR-INSPCHARACTERISTICSAMPLESIZE sy-vline
WA_PINSPRSLTSTAT_STR-BOOCHARACTERISTICVERSION sy-vline
WA_PINSPRSLTSTAT_STR-INSPSPECCHARACTERISTICTYPE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.