How to Display URL/PDF from AL11

Expected Result

*You can see all source code at Appendix A.

Step 1: Place the PDF file on server (AL11) such as HELLO.pdf.

Step 2: Declare internal table parameter as RCGREPFILE type.

*See the structure of RCGREPFILE at Appendix B

Step 3: Read the file (HELLO.pdf) from step 1 in binary mode.

Step 4: Create new screen (100) and drag the Custom Control (Container) object on the layout.

Step 5: At PBO, create the container (PDF) and call LOAD_DATA and SHOW_URL methods respectively.


Appendix A

REPORT zshow_url.

DATA:
  gt_pdf TYPE TABLE OF rcgrepfile.

DATA:
  gv_okcode TYPE sy-ucomm.

START-OF-SELECTION.
  PERFORM get_pdf USING ‘HELLO.pdf’.
  CALL SCREEN 100.

END-OF-SELECTION.

*&———————————————————————*
*& Module SHOW_URL OUTPUT
*&———————————————————————*
MODULE show_url OUTPUT.

  DATA:
    lo_html_container TYPE REF TO cl_gui_custom_container,
    lo_html_control   TYPE REF TO cl_gui_html_viewer,
    lv_url            TYPE char255.

  IF lo_html_container IS NOT BOUND.

    CREATE OBJECT lo_html_container
      EXPORTING
        container_name = ‘PDF’.

    CREATE OBJECT lo_html_control
      EXPORTING
        parent = lo_html_container.

  ENDIF.

  “Load Data
  CALL METHOD lo_html_control->load_data
    EXPORTING
      type                 = ‘application’
      subtype              = ‘pdf’
    IMPORTING
      assigned_url         = lv_ur
    CHANGING
      data_table           = gt_pdf
    EXCEPTIONS
      dp_invalid_parameter = 1
      dp_error_general     = 2
      cntl_error           = 3
      OTHERS               = 4.

  “Show URL
  CALL METHOD lo_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_EXIT  INPUT
*&———————————————————————*
MODULE user_command_0100_exit INPUT.

  CASE gv_okcode.
    WHEN ‘EXIT’ OR ‘CANC’.
      LEAVE PROGRAM.
  ENDCASE.

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

  CASE gv_okcode.
    WHEN ‘BACK’.
      PERFORM get_pdf USING ‘TEST.pdf’.
      LEAVE TO SCREEN 100.

    WHEN ‘EXIT’ OR ‘CANC’.
      EXIT.
  ENDCASE.

ENDMODULE.
*&———————————————————————*
*& Form get_pdf
*&———————————————————————*
FORM get_pdf USING pv_fname TYPE string.

  DATA:
    lw_pdf        TYPE rcgrepfile,
    lv_spath      TYPE eseftappl,
    lv_binsize    TYPE i,
    lv_binsizeall TYPE i.

  REFRESH gt_pdf.

  lv_spath = |D:/usr/sap/ZIP/Training/{ pv_fname }|.
  OPEN DATASET lv_spath FOR INPUT IN BINARY MODE.
  CHECK sy-subrc = 0.

  DO.
    READ DATASET lv_spath INTO lw_pdf LENGTH lv_binsize.
    IF sy-subrc = 0.
      lv_binsizeall = lv_binsizeall + lv_binsize.
      APPEND lw_pdf TO gt_pdf.
    ELSE.
      IF lv_binsize > 0.
        lv_binsizeall = lv_binsizeall + lv_binsize.
        APPEND lw_pdf TO gt_pdf.
      ENDIF.
      EXIT.
    ENDIF.

    CLEAR: lw_pdf, lv_binsize.
  ENDDO.
  CLOSE DATASET lv_spath.

ENDFORM.
*&———————————————————————*
*&      Module  STATUS_0100  OUTPUT
*&———————————————————————*
MODULE status_0100 OUTPUT.
  SET PF-STATUS ‘PF100’.
*  SET TITLEBAR ‘xxx’.
ENDMODULE.
————————————————————————-

Screen 100
PROCESS BEFORE OUTPUT.
  MODULE status_0100.
  MODULE show_url.

PROCESS AFTER INPUT.
  MODULE user_command_0100_exit AT EXIT-COMMAND.
  MODULE user_command_0100.


Appendix B

Leave a Reply

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