Skip to Content
Author's profile photo Michelle Crapo

Classic Dynpro – Display a PDF Document

So.. this is an older way to code things. Please do add things at the bottom of the post – you know things like the objects that could have been used. It will help people on the newer versions.

The project: Create something that can save, create, upload, and e-mail documents. It should be easy to use.

The save, retrieve and e-mail part of the project was covered with my first blog.That was a multi-purpose blog begging people to create information on SAP Community again.

So first off – here is the first screen again.

This screen was created using fields, buttons, a table control, a subs screen and  a custom control box.

For the table control – use the wizard to create it. Make the lines selectable, and clickable.

For the subscreen – it was an easy way to create the select options and be able to save parameters.  I created a normal report program for that piece.  Because it was in a different program, I had to send the fields to the main dynpro program:  I filled global fields.

      PERFORM fill_parameters(sapmzdoc)  TABLES so_crt
                                          USING kunnr
                                                lifnr
                                                 p_ddes
                                                 p_doc
                                                 p_item
                                                 ' '.

Back to the dynpro:

  CALL SUBSCREEN parmaeters.

Then I called the modify module ON CHAIN-REQUEST..  Where I retrieved the line from the table control:

  GET CURSOR FIELD field_name LINE line_number.
  line_number = tc_300-top_line + line_number - 1.

Next – The user command, on this part, they probably want the PDF displayed first. To retrieve the PDF. I simply recreate the file name based on the key entries.  I select that from a Z table.  Next the standard Open / do / read / close

* get the data
  OPEN DATASET docs-file_name FOR INPUT IN BINARY MODE.

  IF sy-subrc <> 0.
    CONCATENATE 'Could not open file' docs-file_name
        INTO message SEPARATED BY space.
    EXIT.
  ENDIF.

  DO.
    READ DATASET docs-file_name INTO pdf LENGTH lv_size.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    pdf_size = pdf_size + lv_size.
    APPEND pdf.
  ENDDO.

  CLOSE DATASET docs-file_name.

So I’ve got the “PDF”.   Let’s display it in that container.

  TYPES: lt_pdf_line(134) TYPE c.
  DATA:  l_url(80)        TYPE c,
         l_pdf_data       TYPE STANDARD TABLE OF lt_pdf_line.

  l_pdf_data[] = p_pdf[].

* transfer data to data provider
  CALL METHOD pdf_html_control->load_data
    EXPORTING
      url          = 'smart.pdf'
      size         = pdf_size
      type         = 'text'
      subtype      = 'pdf'
    IMPORTING
      assigned_url = l_url
    CHANGING
      data_table   = l_pdf_data[]
    EXCEPTIONS
      OTHERS = 1.
  IF sy-subrc <> 0.
    message = 'Internal IT error'.
  ENDIF.

* show data
  CALL METHOD pdf_html_control->show_data
    EXPORTING
      url = l_url
    EXCEPTIONS
      OTHERS = 1.
  IF sy-subrc <> 0.
    message = 'Internal IT error'.
  ENDIF.

 

Done – it is displayed!  The e-mail screen looks like this. The details to send the e-mail are in the previous blog.

The message will be displayed at the top of the screen. Similar to our webpage. The user can type anything they want in the body.  Send e-mail and a list of the partner external addresses are displayed to determine which one(s) they want the mail to go to. There is also an option to send the e-mail only to yourself.

Again – new objects – different way of doing things? I would love to read about them!

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Mauricio Gasparotto Teixeira
      Mauricio Gasparotto Teixeira

      Hi Michelle!
      Nice post!

      What is the TYPE REF of pdf_html_control class?

      Thanks in advance!
      🙂

      Author's profile photo Michelle Crapo
      Michelle Crapo
      Blog Post Author

      Because the class is called directly - there is not type ref needed.

      That's kind of nice because the definitions can be a huge part of your program.  If you want a type ref, you could define one.

      go_html_control type ref to pdf_html_control.

      I just didn't see the need.

      Michelle

      Author's profile photo Mauricio Gasparotto Teixeira
      Mauricio Gasparotto Teixeira

      I just asked because I can't find class pdf_html_control in my client... 🙁

      Probably it is in a later Support Package...

      Thanks!

      Author's profile photo Michelle Crapo
      Michelle Crapo
      Blog Post Author

      Well I'm on an OLD version of SAP 4.6C.

      A search showed me a different class cl_gui_pdf_viewer.  Perhaps that one will be on your system. 🙂

      Author's profile photo Sandra Rossi
      Sandra Rossi

      I guess it must be DATA pdf_html_control TYPE ref to CL_GUI_HTML_VIEWER.

      Nowadays, CL_ABAP_BROWSER should be used as the first choice, but it has less features.