SAP ABAP - PDF Viewer From Application Server Directory
AL11
REPORT ysap_pdf_viewer.
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).
DATA filename TYPE string.
PARAMETERS fname TYPE localfile.
** Selection screen value request
AT SELECTION-SCREEN ON VALUE-REQUEST FOR fname.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = fname.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
START-OF-SELECTION.
filename = '/usr/sap/attachment/'. "AL11 Directory
filename = |{ filename }{ fname }|.
* Read PDF File
PERFORM read_file.
* Display to screen
PERFORM display_pdf.
*&---------------------------------------------------------------------*
*& Form read_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM read_file.
fname = filename.
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 TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
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).
DATA filename TYPE string.
PARAMETERS fname TYPE localfile.
** Selection screen value request
AT SELECTION-SCREEN ON VALUE-REQUEST FOR fname.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = fname.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
START-OF-SELECTION.
filename = '/usr/sap/attachment/'. "AL11 Directory
filename = |{ filename }{ fname }|.
* Read PDF File
PERFORM read_file.
* Display to screen
PERFORM display_pdf.
*&---------------------------------------------------------------------*
*& Form read_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM read_file.
fname = filename.
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 TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
Comments
Post a Comment