ABAP Select data from SAP table V_T7RUGB 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 V_T7RUGB 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 V_T7RUGB. 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 V_T7RUGB 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_V_T7RUGB TYPE STANDARD TABLE OF V_T7RUGB,
      WA_V_T7RUGB TYPE V_T7RUGB,
      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: <V_T7RUGB> TYPE V_T7RUGB.

*Process all fields in table header/work area as string values
  PERFORM process_as_string_field_values CHANGING wa_V_T7RUGB.

SELECT *
*restrict ABAP select to first 10 rows
 UP TO 10 ROWS      
  FROM V_T7RUGB
  INTO TABLE IT_V_T7RUGB.

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM V_T7RUGB
*  INTO TABLE @DATA(IT_V_T7RUGB2).
*--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_V_T7RUGB INDEX 1 INTO DATA(WA_V_T7RUGB2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_V_T7RUGB ASSIGNING <V_T7RUGB>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<V_T7RUGB>-MANDT = 1.
<V_T7RUGB>-MOLGA = 1.
<V_T7RUGB>-LAND1 = 1.
<V_T7RUGB>-ZLSCH = 1.
<V_T7RUGB>-CODTS = 1.
ENDLOOP.

LOOP AT IT_V_T7RUGB INTO WA_V_T7RUGB.
*Write horizonal line to screen report.
  WRITE:/ sy-uline.

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_V_T7RUGB-ENDDA, sy-vline,
WA_V_T7RUGB-BEGDA, sy-vline,
WA_V_T7RUGB-VALE01, sy-vline,
WA_V_T7RUGB-PRZN01, sy-vline,
WA_V_T7RUGB-VALR01, sy-vline,
WA_V_T7RUGB-VALS01, sy-vline.
ENDLOOP. *Add any further fields from structure WA_V_T7RUGB 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_V_T7RUGB 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_V_T7RUGB INTO WA_V_T7RUGB. *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_V_T7RUGB_STR,
MANDT TYPE STRING,
MOLGA TYPE STRING,
LAND1 TYPE STRING,
ZLSCH TYPE STRING,
CODTS TYPE STRING,
ENDDA TYPE STRING,
BEGDA TYPE STRING,
VALE01 TYPE STRING,
PRZN01 TYPE STRING,
VALR01 TYPE STRING,
VALS01 TYPE STRING,
VALM01 TYPE STRING,
VALE02 TYPE STRING,
PRZN02 TYPE STRING,
VALR02 TYPE STRING,
VALS02 TYPE STRING,
VALE03 TYPE STRING,
PRZN03 TYPE STRING,
VALR03 TYPE STRING,
VALS03 TYPE STRING,
VALE04 TYPE STRING,
PRZN04 TYPE STRING,
VALR04 TYPE STRING,
VALS04 TYPE STRING,
VALE05 TYPE STRING,
PRZN05 TYPE STRING,
VALR05 TYPE STRING,
VALS05 TYPE STRING,
VALE06 TYPE STRING,
PRZN06 TYPE STRING,
VALR06 TYPE STRING,
VALS06 TYPE STRING,
VALE07 TYPE STRING,
PRZN07 TYPE STRING,
VALR07 TYPE STRING,
VALS07 TYPE STRING,
VALE08 TYPE STRING,
PRZN08 TYPE STRING,
VALR08 TYPE STRING,
VALS08 TYPE STRING,
VALE09 TYPE STRING,
PRZN09 TYPE STRING,
VALR09 TYPE STRING,
VALS09 TYPE STRING,
VALE10 TYPE STRING,
PRZN10 TYPE STRING,
VALR10 TYPE STRING,
VALS10 TYPE STRING,
LGART TYPE STRING,END OF T_EKKO_STR. DATA: WA_V_T7RUGB_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_V_T7RUGB_STR-MANDT sy-vline
WA_V_T7RUGB_STR-MOLGA sy-vline
WA_V_T7RUGB_STR-LAND1 sy-vline
WA_V_T7RUGB_STR-ZLSCH sy-vline
WA_V_T7RUGB_STR-CODTS sy-vline
WA_V_T7RUGB_STR-ENDDA sy-vline
WA_V_T7RUGB_STR-BEGDA sy-vline
WA_V_T7RUGB_STR-VALE01 sy-vline
WA_V_T7RUGB_STR-PRZN01 sy-vline
WA_V_T7RUGB_STR-VALR01 sy-vline
WA_V_T7RUGB_STR-VALS01 sy-vline
WA_V_T7RUGB_STR-VALM01 sy-vline
WA_V_T7RUGB_STR-VALE02 sy-vline
WA_V_T7RUGB_STR-PRZN02 sy-vline
WA_V_T7RUGB_STR-VALR02 sy-vline
WA_V_T7RUGB_STR-VALS02 sy-vline
WA_V_T7RUGB_STR-VALE03 sy-vline
WA_V_T7RUGB_STR-PRZN03 sy-vline
WA_V_T7RUGB_STR-VALR03 sy-vline
WA_V_T7RUGB_STR-VALS03 sy-vline
WA_V_T7RUGB_STR-VALE04 sy-vline
WA_V_T7RUGB_STR-PRZN04 sy-vline
WA_V_T7RUGB_STR-VALR04 sy-vline
WA_V_T7RUGB_STR-VALS04 sy-vline
WA_V_T7RUGB_STR-VALE05 sy-vline
WA_V_T7RUGB_STR-PRZN05 sy-vline
WA_V_T7RUGB_STR-VALR05 sy-vline
WA_V_T7RUGB_STR-VALS05 sy-vline
WA_V_T7RUGB_STR-VALE06 sy-vline
WA_V_T7RUGB_STR-PRZN06 sy-vline
WA_V_T7RUGB_STR-VALR06 sy-vline
WA_V_T7RUGB_STR-VALS06 sy-vline
WA_V_T7RUGB_STR-VALE07 sy-vline
WA_V_T7RUGB_STR-PRZN07 sy-vline
WA_V_T7RUGB_STR-VALR07 sy-vline
WA_V_T7RUGB_STR-VALS07 sy-vline
WA_V_T7RUGB_STR-VALE08 sy-vline
WA_V_T7RUGB_STR-PRZN08 sy-vline
WA_V_T7RUGB_STR-VALR08 sy-vline
WA_V_T7RUGB_STR-VALS08 sy-vline
WA_V_T7RUGB_STR-VALE09 sy-vline
WA_V_T7RUGB_STR-PRZN09 sy-vline
WA_V_T7RUGB_STR-VALR09 sy-vline
WA_V_T7RUGB_STR-VALS09 sy-vline
WA_V_T7RUGB_STR-VALE10 sy-vline
WA_V_T7RUGB_STR-PRZN10 sy-vline
WA_V_T7RUGB_STR-VALR10 sy-vline
WA_V_T7RUGB_STR-VALS10 sy-vline
WA_V_T7RUGB_STR-LGART sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.