Tuesday, April 29, 2008

SAP ABAP Upload File with Path Selector Dialog Box

SAP ABAP Upload File with Path Selector Dialog Box

SAP ABAP provides a function modules to upload and download files. It also has a function module to call windows dialog box to select the path. We will examine the following function modules.

F4_FILENAME
GUI_UPLOAD

In SAP ABAP F4_FILENAME calls the file selector dialog box and GUI_UPLOAD actually uploads the file to an internal table defined in the code.

EXAMPLE


REPORT ZEX_READFILE_FROMDIR .


Data: d_filename like IBIPPARMS-PATH,
      d_file type string.

data : begin of itab occurs 0,
           values(1000) type c,
           end of itab.

* The following function module calls the File/Path Selector Dialog Box

CALL FUNCTION 'F4_FILENAME'
 EXPORTING
   PROGRAM_NAME         = SYST-CPROG
   DYNPRO_NUMBER        = SYST-DYNNR
   FIELD_NAME                 = ' '
 IMPORTING
   FILE_NAME                   = d_filename.

d_file = d_filename.

* The following function module uploads the file into the internal table

   CALL FUNCTION 'GUI_UPLOAD'
     EXPORTING
      FILENAME                             = d_file
      FILETYPE                               = 'ASC'
      HAS_FIELD_SEPARATOR           = ' '
      HEADER_LENGTH                 = 0
      READ_BY_LINE                      = 'X'
      DAT_MODE                           = ' '
*    IMPORTING
*      FILELENGTH                       =
*      HEADER                             =
     TABLES
       DATA_TAB                          = itab
    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.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.

* Output the internal Table

loop at itab.
   Write:/ ITAB.
endloop.


The output of the above program would be as follows.

Reading File From Dirctory                  
                                            
Filed1,Filed2,Field3,Filed4,Field5,Filed6   
                                            


No comments:

Post a Comment