Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Problem in file upload.

Former Member
0 Likes
780

here is my code:

DECLARATIONS

DATA  P_FILE TYPE STRING.

DATA  I_FILE_TABLE TYPE TABLE OF FILE_TABLE.

DATA  P_EXT TYPE STRING.

DATA  RC TYPE I.

CODE TO UPLOAD FILE.

DATA OBJ TYPE REF TO CL_GUI_FRONTEND_SERVICES.

DATA : BEGIN OF I_TAB OCCURS 0,

   LIFNR(10),

   BUKRS(4),

   EKORG(4),

   WITHT(2),

   WT_WITHCD(2),

   END OF I_TAB.

START-OF-SELECTION.

   CREATE OBJECT OBJ.

   CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

     EXPORTING

       WINDOW_TITLE            = 'Select Excel File To Upload'

*      DEFAULT_EXTENSION       = '.XLS'

       DEFAULT_FILENAME        = P_FILE

*      FILE_FILTER             =

*      WITH_ENCODING           =

*      INITIAL_DIRECTORY       =

*      MULTISELECTION          =

     CHANGING

       FILE_TABLE              = I_FILE_TABLE

       RC                      = RC

*      USER_ACTION             =

*      FILE_ENCODING           =

     EXCEPTIONS

       FILE_OPEN_DIALOG_FAILED = 1

       CNTL_ERROR              = 2

       ERROR_NO_GUI            = 3

       NOT_SUPPORTED_BY_GUI    = 4

       OTHERS                  = 5

           .

   IF SY-SUBRC <> 0.

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

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

   ENDIF.

   CLEAR P_FILE.

   READ TABLE I_FILE_TABLE INTO P_FILE INDEX 1.

   CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD

     EXPORTING

       FILENAME                = P_FILE

       FILETYPE                = 'DAT'

     HAS_FIELD_SEPARATOR     = SPACE

*    HEADER_LENGTH           = 0

     READ_BY_LINE            = 'X'

*    DAT_MODE                = SPACE

*    CODEPAGE                = SPACE

*    IGNORE_CERR             = ABAP_TRUE

*    REPLACEMENT             = '#'

*    VIRUS_SCAN_PROFILE      =

*    SHOW_TRANSFER_STATUS    = 'X'

*  IMPORTING

*    FILELENGTH              =

*    HEADER                  =

     CHANGING

       DATA_TAB                = I_TAB[] "INTERNAL TABLE IN WHICH I WANT DATA

     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

       NOT_SUPPORTED_BY_GUI    = 17

       ERROR_NO_GUI            = 18

       OTHERS                  = 19

           .

   IF SY-SUBRC <> 0.

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

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

   ENDIF.

After the execution of this code the data internal table i_tab is still empty.

plz suggest where am i wrong.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
739

Hi Abi,

I have tryed your code both in Excel and PDF . The ITAB internal tabel is getting populated for me.

And no exception is occured .

Thanks,

Pradeep.

5 REPLIES 5
Read only

Aashish28
Contributor
0 Likes
739

Hiii,

        try with this FM - ALSM_EXCEL_TO_INTERNAL_TABLE

                                 TEXT_CONVERT_XLS_TO_SAP - only for xls

                                  SAP_CONVERT_TO_XLS_FORMAT

Read only

Former Member
0 Likes
739

no...

i want to know where i have mistaken.

Read only

0 Likes
739

Hiiii,

        In your code when you upload data data  automatically converted into other character that's why i've given solution of fm ..... I don't think GUI_UPLOAD handles Excel files well.

Read only

Former Member
0 Likes
740

Hi Abi,

I have tryed your code both in Excel and PDF . The ITAB internal tabel is getting populated for me.

And no exception is occured .

Thanks,

Pradeep.

Read only

Former Member
0 Likes
739

sorry to all. actually my excel file was empty. oops!!

thats why no data is been loaded into internal table.