Introduction

This Document helps to Browse PDF file from Local system and display in Web dynpro .

UI Elements:

                      File Upload

                      Button

                      IFrame

Browse PDF file using Webdynpro ABAP   

Create a Webdynpro Component

Browse PDF file using Webdynpro ABAP

Browse PDF file using Webdynpro ABAP

Create a Node ( BROWSE_PDF)

Browse PDF file using Webdynpro ABAP 

Browse PDF file using Webdynpro ABAP

Browse PDF file using Webdynpro ABAP

Nodes:      BROWSE_PDF      Cardinality: 1:1

Attribute:   URL                       Type: String

Attribute:   DATASOURCE       Type :String

Create a UI Element (File Upload)

Browse PDF file using Webdynpro ABAP

Bind the property of file upload : DATA

Browse PDF file using Webdynpro ABAP

Select Datasource

Browse PDF file using Webdynpro ABAP

Create UI element Button

Browse PDF file using Webdynpro ABAP

Create a action UPLOAD

Browse PDF file using Webdynpro ABAP

Create  a UI Element IFRAME to display the PDF

Browse PDF file using Webdynpro ABAP

Bind the Property  Source 

Browse PDF file using Webdynpro ABAP

Select URL

Browse PDF file using Webdynpro ABAP

Write the code for Action UPLOAD

Browse PDF file using Webdynpro ABAP

   DATA LO_ND_BROWSE_PDF TYPE REF TO IF_WD_CONTEXT_NODE.
   DATA LO_EL_BROWSE_PDF TYPE REF TO IF_WD_CONTEXT_ELEMENT.
   DATA LS_BROWSE_PDF TYPE WD_THIS->ELEMENT_BROWSE_PDF.
   DATA LV_URL LIKE LS_BROWSE_PDF-URL.
   DATA LO_EL_CONTEXT TYPE REF TO IF_WD_CONTEXT_ELEMENT.
   DATA LS_CONTEXT TYPE WD_THIS->ELEMENT_CONTEXT.
   DATA LV_DATASOURCE TYPE WD_THIS->ELEMENT_CONTEXT-DATASOURCE.
   DATA: CACHED_RESPONSE     TYPE REF TO   IF_HTTP_RESPONSE,
         LV_FILE_CONTENT     TYPE          XSTRING,
         LV_GUID             TYPE          GUID_32,
         LV_HOST             TYPE          STRING,
         LV_PORT             TYPE          STRING,
         LV_PROTOCOL         TYPE          STRING.

   LO_EL_CONTEXT = WD_CONTEXT->GET_ELEMENT( ).
   LO_EL_CONTEXT->GET_ATTRIBUTE(
     EXPORTING
       NAME =  `DATASOURCE`
     IMPORTING
       VALUE = LV_DATASOURCE ).

   CREATE OBJECT CACHED_RESPONSE
          TYPE   CL_HTTP_RESPONSE
          EXPORTING ADD_C_MSG = 1.

   LV_FILE_CONTENT = LV_DATASOURCE.
   CACHED_RESPONSE->SET_DATA( LV_FILE_CONTENT ).
   CACHED_RESPONSE->SET_HEADER_FIELD( NAME  = IF_HTTP_HEADER_FIELDS=>CONTENT_TYPE
                                      VALUE = ‘application/pdf’ ).

   CALL FUNCTION ‘GUID_CREATE’
        IMPORTING ev_guid_32 = lv_guid.

     cached_response->set_status( code = 200 reason = ‘OK’ ).
     cached_response->server_cache_expire_rel( expires_rel = 360 ).

       CALL METHOD cl_http_server=>get_location
         EXPORTING
           server       = cl_wdr_task=>server
         IMPORTING
           host         = lv_host
           port         = lv_port
           out_protocol = lv_protocol.

       CONCATENATE
         lv_protocol ‘://’ lv_host ‘:’ lv_port ‘/sap/bc/webdynpro/sap/’
         lv_guid ‘.PDF’
         INTO lv_url.

       cl_http_server=>server_cache_upload( url      = lv_url
                                            response = cached_response ).

   LO_ND_BROWSE_PDF = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_BROWSE_PDF ).
   LO_EL_BROWSE_PDF = LO_ND_BROWSE_PDF->GET_ELEMENT( ).

   LS_BROWSE_PDF-URL = LV_URL.

   lo_el_BROWSE_PDF->set_static_attributeS(
                      static_attributes = ls_BROWSE_PDF ).

Create a Application

Browse PDF file using Webdynpro ABAP

Run the Application

Browse PDF file using Webdynpro ABAP

Choose file

Browse PDF file using Webdynpro ABAP

Browse PDF file using Webdynpro ABAP

Click on Upload button

Browse PDF file using Webdynpro ABAP

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !