Recently I had a requirement of using a file upload UI element within a FPM driven application. So I searched for blogs/discussions on this topic to understand it’s basic behavior but could not find any, which focusses mainly on this. So I thought of jotting the simple steps for using this element herein and evetually provide a demo for file upload  ” Upload an excel file and populate the data in SFLIGHT table ” . Hope this will definitely bring some help to the beginners in FPM like me.

Moreover, I will try to compare the File Upload UI element usage in simple Webdynpro and using it in FPM. This will help understanding the working behaviour of it in FPM.

System details: ECC 6.0 EHP6

Let us take a look back into the simple Webdynpro file upload UI element.

Pic1.jpg

The main 3 attributes supplied by Web Dynpro:

a. DATA : This will populate the file content in datatype XSTRING

b. FILENAME: Will populate the filename of the file in datatype STRING

c. MIMETYPE: Will populate the extension of the file in datatype STRING

This 3 attributes or feature is used in WebDynpro to provide the functionality of file uplaod in application.

Let us now take a look how this functionality has been handled in FPM framework.

Step 1: We need to decide which type of FPM application based on our requirements. For this example, I will create a config for FPM_OVP_COMPONENT

Step 2: I will be using a generic UIBB to design the File Upload element. Below is the config ID for FPM_FORM_UIBB_GL2

Pic2.jpg

Step 3: Let us look at the Feeder class for this config. The Feeder must implement interface IF_FPM_UIBB and IF_FPM_UIBB_FORM

Pic3.jpg

Step 4: Define the structure which must be available for FLUID editor in the config.

Pic4.jpg

Step 5: Let us do a bit of coding and implement the GET_DEFINITION method supplied by interface IF_FPM_FORM_UIBB

   METHOD if_fpm_guibb_form~get_definition.

  DATA: ls_action_definition TYPE fpmgb_s_actiondef,
        ls_field_description TYPE fpmgb_s_formfield_descr.

** gs_form_fields type t_form_fields

  eo_field_catalog ?= cl_abap_structdescr=>describe_by_data(
                                              gs_form_fields ).

* File Name field description
  ls_field_descriptionname = ‘FILE_NAME’.
  ls_field_descriptionread_only = abap_true.

  APPEND ls_field_description TO et_field_description.

* File Upload field description
  ls_field_descriptionmandatory = abap_true.

  CLEAR: ls_field_descriptionmandatory_ref.

  ls_field_descriptionname = ‘FILE_UPLOAD’.
  ls_field_descriptionmime_type_ref = ‘MIME_TYPE’.
  ls_field_descriptionfile_name_ref = ‘FILE_NAME’.

  ls_field_description-default_display_type = ‘FU’.    “FU : File Upload”

  APPEND ls_field_description TO et_field_description.

** Action Button definition
  ls_action_definitionid = ‘UPLOAD’.
  ls_action_definitionenabled = abap_true.

  APPEND ls_action_definition TO et_action_definition.

ENDMETHOD.

Step 6: Let us design the config ID and use FLUID editor (simply nice in EHP6 )

Pic5.jpg

Step 7: An action is assigned to the UPLOAD button. We will handle this action in the Feeder Class

Step 8: Let us handle the action UPLOAD in the GET_DATA menthod.

   METHOD if_fpm_guibb_form~get_data.

  CHECK io_event->mv_event_id = ‘UPLOAD’.

  FIELD-SYMBOLS: <lfs_data> TYPE t_form_fields,
                 <lfs_table> TYPE STANDARD TABLE,
                 <lfs_struc> TYPE any,
                 <lfs_temp> TYPE any.

  DATA: lref_excel             TYPE REF TO cl_fdt_xl_spreadsheet,
        lref_excel_core        TYPE REF TO cx_fdt_excel_core,
        lref_data              TYPE REF TO data,
        lt_worksheets          TYPE STANDARD TABLE OF string,
        lv_ws_name             TYPE string,
        lv_xstring             TYPE xstring,
        ls_sflight             TYPE sflight,
        lt_sflight             TYPE STANDARD TABLE OF sflight.

  ASSIGN cs_data TO <lfs_data>.

  IF <lfs_data> IS ASSIGNED.
    lv_xstring = <lfs_data>file_upload.

    TRY.

        CREATE OBJECT lref_excel
          EXPORTING
            document_name = <lfs_data>file_name
            xdocument     = lv_xstring.
      CATCH cx_fdt_excel_core INTO lref_excel_core.
        RETURN.
    ENDTRY.

* Call method to get list of worksheets in the .xlsx file
    IF lref_excel IS BOUND.
      lref_excel->if_fdt_doc_spreadsheet~get_worksheet_names(
           IMPORTING
             worksheet_names = lt_worksheets ).

* Condition to check whether .xlsx file has any active worksheets

      IF lt_worksheets IS NOT INITIAL.

*   Read active worksheet

        READ TABLE lt_worksheets INDEX 1 INTO lv_ws_name.
* Get reference of .xlsx file contents in the active worksheet
        lref_data =
        lref_excel->if_fdt_doc_spreadsheet~get_itab_from_worksheet(
                                                   lv_ws_name ).

* Check if any blank excel file is uploaded by user
        IF lref_data IS BOUND.
          ASSIGN lref_data->* TO <lfs_table>.

          IF <lfs_table> IS ASSIGNED.

            LOOP AT <lfs_table> ASSIGNING <lfs_struc>.
              IF <lfs_struc> IS ASSIGNED.
                IF sytabix = 1.
                  CONTINUE.
                ENDIF.

                ASSIGN COMPONENT 1 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightcarrid = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 1 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightcarrid = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 2 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightconnid = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 3 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightfldate = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 4 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightprice = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 5 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightcurrency = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 6 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightplanetype = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 7 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightseatsmax = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 8 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightseatsocc = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 9 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightpaymentsum = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 10 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightseatsmax_b = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 11 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightseatsocc_b = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 12 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightseatsmax_f = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.
                ASSIGN COMPONENT 13 OF STRUCTURE <lfs_struc> TO
                  <lfs_temp>.
                IF <lfs_temp> IS ASSIGNED.

                  ls_sflightseatsocc_f = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.

                ls_sflightmandt = symandt.

                APPEND ls_sflight TO lt_sflight.
                CLEAR: ls_sflight.

              ENDIF.

            ENDLOOP.

            IF lt_sflight IS NOT INITIAL.

              MODIFY sflight FROM TABLE lt_sflight.
              IF sysubrc = 0.
                ev_data_changed = abap_true.
              ENDIF.

            ENDIF.

          ENDIF.

        ENDIF.

      ENDIF.
    ENDIF.

  ENDIF.

ENDMETHOD.

Step 9: Thats all!!!  Let us give it a dry run.

a. Run the FPM application. Browse and select an excel (.XLSX) file.

Pic6.jpg

b. Pic7.jpg

c. Check the data in SFLIGHT

Pic8.jpg

I hope that people new to FPM will find it useful.

Thanks to Debasis and Sumit for their support on my journey in FPM

Please share your suggestions if any.

To report this post you need to login first.

5 Comments

You must be Logged on to comment or reply to a post.

  1. Chandra Indukuri

    I have a question.

    I did it similarly but not getting any data in GET_DATA method(no data). In the config we should have “FILE_NAME” as input field (step 6), am I right?

    Thanks,

    Chandra Indukuri

    (0) 

Leave a Reply