Skip to Content
Technical Articles
Author's profile photo Mukesh Kumar

Printing DMS Documents

SAP Document Management (DMS) is one of the central functions in Logistics and cross-application component of SAP ECC. It supports many document management functions for SAP system as well as external systems. Please refer SAP help portal and SCN wiki for more details.

Several times there is requirement to print documents from DMS. One such scenario is printing Work Packets from Maintenance Order (IW32) through menu Order -> Print -> Order (or Operation selection). But the below discussion is not restricted to this scenario and generally applicable for all printing requirements of DMS documents.

These documents may have varying formats – PDF, Word, Excel, PPT, JPEG, etc. They may be stored on some third party system like SharePoint. Sending them to spool for printing for all these formats is not feasible. Here comes handy the standard SAP class supporting many front-end functions CL_GUI_FRONTEND_SERVICES.

If the documents are stored on an external system, you need to get the document as string of Hexadecimal characters (it may be proxy call to PI system, which was the scenario in my case). You can get the document into an internal table in binary format for subsequent processing:

              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.

 

Follow this link to implement F4 help for Presentation Server File Path in SAP ABAP and refer to the source code there.

Just one remark about 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 whatever you are doing! Find more articles on SAP ERP.

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Pavan Golesar
      Pavan Golesar

      Hi,

      Nice document,

      Just out of curiosity, I have a doubt, Is Mass Printing Possible in SAP DMS. As your document talk about external system and printing you may add this point of Mass Printing as well (if it's possible). 😳

      Regards,

      Pavan G

      Author's profile photo Mukesh Kumar
      Mukesh Kumar
      Blog Post Author

      Hi ' Pavan ' Golesar ! Thanks for your appreciation 🙂 I believe the answer to your question should be 'No'. Though we can print multiple documents keeping the above logic to fetch the document, download, print and delete inside a LOOP but thats not mass printing. There is somewhat similar discussion thread which may be helpful. Best Regards !

      .

      Author's profile photo Sandra Rossi
      Sandra Rossi

      Thank you for this article. Just one remark about 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).

      Author's profile photo Mukesh Kumar
      Mukesh Kumar
      Blog Post Author

      Thank you Sandra Rossi for the important info ! Thats what it was missing.

      Author's profile photo Ajay Kumar
      Ajay Kumar

      Nice Blog it will be very useful for one of my requirement .

      Author's profile photo Pushyami Koka
      Pushyami Koka

      Hi Mukesh,

      Thanks for the document. It helped us a lot. We have an additional requirement where we need to print 'Multiple Sheets' in the excel. Can you please share if you have any inputs related to it ?

      Thanks !!

      Pushyami

      Author's profile photo Mukesh Kumar
      Mukesh Kumar
      Blog Post Author

      Thanks a lot but sorry Pushyami, I don't have answer to your question.

      Author's profile photo Bhanu Prakash Maddi
      Bhanu Prakash Maddi

      Hi Mukesh,

      Thanks for this article.

      we have a requirement to print the documents (doc, jpeg, msg) from SAP DMS.

      is this feasible. can you share your insights pls.

       

      Thank you.

      Bhanu