ABAP Select data from SAP table PEWMPICNTLIST02 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 PEWMPICNTLIST02 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 PEWMPICNTLIST02. 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 PEWMPICNTLIST02 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_PEWMPICNTLIST02 TYPE STANDARD TABLE OF PEWMPICNTLIST02, WA_PEWMPICNTLIST02 TYPE PEWMPICNTLIST02, 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: <PEWMPICNTLIST02> TYPE PEWMPICNTLIST02. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PEWMPICNTLIST02. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PEWMPICNTLIST02 INTO TABLE IT_PEWMPICNTLIST02. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PEWMPICNTLIST02 * INTO TABLE @DATA(IT_PEWMPICNTLIST022). *--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_PEWMPICNTLIST02 INDEX 1 INTO DATA(WA_PEWMPICNTLIST022). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PEWMPICNTLIST02 ASSIGNING <PEWMPICNTLIST02>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PEWMPICNTLIST02>-MANDT = 1.
<PEWMPICNTLIST02>-PHYSICALINVENTORYDOCUMENTUUID = 1.
<PEWMPICNTLIST02>-PHYSICALINVENTORYITEMNUMBER = 1.
<PEWMPICNTLIST02>-LINEINDEXOFPINVITEM = 1.
<PEWMPICNTLIST02>-PHYSICALINVENTORYCHANGEVERSION = 1.
ENDLOOP. LOOP AT IT_PEWMPICNTLIST02 INTO WA_PEWMPICNTLIST02. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PEWMPICNTLIST02-PINVDOCUMENTITEMTYPE, sy-vline,
WA_PEWMPICNTLIST02-PHYSICALINVENTORYDOCUMENTTYPE, sy-vline,
WA_PEWMPICNTLIST02-PHYSICALINVENTORYSTATUSTEXT, sy-vline,
WA_PEWMPICNTLIST02-WHSETASKGOODSRECEIPTDATETIME, sy-vline,
WA_PEWMPICNTLIST02-SHELFLIFEEXPIRATIONDATE, sy-vline,
WA_PEWMPICNTLIST02-COUNTRYOFORIGIN, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PEWMPICNTLIST02 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_PEWMPICNTLIST02 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_PEWMPICNTLIST02 INTO WA_PEWMPICNTLIST02. *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 MDLPD, internal->external for field PRODUCTUUID CALL FUNCTION 'CONVERSION_EXIT_MDLPD_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-PRODUCTUUID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-PRODUCTUUID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field HANDLINGUNITNUMBER CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-HANDLINGUNITNUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-HANDLINGUNITNUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ENTITLEDTODISPOSEPARTY CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-ENTITLEDTODISPOSEPARTY IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-ENTITLEDTODISPOSEPARTY.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field STOCKOWNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-STOCKOWNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-STOCKOWNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field EWMSTOCKOWNER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-EWMSTOCKOWNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-EWMSTOCKOWNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field PARENTHANDLINGUNITNUMBER CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-PARENTHANDLINGUNITNUMBER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-PARENTHANDLINGUNITNUMBER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BOOKQUANTITYUNITOFMEASURE CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PEWMPICNTLIST02-BOOKQUANTITYUNITOFMEASURE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PEWMPICNTLIST02-BOOKQUANTITYUNITOFMEASURE.
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_PEWMPICNTLIST02_STR,
MANDT TYPE STRING,
PHYSICALINVENTORYDOCUMENTUUID TYPE STRING,
PHYSICALINVENTORYITEMNUMBER TYPE STRING,
LINEINDEXOFPINVITEM TYPE STRING,
PHYSICALINVENTORYCHANGEVERSION TYPE STRING,
PINVDOCUMENTITEMTYPE TYPE STRING,
PHYSICALINVENTORYDOCUMENTTYPE TYPE STRING,
PHYSICALINVENTORYSTATUSTEXT TYPE STRING,
WHSETASKGOODSRECEIPTDATETIME TYPE STRING,
SHELFLIFEEXPIRATIONDATE TYPE STRING,
COUNTRYOFORIGIN TYPE STRING,
PINVITEMPARENTUUID TYPE STRING,
PINVITEMPARENTTYPE TYPE STRING,
PHYSICALINVENTORYSTOCKUUID TYPE STRING,
PRODUCTUUID TYPE STRING,
BATCHUUID TYPE STRING,
HANDLINGUNITNUMBER TYPE STRING,
ENTITLEDTODISPOSEPARTY TYPE STRING,
STOCKOWNER TYPE STRING,
EWMSTOCKOWNER TYPE STRING,
STOCKTYPE TYPE STRING,
EWMSTOCKTYPE TYPE STRING,
STOCKUSAGE TYPE STRING,
EWMSTOCKUSAGE TYPE STRING,
STOCKDOCUMENTCATEGORY TYPE STRING,
STOCKDOCUMENTNUMBER TYPE STRING,
STOCKITEMNUMBER TYPE STRING,
PRODUCEDMATERIAL TYPE STRING,
WAREHOUSE TYPE STRING,
EWMWAREHOUSE TYPE STRING,
PARENTSTORAGEBIN TYPE STRING,
PARENTHANDLINGUNITNUMBER TYPE STRING,
BOOKQTYOFPINVITEMINBOOKQTYUOM TYPE STRING,
BOOKQUANTITYUNITOFMEASURE TYPE STRING,
CHILDLINEIDX TYPE STRING,END OF T_EKKO_STR. DATA: WA_PEWMPICNTLIST02_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_PEWMPICNTLIST02_STR-MANDT sy-vline
WA_PEWMPICNTLIST02_STR-PHYSICALINVENTORYDOCUMENTUUID sy-vline
WA_PEWMPICNTLIST02_STR-PHYSICALINVENTORYITEMNUMBER sy-vline
WA_PEWMPICNTLIST02_STR-LINEINDEXOFPINVITEM sy-vline
WA_PEWMPICNTLIST02_STR-PHYSICALINVENTORYCHANGEVERSION sy-vline
WA_PEWMPICNTLIST02_STR-PINVDOCUMENTITEMTYPE sy-vline
WA_PEWMPICNTLIST02_STR-PHYSICALINVENTORYDOCUMENTTYPE sy-vline
WA_PEWMPICNTLIST02_STR-PHYSICALINVENTORYSTATUSTEXT sy-vline
WA_PEWMPICNTLIST02_STR-WHSETASKGOODSRECEIPTDATETIME sy-vline
WA_PEWMPICNTLIST02_STR-SHELFLIFEEXPIRATIONDATE sy-vline
WA_PEWMPICNTLIST02_STR-COUNTRYOFORIGIN sy-vline
WA_PEWMPICNTLIST02_STR-PINVITEMPARENTUUID sy-vline
WA_PEWMPICNTLIST02_STR-PINVITEMPARENTTYPE sy-vline
WA_PEWMPICNTLIST02_STR-PHYSICALINVENTORYSTOCKUUID sy-vline
WA_PEWMPICNTLIST02_STR-PRODUCTUUID sy-vline
WA_PEWMPICNTLIST02_STR-BATCHUUID sy-vline
WA_PEWMPICNTLIST02_STR-HANDLINGUNITNUMBER sy-vline
WA_PEWMPICNTLIST02_STR-ENTITLEDTODISPOSEPARTY sy-vline
WA_PEWMPICNTLIST02_STR-STOCKOWNER sy-vline
WA_PEWMPICNTLIST02_STR-EWMSTOCKOWNER sy-vline
WA_PEWMPICNTLIST02_STR-STOCKTYPE sy-vline
WA_PEWMPICNTLIST02_STR-EWMSTOCKTYPE sy-vline
WA_PEWMPICNTLIST02_STR-STOCKUSAGE sy-vline
WA_PEWMPICNTLIST02_STR-EWMSTOCKUSAGE sy-vline
WA_PEWMPICNTLIST02_STR-STOCKDOCUMENTCATEGORY sy-vline
WA_PEWMPICNTLIST02_STR-STOCKDOCUMENTNUMBER sy-vline
WA_PEWMPICNTLIST02_STR-STOCKITEMNUMBER sy-vline
WA_PEWMPICNTLIST02_STR-PRODUCEDMATERIAL sy-vline
WA_PEWMPICNTLIST02_STR-WAREHOUSE sy-vline
WA_PEWMPICNTLIST02_STR-EWMWAREHOUSE sy-vline
WA_PEWMPICNTLIST02_STR-PARENTSTORAGEBIN sy-vline
WA_PEWMPICNTLIST02_STR-PARENTHANDLINGUNITNUMBER sy-vline
WA_PEWMPICNTLIST02_STR-BOOKQTYOFPINVITEMINBOOKQTYUOM sy-vline
WA_PEWMPICNTLIST02_STR-BOOKQUANTITYUNITOFMEASURE sy-vline
WA_PEWMPICNTLIST02_STR-CHILDLINEIDX sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.