DATA: xbuffer TYPE xstring, filelength TYPE i, it_data TYPE TABLE OF tbl1024. CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY‘ EXPORTING buffer = xbuffer IMPORTING output_length = filelength TABLES binary_tab = it_data.
If the document is stored locally, you may perhaps use F/M SDOK_PHIO_LOAD_CONTENT. I have not worked on this scenario though. Once you have the document in the internal table, you can download to the local machine (Concatenate the file name, you desire, to the file_name field below to make it a complete filename with path):
DATA: filelength TYPE i, file_name TYPE string VALUE ‘C:\Temp’, file_len TYPE i. CALL METHOD cl_gui_frontend_services=>gui_download EXPORTING bin_filesize = filelength filename = file_name filetype = ‘BIN’ IMPORTING filelength = file_len CHANGING data_tab = it_data EXCEPTIONS file_write_error = 1 OTHERS = 2.
You may implement F4 help for Presentation Server File Path in SAP ABAP.
Based on feedback from @Sandra_Rossi in the comments below: instead of 'C:\temp', it would be better to use the SAP GUI temporary directory or the workdir (in 2 steps: cl_gui_frontend_services=>get_temp_directory + cl_gui_cfw=>flush for transferring the value to the variable ; note that this directory is emptied from time to time by the SAP GUI).
The bin_filesize parameter above is optional and seems to be innocuous but it’s not. I missed to pass the file length to this parameter (I got from F/M SCMS_XSTRING_TO_BINARY) and to my annoyance I was unable to open the downloaded file (with message: The file is damaged) whatever I did. Somebody with good experience with binary files came to my rescue and suggested to pass this parameter and it worked after that. Lesson of the story is file length (in bytes) is very important when dealing with binary files.
Upon successful download, you can send it to printer by calling the class’s EXECUTE method:
CALL METHOD cl_gui_frontend_services=>execute EXPORTING document = file_name operation = ‘PRINT’ EXCEPTIONS …..
After printing the document successfully, you may want to delete it which can be handled by FILE_DELETE method of the class:
CALL METHOD cl_gui_frontend_services=>file_delete EXPORTING filename = file_name CHANGING rc = rc EXCEPTIONS file_delete_failed = 1 OTHERS = 9. IF rc = 32. MESSAGE i461(iw) WITH ‘File is open in another window. Please close doc ‘. ENDIF.
So that's how this class handles all aspects of front-end handling of file automating download, print and delete functions. You may print several documents of different formats keeping the above logic in a LOOP.
Thanks for stopping by. Wish you All the Best in your endeavors!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 |