ABAP Select data from SAP table /SCWM/S_TO_PREPARE_WHR_INT 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_TO_PREPARE_WHR_INT 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_TO_PREPARE_WHR_INT. 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_TO_PREPARE_WHR_INT 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_TO_PREPARE_WHR_INT TYPE STANDARD TABLE OF /SCWM/S_TO_PREPARE_WHR_INT, WA_/SCWM/S_TO_PREPARE_WHR_INT TYPE /SCWM/S_TO_PREPARE_WHR_INT, 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_TO_PREPARE_WHR_INT> TYPE /SCWM/S_TO_PREPARE_WHR_INT. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/SCWM/S_TO_PREPARE_WHR_INT. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /SCWM/S_TO_PREPARE_WHR_INT INTO TABLE IT_/SCWM/S_TO_PREPARE_WHR_INT. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /SCWM/S_TO_PREPARE_WHR_INT * INTO TABLE @DATA(IT_/SCWM/S_TO_PREPARE_WHR_INT2). *--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_TO_PREPARE_WHR_INT INDEX 1 INTO DATA(WA_/SCWM/S_TO_PREPARE_WHR_INT2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/SCWM/S_TO_PREPARE_WHR_INT ASSIGNING </SCWM/S_TO_PREPARE_WHR_INT>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</SCWM/S_TO_PREPARE_WHR_INT>-RDOCCAT = 1.
</SCWM/S_TO_PREPARE_WHR_INT>-RDOCID = 1.
</SCWM/S_TO_PREPARE_WHR_INT>-RITMID = 1.
</SCWM/S_TO_PREPARE_WHR_INT>-GUID_TO = 1.
</SCWM/S_TO_PREPARE_WHR_INT>-REASON = 1.
ENDLOOP. LOOP AT IT_/SCWM/S_TO_PREPARE_WHR_INT INTO WA_/SCWM/S_TO_PREPARE_WHR_INT. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/SCWM/S_TO_PREPARE_WHR_INT-SQUIT, sy-vline,
WA_/SCWM/S_TO_PREPARE_WHR_INT-NOROU, sy-vline,
WA_/SCWM/S_TO_PREPARE_WHR_INT-MVE_MAT, sy-vline,
WA_/SCWM/S_TO_PREPARE_WHR_INT-ANFME, sy-vline,
WA_/SCWM/S_TO_PREPARE_WHR_INT-ALTME, sy-vline,
WA_/SCWM/S_TO_PREPARE_WHR_INT-OPUNIT, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/SCWM/S_TO_PREPARE_WHR_INT 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_TO_PREPARE_WHR_INT 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_TO_PREPARE_WHR_INT INTO WA_/SCWM/S_TO_PREPARE_WHR_INT. *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 ALTME CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-ALTME IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-ALTME.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field OPUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-OPUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-OPUNIT.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field VLENR CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-VLENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-VLENR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field STU_NUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-STU_NUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-STU_NUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSPWM, internal->external for field STSP CALL FUNCTION 'CONVERSION_EXIT_TSPWM_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-STSP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-STSP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit HUID, internal->external for field NLENR CALL FUNCTION 'CONVERSION_EXIT_HUID_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-NLENR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-NLENR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DTU_NUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-DTU_NUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-DTU_NUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit TSPWM, internal->external for field DTSP CALL FUNCTION 'CONVERSION_EXIT_TSPWM_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-DTSP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-DTSP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPH0, internal->external for field WAVE CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-WAVE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-WAVE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPH0, internal->external for field WAVE_ITM CALL FUNCTION 'CONVERSION_EXIT_ALPH0_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-WAVE_ITM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-WAVE_ITM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field RUOM CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-RUOM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-RUOM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MDLPD, internal->external for field MATID CALL FUNCTION 'CONVERSION_EXIT_MDLPD_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-MATID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-MATID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit BPMAP, internal->external for field OWNER CALL FUNCTION 'CONVERSION_EXIT_BPMAP_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-OWNER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-OWNER.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field ENTITLED CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/SCWM/S_TO_PREPARE_WHR_INT-ENTITLED IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/SCWM/S_TO_PREPARE_WHR_INT-ENTITLED.
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_TO_PREPARE_WHR_INT_STR,
RDOCCAT TYPE STRING,
RDOCID TYPE STRING,
RITMID TYPE STRING,
GUID_TO TYPE STRING,
REASON TYPE STRING,
SQUIT TYPE STRING,
NOROU TYPE STRING,
MVE_MAT TYPE STRING,
ANFME TYPE STRING,
ALTME TYPE STRING,
OPUNIT TYPE STRING,
HUTYP TYPE STRING,
VLTYP TYPE STRING,
VLTYPG TYPE STRING,
VLBER TYPE STRING,
VLPLA TYPE STRING,
VLENR TYPE STRING,
SGUID_HU TYPE STRING,
STU_NUM TYPE STRING,
STU_NUM_EXT TYPE STRING,
STSP TYPE STRING,
NLTYP TYPE STRING,
NLTYPG TYPE STRING,
NLBER TYPE STRING,
NLPLA TYPE STRING,
NLENR TYPE STRING,
DGUID_HU TYPE STRING,
DTU_NUM TYPE STRING,
DTU_NUM_EXT TYPE STRING,
DTSP TYPE STRING,
WAVE TYPE STRING,
WAVE_ITM TYPE STRING,
WAVECAT TYPE STRING,
L2SKA TYPE STRING,
SATIND TYPE STRING,
SEQNO TYPE STRING,
SINGLE_TO TYPE STRING,
FULL_PICK TYPE STRING,
SPLIT_ID TYPE STRING,
RUOM TYPE STRING,
MATID TYPE STRING,
BATCHID TYPE STRING,
CAT TYPE STRING,
STOCK_DOCCAT TYPE STRING,
STOCK_DOCNO TYPE STRING,
STOCK_ITMNO TYPE STRING,
DOCCAT TYPE STRING,
STOCK_USAGE TYPE STRING,
OWNER TYPE STRING,
OWNER_ROLE TYPE STRING,
ENTITLED TYPE STRING,
ENTITLED_ROLE TYPE STRING,
STOCK_CNT TYPE STRING,
INSPID TYPE STRING,
INSPTYP TYPE STRING,
IDPLATE TYPE STRING,
NO_STOCK_DET TYPE STRING,
JIT_RELEVANCE TYPE STRING,
MES_IND TYPE STRING,
PRCES TYPE STRING,
PROCS TYPE STRING,
INACTIV TYPE STRING,
PICK_COMP_DT TYPE STRING,END OF T_EKKO_STR. DATA: WA_/SCWM/S_TO_PREPARE_WHR_INT_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_TO_PREPARE_WHR_INT_STR-RDOCCAT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-RDOCID sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-RITMID sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-GUID_TO sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-REASON sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-SQUIT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NOROU sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-MVE_MAT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-ANFME sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-ALTME sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-OPUNIT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-HUTYP sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-VLTYP sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-VLTYPG sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-VLBER sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-VLPLA sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-VLENR sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-SGUID_HU sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STU_NUM sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STU_NUM_EXT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STSP sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NLTYP sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NLTYPG sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NLBER sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NLPLA sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NLENR sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-DGUID_HU sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-DTU_NUM sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-DTU_NUM_EXT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-DTSP sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-WAVE sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-WAVE_ITM sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-WAVECAT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-L2SKA sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-SATIND sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-SEQNO sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-SINGLE_TO sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-FULL_PICK sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-SPLIT_ID sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-RUOM sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-MATID sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-BATCHID sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-CAT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STOCK_DOCCAT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STOCK_DOCNO sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STOCK_ITMNO sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-DOCCAT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STOCK_USAGE sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-OWNER sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-OWNER_ROLE sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-ENTITLED sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-ENTITLED_ROLE sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-STOCK_CNT sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-INSPID sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-INSPTYP sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-IDPLATE sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-NO_STOCK_DET sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-JIT_RELEVANCE sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-MES_IND sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-PRCES sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-PROCS sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-INACTIV sy-vline
WA_/SCWM/S_TO_PREPARE_WHR_INT_STR-PICK_COMP_DT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.