cancel
Showing results for 
Search instead for 
Did you mean: 

smartforms to pdf and send mail

Former Member
0 Kudos

PROGRAM :

&----


*& Report ZDB_PDFMAIL

*&

&----


*&

*&

&----


REPORT zdb_pdfmail.

  • Internal Table declarations

DATA: i_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,

i_tline TYPE TABLE OF tline WITH HEADER LINE,

i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,

i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Objects to send mail.

i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,

i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,

*i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,

*i_record LIKE SOLIX OCCURS 0 WITH HEADER LINE,

i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,

  • Work Area declarations

w_objhead TYPE soli_tab,

w_ctrlop TYPE ssfctrlop,

w_compop TYPE ssfcompop,

w_return TYPE ssfcrescl,

w_doc_chng TYPE sodocchgi1,

w_data TYPE sodocchgi1,

w_buffer TYPE string,"To convert from 132 to 255

  • Variables declarations

v_form_name TYPE rs38l_fnam,

v_len_in LIKE sood-objlen,

v_len_out LIKE sood-objlen,

v_len_outn TYPE i,

v_lines_txt TYPE i,

v_lines_bin TYPE i.

DATA doc LIKE docs OCCURS 0 WITH HEADER LINE.

DATA bin_fsize TYPE i.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'

EXPORTING

formname = 'ZZZ_TEST2'

IMPORTING

fm_name = v_form_name

EXCEPTIONS

no_form = 1

no_function_module = 2

OTHERS = 3.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

w_ctrlop-getotf = 'X'.

w_ctrlop-no_dialog = 'X'.

w_compop-tdnoprev = 'X'.

CALL FUNCTION v_form_name

EXPORTING

control_parameters = w_ctrlop

output_options = w_compop

user_settings = 'X'

IMPORTING

job_output_info = w_return

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

OTHERS = 5.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

i_otf[] = w_return-otfdata[].

*CALL FUNCTION 'CONVERT_OTF_2_PDF'

    • EXPORTING

    • USE_OTF_MC_CMD = 'X'

    • ARCHIVE_INDEX =

    • IMPORTING

    • BIN_FILESIZE =

  • TABLES

  • otf =

  • doctab_archive =

  • lines =

    • EXCEPTIONS

    • ERR_CONV_NOT_POSSIBLE = 1

    • ERR_OTF_MC_NOENDMARKER = 2

    • OTHERS = 3

  • .

*IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*ENDIF.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

max_linewidth = 132

IMPORTING

bin_filesize = v_len_in

TABLES

otf = i_otf

lines = i_tline

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

OTHERS = 4.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

  • Convert PDF from 132 to 255.

LOOP AT i_tline.

  • Replacing space by ~

TRANSLATE i_tline USING ' ~'.

CONCATENATE w_buffer i_tline INTO w_buffer.

ENDLOOP.

  • Replacing ~ by space

TRANSLATE w_buffer USING '~ '.

DO.

i_record = w_buffer.

  • Appending 255 characters as a record

APPEND i_record.

SHIFT w_buffer LEFT BY 255 PLACES.

IF w_buffer IS INITIAL.

EXIT.

ENDIF.

ENDDO.

*CALL FUNCTION 'CONVERT_OTF'

  • EXPORTING

  • format = 'PDF'

  • max_linewidth = 132

  • IMPORTING

  • bin_filesize = v_len_in

  • TABLES

  • otf = i_otf

  • lines = i_tline

  • EXCEPTIONS

  • err_max_linewidth = 1

  • err_format = 2

  • err_conv_not_possible = 3

  • OTHERS = 4.

*

*IF sy-subrc <> 0.

  • MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

  • WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

*ENDIF.

*

    • Convert PDF from 132 to 255.

*LOOP AT i_tline.

    • Replacing space by ~

  • TRANSLATE i_tline USING ' ~'.

  • CONCATENATE w_buffer i_tline INTO w_buffer.

*ENDLOOP.

    • Replacing ~ by space

*TRANSLATE w_buffer USING '~ '.

*

*DO.

  • i_record = w_buffer.

    • Appending 255 characters as a record

  • APPEND i_record.

  • SHIFT w_buffer LEFT BY 255 PLACES.

  • IF w_buffer IS INITIAL.

  • EXIT.

  • ENDIF.

*ENDDO.

REFRESH: i_reclist,

i_objtxt,

i_objbin,

i_objpack.

CLEAR w_objhead.

  • Object with PDF.

i_objbin[] = i_record[].

DESCRIBE TABLE i_objbin LINES v_lines_bin.

  • Object with main text of the mail.

i_objtxt = 'Find attached the output of the smart form.'.

APPEND i_objtxt.

i_objtxt = 'Regards,'.

APPEND i_objtxt.

i_objtxt = 'J.Jayanthi'.

APPEND i_objtxt.

DESCRIBE TABLE i_objtxt LINES v_lines_txt.

  • Document information.

w_doc_chng-obj_name = 'Smartform'.

w_doc_chng-expiry_dat = sy-datum + 10.

w_doc_chng-obj_descr = 'Smart form output'.

w_doc_chng-sensitivty = 'F'. "Functional object

w_doc_chng-doc_size = v_lines_txt * 255.

  • Pack to main body as RAW.

  • Obj. to be transported not in binary form

CLEAR i_objpack-transf_bin.

  • Start line of object header in transport packet

i_objpack-head_start = 1.

  • Number of lines of an object header in object packet

i_objpack-head_num = 0.

  • Start line of object contents in an object packet

i_objpack-body_start = 1.

  • Number of lines of the object contents in an object packet

i_objpack-body_num = v_lines_txt.

  • Code for document class

i_objpack-doc_type = 'RAW'.

APPEND i_objpack.

  • Packing as PDF.

i_objpack-transf_bin = 'X'.

i_objpack-head_start = 1.

i_objpack-head_num = 1.

i_objpack-body_start = 1.

i_objpack-body_num = v_lines_bin.

i_objpack-doc_type = 'PDF'.

i_objpack-obj_name = 'Smartform'.

CONCATENATE 'Smartform_output' '.pdf'

INTO i_objpack-obj_descr.

i_objpack-doc_size = v_lines_bin * 255.

APPEND i_objpack.

  • Document information.

CLEAR i_reclist.

  • e-mail receivers.

i_reclist-receiver = 'dub@neusoft.com'.

i_reclist-express = 'X'.

i_reclist-rec_type = 'U'. "Internet address

APPEND i_reclist.

  • Sending mail.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = w_doc_chng

put_in_outbox = 'X'

TABLES

packing_list = i_objpack

object_header = w_objhead

contents_hex = i_objbin

contents_txt = i_objtxt

receivers = i_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ERROR:

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_SY_DYN_CALL_ILLEGAL_TYPE', was

not caught and

therefore caused a runtime error.

The reason for the exception is:

In the function "SO_NEW_DOCUMENT_ATT_SEND_API1", the STRUCTURE parameter

"CONTENTS_HEX" is typed in such a way

that only actual parameters are allowed, which are compatible in Unicode

with respect to the fragment view. However, the specified actual

parameter "I_OBJBIN" has an incompatible fragment view.

PLS. TELL ME HOW TO UPDATE . 3KS

WAITING FOR YOUR HELP

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member196280
Active Contributor
0 Kudos

Here is the sample which can solve your problem

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/8cd6adbb-0301-0010-39ba-938c601d5db9">SAMPLE</a>

Regards,

SaiRam

Former Member
0 Kudos

THANKS A LOT .

I EXECUTE THE PROGRAM THAT YOU GIVE ME ,BUT HAVE A ERROR.

"SPOOL REQUEST 0 DOES NOT EXIT."

PLS. TELL ME HOW TO SETTING. 3KS.

Former Member
0 Kudos

SPOOL REQUEST 0 DOES NOT EXIT

Former Member
0 Kudos

SPOOL REQUEST 0 DOES NOT EXIST

Former Member
0 Kudos

when call function 'CONVERT_ABAPSPOOLJOB_2_PDF' ,system raise the error 'Spool request 0 does not exist' . can you tell me how to update. 3ks.

former_member196280
Active Contributor
0 Kudos

GOTO SP02 tcode and see whether the spool is created or not... if created place break-point at "concatenate f_repid+0(9)

f_uname+0(3)

into lc_rq2name." debug and see data in "lc_rq2name" matched with the spool request or not..if not do necessary changes....

regards,

sairam

Former Member
0 Kudos

I HAVE CHECK WHAT YOU SAID.

CONCATENATE f_repid0(9) f_uname0(3) INTO lc_rq2name.

SELECT * FROM tsp01 WHERE rq2name = lc_rq2name

ORDER BY rqcretime DESCENDING.

IN THE TABLE OF TSP01,HAVE NO MY RECORD.

MAYBE MY PRINT REQUEST DOES NOT PUT INTO THE TABLE .

WHY ? HOW TO SETTING ?

OTHER ABAPER USER THE SAME PROGRAM ,HE CAN RUN SUCCESS.

BUT SOMEONE NOT .

Regards