Skip to Content

Hello,

Through many Blog posts and SAP help sites I found it as a challenge to print the PDF in SAP.

Part of below code can be used in many ways:

1. To save the PDF file from any URL link on some shared drive.

2. To print the PDF file from your shared drive at default printer configured at your machine.

3. To print the PDF file at the printer of your choice.

To save the PDF file from any URL link at shared drive you can use FM HTTP_FILE_GET.

Please look into the attached file here for more information on how to use this FM in this scenario.

Things to note before you use this FM:

URL link should not be blocked from your network.

Check your network connection settings on HTTP sites in Tcode: SICF.

While passing name of your shared drive make sure that it would contain path + <filename.pdf> and not only path.

<filename> can be any name you want to give to your file.

Once your file get saved on shared drive you can pick it up to get printed.

FYI we are using here ADS i.e Adobe document services to print file through Sap ABAP Coding

To get this functionality you should use method Execute of Cl_Gui_Frontend_services.

Deatils on how to use the method can be found in attached file here.

Just to tell you what we are doing here:

We are using Adobe document services command through this method to print the file.

We need to pass the command parameters in parameter field of method.

Also we need to pass application name as Adobe.Exe or Acrord32.Exe depending on what is installed at our system in application parameter of method.

For details Kindly refer the full coding attached here for your reference.

Code is FM created for this purpose:

FUNCTION zv_demo_pdf_print.
*”———————————————————————-
*”*”Local Interface:
*”  IMPORTING
*”     REFERENCE(URL) TYPE  C
*”     REFERENCE(PATH) TYPE  C
*”     REFERENCE(PRINTER) TYPE  C
*”  EXPORTING
*”     REFERENCE(STATUS) TYPE  I
*”  EXCEPTIONS
*”      CONNECT_FAILED
*”      TIMEOUT
*”      INTERNAL_ERROR
*”      DOCUMENT_ERROR
*”      TCPIP_ERROR
*”      SYSTEM_FAILURE
*”      COMMUNICATION_FAILURE
*”      CNTL_ERROR
*”      ERROR_NO_GUI
*”      BAD_PARAMETER
*”      FILE_NOT_FOUND
*”      PATH_NOT_FOUND
*”      FILE_EXTENSION_UNKNOWN
*”      ERROR_EXECUTE_FAILED
*”      SYNCHRONOUS_FAILED
*”      NOT_SUPPORTED_BY_GUI
*”      UNKNOWN_ERROR
*”———————————————————————-

  TYPES: BEGIN OF text,
          line(1000),
         END OF text.

  DATA: response         TYPE TABLE OF text WITH HEADER LINE,
        response_headers TYPE TABLE OF text WITH HEADER LINE.
  DATA: p_application TYPE string.

*first save the file from URL
*at shared drive
   CLEAR status.
  CALL FUNCTION ‘HTTP_GET_FILE’
    EXPORTING
      absolute_uri          = url
      document_path         = path
    TABLES
      request_headers       = response
      response_headers      = response_headers
    EXCEPTIONS
      connect_failed        = 1
      timeout               = 2
      internal_error        = 3
      document_error        = 4
      tcpip_error           = 5
      system_failure        = 6
      communication_failure = 7
      OTHERS                = 8.

  status = sy-subrc.
  IF status <> 0.
    CASE status.
      WHEN 1.
        RAISE connect_failed.
      WHEN 2.
        RAISE timeout.
      WHEN 3.
        RAISE internal_error.
      WHEN 4.
        RAISE document_error.
      WHEN 5.
        RAISE tcpip_error.
      WHEN 6.
        RAISE system_failure.
      WHEN 7.
        RAISE communication_failure.
      WHEN OTHERS.
        RAISE unknown_error.
    ENDCASE.
  ELSE.
*if file saved succesfully at shared path
*pick the file and print it on printer

    CONCATENATE ‘/t’ url printer INTO p_application SEPARATED BY space.

    break amitkumar.
    CALL METHOD cl_gui_frontend_services=>execute
      EXPORTING
        application            = ‘ACRORD32.EXE’
        parameter              = p_application
        minimized              = ‘X’
      EXCEPTIONS
        cntl_error             = 1
        error_no_gui           = 2
        bad_parameter          = 3
        file_not_found         = 4
        path_not_found         = 5
        file_extension_unknown = 6
        error_execute_failed   = 7
        synchronous_failed     = 8
        not_supported_by_gui   = 9
        OTHERS                 = 10.
    IF sy-subrc NE 0.
      status = sy-subrc.
      CASE sy-subrc.
        WHEN 1.
          RAISE cntl_error.
        WHEN 2.
          RAISE error_no_gui.
        WHEN 3.
          RAISE bad_parameter.
        WHEN 4.
          RAISE file_not_found.
        WHEN 5.
          RAISE path_not_found.
        WHEN 6.
          RAISE file_extension_unknown.
        WHEN 7.
          RAISE error_execute_failed.
        WHEN 8.
          RAISE synchronous_failed.
        WHEN 9.
          RAISE not_supported_by_gui.
        WHEN OTHERS.
          RAISE unknown_error.
      ENDCASE.
    else.
      status = 0.
    ENDIF.

  ENDIF.

ENDFUNCTION.

Thanks,

Amit

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply