ABAP Select data from SAP table PLM_MAT_SEARCH 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 PLM_MAT_SEARCH 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 PLM_MAT_SEARCH. 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 PLM_MAT_SEARCH 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_PLM_MAT_SEARCH TYPE STANDARD TABLE OF PLM_MAT_SEARCH, WA_PLM_MAT_SEARCH TYPE PLM_MAT_SEARCH, 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: <PLM_MAT_SEARCH> TYPE PLM_MAT_SEARCH. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_PLM_MAT_SEARCH. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM PLM_MAT_SEARCH INTO TABLE IT_PLM_MAT_SEARCH. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM PLM_MAT_SEARCH * INTO TABLE @DATA(IT_PLM_MAT_SEARCH2). *--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_PLM_MAT_SEARCH INDEX 1 INTO DATA(WA_PLM_MAT_SEARCH2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_PLM_MAT_SEARCH ASSIGNING <PLM_MAT_SEARCH>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<PLM_MAT_SEARCH>-PARENT = 1.
<PLM_MAT_SEARCH>-OBJKEY = 1.
<PLM_MAT_SEARCH>-OBJTYPE = 1.
<PLM_MAT_SEARCH>-LOGSYS = 1.
<PLM_MAT_SEARCH>-TEXT = 1.
ENDLOOP. LOOP AT IT_PLM_MAT_SEARCH INTO WA_PLM_MAT_SEARCH. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_PLM_MAT_SEARCH-POSI, sy-vline,
WA_PLM_MAT_SEARCH-TIMESTAMP, sy-vline,
WA_PLM_MAT_SEARCH-MATNR, sy-vline,
WA_PLM_MAT_SEARCH-MATL_DESC, sy-vline,
WA_PLM_MAT_SEARCH-OLD_MAT_NO, sy-vline,
WA_PLM_MAT_SEARCH-MATL_TYPE, sy-vline.
ENDLOOP. *Add any further fields from structure WA_PLM_MAT_SEARCH 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_PLM_MAT_SEARCH 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_PLM_MAT_SEARCH INTO WA_PLM_MAT_SEARCH. *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 LOGSYS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-LOGSYS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-LOGSYS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field MATNR CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-MATNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-MATNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BASE_UOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-BASE_UOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-BASE_UOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit EAN11, internal->external for field EAN_UPC CALL FUNCTION 'CONVERSION_EXIT_EAN11_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-EAN_UPC IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-EAN_UPC.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_OF_WT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-UNIT_OF_WT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-UNIT_OF_WT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field VOLUMEUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-VOLUMEUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-VOLUMEUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_DIM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-UNIT_DIM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-UNIT_DIM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MFR_NO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_PLM_MAT_SEARCH-MFR_NO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_PLM_MAT_SEARCH-MFR_NO.
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_PLM_MAT_SEARCH_STR,
PARENT TYPE STRING,
OBJKEY TYPE STRING,
OBJTYPE TYPE STRING,
LOGSYS TYPE STRING,
TEXT TYPE STRING,
POSI TYPE STRING,
TIMESTAMP TYPE STRING,
MATNR TYPE STRING,
MATL_DESC TYPE STRING,
OLD_MAT_NO TYPE STRING,
MATL_TYPE TYPE STRING,
IND_SECTOR TYPE STRING,
DIVISION TYPE STRING,
MATL_GROUP TYPE STRING,
PROD_HIER TYPE STRING,
BASIC_MATL TYPE STRING,
STD_DESCR TYPE STRING,
LAB_DESIGN TYPE STRING,
PROD_MEMO TYPE STRING,
PAGEFORMAT TYPE STRING,
CONTAINER TYPE STRING,
STOR_CONDS TYPE STRING,
TEMP_CONDS TYPE STRING,
BASE_UOM TYPE STRING,
EAN_UPC TYPE STRING,
EAN_CAT TYPE STRING,
SIZE_DIM TYPE STRING,
GROSS_WT TYPE STRING,
NET_WEIGHT TYPE STRING,
UNIT_OF_WT TYPE STRING,
VOLUME TYPE STRING,
VOLUMEUNIT TYPE STRING,
LENGTH TYPE STRING,
WIDTH TYPE STRING,
HEIGHT TYPE STRING,
UNIT_DIM TYPE STRING,
MANU_MAT TYPE STRING,
MFR_NO TYPE STRING,
BASE_UOM_ISO TYPE STRING,
UNIT_OF_WT_ISO TYPE STRING,
VOLUMEUNIT_ISO TYPE STRING,
UNIT_DIM_ISO TYPE STRING,
CREATED_ON TYPE STRING,
CREATED_BY TYPE STRING,
LAST_CHNGE TYPE STRING,
CHANGED_BY TYPE STRING,
MATL_CAT TYPE STRING,
EMPTIESBOM TYPE STRING,
BASIC_MATL_NEW TYPE STRING,
OLD_MAT_NO_LONG TYPE STRING,
MATDES TYPE STRING,END OF T_EKKO_STR. DATA: WA_PLM_MAT_SEARCH_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_PLM_MAT_SEARCH_STR-PARENT sy-vline
WA_PLM_MAT_SEARCH_STR-OBJKEY sy-vline
WA_PLM_MAT_SEARCH_STR-OBJTYPE sy-vline
WA_PLM_MAT_SEARCH_STR-LOGSYS sy-vline
WA_PLM_MAT_SEARCH_STR-TEXT sy-vline
WA_PLM_MAT_SEARCH_STR-POSI sy-vline
WA_PLM_MAT_SEARCH_STR-TIMESTAMP sy-vline
WA_PLM_MAT_SEARCH_STR-MATNR sy-vline
WA_PLM_MAT_SEARCH_STR-MATL_DESC sy-vline
WA_PLM_MAT_SEARCH_STR-OLD_MAT_NO sy-vline
WA_PLM_MAT_SEARCH_STR-MATL_TYPE sy-vline
WA_PLM_MAT_SEARCH_STR-IND_SECTOR sy-vline
WA_PLM_MAT_SEARCH_STR-DIVISION sy-vline
WA_PLM_MAT_SEARCH_STR-MATL_GROUP sy-vline
WA_PLM_MAT_SEARCH_STR-PROD_HIER sy-vline
WA_PLM_MAT_SEARCH_STR-BASIC_MATL sy-vline
WA_PLM_MAT_SEARCH_STR-STD_DESCR sy-vline
WA_PLM_MAT_SEARCH_STR-LAB_DESIGN sy-vline
WA_PLM_MAT_SEARCH_STR-PROD_MEMO sy-vline
WA_PLM_MAT_SEARCH_STR-PAGEFORMAT sy-vline
WA_PLM_MAT_SEARCH_STR-CONTAINER sy-vline
WA_PLM_MAT_SEARCH_STR-STOR_CONDS sy-vline
WA_PLM_MAT_SEARCH_STR-TEMP_CONDS sy-vline
WA_PLM_MAT_SEARCH_STR-BASE_UOM sy-vline
WA_PLM_MAT_SEARCH_STR-EAN_UPC sy-vline
WA_PLM_MAT_SEARCH_STR-EAN_CAT sy-vline
WA_PLM_MAT_SEARCH_STR-SIZE_DIM sy-vline
WA_PLM_MAT_SEARCH_STR-GROSS_WT sy-vline
WA_PLM_MAT_SEARCH_STR-NET_WEIGHT sy-vline
WA_PLM_MAT_SEARCH_STR-UNIT_OF_WT sy-vline
WA_PLM_MAT_SEARCH_STR-VOLUME sy-vline
WA_PLM_MAT_SEARCH_STR-VOLUMEUNIT sy-vline
WA_PLM_MAT_SEARCH_STR-LENGTH sy-vline
WA_PLM_MAT_SEARCH_STR-WIDTH sy-vline
WA_PLM_MAT_SEARCH_STR-HEIGHT sy-vline
WA_PLM_MAT_SEARCH_STR-UNIT_DIM sy-vline
WA_PLM_MAT_SEARCH_STR-MANU_MAT sy-vline
WA_PLM_MAT_SEARCH_STR-MFR_NO sy-vline
WA_PLM_MAT_SEARCH_STR-BASE_UOM_ISO sy-vline
WA_PLM_MAT_SEARCH_STR-UNIT_OF_WT_ISO sy-vline
WA_PLM_MAT_SEARCH_STR-VOLUMEUNIT_ISO sy-vline
WA_PLM_MAT_SEARCH_STR-UNIT_DIM_ISO sy-vline
WA_PLM_MAT_SEARCH_STR-CREATED_ON sy-vline
WA_PLM_MAT_SEARCH_STR-CREATED_BY sy-vline
WA_PLM_MAT_SEARCH_STR-LAST_CHNGE sy-vline
WA_PLM_MAT_SEARCH_STR-CHANGED_BY sy-vline
WA_PLM_MAT_SEARCH_STR-MATL_CAT sy-vline
WA_PLM_MAT_SEARCH_STR-EMPTIESBOM sy-vline
WA_PLM_MAT_SEARCH_STR-BASIC_MATL_NEW sy-vline
WA_PLM_MAT_SEARCH_STR-OLD_MAT_NO_LONG sy-vline
WA_PLM_MAT_SEARCH_STR-MATDES sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.