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

gui_upload

Former Member
0 Likes
958

hi ,

i am using the following code:

REPORT ZTEST_RECUPLOAD.

*include bdcrecx1.

*Selection screen

*The parameter p_file is for filename and obligatory.

selection-screen begin of block 1 with frame title text-t01 .

parameters p_file type file_table-filename obligatory.

parameters p_sessn type apqi-groupid default 'RECURRING_PAYMENTS'.

selection-screen end of block 1.

*data declaration

data : t_sel_file type filetable,

w_return_code type i.

*type declaration

types : begin of ty_datain,

first(255) type c,

second(255) type c,

end of ty_datain.

data t_datain type table of ty_datain with header line.

*selection screen vaidations

at selection-screen on value-request for p_file.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

EXPORTING

WINDOW_TITLE = 'Select File for upload'

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

FILE_FILTER = '*.xls'

  • WITH_ENCODING =

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

CHANGING

FILE_TABLE = t_sel_file

RC = w_return_code

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

*at selection screen

if sy-subrc EQ 0 and

w_return_code EQ 1.

read table t_sel_file index 1 into p_file.

else.

message 'Error occured while uploading file' type 'I'.

Endif.

at selection-screen on p_sessn.

if p_sessn is initial.

p_sessn = 'RECURRING_PAYMENTS'.

endif.

start-of-selection.

data lv_file type string.

move p_file to lv_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = lv_file

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = t_datain

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

to upload a excel file.

but the uploaded file is not correctly formatted in the table t_datain, when i see the contents in debug mode. can any body tell me what is wrong wiht my code above.

Regards

Narendiran Rathinavelu

6 REPLIES 6
Read only

anversha_s
Active Contributor
0 Likes
781

HI,

chk with this sample code.

types: begin of ttab,

rec(1000) type c,

end of ttab.

types: begin of tdat,

fld1(10) type c,

fld2(10) type c,

fld3(10) type c,

end of tdat.

data: itab type table of ttab with header line.

data: idat type table of tdat with header line.

data: file_str type string.

parameters: p_file type localfile.

at selection-screen on value-request for p_file.

call function 'KD_GET_FILENAME_ON_F4'

exporting

static = 'X'

changing

file_name = p_file.

start-of-selection.

file_str = p_file.

call function 'GUI_UPLOAD'

exporting

filename = file_str

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.

delete itab index 1.

loop at itab.

clear idat.

split itab-rec at cl_abap_char_utilities=>horizontal_tab

into idat-fld1

idat-fld2

idat-fld3.

append idat.

endloop.

loop at idat.

write:/ idat-fld1, idat-fld2, idat-fld3.

endloop.

rgds

anver

Read only

Former Member
0 Likes
781

for excel gui_upload will not be giving correct result, you can go for 'ALSM_EXCEL_TO_INTERNAL_TABLE'.

Read only

Former Member
0 Likes
781

Hi Narendiran,

Refer sample code:

There are two function modules you can use: (1) 'ALSM_EXCEL_TO_INTERNAL_TABLE' or (2) 'KCD_EXCEL_OLE_TO_INT'. Very similar but the first function module (ASLM) used in for foreground processing.

parameters: p_fname LIKE rlgrap-filename

default 'C:\temp\cpv25000.xls' obligatory.

form upload_one_sheet.

Data: st_col type i value 1,

st_row type i value 1,

en_col type i value 90,

en_row type i value 9999. "max number of lines

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_fname

I_BEGIN_COL = st_col

I_BEGIN_ROW = st_row

I_END_COL = en_col

I_END_ROW = en_row

TABLES

INTERN = in

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

case sy-subrc.

when 0.

when 1. message e016(38) with 'Inconsistent parameters'.

when 2. message e016(38) with 'Error upload OLE'.

when others. message e016(38) with 'Error'.

endcase.

endform.

GUI_UPLOAD will allow you to upload directly into an internal table if it has the same layout as the upload file. Is that what you are looking for?

*Internal table to receive excel data

Data: Begin of in occurs 0.

include structure ALSMEX_TABLINE.

Data: End of in.

*internal table with result (your 3 field-table)

Data: begin of ex occurs 0,

f01(32), "max

f02(32),

f03(32),

.....

End of ex.

Data: fname(10).

Field-symbols: <F>.

  • so now you call the function to receive the data from EXCEL into table IN

  • after that:

Fname = 'EX-F'.

Loop at in. "per column one line entry

at new row. Clear: ex. Endat.

move in-col2 to fname4(2).

assign (fname) to <F>.

move in-value to <F>.

at end of row.

append ex2.

Clear: ex.

endat.

endloop.

  • result: your table EX is filled matching your EXCEL sheet

That works flexible for whatever number of column you will receive (in my example max 99).

Hope that gives you a start...

No u cant "directly" upload an excel sheet ... you will have to have some

ABAP that reads the Excel sheet directly or reads a delimited file (save as

delimited from Excel) ... into an itab, then massage the itab data a bit,

then do an update to the table you want or create a BDC to update the

table(s) .. etc.

Now, if you are talking about some type of conversion where the "direct

input" abilities (data transfer workbench - txn SXDA) of SAP should be used,

then you can take that route - like updating SAP Material Master etc ...

Reward points if this Helps.

Manish

Read only

0 Likes
781

hi

can you give me the data decalration for the table "in" in this code?

Regards

Naren

Read only

0 Likes
781

From the post above......




*Internal table to receive excel data
Data: Begin of in occurs 0.
       include structure ALSMEX_TABLINE.
Data: End of in.


Regards,

Rich Heilman

Read only

former_member184495
Active Contributor
0 Likes
781

hi,

try to save the excel file in a de-limited format and then try to upload the file,

hope it should work,

cheers,

Aditya