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