cancel
Showing results for 
Search instead for 
Did you mean: 

Display files on BSP page

Former Member
0 Kudos

Hi,

I am new to BSP, please help me out on this query. This topic has been discussed in multiple threads but i could not find my solution out of them.

I am working on SLC, where my requirement is to enhance the supplier registration page to have attachments. I need to insert a table view to list out all the files related to the supplier(Files will be from Application server). On click of each file(File names should be shown as links in the table) it should open the file.

We should be placing the table under General Company Information.

Please suggest.

Supplier registration page<at buy side>

Thanks,

Prathap

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

There is no direct way to display the files in BSP( untill unless it is a PDF/Smartform) per my understanding. Hence we can construct URL to the application server file and give a hyperlink, so that when user clicks the link, it could save the file in desktop.

Steps:

1.Get all the file path from application server, which you want to display.

2.Get the content of the files using "Open data set" and "Read Data set"

3.Convert the binary data to xstring

4.Get the Mime type of file

5.Construct Dynamic URL for file

6.Load the file in Server cache

Below is the code for Steps:

DATA:i_file TYPE rlgrap-filename ,
          i_datatab
TYPE STANDARD TABLE OF tbl1024,
          wa_datatab
TYPE   tbl1024,
         file TYPE  string,
        dot_offset TYPE I,
        extension TYPE mimetypes-extension,
        l_mimetype TYPE mimetypes-type,

         l_xstring    TYPE xstring,

         l_final_url  TYPE xstring.

FIELD-SYMBOLS <hex_container> TYPE x.

Step1 : Get file path


i_file = '/usr/sap/dir/test1'.

Step 2: Get the content of file using open dataset and Read dataset


OPEN DATASET i_file FOR INPUT IN LEGACY BINARY MODE.
IF sy-subrc NE 0.
MESSAGE e999(00) WITH 'Error opening file' .
ENDIF.

ASSIGN  wa_datatab TO <hex_container> CASTING.


DO.
READ DATASET i_file INTO <hex_container>.
IF sy-subrc = 0.
APPEND wa_datatab TO i_datatab.
ELSE.
EXIT.
ENDIF.

ENDDO.

CLOSE DATASET i_file.

DATA:l_count TYPE i,
l_len
TYPE i.

DESCRIBE TABLE i_datatab LINES l_count.
READ TABLE i_datatab INTO wa_datatab INDEX l_count.
l_len
= XSTRLEN( wa_datatab-line ).
l_len
= l_len + ( l_count - 1 ) * 1022.
 

Step 3: Convert the binary data to xstring


CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length
= l_len
IMPORTING
buffer       = l_xstring
TABLES
binary_tab  
= i_datatab
EXCEPTIONS
failed      
= 1
OTHERS       = 2.
IF sy-subrc <> 0.

ENDIF.

Step 4: Get the Mime type of file


file = i_file.
FIND FIRST OCCURRENCE OF REGEX '\.[^\.]+$' IN file MATCH OFFSET
dot_offset
.
ADD 1 TO dot_offset.
extension
= file+dot_offset.
" Get mime type
CALL FUNCTION 'SDOK_MIMETYPE_GET'
EXPORTING
extension
= extension
IMPORTING
mimetype 
= l_mimetype.

Step 5: Construct Dynamic URL for file

create object lcl_http_Response exporting add_c_msg = 1.

lcl_http_Response->set_data( l_xstring ).

lcl_http_Response->set_header_field( name  = if_http_header_fields=>content_type

value = l_mime_type ).

lcl_http_Response->set_status( code = 200 reason = 'OK' ).

lcl_http_Response->server_cache_expire_rel( expires_rel = 180 ).

call function 'GUID_CREATE'

importing

ev_guid_32 = guid.

concatenate runtime->application_url  '/' guid into l_final_url.

Step 6: Load the file in Server cache

cl_http_server=>server_cache_upload( url      =  l_final_url

response = cached_response ).

Hope this will be useful.

Note: Please ignore my earlier reply, which i intended for another thread. Wrongly replied to this thread

Former Member
0 Kudos

Thank you Meghanand. I have put this code in my DO_HANDLE_EVENT. and using below code in my layout.

<%
if CONTROLLER->DISPLAY_URL is not initial.
%>
        <script language="Javascript">

          window.open(CONTROLLER->DISPLAY_URL).focus();

        </script>
<%
endif.

%>

But yet file is not being displayed. Can you please tell me if I am missing anything here.. Please refer to my code below. DISPLAY_URL is dfined as attribute in Controller class.

DATA: lo_table       TYPE REF TO cl_htmlb_event_tableview,
      lo_model       TYPE REF TO cl_bsp_model,
      lo_ros_model   TYPE REF TO /SRMSMC/CL_ROS_EXT_M_FIRST.

data: lv_index TYPE sy-tabix,
      lv_mimetype             TYPE SKWF_MIME,
      lv_mime_string          TYPE string,
      lv_filename             TYPE SKWF_filnm,
      lv_count                TYPE i,
      lv_len                  TYPE i,
      lv_guid                 TYPE guid_32,
      lv_xstring              TYPE xstring,
      lv_display_url type string,
      lt_file  TYPE ZTT_ZROS_EXT_GUI_IMG,
      lt_datatab TYPE STANDARD TABLE OF tbl1024,

      ls_file  TYPE ZROS_EXT_GUI_IMG,
      ls_datatab TYPE   tbl1024.

field-symbols: <l_model> TYPE lbsp_model_item,
               <lfv_hex_container> TYPE xstring.


IF event = 'id_file'.
  lo_table ?= htmlb_event_ex.
  lv_index = lo_table->row_index.

  READ TABLE m_models INDEX 1 ASSIGNING <l_model>.
  IF sy-subrc = 0.
    lo_model = <l_model>-instance.
    IF lo_model IS BOUND.
      lo_ros_model ?= lo_model.
      lt_file[] = lo_ros_model->mt_file[].

      READ TABLE lt_file INTO ls_file INDEX lv_index.
      IF sy-subrc = 0.
        lv_filename = ls_file-fname.
        CALL FUNCTION 'SKWF_MIMETYPE_OF_FILE_GET'
          EXPORTING
            FILENAME                   = lv_filename
          IMPORTING
            MIMETYPE                   = lv_mimetype.

        lv_filename = ls_file-floca && '/' && ls_file-fname.
        data: lv_msg TYPE c LENGTH 100.
        OPEN DATASET lv_filename FOR INPUT MESSAGE lv_msg IN LEGACY BINARY MODE.
         IF sy-subrc = 0.
*           ASSIGN  ls_datatab TO <lfv_hex_container> CASTING.

           DO.
             READ DATASET lv_filename INTO ls_datatab.
             IF sy-subrc = 0.
               APPEND ls_datatab TO lt_datatab.
             ELSE.
               EXIT.
             ENDIF.
           ENDDO.
         ENDIF.


        CLOSE DATASET lv_filename.


        DESCRIBE TABLE lt_datatab LINES lv_count.
        READ TABLE lt_datatab INTO ls_datatab INDEX lv_count.
        lv_len = XSTRLEN( ls_datatab-line ).
        lv_len = lv_len + ( lv_count - 1 ) * 1022.

        CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
          EXPORTING
            INPUT_LENGTH       = lv_len
          IMPORTING
            BUFFER             = lv_xstring
          TABLES
            BINARY_TAB         = lt_datatab
          EXCEPTIONS
            FAILED             = 1
            OTHERS             = 2.
        IF SY-SUBRC = 0.
          DATA: lo_response TYPE REF TO if_http_response.

          lv_mime_string  = lv_mimetype.
          create object lo_response TYPE CL_HTTP_RESPONSE exporting add_c_msg = 1.
          lo_response->set_data( lv_xstring ).
          lo_response->set_header_field( name  = if_http_header_fields=>content_type value = lv_mime_string ).
          lo_response->set_status( code = 200 reason = 'OK' ).
          lo_response->server_cache_expire_rel( expires_rel = 180 ).
          call function 'GUID_CREATE'
            importing
              ev_guid_32 = lv_guid.

          concatenate runtime->application_url  '/' lv_guid into display_url.

*         Step 6: Load the file in Server cache

           cl_http_server=>server_cache_upload( url      = display_url
                                                response = lo_response ).

        ENDIF.

      ENDIF.

    ENDIF.
  ENDIF.

ENDIF.

Former Member
0 Kudos

Thanks Meghanand. I have paced window.open at end of the page & it worked.

Thanks,

Prathap

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

Try by removing scrollbars in iFrame.

Former Member
0 Kudos

hi Meghanand,

This is in BSP. I could get the list of files on to BSP page. On click of each file, it triggers DO_HANDLE_EVENT method of the controller.

My BSP application is using MVC model. Please help me with sample code to display files in a browser window. I cannot use window.open as it is using MVC framework. Please let me know if my understanding is incorrect.