Skip to Content

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

How Sapscript form can be send by mail

Hello all,

I want to send a Sapscript form by mail.

I think it should first be converted to PDF form and than need to be send by mail.

I have created a z form which is a copy of standard for medruck and also have changed the standard program SAPFM06P. So I need to add functionality in z program so that i can send the sapscript form by mail.

Can any body let me know the complete process how can i do it?

Thanks

Tags:
replied

Hi,

Just follow the below code . I am giving the code which starts from OPEN_FORM. After that one submit program is there u can see the code.

&----


*& Form display_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display_layout.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

device = 'PRINTER'

  • DIALOG = 'X'

form = 'YFIL_DUNN_01'

  • LANGUAGE = SY-LANGU

options = itcpo

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT =

EXCEPTIONS

canceled = 1

device = 2

form = 3

options = 4

unclosed = 5

mail_options = 6

archive_error = 7

invalid_fax_number = 8

more_params_needed_in_batch = 9

spool_error = 10

OTHERS = 11

.

IF sy-subrc <> 0.

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

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

ENDIF.

LOOP AT i_tab INTO wa_tab.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = '531'

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

window = 'MAIN'

IMPORTING

pending_lines = wa_tab.

IF sy-subrc <> 0.

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

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

ENDIF.

ENDLOOP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

result = itcpp

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

unopened = 1

bad_pageformat_for_print = 2

send_error = 3

spool_error = 4

OTHERS = 5.

IF sy-subrc = 0.

IF ( itcpp-userexit IS INITIAL AND

NOT itcpp-tdspoolid IS INITIAL ).

p_spool = itcpp-tdspoolid.

SUBMIT yfir_mailsend_pdf_attachment WITH p_spool = p_spool

WITH p_kunnr = p_kunnr.

ENDIF.

ENDIF.

ENDFORM. " display_layout

&----


*& Form modify_duedate

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM modify_duedate.

SELECT SINGLE mat_rec_no

mat_rec_date FROM yfi_matno

INTO (v_mat_rec_no, v_mat_rec_date)

WHERE vbeln = wa_tab-vbeln.

CHECK sy-subrc EQ 0.

SELECT SINGLE zterm

FROM vbrk INTO v_zterm

WHERE vbeln EQ wa_tab-vbeln.

CHECK sy-subrc EQ 0.

SELECT SINGLE zdays

FROM yfi_payment INTO v_zdays

WHERE zterm EQ v_zterm.

IF sy-subrc EQ 0.

wa_tab-zfbdt_due = ( v_mat_rec_date + v_zdays ).

wa_tab-due_days = ( sy-datum - wa_tab-zfbdt_due ).

  • IF wa_tab-due_days LE 0.

  • wa_tab-due_days = 'N/A'.

  • ENDIF.

IF ( wa_tab-umskz = 'A' AND wa_tab-shkzg = 'H' ).

wa_tab-zfbdt = ' '.

wa_tab-zfbdt_due = ''.

wa_tab-due_days = ''.

ENDIF.

MODIFY i_tab FROM wa_tab INDEX sy-tabix.

CLEAR: v_mat_rec_no, v_mat_rec_date, v_zterm, v_zdays.

ENDIF.

ENDFORM. " modify_duedate

SUBMIT PROGRAM :

REPORT yfir_mailsend_pdf_attachment MESSAGE-ID yf.

&----


*& Program Name : *

& Author :

*& Creation Date : *

*& Program Type : *

*& SAP Release : *

*& Description : *

*& *

*& *

*& Transport No : *

*& Transaction : *

*& *

&----


&----


*& Send document with OTF/ALI attachment from spool to externalreci-

*& pient. OTF/ALI document is converted to PDF/HTML format duringthe

*& SAPconnect send process.

*&

*& This report serves as example documentation for the function

*& modules SO_NEW_DOCUMENT_ATT_SEND_API1 and SO_DOCUMENT_SEND_API1.

*& Following this example you should be able to develop your own

*& report to send documents with all kinds of attachments.

*&

&----


  • Creation of the entry for the compressed document

&----


*& TABLES:

&----


TABLES : kna1,

adr6.

&----


*& INTERNAL TABLES:

&----


***********PDF Declaration*******

DATA: BEGIN OF i_spool OCCURS 0,

rqident LIKE tsp01-rqident,

rqo1name LIKE tsp01-rqo1name,

rqclient LIKE tsp01-rqclient,

END OF i_spool.

&----


*& VARIABLES :

&----


DATA: client LIKE tst01-dclient,

name LIKE tst01-dname,

objtype LIKE rststype-type,

type LIKE rststype-type.

DATA: spoolno LIKE tsp01-rqident,

  • download TYPE c VALUE 'X', "AS CHECKBOX DEFAULT 'X',

  • p_file LIKE rlgrap-filename

  • VALUE 'C:\Invoice.pdf', "#EC NOTEXT

otf LIKE itcoo OCCURS 100 WITH HEADER LINE,

  • cancel,

pdf LIKE tline OCCURS 100 WITH HEADER LINE,

doctab LIKE docs OCCURS 1 WITH HEADER LINE,

numbytes TYPE i,

arc_idx LIKE toa_dara,

pdfspoolid LIKE tsp01-rqident,

jobname LIKE tbtcjob-jobname,

jobcount LIKE tbtcjob-jobcount,

is_otf.

  • Data Declaration

DATA: docdata LIKE sodocchgi1,

objpack LIKE sopcklsti1 OCCURS 1 WITH HEADER LINE,

objhead LIKE solisti1 OCCURS 1 WITH HEADER LINE,

objtxt LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objbin LIKE solisti1 OCCURS 10 WITH HEADER LINE,

objhex LIKE solix OCCURS 10 WITH HEADER LINE,

reclist LIKE somlreci1 OCCURS 1 WITH HEADER LINE.

*objpack-head_start = 1.

*objbin = ' | '. APPEND objbin.

*DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.

DATA: tab_lines TYPE i,

doc_size TYPE i,

att_type LIKE soodk-objtp.

objpack-head_start = 1.

&----


*& PARAMETERS:

&----


PARAMETERS : p_spool LIKE tsp01-rqident NO-DISPLAY,

p_kunnr LIKE kna1-kunnr NO-DISPLAY.

*&**********************************************************************

*& M A I N P R O C E S S

*&**********************************************************************

*&**********************************************************************

*& START OF SELECTION.

*&********************************************************************

START-OF-SELECTION.

SELECT SINGLE

adr6~addrnumber

adr6~smtp_addr

FROM adr6

INNER JOIN kna1

ON kna1~adrnr = adr6~addrnumber

INTO CORRESPONDING FIELDS OF adr6

WHERE kna1~kunnr = p_kunnr.

IF sy-subrc = 0.

  • Create receiver list

reclist-receiver = adr6-smtp_addr. "<-- customer address

reclist-rec_type = 'U'.

APPEND reclist.

ENDIF.

***Convert Spool request to PDF

PERFORM pdf_convert.

docdata-obj_name = 'MAIL_AEIW'.

docdata-obj_descr = 'Dunning'.

  • Main Text

objtxt = 'Hi,'.

APPEND objtxt.

objtxt = 'Dunning'.

APPEND objtxt.

objtxt = 'Regards'.

APPEND objtxt.

  • Write Packing List (Main)

DESCRIBE TABLE objtxt LINES tab_lines.

READ TABLE objtxt INDEX tab_lines.

docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objtxt ).

CLEAR objpack-transf_bin.

objpack-head_start = 1.

objpack-head_num = 0.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = 'RAW'.

APPEND objpack.

  • Create Message Attachment

  • Write Packing List (Attachment)

att_type = 'PDF'.

DESCRIBE TABLE objbin LINES tab_lines.

READ TABLE objbin INDEX tab_lines.

*objpack-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( objbin ).

objpack-doc_size = tab_lines * 255.

objpack-transf_bin = 'X'.

objpack-head_start = 1.

objpack-head_num = 1.

objpack-body_start = 1.

objpack-body_num = tab_lines.

objpack-doc_type = att_type.

objpack-obj_name = 'ATTACHMENT'.

objpack-obj_descr = 'Attached Document'.

APPEND objpack.

*check for not maintaining customer address

IF reclist IS INITIAL.

MESSAGE e000 WITH 'Please Maintain Customer e-Mail ID'.

LEAVE LIST-PROCESSING.

ELSE.

  • Send Message

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = docdata

put_in_outbox = 'X'

  • commit_work = 'X' "used from rel.6.10

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

packing_list = objpack

object_header = objhead

contents_bin = objbin

contents_txt = objtxt

  • CONTENTS_HEX = objhex

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = 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 'SO' TYPE 'S' NUMBER '023'

WITH docdata-obj_name.

ELSE.

WRITE 'Mail sent successfully'.

ENDIF.

ENDIF.

WRITE: / 'End of Program'.

&----


*& Form pdf_convert

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM pdf_convert.

DATA: date1 LIKE sy-datum,

time1 LIKE sy-uzeit,

period1 LIKE tsp01-rqcretime.

date1 = sy-datum.

time1 = sy-uzeit.

date1 = date1 - 1.

CONCATENATE date1 time1 INTO period1.

SELECT rqident

rqo1name

rqclient FROM tsp01 INTO TABLE i_spool

WHERE rqowner = sy-uname AND

rqclient = sy-mandt AND

rqident = p_spool.

IF sy-subrc <> 0.

WRITE: / 'No Spool Request created today'(003)

COLOR COL_NEGATIVE.

EXIT.

ENDIF.

SORT i_spool DESCENDING BY rqident.

READ TABLE i_spool INDEX 1.

CALL FUNCTION 'RSTS_GET_ATTRIBUTES'

EXPORTING

authority = 'SP01'

client = i_spool-rqclient

name = i_spool-rqo1name

part = 1

IMPORTING

  • CHARCO =

  • CREATER =

  • CREDATE =

  • DELDATE =

  • MAX_CREDATE =

  • MAX_DELDATE =

  • NON_UNIQ =

  • NOOF_PARTS =

  • RECTYP =

  • SIZE =

  • STOTYP =

type = type

objtype = objtype

EXCEPTIONS

fb_error = 1

fb_rsts_other = 2

no_object = 3

no_permission = 4.

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = i_spool-rqident

no_dialog = ' '

  • DST_DEVICE =

  • PDF_DESTINATION =

IMPORTING

pdf_bytecount = numbytes

pdf_spoolid = pdfspoolid

  • OTF_PAGECOUNT =

btc_jobname = jobname

btc_jobcount = jobcount

TABLES

pdf = pdf

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 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.

CASE sy-subrc.

WHEN 0.

WHEN 1.

WRITE: / 'Error On Spool Job'(002)

COLOR COL_NEGATIVE.

EXIT.

WHEN 2.

WRITE: / 'No Permission'(003)

COLOR COL_NEGATIVE.

EXIT.

WHEN 3.

WRITE: / 'Conversion Not Possible'(004)

COLOR COL_NEGATIVE.

EXIT.

WHEN OTHERS.

WRITE: / 'Incorrect Destination Device'(005)

COLOR COL_NEGATIVE.

EXIT.

ENDCASE.

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

EXPORTING

line_width_src = 134

line_width_dst = 255

TABLES

content_in = pdf

content_out = objbin

EXCEPTIONS

err_line_width_src_too_long = 1

err_line_width_dst_too_long = 2

err_conv_failed = 3

OTHERS = 4.

ENDFORM. " pdf_convert

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