cancel
Showing results for 
Search instead for 
Did you mean: 

Spool Data as PDF In a Work Item

Former Member
0 Kudos

Hi

I am having a requirement to send spool data as a PDF attachment in a work item.

I have used the FM CONVERT_ABAPSPOOLJOB_2_PDF to covert into PDF,

Then Translated the converted PDF Using ~

Then Converted the string into X String Using SCMS_STRING_TO_XSTRING

Then Passed the X String to Fm SAP_WAPI_ATTACHMENT_ADD.

The Issue here is PDF is attached, But I am not able to open the PDF file. It is saying that the file is incorrecetly decoded while opening the file.

Can any one throw some hints to solve this issue.

I have used many combinations by using the above code, Like

1) Like with out translating using ~ and did other process

2) sending only the TLine data to the fm SAP_WAPI_ATTACHMENT_ADD

( By using text(T) and file extension PDF in the header )

( Also By Using Binary(B) and file extension PDF )

3)Also with out converting the string to Xstring using SCMS_STRING_TO_XSTRING

(Using Binary and Text also)

4) Also I have used X String to Binary, Then also PDF file is not opening

But Still in all the above cases, I am not able to send the correct PDF file.

I have gone through almost all the forums, But could not find the related post.

Please help me in this regard.

Thanks and Regards,

Meshack Prasan Appikatla.

Accepted Solutions (0)

Answers (1)

Answers (1)

anjan_paul
Active Contributor
0 Kudos

Hi, 

  Check like this way

1. When you convert the spool request to PDF using FM CONVERT_ABAPSPOOLJOB_2_PDF . Check is it correcltly converted.

2. And after SCMS_STRING_TO_XSTRING you check it is properly converted.

Generally its coming as PDF has not passed with correct value.

Former Member
0 Kudos

Hi Anjan,

Thanks for the reply,

I have checked the Fms, all are returning subrc as 0, means data is converting correctly.

One Observation: When I put the same code to display PDF in an R/3 Custom Container,

It is also not displaying the PDF. It is displaying the error ' File does not begin with '%PDF-' '.

I think some fault is there in the process after the Fm CONVERT_ABAPSPOOLJOB_2_PDF, the sequence or something else, which I couldnt figure out.

Please let me know if there are any other function modules which directly convert spool data to Binary data?


Thanks and Regards,

Meshack Prasan

anjan_paul
Active Contributor
0 Kudos

Hi,

  I found some link to convert. Check the link

http://www.sapdev.co.uk/reporting/rep_spooltopdf.htm

Former Member
0 Kudos

Hi

I have done this link also. It is only working fine with the Fm SO_DOCUMENT_SEND_API1 to send a mail with PDF attachment.

But here I need to attach a PDF to work Item.

When I use the same code with the Fm SAP_WAPI_ATTACHMENT_ADD, It is not displaying the PDF as said. Either it is not displaying when display from a custom control also.

bpawanchand
Active Contributor
0 Kudos

Hi,

Did you get any chance to check this document. It is not only for decision work items but it can also be done for just a user dialog work items too.

Regards

Pavan

Former Member
0 Kudos

Hi Pavan,

I have gone through that type of requirement also. But it deals with an adobe form.

There the output of the Adobe form is coming as an XString in FPFORMOUTPUT-PDF.

Here I need to attach the spool data as an attachment.Here my output is of the type TLINE.

I am able to add the attachment to the work item,

But the PDF file is not opening means, It should be a conversion error, While converting the PDF generated by the Fm CONVERT_ABAPSPOOLJOB_2_PDF to X String.

I want the process to correctly convert PDF Content which is of the type TLine to X String, So that I can pass that XString value to the FM SAP_WAPI_ATTACHMENT_ADD.

I am trying out different combinations but I am not succcessful.

Or else can you tell me any other way to pull the spool data and fix it as a PDF attachment.

Thanks and Regards,

Meshack Prasan


bpawanchand
Active Contributor
0 Kudos

Hi,

CALL METHOD cl_rplm_qimt_obj_info_model=>get_spool_id
     EXPORTING
       iv_spoolname = lv_spoolname  " Pass the name of the background Job
     IMPORTING
       ev_spool_id  = lv_spool_id.
TSP01 Table name
CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'
       EXPORTING
         i_spoolid      = lv_spool_id
         i_partnum      = '1'
       IMPORTING
         e_pdf          = item_pdf
       EXCEPTIONS
         ads_error      = 1
         usage_error    = 2
         system_error   = 3
         internal_error = 4
         OTHERS         = 5.

Check with the above code snippet I think you need to pass spool Id to this function module

Regards

Pavan


Former Member
0 Kudos

Hi Pavan,

This FM is not working for the Spool Document type ABAP List,

It is throwing the exception InCorrect Document type.

Thanks and Regards,

Meshack Prasan.

bpawanchand
Active Contributor
0 Kudos

Check this thread

Message was edited by: Pavan Bhamidipati

Former Member
0 Kudos

I Have tried using the fms SO_FOLDER_ROOT_ID_GET and SO_DOCUMENT_INSERT also.

But the same issue(PDF is not opening)is coming. But When I tried the same thing with a smart form it is perfectly showing the PDF.

Please check my code pasted and let me know if I am anywhere wrong.

CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'

    EXPORTING

      src_spoolid              = ls_tsp01-rqident

    TABLES

      pdf                      = lt_pdf[]

    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.

CLEAR: ls_pdf.

  LOOP AT lt_pdf INTO ls_pdf.

*    TRANSLATE ls_pdf USING ' ~'.

    CONCATENATE lf_string

                ls_pdf

                INTO lf_string.

    CLEAR: ls_pdf.

  ENDLOOP.

*  TRANSLATE lf_string USING ' ~'.

CLEAR: lf_xstring.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

  EXPORTING

    text   = lf_string

  IMPORTING

    buffer = lf_xstring

  EXCEPTIONS

    failed = 1

    OTHERS = 2.

*Convert XString To Binary

REFRESH: lt_binary_tab[].

CLEAR: lf_output_length.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

  EXPORTING

    buffer        = lf_xstring

  IMPORTING

    output_length = lf_output_length

  TABLES

    binary_tab    = lt_binary_tab[].

CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'

  EXPORTING

    region                = 'B'

  IMPORTING

    folder_id             = ls_folder_id

  EXCEPTIONS

    communication_failure = 1

    owner_not_exist       = 2

    system_failure        = 3

    x_error               = 4

    OTHERS                = 5.

CALL FUNCTION 'SO_DOCUMENT_INSERT'

  EXPORTING

    parent_id                  = ls_folder_id

    object_hd_change           = ls_object_hd_change

    document_type              = 'EXT'

  IMPORTING

    document_id                = ls_document_id

  TABLES

    objcont_bin                = lt_binary_tab[]

  EXCEPTIONS

    active_user_not_exist      = 1

    dl_name_exist              = 2

    folder_not_exist           = 3

    folder_no_authorization    = 4

    object_type_not_exist      = 5

    operation_no_authorization = 6

    owner_not_exist            = 7

    parameter_error            = 8

    substitute_not_active      = 9

    substitute_not_defined     = 10

    x_error                    = 11

    OTHERS                     = 12.

Former Member
0 Kudos

Hi All

Solved the Issue by own.

Check the Code below if anyone need to convert the pdf of type TLINE to XSTRING.

DATA: ls_pdf TYPE tline,

      lt_pdf TYPE STANDARD TABLE OF tline.

FIELD-SYMBOLS: <x> TYPE ANY.

CLEAR: ls_pdf.

LOOP AT lt_pdf INTO ls_pdf.

  ASSIGN ls_pdf TO <x> CASTING TYPE x.

  CONCATENATE lf_xstring <x> INTO lf_xstring

  IN BYTE MODE.

  CLEAR: ls_pdf.

ENDLOOP.

Now we can pass the LF_XSTRING to the Fm SAP_WAPI_ATTACHMENT_ADD

Thanks and Regards,

Meshack Prasan Appikatla