• 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

To report this post you need to login first.

30 Comments

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

  1. 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.

    (0) 
  2. ganesh m

    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

    (0) 
      1. 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.

        (0) 
      2. ganesh m

        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?…… 😕


        (0) 
  3. 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

    (0) 

Leave a Reply