Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata
  • Download A Field Value Leading with zero’s  Using GUI_DOWNLOAD Function Module (i.e. Like ..Material Number, Material Group …etc.. in MM Module).


Screenshot # 1


 

Solution:


Screenshot # 2


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


Source Code :

 

Error rendering macro 'code': Invalid value specified for parameter 'lang'
REPORT  YSCN_DWN_EXL_LED_ZERO  .

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 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
*&---------------------------------------------------------------------*
*&      Form  f_browse
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->FC_FILE    text
*----------------------------------------------------------------------*
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

*&---------------------------------------------------------------------*
*&      Form  DATA_RETRIVEL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*&      Form  HEADER_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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
*&---------------------------------------------------------------------*
*&      Form  DOWLOAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
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 :