ABAP Select data from SAP table /ISDFPS/151PM_INSTDISM 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 /ISDFPS/151PM_INSTDISM 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 /ISDFPS/151PM_INSTDISM. 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 /ISDFPS/151PM_INSTDISM 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_/ISDFPS/151PM_INSTDISM TYPE STANDARD TABLE OF /ISDFPS/151PM_INSTDISM,
      WA_/ISDFPS/151PM_INSTDISM TYPE /ISDFPS/151PM_INSTDISM,
      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: </ISDFPS/151PM_INSTDISM> TYPE /ISDFPS/151PM_INSTDISM.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_/ISDFPS/151PM_INSTDISM.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM /ISDFPS/151PM_INSTDISM
  INTO TABLE IT_/ISDFPS/151PM_INSTDISM.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM /ISDFPS/151PM_INSTDISM
*  INTO TABLE @DATA(IT_/ISDFPS/151PM_INSTDISM2).
*--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_/ISDFPS/151PM_INSTDISM INDEX 1 INTO DATA(WA_/ISDFPS/151PM_INSTDISM2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_/ISDFPS/151PM_INSTDISM ASSIGNING </ISDFPS/151PM_INSTDISM>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
</ISDFPS/151PM_INSTDISM>-STCH_GUID = 1.
</ISDFPS/151PM_INSTDISM>-SEQUNR = 1.
</ISDFPS/151PM_INSTDISM>-MATNR = 1.
</ISDFPS/151PM_INSTDISM>-SERIAL = 1.
</ISDFPS/151PM_INSTDISM>-UII = 1.
ENDLOOP.

LOOP AT IT_/ISDFPS/151PM_INSTDISM INTO WA_/ISDFPS/151PM_INSTDISM.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_/ISDFPS/151PM_INSTDISM-HEQUI, sy-vline,
WA_/ISDFPS/151PM_INSTDISM-TPLNR, sy-vline,
WA_/ISDFPS/151PM_INSTDISM-HEQNR, sy-vline,
WA_/ISDFPS/151PM_INSTDISM-ORDERID, sy-vline,
WA_/ISDFPS/151PM_INSTDISM-ORDER_GUID, sy-vline,
WA_/ISDFPS/151PM_INSTDISM-PLANT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/ISDFPS/151PM_INSTDISM 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_/ISDFPS/151PM_INSTDISM 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_/ISDFPS/151PM_INSTDISM INTO WA_/ISDFPS/151PM_INSTDISM. *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 SEQUNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/ISDFPS/151PM_INSTDISM-SEQUNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ISDFPS/151PM_INSTDISM-SEQUNR.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit GERNR, internal->external for field SERIAL CALL FUNCTION 'CONVERSION_EXIT_GERNR_OUTPUT' EXPORTING input = WA_/ISDFPS/151PM_INSTDISM-SERIAL IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ISDFPS/151PM_INSTDISM-SERIAL.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit TPLNR, internal->external for field TPLNR CALL FUNCTION 'CONVERSION_EXIT_TPLNR_OUTPUT' EXPORTING input = WA_/ISDFPS/151PM_INSTDISM-TPLNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ISDFPS/151PM_INSTDISM-TPLNR.
WRITE:/ 'New Value:', ld_input.

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

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

*Conversion exit GJAHR, internal->external for field DOC_YEAR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_/ISDFPS/151PM_INSTDISM-DOC_YEAR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ISDFPS/151PM_INSTDISM-DOC_YEAR.
WRITE:/ 'New Value:', ld_input.

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

*Conversion exit ABPSN, internal->external for field WBS_ELEM CALL FUNCTION 'CONVERSION_EXIT_ABPSN_OUTPUT' EXPORTING input = WA_/ISDFPS/151PM_INSTDISM-WBS_ELEM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ISDFPS/151PM_INSTDISM-WBS_ELEM.
WRITE:/ 'New Value:', ld_input.

*Conversion exit NUMCV, internal->external for field ACTIVITY CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_/ISDFPS/151PM_INSTDISM-ACTIVITY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/ISDFPS/151PM_INSTDISM-ACTIVITY.
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_/ISDFPS/151PM_INSTDISM_STR,
STCH_GUID TYPE STRING,
SEQUNR TYPE STRING,
MATNR TYPE STRING,
SERIAL TYPE STRING,
UII TYPE STRING,
HEQUI TYPE STRING,
TPLNR TYPE STRING,
HEQNR TYPE STRING,
ORDERID TYPE STRING,
ORDER_GUID TYPE STRING,
PLANT TYPE STRING,
STLOC TYPE STRING,
LGNUM TYPE STRING,
LGTYP TYPE STRING,
LGPLA TYPE STRING,
MOVEMENT_TYPE TYPE STRING,
CREADAT TYPE STRING,
CREABY TYPE STRING,
ACTION_FLAG TYPE STRING,
ID_DATE TYPE STRING,
ID_TIME TYPE STRING,
BATCH TYPE STRING,
GRUND TYPE STRING,
POSNR TYPE STRING,
PLRMV_IND TYPE STRING,
UPRMV_IND TYPE STRING,
FRCFIT_IND TYPE STRING,
FRCRMV_IND TYPE STRING,
SVCND_IND TYPE STRING,
USCND_IND TYPE STRING,
UKCND_IND TYPE STRING,
TASK_CODE TYPE STRING,
TASK_CGRP TYPE STRING,
TASK_CAT TYPE STRING,
NOTIF_GUID TYPE STRING,
CLIENT_COMMITED TYPE STRING,
USR08 TYPE STRING,
RESERV_NO TYPE STRING,
RES_ITEM TYPE STRING,
WITHDRAWN TYPE STRING,
MATDOC TYPE STRING,
DOC_YEAR TYPE STRING,
STCK_TYPE TYPE STRING,
SPEC_STOCK TYPE STRING,
COSTCENTER TYPE STRING,
WBS_ELEM TYPE STRING,
ACTIVITY TYPE STRING,
NEW_VAL_TYPE TYPE STRING,
SKIP_VAL_SERVICE TYPE STRING,
IS_CLNT_RESOLVED TYPE STRING,
RESERV_GUID TYPE STRING,
UII72 TYPE STRING,
POSTING_DATE TYPE STRING,END OF T_EKKO_STR. DATA: WA_/ISDFPS/151PM_INSTDISM_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_/ISDFPS/151PM_INSTDISM_STR-STCH_GUID sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-SEQUNR sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-MATNR sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-SERIAL sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-UII sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-HEQUI sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-TPLNR sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-HEQNR sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-ORDERID sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-ORDER_GUID sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-PLANT sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-STLOC sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-LGNUM sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-LGTYP sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-LGPLA sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-MOVEMENT_TYPE sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-CREADAT sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-CREABY sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-ACTION_FLAG sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-ID_DATE sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-ID_TIME sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-BATCH sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-GRUND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-POSNR sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-PLRMV_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-UPRMV_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-FRCFIT_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-FRCRMV_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-SVCND_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-USCND_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-UKCND_IND sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-TASK_CODE sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-TASK_CGRP sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-TASK_CAT sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-NOTIF_GUID sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-CLIENT_COMMITED sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-USR08 sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-RESERV_NO sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-RES_ITEM sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-WITHDRAWN sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-MATDOC sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-DOC_YEAR sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-STCK_TYPE sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-SPEC_STOCK sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-COSTCENTER sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-WBS_ELEM sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-ACTIVITY sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-NEW_VAL_TYPE sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-SKIP_VAL_SERVICE sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-IS_CLNT_RESOLVED sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-RESERV_GUID sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-UII72 sy-vline
WA_/ISDFPS/151PM_INSTDISM_STR-POSTING_DATE sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.