ABAP Select data from SAP table /OEWB/D_VERS 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 /OEWB/D_VERS 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 /OEWB/D_VERS. 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 /OEWB/D_VERS 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_/OEWB/D_VERS TYPE STANDARD TABLE OF /OEWB/D_VERS, WA_/OEWB/D_VERS TYPE /OEWB/D_VERS, 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: </OEWB/D_VERS> TYPE /OEWB/D_VERS. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_/OEWB/D_VERS. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM /OEWB/D_VERS INTO TABLE IT_/OEWB/D_VERS. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM /OEWB/D_VERS * INTO TABLE @DATA(IT_/OEWB/D_VERS2). *--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_/OEWB/D_VERS INDEX 1 INTO DATA(WA_/OEWB/D_VERS2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_/OEWB/D_VERS ASSIGNING </OEWB/D_VERS>.*To update a field value using a field symbol simply change the value via the field symbol pointer
</OEWB/D_VERS>-MANDT = 1.
</OEWB/D_VERS>-GUID = 1.
</OEWB/D_VERS>-INSTANCE = 1.
</OEWB/D_VERS>-IBASE = 1.
</OEWB/D_VERS>-STLTY = 1.
ENDLOOP. LOOP AT IT_/OEWB/D_VERS INTO WA_/OEWB/D_VERS. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_/OEWB/D_VERS-STLNR, sy-vline,
WA_/OEWB/D_VERS-STLKN, sy-vline,
WA_/OEWB/D_VERS-STPOZ, sy-vline,
WA_/OEWB/D_VERS-DATUV, sy-vline,
WA_/OEWB/D_VERS-AENNR, sy-vline,
WA_/OEWB/D_VERS-LKENZ, sy-vline.
ENDLOOP. *Add any further fields from structure WA_/OEWB/D_VERS 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_/OEWB/D_VERS 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_/OEWB/D_VERS INTO WA_/OEWB/D_VERS. *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 INSTANCE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-INSTANCE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-INSTANCE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field IBASE CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-IBASE IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-IBASE.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field STLNR CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-STLNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-STLNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field AENNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-AENNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-AENNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field IDNRK CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-IDNRK IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-IDNRK.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field POSNR CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-POSNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-POSNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field MEINS CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-MEINS IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-MEINS.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ISOLA, internal->external for field LTXSP CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-LTXSP IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-LTXSP.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field DOKNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-DOKNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-DOKNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit NUMCV, internal->external for field KSTNR CALL FUNCTION 'CONVERSION_EXIT_NUMCV_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-KSTNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-KSTNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field NLFMV CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-NLFMV IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-NLFMV.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field BMEIN CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-BMEIN IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-BMEIN.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field LIFNR CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-LIFNR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-LIFNR.
WRITE:/ 'New Value:', ld_input.
*Conversion exit ALPHA, internal->external for field SAKTO CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-SAKTO IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-SAKTO.
WRITE:/ 'New Value:', ld_input.
*Conversion exit CUNIT, internal->external for field ROMEI CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-ROMEI IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-ROMEI.
WRITE:/ 'New Value:', ld_input.
*Conversion exit MATN1, internal->external for field INTRM CALL FUNCTION 'CONVERSION_EXIT_MATN1_OUTPUT' EXPORTING input = WA_/OEWB/D_VERS-INTRM IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_/OEWB/D_VERS-INTRM.
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_/OEWB/D_VERS_STR,
MANDT TYPE STRING,
GUID TYPE STRING,
INSTANCE TYPE STRING,
IBASE TYPE STRING,
STLTY TYPE STRING,
STLNR TYPE STRING,
STLKN TYPE STRING,
STPOZ TYPE STRING,
DATUV TYPE STRING,
AENNR TYPE STRING,
LKENZ TYPE STRING,
ANDAT TYPE STRING,
ANNAM TYPE STRING,
AEDAT TYPE STRING,
AENAM TYPE STRING,
IDNRK TYPE STRING,
PSWRK TYPE STRING,
POSTP TYPE STRING,
POSNR TYPE STRING,
SORTF TYPE STRING,
MEINS TYPE STRING,
MENGE TYPE STRING,
FMENG TYPE STRING,
AUSCH TYPE STRING,
AVOAU TYPE STRING,
NETAU TYPE STRING,
SCHGT TYPE STRING,
BEIKZ TYPE STRING,
ERSKZ TYPE STRING,
RVREL TYPE STRING,
SANFE TYPE STRING,
SANIN TYPE STRING,
SANKA TYPE STRING,
SANKO TYPE STRING,
SANVS TYPE STRING,
STKKZ TYPE STRING,
REKRI TYPE STRING,
REKRS TYPE STRING,
NLFZT TYPE STRING,
VERTI TYPE STRING,
LIFZT TYPE STRING,
UPSKZ TYPE STRING,
LTXSP TYPE STRING,
POTX1 TYPE STRING,
POTX2 TYPE STRING,
DOKAR TYPE STRING,
DOKNR TYPE STRING,
DOKVR TYPE STRING,
DOKTL TYPE STRING,
CLASS TYPE STRING,
KLART TYPE STRING,
DSPST TYPE STRING,
ALPGR TYPE STRING,
KZNFP TYPE STRING,
NFGRP TYPE STRING,
NFEAG TYPE STRING,
KNDVB TYPE STRING,
KNDBZ TYPE STRING,
KSTTY TYPE STRING,
KSTNR TYPE STRING,
KSTKN TYPE STRING,
KSTPZ TYPE STRING,
CLSZU TYPE STRING,
KZCLB TYPE STRING,
PRVBE TYPE STRING,
NLFZV TYPE STRING,
NLFMV TYPE STRING,
IDPOS TYPE STRING,
ALEKZ TYPE STRING,
ITSOB TYPE STRING,
RFPNT TYPE STRING,
GUIDX TYPE STRING,
CUOBJ_VRS TYPE STRING,
BMEIN TYPE STRING,
BMENG TYPE STRING,
STLST TYPE STRING,
CONFIGURABLE TYPE STRING,
TECHV TYPE STRING,
CADPO TYPE STRING,
ALPOS TYPE STRING,
EWAHR TYPE STRING,
EKGRP TYPE STRING,
LIFNR TYPE STRING,
PREIS TYPE STRING,
PEINH TYPE STRING,
WAERS TYPE STRING,
SAKTO TYPE STRING,
ROANZ TYPE STRING,
ROMS1 TYPE STRING,
ROMS2 TYPE STRING,
ROMS3 TYPE STRING,
ROMEI TYPE STRING,
ROMEN TYPE STRING,
RFORM TYPE STRING,
VALKZ TYPE STRING,
OBJTY TYPE STRING,
MATKL TYPE STRING,
WEBAZ TYPE STRING,
CSSTR TYPE STRING,
POTPR TYPE STRING,
AWAKZ TYPE STRING,
INSKZ TYPE STRING,
VCEKZ TYPE STRING,
VSTKZ TYPE STRING,
VACKZ TYPE STRING,
EKORG TYPE STRING,
CLOBK TYPE STRING,
CLMUL TYPE STRING,
CLALT TYPE STRING,
CVIEW TYPE STRING,
KNOBJ TYPE STRING,
LGORT TYPE STRING,
KZKUP TYPE STRING,
INTRM TYPE STRING,
TPEKZ TYPE STRING,
STVKN TYPE STRING,
DVDAT TYPE STRING,
DVNAM TYPE STRING,
ALPST TYPE STRING,
ALPRF TYPE STRING,
AEHLP TYPE STRING,
IDHIS TYPE STRING,
IDVAR TYPE STRING,
ITMID TYPE STRING,
COSTS_ORIG TYPE STRING,
CURRENCY_ORIG TYPE STRING,END OF T_EKKO_STR. DATA: WA_/OEWB/D_VERS_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_/OEWB/D_VERS_STR-MANDT sy-vline
WA_/OEWB/D_VERS_STR-GUID sy-vline
WA_/OEWB/D_VERS_STR-INSTANCE sy-vline
WA_/OEWB/D_VERS_STR-IBASE sy-vline
WA_/OEWB/D_VERS_STR-STLTY sy-vline
WA_/OEWB/D_VERS_STR-STLNR sy-vline
WA_/OEWB/D_VERS_STR-STLKN sy-vline
WA_/OEWB/D_VERS_STR-STPOZ sy-vline
WA_/OEWB/D_VERS_STR-DATUV sy-vline
WA_/OEWB/D_VERS_STR-AENNR sy-vline
WA_/OEWB/D_VERS_STR-LKENZ sy-vline
WA_/OEWB/D_VERS_STR-ANDAT sy-vline
WA_/OEWB/D_VERS_STR-ANNAM sy-vline
WA_/OEWB/D_VERS_STR-AEDAT sy-vline
WA_/OEWB/D_VERS_STR-AENAM sy-vline
WA_/OEWB/D_VERS_STR-IDNRK sy-vline
WA_/OEWB/D_VERS_STR-PSWRK sy-vline
WA_/OEWB/D_VERS_STR-POSTP sy-vline
WA_/OEWB/D_VERS_STR-POSNR sy-vline
WA_/OEWB/D_VERS_STR-SORTF sy-vline
WA_/OEWB/D_VERS_STR-MEINS sy-vline
WA_/OEWB/D_VERS_STR-MENGE sy-vline
WA_/OEWB/D_VERS_STR-FMENG sy-vline
WA_/OEWB/D_VERS_STR-AUSCH sy-vline
WA_/OEWB/D_VERS_STR-AVOAU sy-vline
WA_/OEWB/D_VERS_STR-NETAU sy-vline
WA_/OEWB/D_VERS_STR-SCHGT sy-vline
WA_/OEWB/D_VERS_STR-BEIKZ sy-vline
WA_/OEWB/D_VERS_STR-ERSKZ sy-vline
WA_/OEWB/D_VERS_STR-RVREL sy-vline
WA_/OEWB/D_VERS_STR-SANFE sy-vline
WA_/OEWB/D_VERS_STR-SANIN sy-vline
WA_/OEWB/D_VERS_STR-SANKA sy-vline
WA_/OEWB/D_VERS_STR-SANKO sy-vline
WA_/OEWB/D_VERS_STR-SANVS sy-vline
WA_/OEWB/D_VERS_STR-STKKZ sy-vline
WA_/OEWB/D_VERS_STR-REKRI sy-vline
WA_/OEWB/D_VERS_STR-REKRS sy-vline
WA_/OEWB/D_VERS_STR-NLFZT sy-vline
WA_/OEWB/D_VERS_STR-VERTI sy-vline
WA_/OEWB/D_VERS_STR-LIFZT sy-vline
WA_/OEWB/D_VERS_STR-UPSKZ sy-vline
WA_/OEWB/D_VERS_STR-LTXSP sy-vline
WA_/OEWB/D_VERS_STR-POTX1 sy-vline
WA_/OEWB/D_VERS_STR-POTX2 sy-vline
WA_/OEWB/D_VERS_STR-DOKAR sy-vline
WA_/OEWB/D_VERS_STR-DOKNR sy-vline
WA_/OEWB/D_VERS_STR-DOKVR sy-vline
WA_/OEWB/D_VERS_STR-DOKTL sy-vline
WA_/OEWB/D_VERS_STR-CLASS sy-vline
WA_/OEWB/D_VERS_STR-KLART sy-vline
WA_/OEWB/D_VERS_STR-DSPST sy-vline
WA_/OEWB/D_VERS_STR-ALPGR sy-vline
WA_/OEWB/D_VERS_STR-KZNFP sy-vline
WA_/OEWB/D_VERS_STR-NFGRP sy-vline
WA_/OEWB/D_VERS_STR-NFEAG sy-vline
WA_/OEWB/D_VERS_STR-KNDVB sy-vline
WA_/OEWB/D_VERS_STR-KNDBZ sy-vline
WA_/OEWB/D_VERS_STR-KSTTY sy-vline
WA_/OEWB/D_VERS_STR-KSTNR sy-vline
WA_/OEWB/D_VERS_STR-KSTKN sy-vline
WA_/OEWB/D_VERS_STR-KSTPZ sy-vline
WA_/OEWB/D_VERS_STR-CLSZU sy-vline
WA_/OEWB/D_VERS_STR-KZCLB sy-vline
WA_/OEWB/D_VERS_STR-PRVBE sy-vline
WA_/OEWB/D_VERS_STR-NLFZV sy-vline
WA_/OEWB/D_VERS_STR-NLFMV sy-vline
WA_/OEWB/D_VERS_STR-IDPOS sy-vline
WA_/OEWB/D_VERS_STR-ALEKZ sy-vline
WA_/OEWB/D_VERS_STR-ITSOB sy-vline
WA_/OEWB/D_VERS_STR-RFPNT sy-vline
WA_/OEWB/D_VERS_STR-GUIDX sy-vline
WA_/OEWB/D_VERS_STR-CUOBJ_VRS sy-vline
WA_/OEWB/D_VERS_STR-BMEIN sy-vline
WA_/OEWB/D_VERS_STR-BMENG sy-vline
WA_/OEWB/D_VERS_STR-STLST sy-vline
WA_/OEWB/D_VERS_STR-CONFIGURABLE sy-vline
WA_/OEWB/D_VERS_STR-TECHV sy-vline
WA_/OEWB/D_VERS_STR-CADPO sy-vline
WA_/OEWB/D_VERS_STR-ALPOS sy-vline
WA_/OEWB/D_VERS_STR-EWAHR sy-vline
WA_/OEWB/D_VERS_STR-EKGRP sy-vline
WA_/OEWB/D_VERS_STR-LIFNR sy-vline
WA_/OEWB/D_VERS_STR-PREIS sy-vline
WA_/OEWB/D_VERS_STR-PEINH sy-vline
WA_/OEWB/D_VERS_STR-WAERS sy-vline
WA_/OEWB/D_VERS_STR-SAKTO sy-vline
WA_/OEWB/D_VERS_STR-ROANZ sy-vline
WA_/OEWB/D_VERS_STR-ROMS1 sy-vline
WA_/OEWB/D_VERS_STR-ROMS2 sy-vline
WA_/OEWB/D_VERS_STR-ROMS3 sy-vline
WA_/OEWB/D_VERS_STR-ROMEI sy-vline
WA_/OEWB/D_VERS_STR-ROMEN sy-vline
WA_/OEWB/D_VERS_STR-RFORM sy-vline
WA_/OEWB/D_VERS_STR-VALKZ sy-vline
WA_/OEWB/D_VERS_STR-OBJTY sy-vline
WA_/OEWB/D_VERS_STR-MATKL sy-vline
WA_/OEWB/D_VERS_STR-WEBAZ sy-vline
WA_/OEWB/D_VERS_STR-CSSTR sy-vline
WA_/OEWB/D_VERS_STR-POTPR sy-vline
WA_/OEWB/D_VERS_STR-AWAKZ sy-vline
WA_/OEWB/D_VERS_STR-INSKZ sy-vline
WA_/OEWB/D_VERS_STR-VCEKZ sy-vline
WA_/OEWB/D_VERS_STR-VSTKZ sy-vline
WA_/OEWB/D_VERS_STR-VACKZ sy-vline
WA_/OEWB/D_VERS_STR-EKORG sy-vline
WA_/OEWB/D_VERS_STR-CLOBK sy-vline
WA_/OEWB/D_VERS_STR-CLMUL sy-vline
WA_/OEWB/D_VERS_STR-CLALT sy-vline
WA_/OEWB/D_VERS_STR-CVIEW sy-vline
WA_/OEWB/D_VERS_STR-KNOBJ sy-vline
WA_/OEWB/D_VERS_STR-LGORT sy-vline
WA_/OEWB/D_VERS_STR-KZKUP sy-vline
WA_/OEWB/D_VERS_STR-INTRM sy-vline
WA_/OEWB/D_VERS_STR-TPEKZ sy-vline
WA_/OEWB/D_VERS_STR-STVKN sy-vline
WA_/OEWB/D_VERS_STR-DVDAT sy-vline
WA_/OEWB/D_VERS_STR-DVNAM sy-vline
WA_/OEWB/D_VERS_STR-ALPST sy-vline
WA_/OEWB/D_VERS_STR-ALPRF sy-vline
WA_/OEWB/D_VERS_STR-AEHLP sy-vline
WA_/OEWB/D_VERS_STR-IDHIS sy-vline
WA_/OEWB/D_VERS_STR-IDVAR sy-vline
WA_/OEWB/D_VERS_STR-ITMID sy-vline
WA_/OEWB/D_VERS_STR-COSTS_ORIG sy-vline
WA_/OEWB/D_VERS_STR-CURRENCY_ORIG sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.