ABAP Select data from SAP table V_FMFIHHST 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_FMFIHHST 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_FMFIHHST. 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_FMFIHHST 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_FMFIHHST TYPE STANDARD TABLE OF V_FMFIHHST, WA_V_FMFIHHST TYPE V_FMFIHHST, 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_FMFIHHST> TYPE V_FMFIHHST. *Process all fields in table header/work area as string values PERFORM process_as_string_field_values CHANGING wa_V_FMFIHHST. SELECT * *restrict ABAP select to first 10 rows UP TO 10 ROWS FROM V_FMFIHHST INTO TABLE IT_V_FMFIHHST. *Select data and declare internal table using in-line method @DATA *SELECT * * FROM V_FMFIHHST * INTO TABLE @DATA(IT_V_FMFIHHST2). *--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_FMFIHHST INDEX 1 INTO DATA(WA_V_FMFIHHST2). *Demonstrate how to loop at an internal table and update values using a FIELD-SYMBOL LOOP AT IT_V_FMFIHHST ASSIGNING <V_FMFIHHST>.*To update a field value using a field symbol simply change the value via the field symbol pointer
<V_FMFIHHST>-MANDT = 1.
<V_FMFIHHST>-ABGJR = 1.
<V_FMFIHHST>-GRUPP_NR = 1.
<V_FMFIHHST>-BEZEICH = 1.
<V_FMFIHHST>-BEZEICH1 = 1.
ENDLOOP. LOOP AT IT_V_FMFIHHST INTO WA_V_FMFIHHST. *Write horizonal line to screen report. WRITE:/ sy-uline. *Write selected data to screen/report before conversion. WRITE:/ sy-vline, WA_V_FMFIHHST-GRUPPE0, sy-vline,
WA_V_FMFIHHST-GRUPPE1, sy-vline,
WA_V_FMFIHHST-GRUPPE2, sy-vline,
WA_V_FMFIHHST-GRUPPE3, sy-vline,
WA_V_FMFIHHST-GRUPPE4, sy-vline,
WA_V_FMFIHHST-GRUPPE5, sy-vline.
ENDLOOP. *Add any further fields from structure WA_V_FMFIHHST 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_FMFIHHST 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_FMFIHHST INTO WA_V_FMFIHHST. *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 GJAHR, internal->external for field ABGJR CALL FUNCTION 'CONVERSION_EXIT_GJAHR_OUTPUT' EXPORTING input = WA_V_FMFIHHST-ABGJR IMPORTING output = ld_input.
WRITE:/ 'Org Value:', WA_V_FMFIHHST-ABGJR.
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_FMFIHHST_STR,
MANDT TYPE STRING,
ABGJR TYPE STRING,
GRUPP_NR TYPE STRING,
BEZEICH TYPE STRING,
BEZEICH1 TYPE STRING,
GRUPPE0 TYPE STRING,
GRUPPE1 TYPE STRING,
GRUPPE2 TYPE STRING,
GRUPPE3 TYPE STRING,
GRUPPE4 TYPE STRING,
GRUPPE5 TYPE STRING,
GRUPPE6 TYPE STRING,
GRUPPE7 TYPE STRING,
GRUPPE8 TYPE STRING,
GRUPPE9 TYPE STRING,
GRUPPE10 TYPE STRING,
GRUPPE11 TYPE STRING,
GRUPPE12 TYPE STRING,
GRUPPE13 TYPE STRING,
GRUPPE14 TYPE STRING,
GRUPPE15 TYPE STRING,
GRUPPE16 TYPE STRING,
GRUPPE17 TYPE STRING,
GRUPPE18 TYPE STRING,
GRUPPE19 TYPE STRING,
GLD1 TYPE STRING,
GLD2 TYPE STRING,
GLD3 TYPE STRING,
GLD4 TYPE STRING,
GLD5 TYPE STRING,
GLD6 TYPE STRING,
GLD7 TYPE STRING,
GLD8 TYPE STRING,
GLD9 TYPE STRING,
GLD10 TYPE STRING,
GLD11 TYPE STRING,
GLD12 TYPE STRING,
GLD13 TYPE STRING,
GLD14 TYPE STRING,
GLD15 TYPE STRING,
GLD16 TYPE STRING,
GLD17 TYPE STRING,
GLD18 TYPE STRING,
GLD19 TYPE STRING,
GLD20 TYPE STRING,
GLD0 TYPE STRING,END OF T_EKKO_STR. DATA: WA_V_FMFIHHST_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_FMFIHHST_STR-MANDT sy-vline
WA_V_FMFIHHST_STR-ABGJR sy-vline
WA_V_FMFIHHST_STR-GRUPP_NR sy-vline
WA_V_FMFIHHST_STR-BEZEICH sy-vline
WA_V_FMFIHHST_STR-BEZEICH1 sy-vline
WA_V_FMFIHHST_STR-GRUPPE0 sy-vline
WA_V_FMFIHHST_STR-GRUPPE1 sy-vline
WA_V_FMFIHHST_STR-GRUPPE2 sy-vline
WA_V_FMFIHHST_STR-GRUPPE3 sy-vline
WA_V_FMFIHHST_STR-GRUPPE4 sy-vline
WA_V_FMFIHHST_STR-GRUPPE5 sy-vline
WA_V_FMFIHHST_STR-GRUPPE6 sy-vline
WA_V_FMFIHHST_STR-GRUPPE7 sy-vline
WA_V_FMFIHHST_STR-GRUPPE8 sy-vline
WA_V_FMFIHHST_STR-GRUPPE9 sy-vline
WA_V_FMFIHHST_STR-GRUPPE10 sy-vline
WA_V_FMFIHHST_STR-GRUPPE11 sy-vline
WA_V_FMFIHHST_STR-GRUPPE12 sy-vline
WA_V_FMFIHHST_STR-GRUPPE13 sy-vline
WA_V_FMFIHHST_STR-GRUPPE14 sy-vline
WA_V_FMFIHHST_STR-GRUPPE15 sy-vline
WA_V_FMFIHHST_STR-GRUPPE16 sy-vline
WA_V_FMFIHHST_STR-GRUPPE17 sy-vline
WA_V_FMFIHHST_STR-GRUPPE18 sy-vline
WA_V_FMFIHHST_STR-GRUPPE19 sy-vline
WA_V_FMFIHHST_STR-GLD1 sy-vline
WA_V_FMFIHHST_STR-GLD2 sy-vline
WA_V_FMFIHHST_STR-GLD3 sy-vline
WA_V_FMFIHHST_STR-GLD4 sy-vline
WA_V_FMFIHHST_STR-GLD5 sy-vline
WA_V_FMFIHHST_STR-GLD6 sy-vline
WA_V_FMFIHHST_STR-GLD7 sy-vline
WA_V_FMFIHHST_STR-GLD8 sy-vline
WA_V_FMFIHHST_STR-GLD9 sy-vline
WA_V_FMFIHHST_STR-GLD10 sy-vline
WA_V_FMFIHHST_STR-GLD11 sy-vline
WA_V_FMFIHHST_STR-GLD12 sy-vline
WA_V_FMFIHHST_STR-GLD13 sy-vline
WA_V_FMFIHHST_STR-GLD14 sy-vline
WA_V_FMFIHHST_STR-GLD15 sy-vline
WA_V_FMFIHHST_STR-GLD16 sy-vline
WA_V_FMFIHHST_STR-GLD17 sy-vline
WA_V_FMFIHHST_STR-GLD18 sy-vline
WA_V_FMFIHHST_STR-GLD19 sy-vline
WA_V_FMFIHHST_STR-GLD20 sy-vline
WA_V_FMFIHHST_STR-GLD0 sy-vline INTO ld_text SEPARATED BY SPACE. *Add any further fields from structure WA_EKKO_STR you want to CONCATENATE... ENDLOOP. ENDFORM.