Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
GFV
Active Contributor
0 Kudos

I needed to implement the SAP How-To solution named “How to Load a Flat File into BW-BPS Using SAPGUI“ (available in SDN

). The solution was pretty good for the problem I had, but I came into trouble when transporting the Function Group (as Function Modules).

May be some of you did solve the problem … but unfortunately when I posted in SDN (see thread BPS - How to Load Flat File ... - Transport RC 8) I didn’t met you! So I came across ABAP forum to have some help (I’m not very familiar with ABAP and I had a very big help there) with the coding and, at the end, here I am to share the solution.




Before going on with the solution I want to thank all the patient guys that answered me in the ABAP Forum (see thread Internal Table declaring on Field-symbol?) with a special mention to Uwe Reichel that gave me a lot of precious answers.







The coding provided in the How-To for the Global Data of the Function Group is the following:





"How To" coding for Global Data


  • Type definitions:

  • Structures and tables that correspond to the planning area.

  • Note: Replace client number (800) and area (ZFILE) corresponding to your setup.

  • ADJUST >>>>

  TYPES: yth_data TYPE /1sem/_yth_data_800zfile,

         yt_data  TYPE /1sem/_yt_data_800zfile,

         ys_data  TYPE /1sem/_ys_data_800zfile,

         yto_chas TYPE /1sem/_yto_chas_800zfile,

         ys_chas  TYPE /1sem/_ys_chas_800zfile,

         ys_kyfs  TYPE /1sem/_ys_kyfs_800zfile.

  • <<<< ADJUST







In my system landscape the Client are different, and that’s why I had problem with the transports. In fact in the transport log I had a message like “The type '/1SEM/_YTH_DATA_800ZFILE' is unknown”.
The problem can be solved with field-symbols, so I replaced the above declarations with the following:







MY coding for Global Data


  • Definitions:

  DATA: lr_plarat TYPE REF TO cl_sem_planarea_attributes,

      lrth_data      TYPE REF TO data,

      lrs_data       TYPE REF TO data.

  FIELD-SYMBOLS:

              

FUNCTION Z_SEM_BPS_EXIT_FILE_LOAD_INIT.

*"----


""Interfaccia locale:

*"  IMPORTING

*"     REFERENCE(I_AREA) TYPE  UPC_Y_AREA

*"     REFERENCE(I_PLEVEL) TYPE  UPC_Y_PLEVEL

*"     REFERENCE(I_PACKAGE) TYPE  UPC_Y_PACKAGE

*"     REFERENCE(I_METHOD) TYPE  UPC_Y_METHOD

*"     REFERENCE(I_PARAM) TYPE  UPC_Y_PARAM

*"     REFERENCE(IT_EXITP) TYPE  UPF_YT_EXITP

*"     REFERENCE(ITO_CHASEL) TYPE  UPC_YTO_CHASEL

*"     REFERENCE(ITO_CHA) TYPE  UPC_YTO_CHA

*"     REFERENCE(ITO_KYF) TYPE  UPC_YTO_KYF

*"  EXPORTING

*"     REFERENCE(ETO_CHAS) TYPE  SORTED TABLE

*"     REFERENCE(ET_MESG) TYPE  UPC_YT_MESG

*"----


  FIELD-SYMBOLS: .

  DATA:

  •        lto_chas TYPE yto_chas,

  •        ls_chas TYPE ys_chas,

        ls_exitp TYPE upf_ys_exitp,

        ls_mesg TYPE upc_ys_mesg,

        ls_chasel TYPE upc_ys_chasel, " TYPE ANY. "<<<INSERT

  • Try to get file name from parameter

  READ TABLE it_exitp INTO ls_exitp WITH KEY parnm = 'FILENAME'.

  IF sy-subrc = 0.

    l_file = ls_exitp-chavl.

  ENDIF.

  • If no file name is given, prompt user for it

  IF l_file IS INITIAL.

    CALL METHOD cl_gui_frontend_services=>file_open_dialog

      EXPORTING

        window_title            = 'Select Upload File'

        default_extension       = 'txt'

        file_filter             = 'Text Files (*.txt)'

      CHANGING

        file_table              = lt_filetab

        rc                      = l_count

        user_action             = l_action

      EXCEPTIONS

        file_open_dialog_failed = 1

        cntl_error              = 2

        OTHERS                  = 3.                        "#EC NOTEXT

    IF sy-subrc <> 0.

      CLEAR ls_mesg.

      MOVE-CORRESPONDING syst TO ls_mesg.

      APPEND ls_mesg TO et_mesg.

      EXIT.

    ENDIF.

    CALL METHOD cl_gui_cfw=>flush.

    LOOP AT lt_filetab INTO ls_filetab.

      l_file = ls_filetab.

    ENDLOOP.

    CHECK l_action = 0.

  ENDIF.

  l_separator = 'X'.

  • Upload file from front-end (PC)

  • File format is tab-delimited ASCII

  CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

      filename                = l_file

      has_field_separator     = l_separator

    TABLES

      data_tab                = gt_file

    EXCEPTIONS

      file_open_error         = 1

      file_read_error         = 2

      no_batch                = 3

      gui_refuse_filetransfer = 4

      invalid_type            = 5

      no_authority            = 6

      unknown_error           = 7

      bad_data_format         = 8

      header_not_allowed      = 9

      separator_not_allowed   = 10

      header_too_long         = 11

      unknown_dp_error        = 12

      access_denied           = 13

      dp_out_of_memory        = 14

      disk_full               = 15

      dp_timeout              = 16

      OTHERS                  = 17.

  IF sy-subrc <> 0.

    CLEAR ls_mesg.

    MOVE-CORRESPONDING syst TO ls_mesg.

    APPEND ls_mesg TO et_mesg.

    EXIT.

  ENDIF.

  • Create one dummy combination

  • If we don't do this, the upload won't work since the second function

  • will not be executed at all in case no transaction data exists so far.

  • The combination must be a subset of the planning level!

  CLEAR

FUNCTION Z_SEM_BPS_EXIT_FILE_LOAD.

*"----


""Interfaccia locale:

*"  IMPORTING

*"     REFERENCE(I_AREA) TYPE  UPC_Y_AREA

*"     REFERENCE(I_PLEVEL) TYPE  UPC_Y_PLEVEL

*"     REFERENCE(I_PACKAGE) TYPE  UPC_Y_PACKAGE

*"     REFERENCE(I_METHOD) TYPE  UPC_Y_METHOD

*"     REFERENCE(I_PARAM) TYPE  UPC_Y_PARAM

*"     REFERENCE(IT_EXITP) TYPE  UPF_YT_EXITP

*"     REFERENCE(ITO_CHASEL) TYPE  UPC_YTO_CHASEL

*"     REFERENCE(ITO_CHA) TYPE  UPC_YTO_CHA

*"     REFERENCE(ITO_KYF) TYPE  UPC_YTO_KYF

*"  EXPORTING

*"     REFERENCE(ET_MESG) TYPE  UPC_YT_MESG

*"  CHANGING

*"     REFERENCE(XTH_DATA) TYPE  HASHED TABLE

*"----


  FIELD-SYMBOLS:  TYPE ANY. " <<< INSERT

  • Has any data been loaded?

  CHECK NOT gt_file[] IS INITIAL.

  • Overwrite existing data or add to existing data?

  • Change the IF depending on which alternative you require

  IF 1 = 1. "  = xth_data. " Keep existing data

  ENDIF.

  • Map and merge loaded data

  LOOP AT gt_file INTO ls_file.

    CHECK sy-tabix > 1. " Skip first line with field names

    CLEAR .

  • >>> INSERT

  • Set fixed fields

    LOOP AT ito_chasel INTO ls_chasel.

      READ TABLE ls_chasel-t_charng INTO ls_charng INDEX 1.

      IF sy-subrc = 0 AND ls_charng-option = 'EQ'.

        ASSIGN COMPONENT ls_chasel-chanm

            OF STRUCTURE  = ls_charng-low.

        ENDIF.

      ENDIF.

    ENDLOOP.

  • <<< INSERT

    COLLECT .

  ENDLOOP.

  • Return loaded data to BPS

  LOOP AT  INTO xth_data.

  ENDLOOP.

  • Clear temporary table

  REFRESH gt_file.

ENDFUNCTION.








Hope it helps




GFV



6 Comments