Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member200388
Active Participant

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.

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

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

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

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_description-name = 'FILE_NAME'.
  ls_field_description-read_only = abap_true.

  APPEND ls_field_description TO et_field_description.

* File Upload field description
  ls_field_description-mandatory = abap_true.

  CLEAR: ls_field_description-mandatory_ref.

  ls_field_description-name = 'FILE_UPLOAD'.
  ls_field_description-mime_type_ref = 'MIME_TYPE'.
  ls_field_description-file_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_definition-id = 'UPLOAD'.
  ls_action_definition-enabled = 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 )

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 sy-tabix = 1.
                  CONTINUE.
                ENDIF.

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

                  ls_sflight-carrid = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-carrid = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-connid = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-fldate = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-price = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-currency = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-planetype = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-seatsmax = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-seatsocc = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-paymentsum = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-seatsmax_b = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-seatsocc_b = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-seatsmax_f = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

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

                  ls_sflight-seatsocc_f = <lfs_temp>.
                  UNASSIGN <lfs_temp>.

                ENDIF.

                ls_sflight-mandt = sy-mandt.

                APPEND ls_sflight TO lt_sflight.
                CLEAR: ls_sflight.

              ENDIF.

            ENDLOOP.

            IF lt_sflight IS NOT INITIAL.

              MODIFY sflight FROM TABLE lt_sflight.
              IF sy-subrc = 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.

b.

c. Check the data in SFLIGHT

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.

7 Comments
Labels in this area