ABAP Select data from SAP table CVS_MVSE 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 CVS_MVSE 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 CVS_MVSE. 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 CVS_MVSE 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_CVS_MVSE TYPE STANDARD TABLE OF CVS_MVSE, WA_CVS_MVSE TYPE CVS_MVSE, 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: <CVS_MVSE> TYPE CVS_MVSE. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_CVS_MVSE. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM CVS_MVSE INTO TABLE IT_CVS_MVSE. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM CVS_MVSE * INTO TABLE @DATA(IT_CVS_MVSE2). *--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_CVS_MVSE INDEX 1 INTO DATA(WA_CVS_MVSE2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_CVS_MVSE ASSIGNING <CVS_MVSE>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<CVS_MVSE>-SELKEY = 1.
<CVS_MVSE>-DF_VIEW = 1.
<CVS_MVSE>-GREEN = 1.
<CVS_MVSE>-YELLOW = 1.
<CVS_MVSE>-RED = 1.
ENDLOOP. LOOP AT IT_CVS_MVSE INTO WA_CVS_MVSE. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_CVS_MVSE-ADAPT, sy-vline,
WA_CVS_MVSE-TK_VS1, sy-vline,
WA_CVS_MVSE-TK_VS2, sy-vline,
WA_CVS_MVSE-TK_VS3, sy-vline,
WA_CVS_MVSE-BD_VS1, sy-vline,
WA_CVS_MVSE-BD_VS2, sy-vline.
ENDLOOP. *Add any further fields from structure WA_CVS_MVSE 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_CVS_MVSE 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_CVS_MVSE INTO WA_CVS_MVSE. *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.
ENDFORM. *&---------------------------------------------------------------------* *& Form process_as_string_field_values *&---------------------------------------------------------------------* FORM process_as_string_field_values CHANGING p_EKKO LIKE wa_EKKO. TYPES: BEGIN OF T_CVS_MVSE_STR,
SELKEY TYPE STRING,
DF_VIEW TYPE STRING,
GREEN TYPE STRING,
YELLOW TYPE STRING,
RED TYPE STRING,
ADAPT TYPE STRING,
TK_VS1 TYPE STRING,
TK_VS2 TYPE STRING,
TK_VS3 TYPE STRING,
BD_VS1 TYPE STRING,
BD_VS2 TYPE STRING,
CCM_VS1 TYPE STRING,
CCM_VS2 TYPE STRING,
CC_VS1 TYPE STRING,
CC_VS2 TYPE STRING,
OR_VS TYPE STRING,
DR_VS TYPE STRING,
DV_VS TYPE STRING,
H0_VS TYPE STRING,
H1_VS TYPE STRING,
H2_VS TYPE STRING,
H3_VS TYPE STRING,
H4_VS TYPE STRING,
H5_VS TYPE STRING,
H6_VS TYPE STRING,
H7_VS TYPE STRING,
H8_VS TYPE STRING,
H9_VS TYPE STRING,
CO1_FIG TYPE STRING,
RB1_FIG TYPE STRING,
RS_FIG TYPE STRING,
CO2_FIG TYPE STRING,
RB2_FIG TYPE STRING,
TST_FIG TYPE STRING,
UNI_FIG TYPE STRING,
HIS_TR TYPE STRING,
ORGSYS TYPE STRING,
TK_SO1 TYPE STRING,
TK_SO2 TYPE STRING,
TK_SO3 TYPE STRING,
BD_SO1 TYPE STRING,
BD_SO2 TYPE STRING,
CCM_SO1 TYPE STRING,
CCM_SO2 TYPE STRING,
CC_SO1 TYPE STRING,
CC_SO2 TYPE STRING,
OR_SO TYPE STRING,
DR_SO TYPE STRING,
DV_SO TYPE STRING,
H0_SO TYPE STRING,
H1_SO TYPE STRING,
H2_SO TYPE STRING,
H3_SO TYPE STRING,
H4_SO TYPE STRING,
H5_SO TYPE STRING,
H6_SO TYPE STRING,
H7_SO TYPE STRING,
H8_SO TYPE STRING,
H9_SO TYPE STRING,END OF T_EKKO_STR. DATA: WA_CVS_MVSE_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_CVS_MVSE_STR-SELKEY sy-vline
WA_CVS_MVSE_STR-DF_VIEW sy-vline
WA_CVS_MVSE_STR-GREEN sy-vline
WA_CVS_MVSE_STR-YELLOW sy-vline
WA_CVS_MVSE_STR-RED sy-vline
WA_CVS_MVSE_STR-ADAPT sy-vline
WA_CVS_MVSE_STR-TK_VS1 sy-vline
WA_CVS_MVSE_STR-TK_VS2 sy-vline
WA_CVS_MVSE_STR-TK_VS3 sy-vline
WA_CVS_MVSE_STR-BD_VS1 sy-vline
WA_CVS_MVSE_STR-BD_VS2 sy-vline
WA_CVS_MVSE_STR-CCM_VS1 sy-vline
WA_CVS_MVSE_STR-CCM_VS2 sy-vline
WA_CVS_MVSE_STR-CC_VS1 sy-vline
WA_CVS_MVSE_STR-CC_VS2 sy-vline
WA_CVS_MVSE_STR-OR_VS sy-vline
WA_CVS_MVSE_STR-DR_VS sy-vline
WA_CVS_MVSE_STR-DV_VS sy-vline
WA_CVS_MVSE_STR-H0_VS sy-vline
WA_CVS_MVSE_STR-H1_VS sy-vline
WA_CVS_MVSE_STR-H2_VS sy-vline
WA_CVS_MVSE_STR-H3_VS sy-vline
WA_CVS_MVSE_STR-H4_VS sy-vline
WA_CVS_MVSE_STR-H5_VS sy-vline
WA_CVS_MVSE_STR-H6_VS sy-vline
WA_CVS_MVSE_STR-H7_VS sy-vline
WA_CVS_MVSE_STR-H8_VS sy-vline
WA_CVS_MVSE_STR-H9_VS sy-vline
WA_CVS_MVSE_STR-CO1_FIG sy-vline
WA_CVS_MVSE_STR-RB1_FIG sy-vline
WA_CVS_MVSE_STR-RS_FIG sy-vline
WA_CVS_MVSE_STR-CO2_FIG sy-vline
WA_CVS_MVSE_STR-RB2_FIG sy-vline
WA_CVS_MVSE_STR-TST_FIG sy-vline
WA_CVS_MVSE_STR-UNI_FIG sy-vline
WA_CVS_MVSE_STR-HIS_TR sy-vline
WA_CVS_MVSE_STR-ORGSYS sy-vline
WA_CVS_MVSE_STR-TK_SO1 sy-vline
WA_CVS_MVSE_STR-TK_SO2 sy-vline
WA_CVS_MVSE_STR-TK_SO3 sy-vline
WA_CVS_MVSE_STR-BD_SO1 sy-vline
WA_CVS_MVSE_STR-BD_SO2 sy-vline
WA_CVS_MVSE_STR-CCM_SO1 sy-vline
WA_CVS_MVSE_STR-CCM_SO2 sy-vline
WA_CVS_MVSE_STR-CC_SO1 sy-vline
WA_CVS_MVSE_STR-CC_SO2 sy-vline
WA_CVS_MVSE_STR-OR_SO sy-vline
WA_CVS_MVSE_STR-DR_SO sy-vline
WA_CVS_MVSE_STR-DV_SO sy-vline
WA_CVS_MVSE_STR-H0_SO sy-vline
WA_CVS_MVSE_STR-H1_SO sy-vline
WA_CVS_MVSE_STR-H2_SO sy-vline
WA_CVS_MVSE_STR-H3_SO sy-vline
WA_CVS_MVSE_STR-H4_SO sy-vline
WA_CVS_MVSE_STR-H5_SO sy-vline
WA_CVS_MVSE_STR-H6_SO sy-vline
WA_CVS_MVSE_STR-H7_SO sy-vline
WA_CVS_MVSE_STR-H8_SO sy-vline
WA_CVS_MVSE_STR-H9_SO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.