cancel
Showing results for 
Search instead for 
Did you mean: 

BSP Download - Response is running for a long time.

GaneshRK
Participant
0 Kudos

Hi All,

I have used the method cl_bsp_utility=>download to download the data to excel file. After clicking on download button the response is running for long time and not completing. Please advice how to get the control back to page.  Thanks.        

CALL METHOD cl_bsp_utility=>download
          EXPORTING
            object_s            = l_xstring
            content_type        = app_type
            content_disposition = 'attachment;filename=CompletedCourse.xls'
            response            = runtime->server->response
            navigation          = navigation.

Regards,

Ganesh R K.

Accepted Solutions (1)

Accepted Solutions (1)

rdiger_plantiko2
Active Contributor
0 Kudos

Hi Ganesh,

I tried with a plain HTML BSP page, and without using the CL_BSP_UTILIES=>DOWNLOAD method. It works fine in my case. Of course, I do get the question whether I want to open or save the downloaded document. That's normal. But when hitting the button, my Excel is downloaded to the computer and when I choose "open", Excel starts and displays the 3x3 magic square.

By the way, this showed me that the file ending .xls together with the MIME type application/vnd.ms-excel works fine (contrary to my recommendation to change this to text/csv).

Maybe this running example of an Excel download page helps you in any way.

Regards,

Rüdiger

P.S.: I don't understand your print question. It should be clear that you can print an Excel sheet only from within Excel. To print the HTML page, use the method print() of the window object. Or what do you want to print?

<%@page language="abap"%>
<% if request->get_form_field('download') eq 'X'.
   data: lv_bin type xstring,
         lv_csv type string,
         lv_row type string,
         lv_text type string,
         lv_length type string,
         lo_conv type ref to cl_abap_conv_out_ce.

  define _add_cols.
    concatenate &1 &2 &3 into lv_row
      separated by cl_abap_char_utilities=>horizontal_tab.
    if lv_csv is not initial.
      concatenate lv_csv lv_row into lv_csv
        separated by cl_abap_char_utilities=>cr_lf.
    else.
      lv_csv = lv_row.
    endif.
  end-of-definition.

  _add_cols:
    '10' '2' '3',  " Du musst verstehn, aus 1 mach 10, die 2 lass gehn, die 3 mach gleich
    '0'  '7' '8',  " Verlier die 4, aus 5 und 6, so sagt die Hex, mach 7 und 8
    '5'  '6' '4'.  " So ist's vollbracht.

  lo_conv = cl_abap_conv_out_ce=>create( ).
  lo_conv->convert( exporting data = lv_csv importing buffer = lv_bin ).

  response->set_header_field( name  = 'Content-Type'
                              value = 'application/vnd.ms-excel; charset=utf-8' ).
  lv_length = xstrlen( lv_bin ).
  response->set_header_field( name  = 'Content-Length'
                              value =  lv_length ).
  response->set_header_field( name  = 'Content-Disposition'
                              value =  'attachment;filename=text.xls' ).
  response->delete_header_field( name  = 'Expires' ).
  response->delete_header_field( name  = 'Pragma' ).
  response->delete_header_field( name  = 'Cache-control' ).

  response->set_data( lv_bin ).

else. %>
<html>
  <head>Test Download</head>
  </head>
  <body>
    <h1>Test Download</h1>
    <form method="post">
      <input type="hidden" name="download" value="X">
      <input type="submit" name="Download">
    </form>
  </body>
</html>
<%endif.%>

GaneshRK
Participant
0 Kudos

Hi Rudiger,

I have tired with you logic without calling method "Download", but still i am facing the same issue. I have tired with out having the Button in the Page, it works fine. If i am having a button on the layout and passing the button parameter to OnInputProcessing event, then the problem is raised. Can you please help me on this.

Regards,

Ganesh R K.

GaneshRK
Participant
0 Kudos

Hi Rudiger,

I have solved that issue. Add the below code to stop the doublesubmit process. Many thanks for your help.

  function wait_timeout()

{

window.setTimeout('showProtectDoubleSubmitWindow(false)', 4000);
window.setTimeout('showProtectActive = null', 4010);
};

  <htmlb:button id      = "submit"
text   = "Download"
onClick = "test"
onClientClick = "wait_timeout( );"
width = "5%"/>

Thanks,

Ganesh R K.

Answers (1)

Answers (1)

rdiger_plantiko2
Active Contributor
0 Kudos
Hi Ganesh,
I don't use CL_BSP_UTILITY=>DOWNLOAD, but I inspected its implementation. I saw that the statements
*  length = xstrlen( <os> ).
*  response->set_header_field( name  = 'Content-Length'
*                              value =  length ).
have been commented out in the implementation. Oddly, in similar case with a pdf download, I had just your symptom - the Internet Explorer waiting indefinitely for the completion of the download - due to the missing field Content-Length. Therefore:
Please set Content-Length before the call of CL_BSP_UTILITY=>DOWNLOAD. (You can set header fields before the call, too. )
Another problem could be with the encoding. The download method expects binary data (raw data, an xstring), whereas Excel data (probably csv), will be given as character sequence (string).  In this case, you must have mapped your character data to an XSTRING before calling CL_BSP_UTILITY=>DOWNLOAD.  Do not use XSTRLEN( ) as Content-Length then, but STRLEN( ) for the original , since you will have to count characters, not bytes.
Regards,
Rüdiger
GaneshRK
Participant
0 Kudos

Hi Rudiger,

Thanks for your inputs. Please see the below code which i have implemented. The navigation to downloading the Excel is works fine. But the control is not returning to BSP application. The message "Wait...Your request is being processed" is still running. Please advice to come back to the same screen.

Layout:

  <htmlb:form>
<htmlb:button id      = "submit"
text   = "Download"
onClick = "test"
width = "5%"/>

</htmlb:form>

Event: OnInputProcessing

   DATA: button_event TYPE REF TO cl_htmlb_event_button ,
           event TYPE REF TO if_htmlb_data.

DATA: wa_history TYPE lsactivity300.
MOVE: activity_table TO activity_table.
DATA: l_delivery TYPE char40,
      l_begda TYPE char10,
      l_endda TYPE char10,
      l_begtm  TYPE char8,
      lv_len           TYPE i,
lv_app_type2     TYPE string,

      l_per    TYPE char4,
      l_pass TYPE char10,
      l_endtm TYPE char8,
  output TYPE string ,
  l_xstring TYPE xstring,
  app_type TYPE string.

event = cl_htmlb_manager=>get_event( runtime->server->request ).

IF event IS NOT INITIAL AND event->event_name =
htmlb_events=>button .

  button_event ?= event .

  IF event->event_server_name EQ 'test'.


    IF lt_histo  IS NOT INITIAL.

      CONCATENATE output
     'Course ID'
    cl_abap_char_utilities=>horizontal_tab
   'Course Description'
cl_abap_char_utilities=>horizontal_tab

'Delivery Method'
cl_abap_char_utilities=>horizontal_tab

'Location'
cl_abap_char_utilities=>horizontal_tab

'Start Date'
cl_abap_char_utilities=>horizontal_tab
'End Date'
cl_abap_char_utilities=>horizontal_tab
'Start Time'
cl_abap_char_utilities=>horizontal_tab
'End Time'
cl_abap_char_utilities=>horizontal_tab

'Progress'
cl_abap_char_utilities=>horizontal_tab
'Status'
         cl_abap_char_utilities=>cr_lf
         INTO output SEPARATED BY space.

      LOOP AT lt_histo INTO wa_history.
        READ TABLE deliveries INTO ls_delivery_txt
        WITH KEY tform = wa_history-tform.
        IF sy-subrc EQ 0.
          MOVE ls_delivery_txt-txtsing TO l_delivery.
        ENDIF.
*          20111018
        CONCATENATE wa_history-begda+4(2) '/' wa_history-begda+6(2) '/' wa_history-begda+0(4)
        INTO l_begda.
        CONCATENATE wa_history-endda+4(2) '/' wa_history-endda+6(2) '/' wa_history-endda+0(4)
        INTO l_endda.

*          235900
        CONCATENATE wa_history-beguz+0(2) ':' wa_history-beguz+2(2) INTO l_begtm.
        CONCATENATE wa_history-enduz+0(2) ':' wa_history-enduz+2(2) INTO l_endtm.
        IF NOT wa_history-activity_achieve IS INITIAL.
          MOVE wa_history-activity_achieve TO l_per.
          CONCATENATE l_per '%' INTO l_per.
        ELSE.
          MOVE space TO l_per.
        ENDIF.
        IF NOT wa_history-show_passed IS   INITIAL.
          MOVE 'Passed' TO l_pass.
        ELSE.
          MOVE 'Not Completed' TO l_pass.
        ENDIF.
        CONCATENATE
        output
          wa_history-activity_id
        cl_abap_char_utilities=>horizontal_tab
         wa_history-activity_text
        cl_abap_char_utilities=>horizontal_tab
        l_delivery
        cl_abap_char_utilities=>horizontal_tab
        wa_history-location_name
        cl_abap_char_utilities=>horizontal_tab
        l_begda
        cl_abap_char_utilities=>horizontal_tab
               l_endda
        cl_abap_char_utilities=>horizontal_tab
               l_begtm
        cl_abap_char_utilities=>horizontal_tab
               l_endtm
        cl_abap_char_utilities=>horizontal_tab
                  l_per
        cl_abap_char_utilities=>horizontal_tab
        l_pass
         cl_abap_char_utilities=>cr_lf
        INTO output SEPARATED BY space.
        CLEAR: l_delivery, l_begda, l_endda, l_endtm, l_begtm, l_per, l_pass.
      ENDLOOP.



      app_type = 'APPLICATION/vnd.MS-EXCEL; charset=utf-8'.

      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
        EXPORTING
          text     = output
          mimetype = 'APPLICATION/vnd.MS-EXCEL; charset=utf-8'
        IMPORTING
          buffer   = l_xstring.

      CONCATENATE
      cl_abap_char_utilities=>byte_order_mark_little
      l_xstring  INTO l_xstring
      IN BYTE MODE.

      CALL METHOD cl_bsp_utility=>download
        EXPORTING
          object_s            = l_xstring
          content_type        = app_type
          content_disposition = 'attachment;filename=CompletedCourse.xls'
          response            = _m_response
          navigation          = navigation.
      navigation->response_complete( ).

    ENDIF.
  ELSE.
  ENDIF.
ENDIF.

Thanks in advance.

Regards,

Ganesh R K.

rdiger_plantiko2
Active Contributor
0 Kudos

Hi Ganesh, the mime type is probably wrong for the csv data that you are actually preparing. Please try "text/csv" instead. Maybe it helps if you add the Content-Length to the header, with the code mentioned above. (Forget what I said above about STRLEN( ). Content-Length in HTTP always is the number of bytes).

Regards,

Rüdiger

  data: lv_length type string.

  lv_length = xstrlen( l_xstring ). 

  m_response->set_header_field( name  = 'Content-Length' 

                              value =  lv_length ).

  CALL METHOD cl_bsp_utility=>download

          EXPORTING

            object_s            = l_xstring

...

GaneshRK
Participant
0 Kudos

Hi Rudiger,

I have tried with the logic which you have provided, but still i am not able to move further. The same message "Wait.. Your request is being proceed" is still appearing. Please advice. 

Regards,

Ganesh R K.

rdiger_plantiko2
Active Contributor
0 Kudos

Hi Ganesh,

so it wasn't the Content-Length issue. Don't lose the patience! 🙂 Keep analysing with all available tools.

I would suggest the following:

  • Does your problem occur on all browsers or only on IE?
  • Test your button in the Firefox Browser. Using the Firebug "Network" tab,  find out on HTTP level which was the response message.
  • Does the HTTP response reach the browser at all?
  • If yes: Analyse the header fields and the content of the response message. Is there something which appears suspicious to you?
  • Analyse the HTTP body: Is ist complete?

Regards,

Rüdiger

GaneshRK
Participant
0 Kudos

Hi Rudiger,

I have tired in Firefox too. The same problem is occurring. I hope i am doing a small mistake in code. Cannot able to figure it out the exact code. Actually i am modifying the HCM_LEARNING bsp application, which will display the list of learning courses completed. User has a requirement to Download the completed course and addition to that to print the particular tray. In the Activities.htm page, which will have 3 trays, one if for completed courses, Current activities and Cancelled courses. I need to download the Completed Courses and user can able to pring the seperate tray's in the entire page. Please find the screenshot attached. One more point, is it posible to print a particular tray in the page. Please advice.

rdiger_plantiko2
Active Contributor
0 Kudos

Hello Ganesh,

please make the following test: Leave away the byte order mark:

CONCATENATE

      cl_abap_char_utilities=>byte_order_mark_little

      l_xstring  INTO l_xstring

      IN BYTE MODE.

I noticed that I have the same "endless wait" situation if I add these lines of your code to my page.

Regards,

Rüdiger