Skip to Content
Technical Articles

Display Xstring as PDF in Report

Hi All,

Introduction

This blog helps you to display PDF using Xstring data from a report.

Procedure:

Step1:

Goto Transaction SE38.

Enter the name of the program and click on the Create button as shown below.

 

 

The below screen will appear and give the program name and type as executable.

Click on the Save button.

 

 

 

Step2:

Create a screen as shown below.

Double click on-screen number.

 

 

A popup is displayed as shown below.

 

Click on Yes.

The below screen will appear and give a short description and click on the Save button.

 

 

Now click on Flow logic.

 

 

The below screen will appear and click on the layout button.

 

 

Create a custom control as shown below.

 

 

Now custom control is created.

 

 

Double click on the control and give the name of the control.

 

 

Step3:

Get Xstring data from database table or from ‘CONVERT_OTF’ FM.

Here we are displaying the Xstring that is stored in database table.

Goto screen 100 and create PBO & PAI Modules as shown below.

Double click on PBO module & the popup is displayed.

Click on the Yes button.

 

 

Select the main program or create a new include. Here we are using the main program and click on continue.

 

 

In the same way, create a PAI module.

Double click on the PAI module and the popup will be displayed.

Click on the Yes button.

 

 

Select the main program or create a new include. Here we are using the same main program and click on continue.

 

 

In the PBO module, implement the required logic.

 

 

Step4:

Create a reference class to the standard class of custom containers and HTML viewer and create objects in the PBO module of the program.

 

 

PDF is the name of the custom control.

 

 

Step5:

Call the function module ‘SCMS_XSTRING_TO_BINARY’ as shown below in the PBO module.

Click on the pattern button.

 

 

Give the name of the function module and click on the continue button.

 

 

Now pass the Xstring data to the function module.

 

 

Now call the method load data from HTML viewer as shown below.

Click on the pattern.

 

 

Select ABAP Objects Patterns and click on continue as shown below.

 

 

Give the name of the HTML viewer and click on the continue button.

 

 

Pass the binary table data as shown below.

 

 

Now call the method to display the data.

Click on the pattern button as shown below.

 

 

Select the ABAP Objects Patterns and click on the continue button as shown below.

Give the name of the class and method and click on the continue button as shown below.

 

 

Pass the URL to SHOW_URL method as shown below.

 

 

Step6:

Refresh the Container.

The container should be refreshed so that it will not display the previous PDF data.

This logic should be implemented in PAI module.

Click on Patterns as shown below.

 

 

Select the ABAP Objects Patterns and click on the continue button.

 

 

Give the name of the class and method and click on the continue button as shown below.

 

 

 

The output is as below.

 

 

 

Conclusion:

Using this method we can display any Xstring data in PDF in an ABAP Report.

 

Thank you.

6 Comments
You must be Logged on to comment or reply to a post.
  • Thank you. Until now there was no simple blog post to show how to display a PDF in SAP GUI for Windows, you did it!

    But can you post the code as text instead of screenshots? –because currently people have to type the whole code to try your solution– (eventually provide it in an abapGit repository)

    • Sure Sandra.

      DATAg_html_container TYPE REF TO cl_gui_custom_container,
      g_html_control   TYPE REF TO cl_gui_html_viewer,
      lv_url           TYPE char255,
      lt_data          TYPE STANDARD TABLE OF x255.

      START-OF-SELECTION.
      CALL SCREEN 100.
      *&———————————————————————*
      *&      Module  STATUS_0100  OUTPUT
      *&———————————————————————*
      MODULE status_0100 OUTPUT.

      SELECT SINGLE xstring FROM zxstring INTO @DATA(lv_string).

      CREATE OBJECT g_html_container
      EXPORTING
      container_name ‘PDF’.

      CREATE OBJECT g_html_control
      EXPORTING
      parent g_html_container.

      CALL FUNCTION ‘SCMS_XSTRING_TO_BINARY’
      EXPORTING
      buffer     lv_string
      TABLES
      binary_tab lt_data.

      CALL METHOD g_html_control->load_data
      EXPORTING
      type                   ‘application’
      subtype                ‘pdf’
      IMPORTING
      assigned_url           lv_url
      CHANGING
      data_table             lt_data
      EXCEPTIONS
      dp_invalid_parameter   1
      dp_error_general       2
      cntl_error             3
      html_syntax_notcorrect 4
      OTHERS                 5.

      CALL METHOD g_html_control->show_url
      EXPORTING
      url                    lv_url
      in_place               ‘ X’
      EXCEPTIONS
      cntl_error             1
      cnht_error_not_allowed 2
      cnht_error_parameter   3
      dp_error_general       4
      OTHERS                 5.

      ENDMODULE.
      *&———————————————————————*
      *&      Module  USER_COMMAND_0100  INPUT
      *&———————————————————————*
      MODULE user_command_0100 INPUT.

      CALL METHOD g_html_control->free
      EXCEPTIONS
      cntl_error        1
      cntl_system_error 2
      OTHERS            3.

      ENDMODULE.

  • Nice Article sarath chandra, very precise. Cheers!!

    Just for the improvement of this blog post, you can remove the screenshots of the coding part and post the code as text by pressing the “Insert/edit code sample” button as below:

    Regards,

    Mohit Sharma

    /