ABAP Select data from SAP table UMB_S_DATA 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 UMB_S_DATA 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 UMB_S_DATA. 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 UMB_S_DATA 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_UMB_S_DATA TYPE STANDARD TABLE OF UMB_S_DATA,
      WA_UMB_S_DATA TYPE UMB_S_DATA,
      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: <UMB_S_DATA> TYPE UMB_S_DATA.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM UMB_S_DATA
*  INTO TABLE @DATA(IT_UMB_S_DATA2).
*--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_UMB_S_DATA INDEX 1 INTO DATA(WA_UMB_S_DATA2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_UMB_S_DATA ASSIGNING <UMB_S_DATA>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<UMB_S_DATA>-PERIOD = 1.
<UMB_S_DATA>-TREND = 1.
<UMB_S_DATA>-SCORE = 1.
<UMB_S_DATA>-STATUS = 1.
<UMB_S_DATA>-UNIT = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_UMB_S_DATA-VAL01, sy-vline,
WA_UMB_S_DATA-VAL01_FORMATED, sy-vline,
WA_UMB_S_DATA-VAL02, sy-vline,
WA_UMB_S_DATA-VAL02_FORMATED, sy-vline,
WA_UMB_S_DATA-VAL03, sy-vline,
WA_UMB_S_DATA-VAL03_FORMATED, sy-vline.
ENDLOOP. *Add any further fields from structure WA_UMB_S_DATA 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_UMB_S_DATA 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_UMB_S_DATA INTO WA_UMB_S_DATA. *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_UMB_S_DATA_STR,
PERIOD TYPE STRING,
TREND TYPE STRING,
SCORE TYPE STRING,
STATUS TYPE STRING,
UNIT TYPE STRING,
VAL01 TYPE STRING,
VAL01_FORMATED TYPE STRING,
VAL02 TYPE STRING,
VAL02_FORMATED TYPE STRING,
VAL03 TYPE STRING,
VAL03_FORMATED TYPE STRING,
VAL04 TYPE STRING,
VAL04_FORMATED TYPE STRING,
VAL05 TYPE STRING,
VAL05_FORMATED TYPE STRING,
VAL06 TYPE STRING,
VAL06_FORMATED TYPE STRING,
VAL07 TYPE STRING,
VAL07_FORMATED TYPE STRING,
VAL08 TYPE STRING,
VAL08_FORMATED TYPE STRING,
VAL09 TYPE STRING,
VAL09_FORMATED TYPE STRING,
VAL10 TYPE STRING,
VAL10_FORMATED TYPE STRING,
VAL11 TYPE STRING,
VAL11_FORMATED TYPE STRING,
VAL12 TYPE STRING,
VAL12_FORMATED TYPE STRING,
VAL13 TYPE STRING,
VAL13_FORMATED TYPE STRING,
VAL14 TYPE STRING,
VAL14_FORMATED TYPE STRING,
VAL15 TYPE STRING,
VAL15_FORMATED TYPE STRING,
VAL16 TYPE STRING,
VAL16_FORMATED TYPE STRING,
VAL17 TYPE STRING,
VAL17_FORMATED TYPE STRING,
VAL18 TYPE STRING,
VAL18_FORMATED TYPE STRING,
VAL19 TYPE STRING,
VAL19_FORMATED TYPE STRING,
VAL20 TYPE STRING,
VAL20_FORMATED TYPE STRING,
VAL21 TYPE STRING,
VAL21_FORMATED TYPE STRING,
VAL22 TYPE STRING,
VAL22_FORMATED TYPE STRING,
VAL23 TYPE STRING,
VAL23_FORMATED TYPE STRING,
VAL24 TYPE STRING,
VAL24_FORMATED TYPE STRING,
VAL25 TYPE STRING,
VAL25_FORMATED TYPE STRING,END OF T_EKKO_STR. DATA: WA_UMB_S_DATA_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_UMB_S_DATA_STR-PERIOD sy-vline
WA_UMB_S_DATA_STR-TREND sy-vline
WA_UMB_S_DATA_STR-SCORE sy-vline
WA_UMB_S_DATA_STR-STATUS sy-vline
WA_UMB_S_DATA_STR-UNIT sy-vline
WA_UMB_S_DATA_STR-VAL01 sy-vline
WA_UMB_S_DATA_STR-VAL01_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL02 sy-vline
WA_UMB_S_DATA_STR-VAL02_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL03 sy-vline
WA_UMB_S_DATA_STR-VAL03_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL04 sy-vline
WA_UMB_S_DATA_STR-VAL04_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL05 sy-vline
WA_UMB_S_DATA_STR-VAL05_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL06 sy-vline
WA_UMB_S_DATA_STR-VAL06_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL07 sy-vline
WA_UMB_S_DATA_STR-VAL07_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL08 sy-vline
WA_UMB_S_DATA_STR-VAL08_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL09 sy-vline
WA_UMB_S_DATA_STR-VAL09_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL10 sy-vline
WA_UMB_S_DATA_STR-VAL10_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL11 sy-vline
WA_UMB_S_DATA_STR-VAL11_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL12 sy-vline
WA_UMB_S_DATA_STR-VAL12_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL13 sy-vline
WA_UMB_S_DATA_STR-VAL13_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL14 sy-vline
WA_UMB_S_DATA_STR-VAL14_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL15 sy-vline
WA_UMB_S_DATA_STR-VAL15_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL16 sy-vline
WA_UMB_S_DATA_STR-VAL16_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL17 sy-vline
WA_UMB_S_DATA_STR-VAL17_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL18 sy-vline
WA_UMB_S_DATA_STR-VAL18_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL19 sy-vline
WA_UMB_S_DATA_STR-VAL19_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL20 sy-vline
WA_UMB_S_DATA_STR-VAL20_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL21 sy-vline
WA_UMB_S_DATA_STR-VAL21_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL22 sy-vline
WA_UMB_S_DATA_STR-VAL22_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL23 sy-vline
WA_UMB_S_DATA_STR-VAL23_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL24 sy-vline
WA_UMB_S_DATA_STR-VAL24_FORMATED sy-vline
WA_UMB_S_DATA_STR-VAL25 sy-vline
WA_UMB_S_DATA_STR-VAL25_FORMATED sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.