Skip to Content
0
Former Member
Apr 01, 2009 at 08:21 PM

BSP PDF not working in ECC 6.0

34 Views

Hello all, we are upgrading from 4.7 to ECC 6.0 and we have several BSP programs that create pdf reports by converting data from the r/3 spool. This following code works fine in SAP 4.7 but in ECC 6.0, I am getting the error: 'File does not begin with '%pdf-'. The following is the code to convert a file from the spool and display in pdf format. Again, this works in 4.7.

Any help is appreciated

IF ztsp01-rqapprule LE 99.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = ztsp01-rqident

no_dialog = 'X'

TABLES

pdf = witab

EXCEPTIONS

err_no_abap_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_destdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 8

err_btcjob_submit_failed = 9

err_btcjob_close_failed = 10

OTHERS = 11.

  • Get spool name.

zabapspoolid = ztsp01-rqident.

  • Delete spool.

CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'

EXPORTING

spoolid = zabapspoolid.

IF sy-subrc EQ 0.

LOOP AT witab INTO itab.

TRANSLATE itab USING ' ~'.

CONCATENATE output itab INTO output IN CHARACTER MODE.

ENDLOOP.

TRANSLATE output USING '~ ' .

  • Convert the Character String to Binary String.

DATA: r_string TYPE string.

DATA: r_xstring TYPE xstring.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = output

IMPORTING

buffer = outputx.

CREATE OBJECT cached_response TYPE cl_http_response EXPORTING

add_c_msg = 1.

DATA:l_pdf_len TYPE i.

l_pdf_len = XSTRLEN( outputx ).

  • l_pdf_len = strlen( output ).

cached_response->set_data( data = outputx

  • cached_response->set_cdata( data = output

length = l_pdf_len ).

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 = 30 ).

CALL FUNCTION 'GUID_CREATE'

IMPORTING

ev_guid_32 = guid.

CONCATENATE runtime->page_url '/' guid '.pdf' INTO

display_url.

cl_http_server=>server_cache_upload( url = display_url

response = cached_response ).

ENDIF.

RETURN.

ELSE.

zabapspoolid = ztsp01-rqident.

  • Delete spool.

CALL FUNCTION 'RSPO_R_RDELETE_SPOOLREQ'

EXPORTING

spoolid = zabapspoolid.

page->messages->add_message(

condition = 'page'

message =

'Display is greater than 99 pages. Use a smaller selection.'

severity = page->messages->co_severity_error ).

ENDIF.