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

UPLOAD and GUI_UPLOAD

Francis417
Participant
0 Likes
3,714

Hi,

We have just upgraded to ERP2005 from 4.5B and would like to know how I can change the program from calling the function 'UPLOAD' to use 'GUI_UPLOAD'.

It seems that 'GUI_UPLOAD' doesn't prompt user for the file to be upload. Which function should I call so that the user will be prompt for selecting the file to be upload.

Many Thanks in advance

Francis

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,085

Hi francis,

1. you want 2 things

a) show the open dialog box for file selection

b) upload the file in internal table

2. for this purpose, i have made one subroutine FORM,

which needs to be called

(in place of your old code for 'UPLOAD')

3. while calling this form using perform,

we need to pass the internal table.

like :

PERFORM MYUPLOAD tables itab.

4. U may make modifications/enhancements to the FORM.

5.

*----


  • INDEPENDENT FORM

*----


FORM MYUPLOAD tables myitab.

data : filetable type filetable.

data : fwa type line of filetable.

data : rc type i.

data : filename type string.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

CHANGING

FILE_TABLE = filetable

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

.

read table filetable into fwa index 1.

if sy-subrc = 0.

filename = fwa-filename.

endif.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

TABLES

DATA_TAB = myitab

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.

ENDFORM. "MYUPLOAD

regards,

amit m.

18 REPLIES 18
Read only

Former Member
0 Likes
3,085

You should use the class CL_GUI_FRONTEND_SERVICES

Use the FILE_OPEN_DIALOG method to get the file name from the user and then use GUI_UPLOAD method to upload the file data.

Regards,

Ravi

Note : Please mark the helpful answers

Read only

Former Member
0 Likes
3,085

Hi Francis,

To prompt for file to be upload,use method FILE_OPEN_DIALOG.This is aviaLAble under class CL_GUI_FRONTEND_SERVICES.

Thanks,

Vinay

Read only

0 Likes
3,085

Hi Vinay,

I've tried call the file_open_dialog but I've some difficulties with the parameters. It always says that the data type for the file_table does not match. Just wonder if you have any sample codes that can be shared here.

Thanks,

Francis

Read only

0 Likes
3,085

Hi Francis,

I am very sorry to provide code. Right now I had some problem with my system. But I will give you few data type matchings which helps you to resolve your problem.

1)UPLOAD will take 'FILENAME' as RLGRAP-FILENAME,but 'GUI_UPLOAD' method will consider this as STRING. To do this take a STRING variable and pass the FILENAME of UPLOAD to STRING variable.

2)UPLOAD will take 'FILTYPE' as RLGRAP-FILETYPE,but 'GUI_UPLOAD' method will consider this as CHAR10. To do this take a CHAR10 variable and pass the FILETYPE of UPLOAD to CHAR10 variable.

3)FILETABLE of FILE_OPEN_DIALOG is an internal table. To get filename use READ statement on FILETABLE.

READ IT_FILETABLE INTO V_FILENAME INDEX 1.

Do all these conversions before you call method 'GUI_UPLOAD'.

This is the code for FILE_OPEN_DIALOG method.

DATA: it_filetable TYPE filetable,

lv_rc TYPE i.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

initial_directory = v_path

CHANGING

file_table = it_filetable

rc = lv_rc

EXCEPTIONS

file_open_dialog_failed = 1

cntl_error = 2

error_no_gui = 3

not_supported_by_gui = 4

OTHERS = 5.

IF sy-subrc = 0.

  • READ TABLE IT_FILETABLE INTO P_PFILE INDEX 1.

READ TABLE it_filetable INTO l_file INDEX 1.

ENDIF.

Thanks,

Vinay

Message was edited by: Vinaykumar Gorrela

Read only

Former Member
0 Likes
3,085

Hey Francis,

you can use the following logic so that the user will be prompt for selecting the file to be uploaded.

&----


*& Report ZKUN_FILE1 *

*& *

&----


*& *

*& *

&----


REPORT ZKUN_FILE1 .

tables : zkunal1.

data : begin of itab1 occurs 0.

include structure zkunal1.

data: end of itab1.

data : begin of gv_itab occurs 0.

include structure zkunal1.

data: end of gv_itab.

*data : begin of gv_itab occurs 0,

  • fname like zkunal1-fname,

  • lname like zkunal1-lname,

  • place like zkunal1-place,

  • end of gv_itab.

data : gv_file type string.

*****************************************************************

*SELECTION SCREEN *

*****************************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

<b>PARAMETERS: p_file LIKE ibipparms-path obligatory.</b> " For file selection

SELECTION-SCREEN END OF BLOCK b1.

*****************************************************************

*AT SELECTION SCREEN *

*****************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

<b>CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = p_file.</b>

*****************************************************************

*START OF SELECTION * *

*****************************************************************

START-OF-SELECTION.

  • P_FILE is not compatible with the FM GUI_UPLOAD, so pass it to

  • GV_FILE.

gv_file = p_file.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = gv_file

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = '#'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = gv_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.

*FIELD-SYMBOLS: <fs_zco001> TYPE zco001.

  • select * from zkunal1 into table itab1. "#EC CI_NOWHERE

loop at gv_itab.

write : / gv_itab-fname, gv_itab-lname, gv_itab-place.

endloop.

Regards,

Kunal.

Message was edited by: Kunal Kumar

Read only

0 Likes
3,085

Hi Kunal,

Thanks for your suggestion.

Instead of using a input parameter for the upload file name, I prefer to popup a window to prompt user to select the file to be upload just like what the function 'UPLOAD' did.

Any idea how I can achieve this?

Thanks,

Francis

Read only

0 Likes
3,085

Hi Francis,

If you want a popup window then you should use this code and after getting the file name, you can make use of the fm gui_upload. just run this , you will get the solution.

&----


*& Report ZKUN_FILE11 *

*& *

&----


*& *

*& *

&----


REPORT ZKUN_FILE12 .

data : count type i,

gv_file type string,

dir type string,

fil type string,

ch type c value '\'.

data: begin of itab occurs 0 ,

content(1000) type c,

end of itab.

data: wa_file_table type file_table,

tab type standard table of file_table.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

  • EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

  • WITH_ENCODING =

CHANGING

file_table = tab

rc = count

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

Regards,

Kunal.

Read only

0 Likes
3,085

Hi Kunal,

Would you be kind enough to give me some more hint on how I can pass the filename to GUI_UPLOAD? I'm getting the error that the data type cannot be converted.

Thanks in advance

Francis

Read only

0 Likes
3,085

Hey Francis ,

You copy this code and run it. your whole problem will be solved.

&----


*& Report ZKUN_FILE11 *

*& *

&----


*& *

*& *

&----


REPORT ZKUN_FILE12 .

data : count type i,

gv_file type string,

dir type string,

fil type string,

ch type c value '\'.

data: begin of itab occurs 0 ,

content(1000) type c,

end of itab.

data: wa_file_table type file_table,

tab type standard table of file_table.

CALL METHOD cl_gui_frontend_services=>file_open_dialog

  • EXPORTING

  • WINDOW_TITLE =

  • DEFAULT_EXTENSION =

  • DEFAULT_FILENAME =

  • FILE_FILTER =

  • INITIAL_DIRECTORY =

  • MULTISELECTION =

  • WITH_ENCODING =

CHANGING

file_table = tab

rc = count

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

loop at tab into wa_file_table.

write : / wa_file_table-FILENAME.

gv_file = wa_file_table-FILENAME.

condense gv_file.

*concatenate gv_file into fil.

*condense fil.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = gv_file

  • FILETYPE = 'ASC'

  • HAS_FIELD_SEPARATOR = ' '

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

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

loop at itab.

write : / itab-content.

endloop.

clear itab[].

endloop.

Regards,

Kunal.

Note : Francis , if you have solved the problem do reward with appropriate points. If you have any further doubt, you are most welcome.

Read only

0 Likes
3,085

Hi Francis,

Refer the following code.

DATA: lv_filename TYPE string,

lv_credit_value1 TYPE string,

lv_acctbal1 TYPE string,

lv_item_guid1 TYPE string.

DATA: lit_pres_data TYPE TABLE OF string.

DATA: wa_pres_data LIKE LINE OF lit_pres_data.

  • Open the Browse Dialog Box on the Desktop

CALL METHOD cl_gui_frontend_services=>file_open_dialog

EXPORTING

window_title = gc_wondowtitle

default_filename = gc_defaultfile

initial_directory = gc_defaultdir

CHANGING

file_table = git_tab

rc = gv_subrc.

  • Assign the selected file name to the file path field

READ TABLE git_tab INTO lv_filename INDEX 1.

  • Call function module to upload the file on the presentation server

CALL METHOD cl_gui_frontend_services=>gui_upload

EXPORTING

filename = lv_filename

CHANGING

data_tab = lit_pres_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.

<b>Please reward points if it helps.</b>

Regards,

Amit Mishra

Message was edited by: Amit Mishra

Read only

Former Member
0 Likes
3,085

H Francis

Thie code will solve your problem,

----


  • METHOD GET_PRESENTATION_SERVER_PATH

----


  • This method will display a dialog that displays the Presentation

  • Server Directories, from which users can choose directories for

  • downloading files

----


METHOD get_presentation_server_path.

DATA: lv_path TYPE string,

lv_title TYPE string,

lv_folder TYPE string.

lv_title = text-005.

lv_folder = text-006.

CALL METHOD cl_gui_frontend_services=>directory_browse

EXPORTING

window_title = lv_title

initial_folder = lv_folder

CHANGING

selected_folder = lv_path

EXCEPTIONS

cntl_error = 1

error_no_gui = 2

not_supported_by_gui = 3

OTHERS = 4.

IF sy-subrc EQ 0.

p_preser = lv_path.

ELSE.

MESSAGE i206(zwwu_pm).

ENDIF.

CLEAR: lv_path, lv_title, lv_folder.

ENDMETHOD. "get_presentation_server_pat

and download the file as

  • Presentation Server file download

CONCATENATE p_preser '\'

wa_zhesi-filenumber '_'

wa_zhesi-creation_date '_'

wa_zhesi-creation_time '.'

wa_zhesi-file_type

INTO v_supplier_file.

CALL METHOD cl_gui_frontend_services=>gui_download

EXPORTING

filename = v_supplier_file

filetype = 'ASC'

CHANGING

data_tab = i_supplier_table

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

not_supported_by_gui = 22

error_no_gui = 23

OTHERS = 24.

Thanks

Kathir

Read only

0 Likes
3,085

Hi Kathirvel,

Just wonder if you have a similar program for GUI_UPLOAD, that is prompting user for the file and then call gui_upload?

Thanks,

Francis

Read only

0 Likes
3,085

Hi,

Check this link

http://www.sapdevelopment.co.uk/file/file_updown.htm

here you can see lot of examples.

Regards

vijay

Read only

0 Likes
3,085

Hi,

If you call the FILE_OPEN_DIALOG method in AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file that is what exactly it does. It throws the screen where the user can browse and select the file and then you can call the GUI_UPLOAD method for the file in the parameter.

Look at my previous post.

Regards,

Ravi

Read only

0 Likes
3,085

Hi Ravi,

I know your codes do work. However, I just want the program to behave exactly the same way as it is before the upgrade. So I don't want to have an extra input parameter for the file name in the selection screen.

Regards,

Francis

Message was edited by: Francis Luk

Read only

Former Member
0 Likes
3,085

Hai Francis

Check the following Code for UPLOAD/GUI_UPLOAD for old and New Versions

*-- Begin of delete Neelimab 21/11/2005

  • CALL FUNCTION 'UPLOAD'

  • EXPORTING

  • codepage = 'IBM'

  • filename = p_file

  • filetype = 'DAT'

  • TABLES

  • data_tab = t_root

  • EXCEPTIONS

  • conversion_error = 1

  • file_open_error = 2

  • file_read_error = 3

  • invalid_table_width = 4

  • invalid_type = 5

  • no_batch = 6

  • unknown_error = 7

  • gui_refuse_filetransfer = 8.

*-- End of delete Neelimab 21/11/2005

*-- Begin of add Neelimab 21/11/2005

DATA: D_FILENAME TYPE STRING.

D_FILENAME = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = D_FILENAME

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

DAT_MODE = 'X'

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = t_root

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

Thanks & regards

Sreenivasulu P

Read only

Former Member
0 Likes
3,086

Hi francis,

1. you want 2 things

a) show the open dialog box for file selection

b) upload the file in internal table

2. for this purpose, i have made one subroutine FORM,

which needs to be called

(in place of your old code for 'UPLOAD')

3. while calling this form using perform,

we need to pass the internal table.

like :

PERFORM MYUPLOAD tables itab.

4. U may make modifications/enhancements to the FORM.

5.

*----


  • INDEPENDENT FORM

*----


FORM MYUPLOAD tables myitab.

data : filetable type filetable.

data : fwa type line of filetable.

data : rc type i.

data : filename type string.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

CHANGING

FILE_TABLE = filetable

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

.

read table filetable into fwa index 1.

if sy-subrc = 0.

filename = fwa-filename.

endif.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = filename

TABLES

DATA_TAB = myitab

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.

ENDFORM. "MYUPLOAD

regards,

amit m.

Read only

Former Member
0 Likes
3,085

Hi,

data :constants: ws_c_mask(20) type c value '. , ..'.

select-options: p_mifile like rlgrap-filename.

at selection-screen on value-request for p_mifile .

perform f7000_file_selection using p_mifile. "selects a file

form f7000_file_selection using p_p_mifile.

call function 'WS_FILENAME_GET'

exporting

def_filename = p_p_mifile

def_path = 'ASC '

mask = ws_c_mask

mode = 'O'

  • TITLE = ' '

importing filename = p_p_mifile

  • RC =

exceptions inv_winsys = 1

no_batch = 2

selection_cancel = 3

selection_error = 4

others = 5.

endform. " F7000_FILE_SELECTION