Open and display pdf file with SAP ABAP



User Rating:  / 21
PoorBest 
Details

The following ABAP Program open PDF file and display into SAP Screen :

View source
*&---------------------------------------------------------------------*
*& Report  ZDISPPDF
*&
*&---------------------------------------------------------------------*
*&  www.developerpages.gr
*&
*&---------------------------------------------------------------------*
 
REPORT  ZDISPPDF.
 
data : lt_data TYPE TABLE OF x255.
data : wa_line type x255.
 
data: lo_docking_container type ref to cl_gui_docking_container.
data: lo_html    TYPE REF TO cl_gui_html_viewer.
DATA: lv_url TYPE char255.
data: ok_code(20).
 
PARAMETERS fname TYPE string.
 
* Read PDF File
PERFORM read_file.
 
* Display to screen
PERFORM display_pdf.
 
 
*&---------------------------------------------------------------------*
*&      Form  read_file
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM read_file.
 
  OPEN DATASET fname for INPUT in BINARY MODE.
  if sy-subrc = 0.
    do.
      read DATASET fname INTO wa_line.
      if sy-subrc = 0.
        append wa_line to lt_data.
      else.
        append wa_line to lt_data.
        exit.
      endif.
    enddo.
  endif.
 
ENDFORM.                    "read_file
 
 
*&---------------------------------------------------------------------*
*&      Form  display_pdf
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_pdf.
  if not lt_data is INITIAL.
    call screen 100.
  else.
    write :/ 'No data to display'.
  endif.
endform.                    "display_pdf
 
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'MAIN'.
  clear ok_code.
  IF NOT ( lo_docking_container IS INITIAL ).
    CALL METHOD lo_docking_container->free
      EXCEPTIONS
        cntl_error        = 1
        cntl_system_error = 2
        OTHERS            = 3.
  endif.
 
  IF NOT ( lo_html IS INITIAL ).
    CALL METHOD lo_html->free
      EXCEPTIONS
        cntl_error        = 1
        cntl_system_error = 2
        OTHERS            = 3.
  endif.
 
  create object lo_docking_container
    EXPORTING
      repid     = sy-repid
      dynnr     = sy-dynnr
      extension = 5000.
 
  CREATE OBJECT lo_html
    EXPORTING
      parent = lo_docking_container.
*
* Load the HTML
  lo_html->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
      OTHERS               = 4 ).
 
* Show it
 
  lo_html->show_url( url = lv_url  in_place = 'X' ).
 
ENDMODULE.                 " STATUS_0100  OUTPUT
 
 
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
 
  CASE sy-ucomm.
    WHEN 'BACK' or 'EXIT' or 'CANC'.
      IF NOT ( lo_docking_container IS INITIAL ).
        CALL METHOD lo_docking_container->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2
            OTHERS            = 3.
      endif.
 
      IF NOT ( lo_html IS INITIAL ).
        CALL METHOD lo_html->free
          EXCEPTIONS
            cntl_error        = 1
            cntl_system_error = 2
            OTHERS            = 3.
      endif.
 
      LEAVE SCREEN.
  ENDCASE.
 
 
 
ENDMODULE.                 " USER_COMMAND_0100  INPUT

screen 100 : 

 

status MAIN:

My example :


You have no rights to post comments

   

Login  

   

     

© Developerpages