ABAP Select data from SAP table /SCWM/S_SCRAP_HU 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 /SCWM/S_SCRAP_HU 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 /SCWM/S_SCRAP_HU. 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 /SCWM/S_SCRAP_HU 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_/SCWM/S_SCRAP_HU TYPE STANDARD TABLE OF /SCWM/S_SCRAP_HU, WA_/SCWM/S_SCRAP_HU TYPE /SCWM/S_SCRAP_HU, 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: </SCWM/S_SCRAP_HU> TYPE /SCWM/S_SCRAP_HU. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SCWM/S_SCRAP_HU. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SCWM/S_SCRAP_HU INTO TABLE IT_/SCWM/S_SCRAP_HU. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SCWM/S_SCRAP_HU * INTO TABLE @DATA(IT_/SCWM/S_SCRAP_HU2). *--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_/SCWM/S_SCRAP_HU INDEX 1 INTO DATA(WA_/SCWM/S_SCRAP_HU2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SCWM/S_SCRAP_HU ASSIGNING </SCWM/S_SCRAP_HU>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_SCRAP_HU>-SCRAP_QUANTITY = 1.
</SCWM/S_SCRAP_HU>-UNIT = 1.
</SCWM/S_SCRAP_HU>-LGTYP = 1.
</SCWM/S_SCRAP_HU>-LGNUM = 1.
</SCWM/S_SCRAP_HU>-HUIDENT = 1.
ENDLOOP. LOOP AT IT_/SCWM/S_SCRAP_HU INTO WA_/SCWM/S_SCRAP_HU. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SCWM/S_SCRAP_HU-PMAT, sy-vline,
WA_/SCWM/S_SCRAP_HU-LETYP, sy-vline,
WA_/SCWM/S_SCRAP_HU-HUIDENT_PARENT, sy-vline,
WA_/SCWM/S_SCRAP_HU-HUIDENT_TOP, sy-vline,
WA_/SCWM/S_SCRAP_HU-LGPLA, sy-vline,
WA_/SCWM/S_SCRAP_HU-RSRC, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_SCRAP_HU 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_/SCWM/S_SCRAP_HU 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_/SCWM/S_SCRAP_HU INTO WA_/SCWM/S_SCRAP_HU. *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 CUNIT, internal->external for field UNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field HUIDENT CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-HUIDENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-HUIDENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field PMAT CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-PMAT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-PMAT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field HUIDENT_PARENT CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-HUIDENT_PARENT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-HUIDENT_PARENT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field HUIDENT_TOP CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-HUIDENT_TOP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-HUIDENT_TOP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field TU_NUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-TU_NUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-TU_NUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field TSP CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-TSP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-TSP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_GW CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT_GW IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT_GW.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_TW CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT_TW IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT_TW.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_GV CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT_GV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT_GV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_TV CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT_TV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT_TV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_LWH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT_LWH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT_LWH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field UNIT_MAX_LWH CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-UNIT_MAX_LWH IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-UNIT_MAX_LWH.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PS_LEVEL_SEQ CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-PS_LEVEL_SEQ IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-PS_LEVEL_SEQ.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field PSA CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_SCRAP_HU-PSA IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_SCRAP_HU-PSA.
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_/SCWM/S_SCRAP_HU_STR,
SCRAP_QUANTITY TYPE STRING,
UNIT TYPE STRING,
LGTYP TYPE STRING,
LGNUM TYPE STRING,
HUIDENT TYPE STRING,
PMAT TYPE STRING,
LETYP TYPE STRING,
HUIDENT_PARENT TYPE STRING,
HUIDENT_TOP TYPE STRING,
LGPLA TYPE STRING,
RSRC TYPE STRING,
TU_NUM TYPE STRING,
TU_NUM_EXT TYPE STRING,
TSP TYPE STRING,
CREATED_BY TYPE STRING,
CREATED_DATE TYPE STRING,
CREATED_TIME TYPE STRING,
CHANGED_BY TYPE STRING,
CHANGED_DATE TYPE STRING,
CHANGED_TIME TYPE STRING,
G_WEIGHT TYPE STRING,
N_WEIGHT TYPE STRING,
UNIT_GW TYPE STRING,
T_WEIGHT TYPE STRING,
UNIT_TW TYPE STRING,
G_VOLUME TYPE STRING,
N_VOLUME TYPE STRING,
UNIT_GV TYPE STRING,
T_VOLUME TYPE STRING,
UNIT_TV TYPE STRING,
G_CAPA TYPE STRING,
N_CAPA TYPE STRING,
T_CAPA TYPE STRING,
LENGTH TYPE STRING,
WIDTH TYPE STRING,
HEIGHT TYPE STRING,
UNIT_LWH TYPE STRING,
MAX_WEIGHT TYPE STRING,
TOLW TYPE STRING,
TARE_VAR TYPE STRING,
MAX_VOLUME TYPE STRING,
TOLV TYPE STRING,
CLOSED_PACKAGE TYPE STRING,
MAX_CAPA TYPE STRING,
MAX_LENGTH TYPE STRING,
MAX_WIDTH TYPE STRING,
MAX_HEIGHT TYPE STRING,
UNIT_MAX_LWH TYPE STRING,
VHI TYPE STRING,
FLGAVQ TYPE STRING,
FLGMOVE TYPE STRING,
PROCS TYPE STRING,
COPST TYPE STRING,
PRCES TYPE STRING,
LOGPOS TYPE STRING,
LOGPOS_EXT TYPE STRING,
DSTGRP TYPE STRING,
WKLID TYPE STRING,
PMTYP TYPE STRING,
PACKGR TYPE STRING,
PHYSTAT TYPE STRING,
TOP TYPE STRING,
BOTTOM TYPE STRING,
STSMA TYPE STRING,
PS_LEVEL_SEQ TYPE STRING,
HZMT TYPE STRING,
PMTEXT TYPE STRING,
PMCAT TYPE STRING,
HUTYPGRP TYPE STRING,
KAPAP TYPE STRING,
HDR_EPC TYPE STRING,
SYSTEM_STATUS TYPE STRING,
USER_STATUS TYPE STRING,
PSA TYPE STRING,
MFS_STOCKTRANS_CNT TYPE STRING,
HU_GUID_EXT TYPE STRING,
NO_ATTACHMENT TYPE STRING,
HUHDR_DUMMY TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_SCRAP_HU_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_/SCWM/S_SCRAP_HU_STR-SCRAP_QUANTITY sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LGTYP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LGNUM sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HUIDENT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PMAT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LETYP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HUIDENT_PARENT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HUIDENT_TOP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LGPLA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-RSRC sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TU_NUM sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TU_NUM_EXT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TSP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CREATED_BY sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CREATED_DATE sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CREATED_TIME sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CHANGED_BY sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CHANGED_DATE sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CHANGED_TIME sy-vline
WA_/SCWM/S_SCRAP_HU_STR-G_WEIGHT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-N_WEIGHT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT_GW sy-vline
WA_/SCWM/S_SCRAP_HU_STR-T_WEIGHT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT_TW sy-vline
WA_/SCWM/S_SCRAP_HU_STR-G_VOLUME sy-vline
WA_/SCWM/S_SCRAP_HU_STR-N_VOLUME sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT_GV sy-vline
WA_/SCWM/S_SCRAP_HU_STR-T_VOLUME sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT_TV sy-vline
WA_/SCWM/S_SCRAP_HU_STR-G_CAPA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-N_CAPA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-T_CAPA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LENGTH sy-vline
WA_/SCWM/S_SCRAP_HU_STR-WIDTH sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HEIGHT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT_LWH sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MAX_WEIGHT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TOLW sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TARE_VAR sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MAX_VOLUME sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TOLV sy-vline
WA_/SCWM/S_SCRAP_HU_STR-CLOSED_PACKAGE sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MAX_CAPA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MAX_LENGTH sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MAX_WIDTH sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MAX_HEIGHT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-UNIT_MAX_LWH sy-vline
WA_/SCWM/S_SCRAP_HU_STR-VHI sy-vline
WA_/SCWM/S_SCRAP_HU_STR-FLGAVQ sy-vline
WA_/SCWM/S_SCRAP_HU_STR-FLGMOVE sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PROCS sy-vline
WA_/SCWM/S_SCRAP_HU_STR-COPST sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PRCES sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LOGPOS sy-vline
WA_/SCWM/S_SCRAP_HU_STR-LOGPOS_EXT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-DSTGRP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-WKLID sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PMTYP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PACKGR sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PHYSTAT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-TOP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-BOTTOM sy-vline
WA_/SCWM/S_SCRAP_HU_STR-STSMA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PS_LEVEL_SEQ sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HZMT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PMTEXT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PMCAT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HUTYPGRP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-KAPAP sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HDR_EPC sy-vline
WA_/SCWM/S_SCRAP_HU_STR-SYSTEM_STATUS sy-vline
WA_/SCWM/S_SCRAP_HU_STR-USER_STATUS sy-vline
WA_/SCWM/S_SCRAP_HU_STR-PSA sy-vline
WA_/SCWM/S_SCRAP_HU_STR-MFS_STOCKTRANS_CNT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HU_GUID_EXT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-NO_ATTACHMENT sy-vline
WA_/SCWM/S_SCRAP_HU_STR-HUHDR_DUMMY sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.