ABAP Select data from SAP table MSR_S_PRINT_VBDPA 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 MSR_S_PRINT_VBDPA 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 MSR_S_PRINT_VBDPA. 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 MSR_S_PRINT_VBDPA 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_MSR_S_PRINT_VBDPA TYPE STANDARD TABLE OF MSR_S_PRINT_VBDPA, WA_MSR_S_PRINT_VBDPA TYPE MSR_S_PRINT_VBDPA, 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: <MSR_S_PRINT_VBDPA> TYPE MSR_S_PRINT_VBDPA. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_MSR_S_PRINT_VBDPA. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM MSR_S_PRINT_VBDPA INTO TABLE IT_MSR_S_PRINT_VBDPA. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM MSR_S_PRINT_VBDPA * INTO TABLE @DATA(IT_MSR_S_PRINT_VBDPA2). *--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_MSR_S_PRINT_VBDPA INDEX 1 INTO DATA(WA_MSR_S_PRINT_VBDPA2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_MSR_S_PRINT_VBDPA ASSIGNING <MSR_S_PRINT_VBDPA>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<MSR_S_PRINT_VBDPA>-MSR_ID = 1.
<MSR_S_PRINT_VBDPA>-MSR_ITEM = 1.
<MSR_S_PRINT_VBDPA>-RMA_CUSTOMER = 1.
<MSR_S_PRINT_VBDPA>-MSR_RET_REASON = 1.
<MSR_S_PRINT_VBDPA>-MSR_RET_REASON_TEXT = 1.
ENDLOOP. LOOP AT IT_MSR_S_PRINT_VBDPA INTO WA_MSR_S_PRINT_VBDPA. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_MSR_S_PRINT_VBDPA-MSR_MAT_RECEIVED, sy-vline,
WA_MSR_S_PRINT_VBDPA-MSR_FU_CODE, sy-vline,
WA_MSR_S_PRINT_VBDPA-MSR_FU_CODE_TEXT, sy-vline,
WA_MSR_S_PRINT_VBDPA-MSR_FORW_VENDOR, sy-vline,
WA_MSR_S_PRINT_VBDPA-MSR_FWV_TITLE, sy-vline,
WA_MSR_S_PRINT_VBDPA-MSR_FWV_ADDRNUM, sy-vline.
ENDLOOP. *Add any further fields from structure WA_MSR_S_PRINT_VBDPA 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_MSR_S_PRINT_VBDPA 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_MSR_S_PRINT_VBDPA INTO WA_MSR_S_PRINT_VBDPA. *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 MSR_ID CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_ID IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_ID.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MSR_FORW_VENDOR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_FORW_VENDOR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_FORW_VENDOR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MSR_FWV_ADDRNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_FWV_ADDRNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_FWV_ADDRNUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MSR_FWV_CITY_CODE2 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_FWV_CITY_CODE2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_FWV_CITY_CODE2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field MSR_FWV_LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_FWV_LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_FWV_LANGU.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MSR_DDA_ADDRNUM CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_DDA_ADDRNUM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_DDA_ADDRNUM.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field MSR_DDA_CITY_CODE2 CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_DDA_CITY_CODE2 IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_DDA_CITY_CODE2.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field MSR_DDA_LANGU CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_MSR_S_PRINT_VBDPA-MSR_DDA_LANGU IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_MSR_S_PRINT_VBDPA-MSR_DDA_LANGU.
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_MSR_S_PRINT_VBDPA_STR,
MSR_ID TYPE STRING,
MSR_ITEM TYPE STRING,
RMA_CUSTOMER TYPE STRING,
MSR_RET_REASON TYPE STRING,
MSR_RET_REASON_TEXT TYPE STRING,
MSR_MAT_RECEIVED TYPE STRING,
MSR_FU_CODE TYPE STRING,
MSR_FU_CODE_TEXT TYPE STRING,
MSR_FORW_VENDOR TYPE STRING,
MSR_FWV_TITLE TYPE STRING,
MSR_FWV_ADDRNUM TYPE STRING,
MSR_FWV_NAME1 TYPE STRING,
MSR_FWV_NAME2 TYPE STRING,
MSR_FWV_NAME3 TYPE STRING,
MSR_FWV_NAME4 TYPE STRING,
MSR_FWV_STREET TYPE STRING,
MSR_FWV_PO_BOX TYPE STRING,
MSR_FWV_PO_BOX_LOC TYPE STRING,
MSR_FWV_CITY_CODE2 TYPE STRING,
MSR_FWV_COUNTRY TYPE STRING,
MSR_FWV_LANGU TYPE STRING,
MSR_FWV_POST_CODE1 TYPE STRING,
MSR_FWV_CITY1 TYPE STRING,
MSR_FWV_CITY2 TYPE STRING,
MSR_FWV_REGION TYPE STRING,
MSR_DDA_TITLE TYPE STRING,
MSR_DDA_ADDRNUM TYPE STRING,
MSR_DDA_NAME1 TYPE STRING,
MSR_DDA_NAME2 TYPE STRING,
MSR_DDA_NAME3 TYPE STRING,
MSR_DDA_NAME4 TYPE STRING,
MSR_DDA_STREET TYPE STRING,
MSR_DDA_PO_BOX TYPE STRING,
MSR_DDA_PO_BOX_LOC TYPE STRING,
MSR_DDA_CITY_CODE2 TYPE STRING,
MSR_DDA_COUNTRY TYPE STRING,
MSR_DDA_LANGU TYPE STRING,
MSR_DDA_POST_CODE1 TYPE STRING,
MSR_DDA_CITY1 TYPE STRING,
MSR_DDA_CITY2 TYPE STRING,
MSR_DDA_REGION TYPE STRING,
RMA_VENDOR TYPE STRING,
MSR_INSP_CODE TYPE STRING,
MSR_INSP_CODE_TX TYPE STRING,
INSPECTION_CODE_FTEXT1 TYPE STRING,
INSPECTION_CODE_FTEXT2 TYPE STRING,
INSPECTION_CODE_FTEXT3 TYPE STRING,
INSPECTION_CODE_FTEXT4 TYPE STRING,
AT_CUSTOMER_SITE TYPE STRING,
MSR_REFUND_CODE TYPE STRING,
MSR_REFUND_CODE_TEXT TYPE STRING,
MSR_FORW_PLANT1 TYPE STRING,
MSR_PLANT1_TXT TYPE STRING,
MSR_FORW_PLANT2 TYPE STRING,
MSR_PLANT2_TXT TYPE STRING,
MSR_FORW_PLANT3 TYPE STRING,
MSR_PLANT3_TXT TYPE STRING,END OF T_EKKO_STR. DATA: WA_MSR_S_PRINT_VBDPA_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_MSR_S_PRINT_VBDPA_STR-MSR_ID sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_ITEM sy-vline
WA_MSR_S_PRINT_VBDPA_STR-RMA_CUSTOMER sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_RET_REASON sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_RET_REASON_TEXT sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_MAT_RECEIVED sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FU_CODE sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FU_CODE_TEXT sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FORW_VENDOR sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_TITLE sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_ADDRNUM sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_NAME1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_NAME2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_NAME3 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_NAME4 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_STREET sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_PO_BOX sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_PO_BOX_LOC sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_CITY_CODE2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_COUNTRY sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_LANGU sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_POST_CODE1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_CITY1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_CITY2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FWV_REGION sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_TITLE sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_ADDRNUM sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_NAME1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_NAME2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_NAME3 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_NAME4 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_STREET sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_PO_BOX sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_PO_BOX_LOC sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_CITY_CODE2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_COUNTRY sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_LANGU sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_POST_CODE1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_CITY1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_CITY2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_DDA_REGION sy-vline
WA_MSR_S_PRINT_VBDPA_STR-RMA_VENDOR sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_INSP_CODE sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_INSP_CODE_TX sy-vline
WA_MSR_S_PRINT_VBDPA_STR-INSPECTION_CODE_FTEXT1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-INSPECTION_CODE_FTEXT2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-INSPECTION_CODE_FTEXT3 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-INSPECTION_CODE_FTEXT4 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-AT_CUSTOMER_SITE sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_REFUND_CODE sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_REFUND_CODE_TEXT sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FORW_PLANT1 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_PLANT1_TXT sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FORW_PLANT2 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_PLANT2_TXT sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_FORW_PLANT3 sy-vline
WA_MSR_S_PRINT_VBDPA_STR-MSR_PLANT3_TXT sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.