Writing File Using Methods Of CL_GUI_FRONTEND SERVICES

 

  • CL_GUI_FRONTEND SERVICES is one of the important classes provided by SAP in object oriented concepts.
  • In ABAP we can use GUI_DOWNLOAD method of CL_GUI_FRONTEND_SERVICES to download the contents of a internal table into file.

Requirement :-

  • Use want to download the details of Sales Document for a particular range into his local desktop.



Solution :-

  • Step 1 :- Create a executable program in ABAP Editor.



  • Step 2 :- Create a type structure for VBAK table and then create its corresponding internal table.



  • Step 3 :- create a select option for user input.





  • Step 4 :- Write select queries to fetch the details.



  • Step 5 :- Use method GUI_DOWNLOAD of CL_GUI_FRONTEND_SERVICES to download the file.




Code :-

*&---------------------------------------------------------------------*
*& Report ZAR_FILE_DOWNLOAD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZAR_FILE_DOWNLOAD.

types : begin of ty_vbak,
   vbeln type vbeln_va,
   erdat type erdat,
  erzet type erzet,
  ernam type ernam,
  vbtyp type vbtypl,
  end of ty_vbak.

  DATA : lt_vbak type table of ty_vbak.
  DATA : lv_vbeln type vbeln_va.
  SELECT-OPTIONS : s_vbeln for lv_vbeln.

  START-OF-SELECTION.

  select vbeln erdat erzet ernam vbtyp
    from vbak into table lt_vbak
    where vbeln in s_vbeln.

    if lt_vbak is NOT INITIAL.

    CALL METHOD cl_gui_frontend_services=>gui_download
      EXPORTING
*        bin_filesize              =
        filename                  = 'C:\\Users\\s419ah02\\Desktop\\NON SAP.txt'
*        filetype                  = 'ASC'
*        append                    = SPACE
        write_field_separator     = 'X'
      changing
        data_tab                  = lt_vbak
      EXCEPTIONS
        file_write_error          = 1
        no_batch                  = 2
        gui_refuse_filetransfer   = 3
        invalid_type              = 4
        no_authority              = 5
        unknown_error             = 6
        header_not_allowed        = 7
        separator_not_allowed     = 8
        filesize_not_allowed      = 9
        header_too_long           = 10
        dp_error_create           = 11
        dp_error_send             = 12
        dp_error_write            = 13
        unknown_dp_error          = 14
        access_denied             = 15
        dp_out_of_memory          = 16
        disk_full                 = 17
        dp_timeout                = 18
        file_not_found            = 19
        dataprovider_exception    = 20
        control_flush_error       = 21
        not_supported_by_gui      = 22
        error_no_gui              = 23
        others                    = 24
            .
    IF sy-subrc <> 0.
*     Implement suitable error handling here
    ENDIF.

    endif.

Execute the Code :-



  • Press F8 and data will be downloaded to your file.



Comments

Popular posts from this blog

Understanding Different Types of SAP Function Modules: Normal, RFC, and Update

Unlocking SAP ABAP Secrets: Interactive Classical Reports with GET CURSOR, At User Command, and a Comparison of HIDE Statements

Mastering ABAP: A Step-by-Step Guide to Function Modules and Groups for Modularized Programming