ABAP Select data from SAP table V_VIBDMEASAO_DS 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_VIBDMEASAO_DS 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_VIBDMEASAO_DS. 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_VIBDMEASAO_DS 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_VIBDMEASAO_DS TYPE STANDARD TABLE OF V_VIBDMEASAO_DS,
      WA_V_VIBDMEASAO_DS TYPE V_VIBDMEASAO_DS,
      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_VIBDMEASAO_DS> TYPE V_VIBDMEASAO_DS.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM V_VIBDMEASAO_DS
*  INTO TABLE @DATA(IT_V_VIBDMEASAO_DS2).
*--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_VIBDMEASAO_DS INDEX 1 INTO DATA(WA_V_VIBDMEASAO_DS2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_V_VIBDMEASAO_DS ASSIGNING <V_VIBDMEASAO_DS>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<V_VIBDMEASAO_DS>-MANDT = 1.
<V_VIBDMEASAO_DS>-INTRENO = 1.
<V_VIBDMEASAO_DS>-MEAS = 1.
<V_VIBDMEASAO_DS>-VALIDTO = 1.
<V_VIBDMEASAO_DS>-VALIDFROM = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_V_VIBDMEASAO_DS-MEASVALUE, sy-vline,
WA_V_VIBDMEASAO_DS-MEASVALUECMPL, sy-vline,
WA_V_VIBDMEASAO_DS-MEASUNIT, sy-vline,
WA_V_VIBDMEASAO_DS-ISMANUALLYSET, sy-vline,
WA_V_VIBDMEASAO_DS-ISHIERARCHICAL, sy-vline,
WA_V_VIBDMEASAO_DS-AOID, sy-vline.
ENDLOOP. *Add any further fields from structure WA_V_VIBDMEASAO_DS 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_VIBDMEASAO_DS 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_VIBDMEASAO_DS INTO WA_V_VIBDMEASAO_DS. *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 MEAS CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_V_VIBDMEASAO_DS-MEAS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_VIBDMEASAO_DS-MEAS.
WRITE:/ 'New Value:', ld_input.

*Conversion exit REDAT, internal->external for field VALIDTO CALL FUNCTION 'CONVERSION_EXIT_REDAT_OUTPUT' EXPORTING input = WA_V_VIBDMEASAO_DS-VALIDTO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_VIBDMEASAO_DS-VALIDTO.
WRITE:/ 'New Value:', ld_input.

*Conversion exit CUNIT, internal->external for field MEASUNIT CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_V_VIBDMEASAO_DS-MEASUNIT IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_VIBDMEASAO_DS-MEASUNIT.
WRITE:/ 'New Value:', ld_input.

*Conversion exit ALPHA, internal->external for field AOFUNCTION CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_V_VIBDMEASAO_DS-AOFUNCTION IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_VIBDMEASAO_DS-AOFUNCTION.
WRITE:/ 'New Value:', ld_input.

*Conversion exit REDAT, internal->external for field VALIDTOAO CALL FUNCTION 'CONVERSION_EXIT_REDAT_OUTPUT' EXPORTING input = WA_V_VIBDMEASAO_DS-VALIDTOAO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_VIBDMEASAO_DS-VALIDTOAO.
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_V_VIBDMEASAO_DS_STR,
MANDT TYPE STRING,
INTRENO TYPE STRING,
MEAS TYPE STRING,
VALIDTO TYPE STRING,
VALIDFROM TYPE STRING,
MEASVALUE TYPE STRING,
MEASVALUECMPL TYPE STRING,
MEASUNIT TYPE STRING,
ISMANUALLYSET TYPE STRING,
ISHIERARCHICAL TYPE STRING,
AOID TYPE STRING,
AOTYPE TYPE STRING,
AONR TYPE STRING,
PARTSEPARATOR TYPE STRING,
PARTAOID TYPE STRING,
XAO TYPE STRING,
AOFUNCTION TYPE STRING,
USAGECOMMON TYPE STRING,
OBJNR TYPE STRING,
AUTHGRP TYPE STRING,
RERF TYPE STRING,
DERF TYPE STRING,
TERF TYPE STRING,
REHER TYPE STRING,
RBEAR TYPE STRING,
DBEAR TYPE STRING,
TBEAR TYPE STRING,
RBHER TYPE STRING,
RESPONSIBLE TYPE STRING,
USEREXCLUSIVE TYPE STRING,
LASTRENO TYPE STRING,
MEASSTRC TYPE STRING,
DOORPLT TYPE STRING,
RSAREA TYPE STRING,
SINSTBEZ TYPE STRING,
SVERKEHR TYPE STRING,
SLAGEWE TYPE STRING,
SOBJLAGE TYPE STRING,
RGRNART TYPE STRING,
RBEPLAN TYPE STRING,
DBEPLAN TYPE STRING,
RNBPLAN TYPE STRING,
XNUTZGRU TYPE STRING,
SUNUTZA TYPE STRING,
JUNUTZA TYPE STRING,
NZGRZ TYPE STRING,
NZGFZ TYPE STRING,
NZBMZ TYPE STRING,
NTGRZ TYPE STRING,
NTGFZ TYPE STRING,
NTBMZ TYPE STRING,
SGRART TYPE STRING,
SGRQAL TYPE STRING,
SGRFRM TYPE STRING,
SGRGZS TYPE STRING,
JERBBAU TYPE STRING,
ZULBAUH TYPE STRING,
RGEBART TYPE STRING,
RGEBZUST TYPE STRING,
YBAUJAHR TYPE STRING,
JNURJAHR TYPE STRING,
YMODERN TYPE STRING,
YAUFBAU TYPE STRING,
DBAUBEGI TYPE STRING,
DBAUVOR TYPE STRING,
DVORBES TYPE STRING,
DANTBAU TYPE STRING,
DBAUGENE TYPE STRING,
XBAUGENE TYPE STRING,
DFERTIG TYPE STRING,
DSCHLUSS TYPE STRING,
DBEZUGSF TYPE STRING,
RDAZUST TYPE STRING,
RFAZUST TYPE STRING,
JDENKMAL TYPE STRING,
DFRDVON TYPE STRING,
DFRDBIS TYPE STRING,
BANZGE TYPE STRING,
AUGESCH TYPE STRING,
SSTCKBIS TYPE STRING,
SLIFTBIS TYPE STRING,
NSTCKLFT TYPE STRING,
ESTATEDESCR TYPE STRING,
VALIDFROMAO TYPE STRING,
VALIDTOAO TYPE STRING,END OF T_EKKO_STR. DATA: WA_V_VIBDMEASAO_DS_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_VIBDMEASAO_DS_STR-MANDT sy-vline
WA_V_VIBDMEASAO_DS_STR-INTRENO sy-vline
WA_V_VIBDMEASAO_DS_STR-MEAS sy-vline
WA_V_VIBDMEASAO_DS_STR-VALIDTO sy-vline
WA_V_VIBDMEASAO_DS_STR-VALIDFROM sy-vline
WA_V_VIBDMEASAO_DS_STR-MEASVALUE sy-vline
WA_V_VIBDMEASAO_DS_STR-MEASVALUECMPL sy-vline
WA_V_VIBDMEASAO_DS_STR-MEASUNIT sy-vline
WA_V_VIBDMEASAO_DS_STR-ISMANUALLYSET sy-vline
WA_V_VIBDMEASAO_DS_STR-ISHIERARCHICAL sy-vline
WA_V_VIBDMEASAO_DS_STR-AOID sy-vline
WA_V_VIBDMEASAO_DS_STR-AOTYPE sy-vline
WA_V_VIBDMEASAO_DS_STR-AONR sy-vline
WA_V_VIBDMEASAO_DS_STR-PARTSEPARATOR sy-vline
WA_V_VIBDMEASAO_DS_STR-PARTAOID sy-vline
WA_V_VIBDMEASAO_DS_STR-XAO sy-vline
WA_V_VIBDMEASAO_DS_STR-AOFUNCTION sy-vline
WA_V_VIBDMEASAO_DS_STR-USAGECOMMON sy-vline
WA_V_VIBDMEASAO_DS_STR-OBJNR sy-vline
WA_V_VIBDMEASAO_DS_STR-AUTHGRP sy-vline
WA_V_VIBDMEASAO_DS_STR-RERF sy-vline
WA_V_VIBDMEASAO_DS_STR-DERF sy-vline
WA_V_VIBDMEASAO_DS_STR-TERF sy-vline
WA_V_VIBDMEASAO_DS_STR-REHER sy-vline
WA_V_VIBDMEASAO_DS_STR-RBEAR sy-vline
WA_V_VIBDMEASAO_DS_STR-DBEAR sy-vline
WA_V_VIBDMEASAO_DS_STR-TBEAR sy-vline
WA_V_VIBDMEASAO_DS_STR-RBHER sy-vline
WA_V_VIBDMEASAO_DS_STR-RESPONSIBLE sy-vline
WA_V_VIBDMEASAO_DS_STR-USEREXCLUSIVE sy-vline
WA_V_VIBDMEASAO_DS_STR-LASTRENO sy-vline
WA_V_VIBDMEASAO_DS_STR-MEASSTRC sy-vline
WA_V_VIBDMEASAO_DS_STR-DOORPLT sy-vline
WA_V_VIBDMEASAO_DS_STR-RSAREA sy-vline
WA_V_VIBDMEASAO_DS_STR-SINSTBEZ sy-vline
WA_V_VIBDMEASAO_DS_STR-SVERKEHR sy-vline
WA_V_VIBDMEASAO_DS_STR-SLAGEWE sy-vline
WA_V_VIBDMEASAO_DS_STR-SOBJLAGE sy-vline
WA_V_VIBDMEASAO_DS_STR-RGRNART sy-vline
WA_V_VIBDMEASAO_DS_STR-RBEPLAN sy-vline
WA_V_VIBDMEASAO_DS_STR-DBEPLAN sy-vline
WA_V_VIBDMEASAO_DS_STR-RNBPLAN sy-vline
WA_V_VIBDMEASAO_DS_STR-XNUTZGRU sy-vline
WA_V_VIBDMEASAO_DS_STR-SUNUTZA sy-vline
WA_V_VIBDMEASAO_DS_STR-JUNUTZA sy-vline
WA_V_VIBDMEASAO_DS_STR-NZGRZ sy-vline
WA_V_VIBDMEASAO_DS_STR-NZGFZ sy-vline
WA_V_VIBDMEASAO_DS_STR-NZBMZ sy-vline
WA_V_VIBDMEASAO_DS_STR-NTGRZ sy-vline
WA_V_VIBDMEASAO_DS_STR-NTGFZ sy-vline
WA_V_VIBDMEASAO_DS_STR-NTBMZ sy-vline
WA_V_VIBDMEASAO_DS_STR-SGRART sy-vline
WA_V_VIBDMEASAO_DS_STR-SGRQAL sy-vline
WA_V_VIBDMEASAO_DS_STR-SGRFRM sy-vline
WA_V_VIBDMEASAO_DS_STR-SGRGZS sy-vline
WA_V_VIBDMEASAO_DS_STR-JERBBAU sy-vline
WA_V_VIBDMEASAO_DS_STR-ZULBAUH sy-vline
WA_V_VIBDMEASAO_DS_STR-RGEBART sy-vline
WA_V_VIBDMEASAO_DS_STR-RGEBZUST sy-vline
WA_V_VIBDMEASAO_DS_STR-YBAUJAHR sy-vline
WA_V_VIBDMEASAO_DS_STR-JNURJAHR sy-vline
WA_V_VIBDMEASAO_DS_STR-YMODERN sy-vline
WA_V_VIBDMEASAO_DS_STR-YAUFBAU sy-vline
WA_V_VIBDMEASAO_DS_STR-DBAUBEGI sy-vline
WA_V_VIBDMEASAO_DS_STR-DBAUVOR sy-vline
WA_V_VIBDMEASAO_DS_STR-DVORBES sy-vline
WA_V_VIBDMEASAO_DS_STR-DANTBAU sy-vline
WA_V_VIBDMEASAO_DS_STR-DBAUGENE sy-vline
WA_V_VIBDMEASAO_DS_STR-XBAUGENE sy-vline
WA_V_VIBDMEASAO_DS_STR-DFERTIG sy-vline
WA_V_VIBDMEASAO_DS_STR-DSCHLUSS sy-vline
WA_V_VIBDMEASAO_DS_STR-DBEZUGSF sy-vline
WA_V_VIBDMEASAO_DS_STR-RDAZUST sy-vline
WA_V_VIBDMEASAO_DS_STR-RFAZUST sy-vline
WA_V_VIBDMEASAO_DS_STR-JDENKMAL sy-vline
WA_V_VIBDMEASAO_DS_STR-DFRDVON sy-vline
WA_V_VIBDMEASAO_DS_STR-DFRDBIS sy-vline
WA_V_VIBDMEASAO_DS_STR-BANZGE sy-vline
WA_V_VIBDMEASAO_DS_STR-AUGESCH sy-vline
WA_V_VIBDMEASAO_DS_STR-SSTCKBIS sy-vline
WA_V_VIBDMEASAO_DS_STR-SLIFTBIS sy-vline
WA_V_VIBDMEASAO_DS_STR-NSTCKLFT sy-vline
WA_V_VIBDMEASAO_DS_STR-ESTATEDESCR sy-vline
WA_V_VIBDMEASAO_DS_STR-VALIDFROMAO sy-vline
WA_V_VIBDMEASAO_DS_STR-VALIDTOAO sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.