Application Development 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: 

how to upload a pdf file and download/open it

Former Member
0 Kudos

hi experts,

i want to upload a pdf or word format files to server and let user download or open it when user click a button, how to do that, can you post some sample codes, hunger for your advices and thanks a lot !!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

Check this example....


report ztest.

data: begin of itab occurs 0,
field(256),
end of itab.
data: dsn(100) value '/usr/sap/xfr/FIS/testpdf',
length like sy-tabix,
lengthn like sy-tabix.

call function 'GUI_UPLOAD'
exporting
filename = 'c:\temp\test.pdf'
filetype = 'BIN'
importing
filelength = length
tables
data_tab = itab.

open dataset dsn for output in binary mode.

loop at itab.
transfer itab-field to dsn.
endloop.

close dataset dsn.
clear itab.
refresh itab.



To crosscheck if it went well 

open dataset dsn for input in binary mode.

do.
read dataset dsn into itab-field.
if sy-subrc = 0.
append itab.
else.
exit.
endif.
enddo.

call function 'GUI_DOWNLOAD'
exporting
filename = 'c:\temp\testn.pdf'
filetype = 'BIN'
bin_filesize = length
importing
filelength = lengthn
tables
data_tab = itab.

Or

Use the TCode

CG3Z or CG3Y

for downloading to Application Server.

Regards,

Satish

3 REPLIES 3

Former Member
0 Kudos

Hi,

Check the Foll Func Modules in se37

GUI_UPLOAD

GUI_DOWNLOAD

GUI_EXEC

GUI_RUN

All these FMs come with very good documentation and examples (se37)

Cheers,

Will.

Former Member
0 Kudos

Hi,

Check this example....


report ztest.

data: begin of itab occurs 0,
field(256),
end of itab.
data: dsn(100) value '/usr/sap/xfr/FIS/testpdf',
length like sy-tabix,
lengthn like sy-tabix.

call function 'GUI_UPLOAD'
exporting
filename = 'c:\temp\test.pdf'
filetype = 'BIN'
importing
filelength = length
tables
data_tab = itab.

open dataset dsn for output in binary mode.

loop at itab.
transfer itab-field to dsn.
endloop.

close dataset dsn.
clear itab.
refresh itab.



To crosscheck if it went well 

open dataset dsn for input in binary mode.

do.
read dataset dsn into itab-field.
if sy-subrc = 0.
append itab.
else.
exit.
endif.
enddo.

call function 'GUI_DOWNLOAD'
exporting
filename = 'c:\temp\testn.pdf'
filetype = 'BIN'
bin_filesize = length
importing
filelength = lengthn
tables
data_tab = itab.

Or

Use the TCode

CG3Z or CG3Y

for downloading to Application Server.

Regards,

Satish

Former Member
0 Kudos

Hi,

We have 3 types of uploads n downloads Function Modules.in ABAP.

1. UPLOAD

2.WS_UPLOAD

3.GUI_UPLOAD

1.DOWNLOAD

2.WS_DOWNLOAD

3.GUI_DOWNLOAD

Now we r making use of only GUI_UPLOAD n GUI_DOWNLOAD in our programs.

You can go through this code which will go u an idea about the GUI_Upload n gui_download. This may lead u to understand there function modules in more detail.

REPORT zjavacreate message-id zmsgnew.

************************Creation of Internal table******************

DATA: BEGIN OF ti_record OCCURS 200,

Line(250),

END OF ti_record.

DATA: BEGIN OF ti_rec OCCURS 200,

Line(250),

END OF ti_rec.

*****************************Selection screen************************

selection-screen begin of block b1 with frame .

Parameters create radiobutton group g1.

PARAMETERS: JavaName(30) lower case.

parameters modify radiobutton group g1.

selection-screen end of block b1.

******************Calling the java program creation page**************

at selection-screen.

if CREATE = 'X'.

if javaname is not initial.

refresh ti_record[].

concatenate 'public class' javaname into ti_record-line separated by space.

concatenate ti_record-line '{' into ti_record-line separated by space.

Append ti_record.

ti_record-line = 'public static void main(String []args){'.

Append ti_record.

ti_record-line ='//enter ur code here'.

append ti_record.

ti_record-line ='}'.

Append ti_record.

ti_record-line ='}'.

Append ti_record.

EDITOR-CALL FOR ti_record .

else.

Message e001.

endif.

**************************Saving the java program********************

data tfile type string.

concatenate 'D:\Programs\' javaname '.java' into tfile.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = tfile

FILETYPE = 'ASC'

TABLES

DATA_TAB = ti_record.

endif.

data new(15).

if MODIFY = 'X'.

new = 'ZJAVAMODIFY1'.

CALL TRANSACTION NEW.

endif.

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

ZJAVAMODIFY:

REPORT zjavamodify.

**********************selection screen.********************

selection-screen begin of block b1 with frame .

Parameters compile radiobutton group g1.

Parameters modify radiobutton group g1.

Parameters execute radiobutton group g1.

PARAMETER : FILE(100) lower case.

selection-screen end of block b1.

DATA: BEGIN OF TI_RECORD OCCURS 1,

LINE(200),

END OF TI_RECORD.

data: st1(30),st2(30).

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

  • DEF_FILENAME = ' '

DEF_PATH = '.'

  • MASK = ' '

  • MODE = ' '

  • TITLE = ' '

IMPORTING

FILENAME = FILE

  • RC =

.

End-of-selection.

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

****************************MODIFY********************************

if modify = 'X'.

data: TXT_FILE1 TYPE STRING .

txt_file1 = file.

**************FM GUI_UPLOAD

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = txt_file1

TABLES

DATA_TAB = ti_recORD[].

**********End FM GUI_UPLOAD

EDITOR-CALL FOR ti_record .

**************FM GUI_UPLOAD

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = txt_file1

FILETYPE = 'ASC'

TABLES

DATA_TAB = ti_record.

**********End FM GUI_UPLOAD

endif.

*******************end of modify*******************

*******************BAT file for compilation n

execution.****************

if compile = 'X'.

DATA: begin of itab_bat_create occurs 0,

row(500) type c,

end of itab_bat_create.

data:comp_join1(250).

concatenate 'java' 'jCompiler' file into comp_join1

separated

by space.

itab_bat_create-row = 'c:'.

append itab_bat_create.

itab_bat_create-row = 'cd Documents and Settings\127740'.

append itab_bat_create.

itab_bat_create-row = comp_join1.

append itab_bat_create.

********FM GUI_DOWNLOAD

data: st type string.

st = 'C:\Documents and Settings\127740\compile_java.bat'.

call function 'GUI_DOWNLOAD'

EXPORTING

filename = st

filetype = 'ASC'

TABLES

data_tab = itab_bat_create[]

EXCEPTIONS

file_open_error = 1

file_write_error = 2

others = 3.

********end FM GUI_DOWNLOAD

*****FM dvsvas_doc_ws_execute_50

CALL FUNCTION 'DSVAS_DOC_WS_EXECUTE_50'

EXPORTING

PROGRAM = 'C:\Documents and Settings\127740\compile_java.bat'.

*****end FM dvsvas_doc_ws_execute_50

endif.

***********************end of compile*******************************

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

                                                                              • output***********************

if execute = 'X'.

data: TXT_FILE3 TYPE STRING .

split File AT '.java' into: st1 st2 .

concatenate st1 'error.txt' into TXT_FILE3.

**************FM GUI_UPLOAD

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = txt_file3

TABLES

DATA_TAB = ti_recORD[].

**********End FM GUI_UPLOAD

if not ti_record[] is initial.

loop at ti_record.

write:/ ti_record.

endloop.

else.

data: TXT_FILE4 TYPE STRING .

split File AT '.java' into: st1 st2 .

concatenate st1 'output.txt' into TXT_FILE4.

**************FM GUI_UPLOAD

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = TXT_FILE4

TABLES

DATA_TAB = ti_recORD[].

**********End FM GUI_UPLOAD

loop at ti_record.

write:/ ti_record.

endloop.

endif.

endif.

************************end of

output****************************************