PDF File opening error

10-11  Source: Network gathering  Views:0 

Advertisement
Hi,
I have an BSP application in which I am fetching the pdf file data from an oracle table to a variable of data type xstring.
Now I have to display this xstring again in pdf format in this BSP. The pdf file is generated but while opening it is giving error "There is an error in opening this document.The file is damaged and could not be repaired".
What could be the reason.
My On initialisation code is as:
data: outputx type xstring.
(The pdf file data is fetched from oracle table to outputx.)
CREATE OBJECT cached_response TYPE CL_HTTP_RESPONSE EXPORTING add_c_msg
= 1.
    cached_response->set_header_field( name  =
          if_http_header_fields=>content_type
                                  value = 'application/pdf' ).
    cached_response->set_status( code = 200 reason = 'OK' ).
    cached_response->server_cache_expire_rel( expires_rel = 180 ).
    l_pdf_len = xstrlen( outputx ).
    response->set_data( data = outputx
                             length = l_pdf_len ).
     response->set_header_field(
                        name  = 'content-disposition'
                        value = 'attachment; filename=attach_pdf.pdf' ).
CALL FUNCTION 'GUID_CREATE'
      IMPORTING
        ev_guid_32 = guid.
    CONCATENATE runtime->application_url '/' guid '.pdf' INTO
display_url.
    cl_http_server=>server_cache_upload( url      = display_url
                                         response = cached_response ).
  navigation->response_complete( ).
Still the pdf file is not opening.
My On Initilisation code is as below:
EXEC SQL.
  OPEN CUR FOR SELECT ORDER_NO,ORDER_DESC,DOC_TYPE
             FROM SAPIBM.T_ORDER
             where ORDER_NO = :orderno
ENDEXEC.
refresh : t_order.
do.
  clear : wk_order.
  EXEC SQL.
    FETCH NEXT CUR INTO
                     :wk_order-ORDER_NO,
                     :wk_order-ORDER_DESC,
                     :WK_ORDER-DOC_TYPE
  ENDEXEC.
  if sy-subrc = 0.
    append wk_order   to t_order.
  else.
    exit.
  endif.
enddo.
EXEC SQL.
  CLOSE CUR
ENDEXEC.
if not t_order[] is initial.
  read table t_order into wk_order index 1.
  w_doctype = wk_order-doc_type.
  case w_doctype.
    when 'P'.
outputx = wk_order-order_desc.
CREATE OBJECT cached_response TYPE CL_HTTP_RESPONSE EXPORTING add_c_msg
= 1.
IF XSTRLEN( OUTPUTX ) > 0.
response->delete_header_field(
name = if_http_header_fields=>cache_control ).
response->delete_header_field(
name = if_http_header_fields=>expires ).
response->delete_header_field(
name = if_http_header_fields=>pragma ).
response->set_header_field(
name = if_http_header_fields=>content_type
value = 'application/pdf' ).
   response->set_status( code = 200 reason = 'OK' ).
   response->server_cache_expire_rel( expires_rel = 180 ).
    response->set_header_field(
                      name  = 'content-disposition'
                       value = 'attachment; filename=attach_pdf.pdf' )
    response->set_header_field(
                   name  = 'cache-control'
                   value = 'max-age=0' ).
    l_pdf_len = xstrlen( wk_order-order_desc ).
    response->set_data( data = wk_order-order_desc
                             length = l_pdf_len ).
    CALL FUNCTION 'GUID_CREATE'
      IMPORTING
        ev_guid_32 = guid.
    CONCATENATE runtime->application_url '/' guid '.pdf' INTO
display_url.
    cl_http_server=>server_cache_upload( url      = display_url
                                         response = cached_response ).
  navigation->response_complete( ).
endif.
  endcase.
endif.
Related articles