Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert BSP output to PDF

Hi All,

I have a BSP application wherein a Dashboard report is presented. basically it has a selection screen and a tableview which is displayed. There are two buttons to decide whether its a management report or a regular report. Depending upon the buttons the output inthe table changes. This part is working fine. In case of management report i have to color some cells based on a particular condition. There is another button for ' Export to PDF'. I need to convert the output of the tableview to PDF. I could not find a direct way to do , so I created an ABAP report of similair output called Z01_BSPPRDDASH_SPOOL . when user presses the button, the report output is genereated and sent to spool. The spool is converrted to PDF using the std FM 'CONVERT_ABAPSPOOLJOB_2_PDF'. After this i need to display the pdf. but the code given below is not doing that. I am unable to see any output. Can you pls telle me what is going wrong . Also let me know if my approach is correct. Can there be any other way of converting a tableview to pdf. I need to solve this urgently as my delivery date is nearing for this object.

Code :

DATA: ITAB TYPE TLINE,

WITAB TYPE TABLE OF TLINE,

OUTPUT TYPE STRING ,

  • CONTENT TYPE XSTRING,

WF_SPONO TYPE TSP01-RQIDENT ,

WF_PARAMS TYPE PRI_PARAMS,

VALID_FLAG(1) TYPE C ,

LC_RQ2NAME TYPE TSP01-RQ2NAME ,

TSP01_WA TYPE TSP01 .

DATA: CACHED_RESPONSE TYPE REF TO IF_HTTP_RESPONSE.

DATA: RESPONSE TYPE REF TO IF_HTTP_RESPONSE.

DATA: GUID TYPE GUID_32.

DATA: L_PDF_XSTRING TYPE XSTRING,

  • lt_lines type table of tline,

LS_LINE TYPE TLINE,

DISPLAY_URL TYPE STRING,

L_PDF_LEN TYPE I.

DATA: OUTPUT_OPTIONS TYPE SSFCOMPOP,

CONTROL_PARAMETERS TYPE SSFCTRLOP,

OUTPUT_DATA TYPE SSFCRESCL,

DEVTYPE TYPE RSPOPTYPE.

*

CALL FUNCTION 'GET_PRINT_PARAMETERS'

EXPORTING

DESTINATION = 'LOCL'

IMMEDIATELY = ' '

RELEASE = ' '

NEW_LIST_ID = 'X'

LINE_SIZE = 255

LINE_COUNT = 65

LAYOUT = 'X_65_255'

SAP_COVER_PAGE = 'X'

RECEIVER = 'SAP*'

DEPARTMENT = ''

NO_DIALOG = 'X'

IMPORTING

OUT_PARAMETERS = WF_PARAMS

VALID = VALID_FLAG.

IF VALID_FLAG = 'X' AND SY-SUBRC = 0.

SUBMIT Z01_BSPPRDDASH_SPOOL TO SAP-SPOOL WITHOUT SPOOL DYNPRO

SPOOL PARAMETERS WF_PARAMS

AND RETURN .

ENDIF.

  • this is to get the spool no. created. Not a real nice

  • way though. if someone knows a better method please do

  • share

CONCATENATE 'SAPMHTTP'

SY-UNAME+0(3)

INTO LC_RQ2NAME SEPARATED BY '_'.

SELECT * FROM TSP01 INTO TSP01_WA WHERE RQ2NAME = LC_RQ2NAME AND

RQOWNER = SY-UNAME

ORDER BY RQCRETIME DESCENDING.

WF_SPONO = TSP01_WA-RQIDENT.

EXIT.

ENDSELECT.

IF SY-SUBRC NE 0.

CLEAR WF_SPONO.

ENDIF.

IF NOT WF_SPONO IS INITIAL.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

EXPORTING

SRC_SPOOLID = WF_SPONO

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.

ENDIF.

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 '~ ' .

CREATE OBJECT CACHED_RESPONSE TYPE CL_HTTP_RESPONSE EXPORTING

ADD_C_MSG = 1.

L_PDF_LEN = STRLEN( OUTPUT ).

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

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->goto_page( display_url ).

.

RETURN .

Regards,

Sriprabha

Former Member
replied

Hi Srippy,

try this.

DATA: witab       TYPE TABLE OF tline,
      itab        TYPE tline,
      outputx     TYPE xstring,
      display_url TYPE string.

FIELD-SYMBOLS: <p> TYPE x.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
  EXPORTING
    src_spoolid              = 3831
    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   = 9
    err_btcjob_submit_failed = 10
    err_btcjob_close_failed  = 11
    OTHERS                   = 12.

IF sy-subrc = 0.

  LOOP AT witab INTO itab .
    ASSIGN itab TO <p> CASTING TYPE x.
    CONCATENATE outputx <p> INTO outputx IN BYTE MODE.
  ENDLOOP.

  response->set_data( data = outputx ).

  response->set_header_field( name = 'content-type'
                              value = 'application/pdf' ).

  response->set_header_field( name = 'cache-control'
                              value = 'max-age=0' ).

  CONCATENATE 'attachment; filename=' 'test.pdf'
    INTO display_url.

  response->set_header_field( name = 'content-disposition'
                              value = display_url ).

  navigation->response_complete( ).

ENDIF.

Cheers

Graham Robbo

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question