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: 

Opening Attachments (Word, Excel, JPG) from files stored in Unix via ABAP.

john_kossits
Discoverer
0 Kudos

I am having difficulty finding the proper technique to open attachments stored in Unix via an Abap program. For files on a PC the class CL_GUI_FRONTEND_SERVICES is available for this purpose. What about files in Unix?

Thanks for any help.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

I think you need to use the below Statements

OPEN DATASET <UNIX Filepath> FOR INPUT IN BINARY MODE.

READ DATASET..

CLOSE DATASET <UNIX Filepath>.

I think this may help you.

Regards,

SRinivas

2 REPLIES 2

Former Member
0 Kudos

Hi,

I think you need to use the below Statements

OPEN DATASET <UNIX Filepath> FOR INPUT IN BINARY MODE.

READ DATASET..

CLOSE DATASET <UNIX Filepath>.

I think this may help you.

Regards,

SRinivas

0 Kudos

Srinivas,

Thank you for your reply. It helped me get to a solution. In essence I needed to copy the Unix file to an internal table and then save it to the end user's PC file. Then I am able to open the document / attachment.

I created a new function to:

1) call method cl_gui_frontend_services=>directory_browse, to ask the end user to pick a PC directory to copy the Unix file attachment to.

2) Then using the following code, copy the Unix file (as determined by application or user) to an internal table. Note that the line is not limited by a certain length.

types: begin of t_tab,

line type string,

end of t_tab.

data: k_wa_itab type t_tab,

t_it_itab type standard table of t_tab.

open dataset v_unixfilename for input in binary mode.

if sy-subrc <> 0.

raise unix_filename_read_error.

endif.

do.

read dataset v_unixfilename into k_wa_itab-line.

if sy-subrc <> 0.

exit.

endif.

append k_wa_itab to t_it_itab.

enddo.

close dataset v_unixfilename.

3) Using call method cl_gui_frontend_services=>gui_download, save the contents of the internal table to the PC directory from step 1 above.

4) Open the Attachment from the end users PC via:

call method cl_gui_frontend_services=>execute

It seems like a long way to get this to work, but it is working. If there is a better way maybe someone else can fill in the blanks. Ideally a tool to read and open from a file from Unix without using the cl_gui_frontend_services would be ideal.