PDF Download in ABAP

Preface – This post is part of the ABAP Programs series.

In this article, you will learn how to convert xstring to pdf in abap and how to use GUI_DOWNLOAD Function Module to perform pdf download in ABAP.


In our previous article we have uploaded a PDF file. To view it click here. Now we will be Downloading that file into our system. To do that we need to convert the XSTRING file into a PDF file. The program shown below uses Function Module GUI_DOWNLOAD to download the file and Function Module SCMS_XSTRING_TO_BINARY to convert the XSTRING File to a Binary file which is further converted to a PDF file using GUI_DOWNLOAD Function Module.
Program to Download PDF in ABAP

  p_fname type z1127582_upload-filename lower case,
  p_path type string lower case.

      gs_store_file type z1127582_upload,
      xstr_content type xstring,
      gt_content type standard table of tdline,
      len type i,
      str_fname type string.


  select single * from z1127582_upload
    into gs_store_file
    where filename = p_fname.

  xstr_content  = gs_store_file-file_content.

  "Convert xstring/rawstring to binary ITAB
  call function 'SCMS_XSTRING_TO_BINARY'
      buffer        = xstr_content
      output_length = len
      binary_tab    = gt_content.

  if sy-subrc <> 0.
    message 'Unable to convert xstring to binary'
      type 'E'.

  str_fname = p_fname.

  call function 'GUI_DOWNLOAD'
      bin_filesize            = len
      filename                = p_path
      filetype                = 'BIN'
      data_tab                = gt_content
      file_write_error        = 1
      no_batch                = 2
      gui_refuse_filetransfer = 3
      invalid_type            = 4
      no_authority            = 5
      unknown_error           = 6
      header_not_allowed      = 7
      separator_not_allowed   = 8
      filesize_not_allowed    = 9
      header_too_long         = 10
      dp_error_create         = 11
      dp_error_send           = 12
      dp_error_write          = 13
      unknown_dp_error        = 14
      access_denied           = 15
      dp_out_of_memory        = 16
      disk_full               = 17
      dp_timeout              = 18
      file_not_found          = 19
      dataprovider_exception  = 20
      control_flush_error     = 21
      others                  = 22.
  if sy-subrc <> 0.
    message 'Unable to download file from SAP'
      type 'E'.


Initially, we have defined variables in two parts:

  • Parameter: p_fname is the name of file and p_path stores location of file
  • gs_store_file, gt_content, len, xstr_content: data related to file i.e. where file will be store, how the content will be stored, length of the file and type of content.

Function Module used:


What exactly is stored in the table that will be accessed by the Function Module to perform PDF download in ABAP:

  1. PDF file location
  2. PDF file name
  3. File type
  4. File X-STRING Data [This is the actual file that is converted in x-string]

Later on we have called different Function Modules. We have added respective comment in the code itself.

Tutorial Video

You can watch the video below to learn implementation:


  • Barry Allen

    A Full Stack Developer with 10+ years of experience in different domain including SAP, Blockchain, AI and Web Development.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.