Skip to main content

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



Comments

Popular posts from this blog

How to Create a REST API in SAP ABAP — Step-by-step Guide

How to Create a REST API in SAP ABAP — Step-by-step Guide Summary: This tutorial shows how to build a REST API in SAP ABAP by creating a handler class, configuring SICF service, registering endpoints with cl_rest_router , implementing endpoint logic (example GET method), and testing the API. Based on an internal implementation reference. Why expose REST APIs from SAP? REST APIs allow SAP systems to integrate with web, mobile, and external services using standard HTTP and JSON payloads. Implementing REST endpoints in ABAP provides secure, reusable, and maintainable integration points for modern applications. Prerequisites Access to an SAP system with authorization to create classes (SE24) and SICF services (SICF). Familiarity with ABAP object-oriented concepts and basic SAP transaction codes. ABAP classes CL_REST_RESOURCE , CL_REST_ROUTER and utilities like /UI2/CL_JSON . High-level overview (4 steps) Create an API handler class (e.g. ZCL_API_HANDLER ). R...

SAP ABAP - User Exit Set Batch Characteristic Value In MIGO Goods Receipt

Customer Exit  :  MBCFC004 ( EXIT_SAPMM07M_004) Set Up Customer Exit for Classification of User-Defined Characteristics You use SAP enhancement MBCFC004 EXIT_SAPMM07M_004, which contains function module exit EXIT_SAPMM07M_004 to classify user-defined characteristics automatically during goods movements in Inventory Management. This is only possible for characteristics which are not assigned values during quality inspection. Requirements 1. The class of the batch to be classified must be known.  This means that a class must be assigned either to the material or at least to one batch of this material. 2. The exit call must be activated for the respective movement type in activity Activate batch classification during goods movements in IM using indicator 'Extended classification' . Open tcode OMC...

IT Asset Management Dengan PHP MySQL

Pada postingan kali saya akan share sebuah aplikasi IT Asset management yang fungsinya untuk memonitoring semua Asset khusus IT, contohnya : Laptop/komputer , Printer, Router, Hardisk, dll. Dalam aplkasi ini kita bisa mengetahui Asset IT posisinya dimana dan digunakan oleh siapa. untuk data-data yang dibutuhkan antara lain : 1. data kategori asset dalam menu ini kita bisa meng-input jenis2 kategory asset : tambah kategori asset : 2. data department 3. data karyawan 4. data department per karyawan 5. data asset location  6. data satuan asset dan untuk transaksi yang ada dalam aplikasi ini adalah,  1. create asset, pada menu create asset ini kita akan mengalokasikan sebuah asset ke karyawan/personnel tampilannya seperti berikut: setelah klik tombol save akan muncul seperti dibawah : untuk melihat detail asset yang sudah dibuat tadi, kita bisa pilih...