ABAP Select data from SAP table F107V 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 F107V 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 F107V. 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 F107V 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_F107V TYPE STANDARD TABLE OF F107V,
      WA_F107V TYPE F107V,
      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: <F107V> TYPE F107V.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM F107V
*  INTO TABLE @DATA(IT_F107V2).
*--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_F107V INDEX 1 INTO DATA(WA_F107V2).


*Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL
LOOP AT IT_F107V ASSIGNING <F107V>.
*To update a field value using a field symbol simply change the value via the field symbol pointer
<F107V>-LAUFD = 1.
<F107V>-LAUFI = 1.
<F107V>-COPYD = 1.
<F107V>-COPYI = 1.
<F107V>-BUKLS = 1.
ENDLOOP.

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

*Write selected data to screen/report before conversion.
  WRITE:/ sy-vline,   WA_F107V-AUSDT, sy-vline,
WA_F107V-VONKD, sy-vline,
WA_F107V-BISKD, sy-vline,
WA_F107V-VONKK, sy-vline,
WA_F107V-BISKK, sy-vline,
WA_F107V-FLDNA, sy-vline.
ENDLOOP. *Add any further fields from structure WA_F107V 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_F107V 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_F107V INTO WA_F107V. *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 VONKD CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_F107V-VONKD IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_F107V-VONKD.
WRITE:/ 'New Value:', ld_input.

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

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

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

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

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

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

*Conversion exit SPDEV, internal->external for field PDEST CALL FUNCTION 'CONVERSION_EXIT_SPDEV_OUTPUT' EXPORTING input = WA_F107V-PDEST IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_F107V-PDEST.
WRITE:/ 'New Value:', ld_input.

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

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

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

*Conversion exit ALPHA, internal->external for field KOVER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_F107V-KOVER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_F107V-KOVER.
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_F107V_STR,
LAUFD TYPE STRING,
LAUFI TYPE STRING,
COPYD TYPE STRING,
COPYI TYPE STRING,
BUKLS TYPE STRING,
AUSDT TYPE STRING,
VONKD TYPE STRING,
BISKD TYPE STRING,
VONKK TYPE STRING,
BISKK TYPE STRING,
FLDNA TYPE STRING,
FLDBD TYPE STRING,
FLDL1 TYPE STRING,
FLDL2 TYPE STRING,
IGNOR TYPE STRING,
KOART TYPE STRING,
KONTO TYPE STRING,
KUNNR TYPE STRING,
LIFNR TYPE STRING,
BUKRS TYPE STRING,
BUSAB TYPE STRING,
XDANP TYPE STRING,
ANZPO TYPE STRING,
ABPOS TYPE STRING,
AUSWJ TYPE STRING,
AUSWN TYPE STRING,
ANZT1 TYPE STRING,
ABTP1 TYPE STRING,
ANZT2 TYPE STRING,
ABTP2 TYPE STRING,
ANZT3 TYPE STRING,
ABTP3 TYPE STRING,
STEXT TYPE STRING,
HWAERS TYPE STRING,
VONLD TYPE STRING,
BISLD TYPE STRING,
STRDT TYPE STRING,
STRZT TYPE STRING,
STRRE TYPE STRING,
XSTRF TYPE STRING,
XDRAN TYPE STRING,
PDEST TYPE STRING,
IDLOE TYPE STRING,
XVORL TYPE STRING,
VERTN TYPE STRING,
VONVN TYPE STRING,
BISVN TYPE STRING,
KOVER TYPE STRING,
PROGN TYPE STRING,
VARI1 TYPE STRING,
BHOST TYPE STRING,
PCOUNT TYPE STRING,
PIMMED TYPE STRING,
OFIST TYPE STRING,
ICCD TYPE STRING,
DB_ITEM TYPE STRING,
DB_ACC TYPE STRING,
L_INCL TYPE STRING,
DUJ_TYPE TYPE STRING,
ANZ TYPE STRING,
UMBWM TYPE STRING,
CURTP TYPE STRING,
BWBER TYPE STRING,
XGRUP TYPE STRING,
BINPUT TYPE STRING,
BBLART TYPE STRING,
BSBLAR TYPE STRING,
BBUDAT TYPE STRING,
SBUDAT TYPE STRING,
BBUPEM TYPE STRING,
SBUPEM TYPE STRING,
BMAPPE TYPE STRING,
SZBMETH TYPE STRING,
NETDT_MIN TYPE STRING,
XZINSEXP TYPE STRING,
VZSKZ TYPE STRING,
PREV_AUSDT TYPE STRING,
MON_MIN TYPE STRING,
XAGGR_OFF TYPE STRING,END OF T_EKKO_STR. DATA: WA_F107V_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_F107V_STR-LAUFD sy-vline
WA_F107V_STR-LAUFI sy-vline
WA_F107V_STR-COPYD sy-vline
WA_F107V_STR-COPYI sy-vline
WA_F107V_STR-BUKLS sy-vline
WA_F107V_STR-AUSDT sy-vline
WA_F107V_STR-VONKD sy-vline
WA_F107V_STR-BISKD sy-vline
WA_F107V_STR-VONKK sy-vline
WA_F107V_STR-BISKK sy-vline
WA_F107V_STR-FLDNA sy-vline
WA_F107V_STR-FLDBD sy-vline
WA_F107V_STR-FLDL1 sy-vline
WA_F107V_STR-FLDL2 sy-vline
WA_F107V_STR-IGNOR sy-vline
WA_F107V_STR-KOART sy-vline
WA_F107V_STR-KONTO sy-vline
WA_F107V_STR-KUNNR sy-vline
WA_F107V_STR-LIFNR sy-vline
WA_F107V_STR-BUKRS sy-vline
WA_F107V_STR-BUSAB sy-vline
WA_F107V_STR-XDANP sy-vline
WA_F107V_STR-ANZPO sy-vline
WA_F107V_STR-ABPOS sy-vline
WA_F107V_STR-AUSWJ sy-vline
WA_F107V_STR-AUSWN sy-vline
WA_F107V_STR-ANZT1 sy-vline
WA_F107V_STR-ABTP1 sy-vline
WA_F107V_STR-ANZT2 sy-vline
WA_F107V_STR-ABTP2 sy-vline
WA_F107V_STR-ANZT3 sy-vline
WA_F107V_STR-ABTP3 sy-vline
WA_F107V_STR-STEXT sy-vline
WA_F107V_STR-HWAERS sy-vline
WA_F107V_STR-VONLD sy-vline
WA_F107V_STR-BISLD sy-vline
WA_F107V_STR-STRDT sy-vline
WA_F107V_STR-STRZT sy-vline
WA_F107V_STR-STRRE sy-vline
WA_F107V_STR-XSTRF sy-vline
WA_F107V_STR-XDRAN sy-vline
WA_F107V_STR-PDEST sy-vline
WA_F107V_STR-IDLOE sy-vline
WA_F107V_STR-XVORL sy-vline
WA_F107V_STR-VERTN sy-vline
WA_F107V_STR-VONVN sy-vline
WA_F107V_STR-BISVN sy-vline
WA_F107V_STR-KOVER sy-vline
WA_F107V_STR-PROGN sy-vline
WA_F107V_STR-VARI1 sy-vline
WA_F107V_STR-BHOST sy-vline
WA_F107V_STR-PCOUNT sy-vline
WA_F107V_STR-PIMMED sy-vline
WA_F107V_STR-OFIST sy-vline
WA_F107V_STR-ICCD sy-vline
WA_F107V_STR-DB_ITEM sy-vline
WA_F107V_STR-DB_ACC sy-vline
WA_F107V_STR-L_INCL sy-vline
WA_F107V_STR-DUJ_TYPE sy-vline
WA_F107V_STR-ANZ sy-vline
WA_F107V_STR-UMBWM sy-vline
WA_F107V_STR-CURTP sy-vline
WA_F107V_STR-BWBER sy-vline
WA_F107V_STR-XGRUP sy-vline
WA_F107V_STR-BINPUT sy-vline
WA_F107V_STR-BBLART sy-vline
WA_F107V_STR-BSBLAR sy-vline
WA_F107V_STR-BBUDAT sy-vline
WA_F107V_STR-SBUDAT sy-vline
WA_F107V_STR-BBUPEM sy-vline
WA_F107V_STR-SBUPEM sy-vline
WA_F107V_STR-BMAPPE sy-vline
WA_F107V_STR-SZBMETH sy-vline
WA_F107V_STR-NETDT_MIN sy-vline
WA_F107V_STR-XZINSEXP sy-vline
WA_F107V_STR-VZSKZ sy-vline
WA_F107V_STR-PREV_AUSDT sy-vline
WA_F107V_STR-MON_MIN sy-vline
WA_F107V_STR-XAGGR_OFF sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.