ABAP Select data from SAP table F150V 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 F150V 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 F150V. 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 F150V 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_F150V TYPE STANDARD TABLE OF F150V,
      WA_F150V TYPE F150V,
      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: <F150V> TYPE F150V.

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

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

*Select data and declare internal table using in-line method @DATA
*SELECT *
*  FROM F150V
*  INTO TABLE @DATA(IT_F150V2).
*--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_F150V INDEX 1 INTO DATA(WA_F150V2).


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

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

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

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

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

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

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

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

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

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

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

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

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

*Conversion exit ALPHA, internal->external for field KOVER CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = WA_F150V-KOVER IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_F150V-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_F150V_STR,
LAUFD TYPE STRING,
LAUFI TYPE STRING,
COPYD TYPE STRING,
COPYI TYPE STRING,
BUKLS TYPE STRING,
AUSDT TYPE STRING,
GRDAT TYPE STRING,
VONKD TYPE STRING,
BISKD TYPE STRING,
VONKK TYPE STRING,
BISKK TYPE STRING,
VONMS TYPE STRING,
BISMS 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,
MABER TYPE STRING,
MAHNS TYPE STRING,
NAME1 TYPE STRING,
NAME2 TYPE STRING,
STRAS TYPE STRING,
PLORT TYPE STRING,
MAHNN TYPE STRING,
MANSK TYPE STRING,
MANSP 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,
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,
ZENDE 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,
ACTVT TYPE STRING,
ACTXT TYPE STRING,
ACICO TYPE STRING,
XTEXT TYPE STRING,
COPY_PARAM TYPE STRING,END OF T_EKKO_STR. DATA: WA_F150V_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_F150V_STR-LAUFD sy-vline
WA_F150V_STR-LAUFI sy-vline
WA_F150V_STR-COPYD sy-vline
WA_F150V_STR-COPYI sy-vline
WA_F150V_STR-BUKLS sy-vline
WA_F150V_STR-AUSDT sy-vline
WA_F150V_STR-GRDAT sy-vline
WA_F150V_STR-VONKD sy-vline
WA_F150V_STR-BISKD sy-vline
WA_F150V_STR-VONKK sy-vline
WA_F150V_STR-BISKK sy-vline
WA_F150V_STR-VONMS sy-vline
WA_F150V_STR-BISMS sy-vline
WA_F150V_STR-FLDNA sy-vline
WA_F150V_STR-FLDBD sy-vline
WA_F150V_STR-FLDL1 sy-vline
WA_F150V_STR-FLDL2 sy-vline
WA_F150V_STR-IGNOR sy-vline
WA_F150V_STR-KOART sy-vline
WA_F150V_STR-KONTO sy-vline
WA_F150V_STR-KUNNR sy-vline
WA_F150V_STR-LIFNR sy-vline
WA_F150V_STR-BUKRS sy-vline
WA_F150V_STR-BUSAB sy-vline
WA_F150V_STR-MABER sy-vline
WA_F150V_STR-MAHNS sy-vline
WA_F150V_STR-NAME1 sy-vline
WA_F150V_STR-NAME2 sy-vline
WA_F150V_STR-STRAS sy-vline
WA_F150V_STR-PLORT sy-vline
WA_F150V_STR-MAHNN sy-vline
WA_F150V_STR-MANSK sy-vline
WA_F150V_STR-MANSP sy-vline
WA_F150V_STR-XDANP sy-vline
WA_F150V_STR-ANZPO sy-vline
WA_F150V_STR-ABPOS sy-vline
WA_F150V_STR-AUSWJ sy-vline
WA_F150V_STR-AUSWN sy-vline
WA_F150V_STR-ANZT1 sy-vline
WA_F150V_STR-ABTP1 sy-vline
WA_F150V_STR-ANZT2 sy-vline
WA_F150V_STR-ABTP2 sy-vline
WA_F150V_STR-ANZT3 sy-vline
WA_F150V_STR-ABTP3 sy-vline
WA_F150V_STR-STEXT sy-vline
WA_F150V_STR-VONLD sy-vline
WA_F150V_STR-BISLD sy-vline
WA_F150V_STR-STRDT sy-vline
WA_F150V_STR-STRZT sy-vline
WA_F150V_STR-STRRE sy-vline
WA_F150V_STR-XSTRF sy-vline
WA_F150V_STR-XDRAN sy-vline
WA_F150V_STR-PDEST sy-vline
WA_F150V_STR-IDLOE sy-vline
WA_F150V_STR-XVORL sy-vline
WA_F150V_STR-ZENDE sy-vline
WA_F150V_STR-VERTN sy-vline
WA_F150V_STR-VONVN sy-vline
WA_F150V_STR-BISVN sy-vline
WA_F150V_STR-KOVER sy-vline
WA_F150V_STR-PROGN sy-vline
WA_F150V_STR-VARI1 sy-vline
WA_F150V_STR-BHOST sy-vline
WA_F150V_STR-PCOUNT sy-vline
WA_F150V_STR-PIMMED sy-vline
WA_F150V_STR-OFIST sy-vline
WA_F150V_STR-ICCD sy-vline
WA_F150V_STR-DB_ITEM sy-vline
WA_F150V_STR-DB_ACC sy-vline
WA_F150V_STR-L_INCL sy-vline
WA_F150V_STR-DUJ_TYPE sy-vline
WA_F150V_STR-ANZ sy-vline
WA_F150V_STR-ACTVT sy-vline
WA_F150V_STR-ACTXT sy-vline
WA_F150V_STR-ACICO sy-vline
WA_F150V_STR-XTEXT sy-vline
WA_F150V_STR-COPY_PARAM sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.