cancel
Showing results for 
Search instead for 
Did you mean: 

Reading smartform output fromspool to PDF and sending to mail as attachment

former_member192432
Participant
0 Kudos

Hi ,

I am fetching smartform out from spool to string variable by using FM 'RSPO_RETURN_SPOOLJOB' and i am creating

reference and adding as attachment as shown below . My problem is i am not able to see the smartform out put data into my

attached pdf file . The attachment is coming as pdf but after double clicking on it showing error message as DATA CAN'T BE READ or FILE DAMAGE ERROR .Please help if any one knows about it.

I tried FM CONVERT_OTFSPOOLJOB_2_PDF for converting to PDF but it did not work .

DATA : pick_data TYPE   soli_tab .

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
    EXPORTING
      rqident    = ls_spoolid
      first_line = 1
      last_line  = 0
      desired_type = 'RAW'
    TABLES
      buffer     = lt_string.

LOOP AT lt_string INTO ls_string .
      APPEND ls_string TO pick_data.
    ENDLOOP.

    APPEND 'Hello world!' TO lv_string1.
    "creates reference for attachment
    TRY.
        CALL METHOD cl_document_bcs=>create_document
          EXPORTING
            i_type        = 'PDF'
            i_subject     = 'Testing'
            i_length      = '12'
            i_text        = lv_string1
          RECEIVING
            result        = lv_document
            .
      CATCH cx_document_bcs .
    ENDTRY.

    "Add attachment to mail
    "----------------------------------------------------------------
    "Adds the attachment to reference
    TRY.
        lv_document->add_attachment(
                  i_attachment_type     = 'PDF'
                  i_attachment_subject  = 'test_attachment'
*                  i_attachment_size     = size
                  i_att_content_text    = pick_data ). " changes pick_date to binary_content
      CATCH cx_document_bcs .
    ENDTRY.

Regards

Chetan

Edited by: kishan P on Oct 28, 2010 10:55 AM

Accepted Solutions (1)

Accepted Solutions (1)

aidan_black
Active Contributor
0 Kudos

Hi,

See sample program BCS_EXAMPLE_8 in SAP Note #1324547. You must use the BIN_FILE parameter when calling CONVERT_OTFSPOOLJOB_2_PDF.

Regards,

Aidan

former_member192432
Participant
0 Kudos

Thanks Aidan ,

I got the solution by using BIN_file and converting it into binary and sending as attachment by using class cl_documents_bcs .

Regards

Chetan

former_member192432
Participant
0 Kudos

Hi Aidan ,

i got the pdf file output . But after double clicking on PDF file it is showing smartform output by 10 times more pages than usal pages.ie instead showing 3 pages it is showing same 3 pages 10 times.

Regards

Chetan

Former Member
0 Kudos

you got to tell your form to create a new spool everytime. Like it seems when you have a spool and print it again your spool just gets appended, so when you then go and get the spool it may contain more than one printout.

Answers (3)

Answers (3)

former_member192432
Participant
0 Kudos

Got the solution . But after double clicking on PDF file it is showing smartform output by 10 times more pages than usal pages.ie instead showing 3 pages it is showing same 3 pages 10 times.

Regards

Chetan

nabheetscn
Active Contributor
0 Kudos

Here is the working code.

Moderator message - Please respect the 2,500 character maximum when posting. Post only the relevant portions of code

Edited by: Rob Burbank on Oct 29, 2010 12:10 PM

nabheetscn
Active Contributor
0 Kudos

Thanks ROB I will take care of this thingin future. Inconvenience regretted.

Nabheet

Former Member
0 Kudos

Hi,

Check this link [http://wiki.sdn.sap.com/wiki/display/Snippets/ConvertsspoolrequestintoPDFdocumentand+emails]

BR,

Lokeswari.

former_member192432
Participant
0 Kudos

Hi Lokeswari,

Itried all these methods but it did not work.

Regards

Chetan