Skip to Content
Author's profile photo Former Member

How to Download Leading with Zeros from SAP to Excel Sheet using GUI_Download FM

  • Some Time We Need Download A Field Value Leading with zero’s Using GUI_DOWNLOAD Function Module (i.e. Like  …Material Number, Material Group …etc.. in MM Module).

/wp-content/uploads/2013/10/s1_295716.png

Screenshot # 1

Solution :  Using File type as ‘DBF’  , We easily got Field value in MS.Excel leading with Zero’s , Like Material Number from MARA Table .

‘DBF’ :

Data is downloaded in dBase format. Since in this format the data types of the individual columns are stored as well, you can often avoid import problems, for example, into Microsoft Excel, especially when interpreting numeric values.

Screenshot2.png

Screenshot # 2

  1.   Create Custom Download Program using ‘GUI_DOWNLOAD’ Functional Module.

Data Declaration


TYPES: BEGIN OF TY_FINAL ,

        MBRSH     LIKE     MARA-MBRSH,

        MTART     LIKE     MARA-MTART,

        MATNR     LIKE     MARA-MATNR,

        MEINS     LIKE     MARA-MEINS,

        MATKL     LIKE     MARA-MATKL,

   END OF TY_FINAL.

DATA: I_FINAL TYPE STANDARD TABLE OF TY_FINAL INITIAL SIZE 0,  ” Final internal Table

      WA_FINAL TYPE TY_FINAL.  ” Work Area

DATA : BEGIN OF INT_HEAD OCCURS 0,

FILED1(20) TYPE C,                     ” Header Data

END OF INT_HEAD.

DATA: LO_GUI TYPE REF TO CL_GUI_FRONTEND_SERVICES,

      LV_TITLE TYPE STRING,

      LV_FOLDER TYPE STRING,    “

      LV_DIR TYPE STRING,       ” Select Folder Location

      V_FILETYPE TYPE STRING,   ” File Type ‘.xls’

      V_FILENAME TYPE STRING,

      LV_FILENAME TYPE STRING.

Selection Screen

**SELECTION SCREEN DETAILS

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETER P_FILE LIKE RLGRAP-FILENAME .  ” Input File Name with Specific Path like ‘C:\Temp\Test.Xls’

SELECTION-SCREEN END OF BLOCK B1.

AT SELECTION-SCREEN.

  IF P_FILE IS INITIAL.

    MESSAGE S368(00) WITH ‘Please input filename’. STOP.

  ENDIF.

F4 Help getting Excel File Name with Comlete Path

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

  PERFORM F_BROWSE CHANGING P_FILE.

START-OF-SELECTION.

  PERFORM DATA_RETRIVEL.   ” Data Retrive

  PERFORM HEADER_DATA.     ” Excel Technical Field Names

  PERFORM DOWLOAD.         ” Download Excel File to the Specific Location

F4 Help getting Excel File Name with Complete Path using Class  ‘CL_GUI_FRONTEND_SERVICES‘  and  Method ‘DIRECTORY_BROWSE‘.

FORM F_BROWSE CHANGING FC_FILE.

  DATA: LO_GUI TYPE REF TO CL_GUI_FRONTEND_SERVICES,

  LV_TITLE TYPE STRING,

  LV_FOLDER TYPE STRING,

  LV_DIR TYPE STRING.

  CREATE OBJECT LO_GUI.

  LV_TITLE = ‘Define download location’.

  LV_FOLDER = ‘C:\TEMP\’.

  CALL METHOD LO_GUI->DIRECTORY_BROWSE

    EXPORTING

      WINDOW_TITLE    = LV_TITLE       “Title of the browser window

      INITIAL_FOLDER  = LV_FOLDER      “Browse begins here

    CHANGING

      SELECTED_FOLDER = LV_DIR.        “Folder Selected By User

      FC_FILE = LV_DIR.

ENDFORM.                    “f_browse


Data Retrival

FORM DATA_RETRIVEL .

  SELECT MARA~MATKL MARA~MATNR MARA~MBRSH MARA~MEINS MARA~MTART

     INTO CORRESPONDING FIELDS OF TABLE I_FINAL

    FROM MARA UP TO 10 ROWS

    WHERE MBRSH EQ ‘M’

    AND MTART EQ ‘ERSA’.

ENDFORM.                     “DATA_RETRIVEL

Header Field Name

FORM HEADER_DATA .

  INT_HEAD-FILED1 =  ‘MBRSH’.

  APPEND INT_HEAD.

  CLEAR INT_HEAD.

  INT_HEAD-FILED1 =  ‘MTART’.

  APPEND INT_HEAD.

  CLEAR INT_HEAD.

  INT_HEAD-FILED1 =  ‘MATNR’.

  APPEND INT_HEAD.

  CLEAR INT_HEAD.

  INT_HEAD-FILED1 =  ‘MEINS’.

  APPEND INT_HEAD.

  CLEAR INT_HEAD.

  INT_HEAD-FILED1 =  ‘MATKL’.

  APPEND INT_HEAD.

  CLEAR INT_HEAD.

ENDFORM.                    ” HEADER_DATA

Transfer data to ExcelSheet (i.e. .Xls File)

FORM DOWLOAD .

  V_FILETYPE = ‘.xls’.                                                               ” Excel File Extentation .xls

  V_FILENAME = P_FILE.                                                         ” File Name

  CONCATENATE P_FILE V_FILETYPE INTO LV_FILENAME.

  CALL FUNCTION ‘GUI_DOWNLOAD’

    EXPORTING

      FILENAME                              = LV_FILENAME                  ” Excel File with path and extentation like “C:\Temp\Test.Xls

      FILETYPE                              = ‘DBF’

      WRITE_FIELD_SEPARATOR   = ‘ ‘

    TABLES

      DATA_TAB                              = I_FINAL     ” Final Internal table with Data

      FIELDNAMES                          = INT_HEAD    ” Technical Field Name

    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

      OTHERS                  = 22.

  IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

ENDFORM.                    ” DOWLOAD


Output:

/wp-content/uploads/2013/10/s1_295716.png

Screenshot # 3

Note: File Name : Test without  .Xls Extension  ( Extension already mentation in Source Code )

           File Location :  ‘C:\Temp\’


/wp-content/uploads/2013/10/s1_295716.png

Screenshot # 4



Reference : “GUI_DOWNLOAD” Function Module Documentation

Source Code : How to Download Leading With Zeros from SAP to Excel Sheet using GUI_Download Function Module – A…

Regard’s

Smruti

Assigned Tags

      31 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Venkat B
      Venkat B

      Hi Mohanty,

      Small Tip, but it gives magical output(Very Useful), which i haven't seen in SDN. Thanks for the document

      Regards,

      Venkat.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Venkat.. 🙂

      Regard's

      Smruti

      Author's profile photo Modadugu Hemanth Kumar
      Modadugu Hemanth Kumar

      Infomative with step by step 😀 .. Good work Smruti Ranjan.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Hemanth... 🙂

      Regard's

      Smruti

      Author's profile photo rajesh bethamcharla
      rajesh bethamcharla

      Good analysis....keep it up.. 🙂

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Rajesh  🙂

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Hi Smruti Ranjan Mohanty,

      Nothing New......

      You are just defining DBF

      CALL FUNCTION 'GUI_DOWNLOAD'

          EXPORTING

            FILENAME                = LV_FILENAME " Excel File with path and extentation like "C:\Temp\Test.Xls

            FILETYPE                = 'DBF'

            WRITE_FIELD_SEPARATOR   = ' '

          TABLES

            DATA_TAB                = I_FINAL     " Final Internal table with Data

            FIELDNAMES              = INT_HEAD    " Technical Field Name

          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

            OTHERS                  = 22.

        IF SY-SUBRC <> 0.

      * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

      *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

        ENDIF.

      This concept already covered in 2008

      refer this links

      http://scn.sap.com/thread/755798

      https://scn.sap.com/thread/767766

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Ganesh for your Comment... 🙂

      Yeah i know this FM is Not new for any abaper but in scn i hope it is new document which will download the data in '.Xls' format and leading with Zero.

      http://scn.sap.com/thread/755798

      https://scn.sap.com/thread/767766

      and about your link which  indicates "Assumed Answered." not "Helpfull or Correct Answar" 🙁

      Regard's

      Smruti

      Author's profile photo Matthew Billingham
      Matthew Billingham

      Smruti Ranjan Mohanty wrote:

                             

      ...

      and about your link which  indicates "Assumed Answered." not "Helpfull or Correct Answar" 🙁

      Regard's

      Smruti

                         

      That just means the OP never went back and marked the answer. There are anti-social people like that - especially on the older threads. Given the number of answers that are marked helpful or even correct which are neither, it's hardly a measure of content quality.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks for Feedback Matthew Billingham

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Nice reply from you......

      and about your link which  indicates "Assumed Answered." not "Helpfull or Correct Answar" 🙁

      Than what you say in 2008 it is Not Correct Answer in 2013 after posting you it become Correct Answer?...... 😕


      Author's profile photo Former Member
      Former Member
      Blog Post Author

      😆 with source code and output. .....

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Silly reply .... 😛

      Author's profile photo Former Member
      Former Member

      Thanks for the tip....

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Ravi... 🙂

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Helpful tip,Thanks For providing with steps.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Giri.. 🙂

      Regard's

      Smruti

      Author's profile photo Varun Kumar Sahu
      Varun Kumar Sahu

      Hi Smruti,

      Many thanks for the tip. A very handy and wonderful tip. Will go long way!

      Regards,

      Varun Kumar Sahu

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Varun Kumar Sahu .. 🙂

      Regard's

      Smruti

      Author's profile photo Anupam Anand
      Anupam Anand

      Hi Smruti,

      Had read about the DBF filetype for GUI_DOWNLOAD. Good to see that in use.

      A helpful note. Shall definetely go down in my tips and tricks notes.

      Thanks,

      Anupam

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Anupam Anand 🙂

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Hi Smruthi,

      Informative. Thanks for sharing.

      Regrads,

      Riju

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Riju Thomas 🙂

      Regard's

      Smruti

      Author's profile photo Srinu S
      Srinu S

      Hi,

      Very useful. Keep rocking.

      thanks for sharing.

      Srinu.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Srinivas S 🙂

      Regard's

      Smruti

      Author's profile photo Bisweswar Sahu
      Bisweswar Sahu

      Hi,

      Saved a lot time during data validation activities.

      Thanks a lot.

      Regards,

      Bisweswar

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Bisweswar Sahu   🙂

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Thanks for sharing. Learned a lot from your post.

      Keep sharing n posting.

      Author's profile photo Former Member
      Former Member
      Blog Post Author

      Thanks Amaranatha Madhaba 🙂

      Regard's

      Smruti

      Author's profile photo Former Member
      Former Member

      Hi Smruti, But using DBF extension the heading for cloumns is restricted to 10 characters only. So,how to over come that problem.

      Author's profile photo Ashwin Vengurlekar
      Ashwin Vengurlekar

      I used the same technique in my program but when we use special symbols then this technique is not working , In download it will show # character for that special symbol