Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

scrip to e-mail

Former Member
0 Kudos

hi ,

Pls help me in sending customized SAP scrip to external e-mails

pls send the sample code ... very desparate ...

Thank U.

Ramesh

1 ACCEPTED SOLUTION

Former Member
0 Kudos

try these Links :

********************************

Go through the following Code

REPORT ZRICH_0003.

DATA: ITCPO LIKE ITCPO,

TAB_LINES LIKE SY-TABIX.

  • Variables for EMAIL functionality

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

PERFORM SEND_FORM_VIA_EMAIL.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

FORM SEND_FORM_VIA_EMAIL.

CLEAR: MAILDATA, MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

REFRESH: MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

  • Mail Contents

MAILTXT-LINE = 'Here is your file'.

APPEND MAILTXT.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

  • Set recipient - email address here!!!

MAILREC-RECEIVER = 'itsme@whatever.com'.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = ' '

TABLES

PACKING_LIST = MAILPACK

OBJECT_HEADER = MAILHEAD

CONTENTS_BIN = MAILBIN

CONTENTS_TXT = MAILTXT

RECEIVERS = MAILREC

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

FORM PREPARE_PACKING_LIST.

CLEAR: MAILPACK, MAILBIN, MAILHEAD.

REFRESH: MAILPACK, MAILBIN, MAILHEAD.

DESCRIBE TABLE MAILTXT LINES TAB_LINES.

READ TABLE MAILTXT INDEX TAB_LINES.

MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).

  • Creation of the entry for the compressed document

CLEAR MAILPACK-TRANSF_BIN.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 0.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'RAW'.

APPEND MAILPACK.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM GET_OTF_CODE.

LOOP AT SOLISTI1.

MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.

APPEND MAILBIN.

ENDLOOP.

DESCRIBE TABLE MAILBIN LINES TAB_LINES.

MAILHEAD = 'TEST.OTF'.

APPEND MAILHEAD.

    • Creation of the entry for the compressed attachment

MAILPACK-TRANSF_BIN = 'X'.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 1.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'OTF'.

MAILPACK-OBJ_NAME = 'TEST'.

MAILPACK-OBJ_DESCR = 'Subject'.

MAILPACK-DOC_SIZE = TAB_LINES * 255.

APPEND MAILPACK.

ENDFORM.

************************************************************************

  • Form GET_OTF_CODE

************************************************************************

FORM GET_OTF_CODE.

DATA: BEGIN OF OTF OCCURS 0.

INCLUDE STRUCTURE ITCOO .

DATA: END OF OTF.

DATA: ITCPO LIKE ITCPO.

DATA: ITCPP LIKE ITCPP.

CLEAR ITCPO.

ITCPO-TDGETOTF = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'ZTEST_FORM'

LANGUAGE = SY-LANGU

OPTIONS = ITCPO

DIALOG = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

MOVE-CORRESPONDING ITCPO TO ITCPP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = ITCPP

TABLES

OTFDATA = OTF

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR SOLISTI1. REFRESH SOLISTI1.

LOOP AT OTF.

SOLISTI1-LINE = OTF.

APPEND SOLISTI1.

ENDLOOP.

ENDFORM.

***************************************************

hope it helps to u

REPORT ZMAIL_SEND.

DATA : x_itcpo TYPE itcpo, "SAPscript output interface

x_itcpp1 TYPE itcpp, "SAPscript output parameters

x_itcpp2 TYPE itcpp,

c_std_text(8) TYPE c VALUE 'STD_TEXT', "variable that is used in SAP SCRIPT

it_packing_list TYPE TABLE OF sopcklsti1 INITIAL SIZE 0 WITH HEADER LINE,

it_objtxt TYPE TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE,

s_spool TYPE tsp01-rqident,

it_spool_file TYPE TABLE OF soli INITIAL SIZE 0 WITH HEADER LINE,

v_sender TYpe soextreci1-receiver VALUE 'B00732@FREESCALE.COM',

c_addr_type TYPE soextreci1-adr_typ VALUE 'INT',

it_reclist TYPE TABLE OF somlreci1 INITIAL SIZE 0 WITH HEADER LINE,

v_receiver TYPE somlreci1-receiver VALUE 'RAJKUMAR.S@LNTINFOTECH.COM',

x_docdata TYPE sodocchgi1,

tab_lines TYPE sy-tabix,

lin1 TYPE i.

------ Printer settings structure -


x_itcpo-tddest = ''.

x_itcpo-tdrdidev = ''.

x_itcpo-tdnewid = 'X'.

x_itcpo-tdsenddate = sy-datum.

x_itcpo-tdsendtime = sy-uzeit.

x_itcpo-tdschedule = 'IMM'.

x_itcpo-tdimmed = ' '.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

device = 'PRINTER'

dialog = 'X'

form = 'ZTEST_FORM '

language = sy-langu

options = x_itcpo

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • SPONUMIV =

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT = X_ITCPP1

  • 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

  • CODEPAGE = 11

  • OTHERS = 12

.

IF sy-subrc <> 0.

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

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

ENDIF.

*Assigning the standard text name

CALL FUNCTION 'TEXT_SYMBOL_SETVALUE'

EXPORTING

name = c_std_text

value = 'ZTEST_STD1'

value_length = 0

replace_symbols = 'X'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'E05_HEADER '

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

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 'WRITE_FORM'

EXPORTING

element = 'ELEMENT1'

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

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 'WRITE_FORM'

EXPORTING

element = 'E05_FOOTER '

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

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 'CLOSE_FORM'

IMPORTING

RESULT = x_itcpp2

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

CODEPAGE = 5

OTHERS = 6

.

IF sy-subrc <> 0.

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

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

ENDIF.

***********************EXECUTES SUCCESSFULLY UNTIL THIS*********************************

------- spool no. of the spool generated -


s_spool = x_itcpp2-tdspoolid.

------- Fetching of the spool contents -


IF NOT s_spool IS INITIAL.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = s_spool

first_line = 1

last_line = 1000

desired_type = 'RAW'

  • IMPORTING

  • REAL_TYPE =

  • SP_LANG =

TABLES

buffer = it_spool_file "mail content

  • BUFFER_PDF =

  • EXCEPTIONS

  • NO_SUCH_JOB = 1

  • JOB_CONTAINS_NO_DATA = 2

  • SELECTION_EMPTY = 3

  • NO_PERMISSION = 4

  • CAN_NOT_ACCESS = 5

  • READ_ERROR = 6

  • TYPE_NO_MATCH = 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.

ENDIF.

CALCULATING THE NO OF RECORDS IN IT_SPOOL_FILE************

DESCRIBE TABLE it_spool_file LINES lin1.

*------ Filling the spool contents into internal table obtxt,-----

*------ whose contents will be displayed as the body of email -


*

CLEAR it_objtxt.

IF lin1 GT 0.

LOOP AT it_spool_file.

it_objtxt-line = it_spool_file-line.

APPEND it_objtxt.

CLEAR it_objtxt.

CLEAR it_spool_file-line.

ENDLOOP.

ENDIF.

DESCRIBE TABLE it_objtxt LINES tab_lines.

READ TABLE it_objtxt INDEX tab_lines.

*------ Calculating doc. size which is email -


*

x_docdata-obj_name = 'ZTEST_STD1'.

x_docdata-obj_descr = 'HAI TEST'.

x_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).

*THIS SET OF CODE IS TO UPDATE THE RECEIVER EMAIL ADDRESS

CLEAR it_reclist.

REFRESH it_reclist.

it_reclist-receiver = v_receiver.

it_reclist-rec_type = 'U'.

it_reclist-copy = 'X'.

it_reclist-blind_copy = ' '.

APPEND it_reclist.

*contains the document description

CLEAR it_packing_list.

REFRESH it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

DESCRIBE TABLE it_objtxt LINES it_packing_list-body_num.

*

it_packing_list-doc_type = 'RAW'.

APPEND it_packing_list.

*this is the function module which sends the mail

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = x_docdata

put_in_outbox = 'X'

sender_address = v_sender "senders mail address

sender_address_type = 'INT'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

  • SENDER_ID =

TABLES

packing_list = it_packing_list

  • OBJECT_HEADER =

  • CONTENTS_BIN =

contents_txt = it_objtxt "this is the table which contains the content of the mail

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = it_reclist "contains the receivers mail id

  • 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.

*****************************************

check the links:

http://searchsap.techtarget.com/tip/0,289483,sid21_gci858658,00.html

http://searchsap.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid21_gci1027361,00.html

http://sap.ittoolbox.com/groups/technical-functional/sap-r3-dev/dev-abap-how-to-convert-sap-script-o...

hope this helps.

4 REPLIES 4

former_member223537
Active Contributor
0 Kudos

Hi,

You need to convert the SAP Script output -- SPOOL output into pdf or html & then send email.

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

Best regards,

Prashant

Former Member
0 Kudos

Hi

Use the Medium as 7 for sending mail during the output determination

Medium as 1 is used to printout, 2 for fax

configure the output with medium as 7 to send mail

the script/smartform std drdriver program will determine the medium to which the output to be sent (fun module ADDR_GET_NEXT_COMM_TYPE)

ensure that SCOT and SOST settings to be done first for this.

Regards

Anji

Former Member
0 Kudos

Thank U for fast responce ...

Very first time i am working on this ..

could u b lil more elobarative plz

Former Member
0 Kudos

try these Links :

********************************

Go through the following Code

REPORT ZRICH_0003.

DATA: ITCPO LIKE ITCPO,

TAB_LINES LIKE SY-TABIX.

  • Variables for EMAIL functionality

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

PERFORM SEND_FORM_VIA_EMAIL.

************************************************************************

  • FORM SEND_FORM_VIA_EMAIL *

************************************************************************

FORM SEND_FORM_VIA_EMAIL.

CLEAR: MAILDATA, MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

REFRESH: MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

  • Mail Contents

MAILTXT-LINE = 'Here is your file'.

APPEND MAILTXT.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

  • Set recipient - email address here!!!

MAILREC-RECEIVER = 'itsme@whatever.com'.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = ' '

TABLES

PACKING_LIST = MAILPACK

OBJECT_HEADER = MAILHEAD

CONTENTS_BIN = MAILBIN

CONTENTS_TXT = MAILTXT

RECEIVERS = MAILREC

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM.

************************************************************************

  • Form PREPARE_PACKING_LIST

************************************************************************

FORM PREPARE_PACKING_LIST.

CLEAR: MAILPACK, MAILBIN, MAILHEAD.

REFRESH: MAILPACK, MAILBIN, MAILHEAD.

DESCRIBE TABLE MAILTXT LINES TAB_LINES.

READ TABLE MAILTXT INDEX TAB_LINES.

MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).

  • Creation of the entry for the compressed document

CLEAR MAILPACK-TRANSF_BIN.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 0.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'RAW'.

APPEND MAILPACK.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM GET_OTF_CODE.

LOOP AT SOLISTI1.

MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.

APPEND MAILBIN.

ENDLOOP.

DESCRIBE TABLE MAILBIN LINES TAB_LINES.

MAILHEAD = 'TEST.OTF'.

APPEND MAILHEAD.

    • Creation of the entry for the compressed attachment

MAILPACK-TRANSF_BIN = 'X'.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 1.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'OTF'.

MAILPACK-OBJ_NAME = 'TEST'.

MAILPACK-OBJ_DESCR = 'Subject'.

MAILPACK-DOC_SIZE = TAB_LINES * 255.

APPEND MAILPACK.

ENDFORM.

************************************************************************

  • Form GET_OTF_CODE

************************************************************************

FORM GET_OTF_CODE.

DATA: BEGIN OF OTF OCCURS 0.

INCLUDE STRUCTURE ITCOO .

DATA: END OF OTF.

DATA: ITCPO LIKE ITCPO.

DATA: ITCPP LIKE ITCPP.

CLEAR ITCPO.

ITCPO-TDGETOTF = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'ZTEST_FORM'

LANGUAGE = SY-LANGU

OPTIONS = ITCPO

DIALOG = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

MOVE-CORRESPONDING ITCPO TO ITCPP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = ITCPP

TABLES

OTFDATA = OTF

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR SOLISTI1. REFRESH SOLISTI1.

LOOP AT OTF.

SOLISTI1-LINE = OTF.

APPEND SOLISTI1.

ENDLOOP.

ENDFORM.

***************************************************

hope it helps to u

REPORT ZMAIL_SEND.

DATA : x_itcpo TYPE itcpo, "SAPscript output interface

x_itcpp1 TYPE itcpp, "SAPscript output parameters

x_itcpp2 TYPE itcpp,

c_std_text(8) TYPE c VALUE 'STD_TEXT', "variable that is used in SAP SCRIPT

it_packing_list TYPE TABLE OF sopcklsti1 INITIAL SIZE 0 WITH HEADER LINE,

it_objtxt TYPE TABLE OF solisti1 INITIAL SIZE 0 WITH HEADER LINE,

s_spool TYPE tsp01-rqident,

it_spool_file TYPE TABLE OF soli INITIAL SIZE 0 WITH HEADER LINE,

v_sender TYpe soextreci1-receiver VALUE 'B00732@FREESCALE.COM',

c_addr_type TYPE soextreci1-adr_typ VALUE 'INT',

it_reclist TYPE TABLE OF somlreci1 INITIAL SIZE 0 WITH HEADER LINE,

v_receiver TYPE somlreci1-receiver VALUE 'RAJKUMAR.S@LNTINFOTECH.COM',

x_docdata TYPE sodocchgi1,

tab_lines TYPE sy-tabix,

lin1 TYPE i.

------ Printer settings structure -


x_itcpo-tddest = ''.

x_itcpo-tdrdidev = ''.

x_itcpo-tdnewid = 'X'.

x_itcpo-tdsenddate = sy-datum.

x_itcpo-tdsendtime = sy-uzeit.

x_itcpo-tdschedule = 'IMM'.

x_itcpo-tdimmed = ' '.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

device = 'PRINTER'

dialog = 'X'

form = 'ZTEST_FORM '

language = sy-langu

options = x_itcpo

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • SPONUMIV =

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT = X_ITCPP1

  • 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

  • CODEPAGE = 11

  • OTHERS = 12

.

IF sy-subrc <> 0.

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

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

ENDIF.

*Assigning the standard text name

CALL FUNCTION 'TEXT_SYMBOL_SETVALUE'

EXPORTING

name = c_std_text

value = 'ZTEST_STD1'

value_length = 0

replace_symbols = 'X'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'E05_HEADER '

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

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 'WRITE_FORM'

EXPORTING

element = 'ELEMENT1'

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

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 'WRITE_FORM'

EXPORTING

element = 'E05_FOOTER '

function = 'SET'

type = 'BODY'

window = 'MAIN'

  • IMPORTING

  • PENDING_LINES =

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

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 'CLOSE_FORM'

IMPORTING

RESULT = x_itcpp2

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

EXCEPTIONS

UNOPENED = 1

BAD_PAGEFORMAT_FOR_PRINT = 2

SEND_ERROR = 3

SPOOL_ERROR = 4

CODEPAGE = 5

OTHERS = 6

.

IF sy-subrc <> 0.

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

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

ENDIF.

***********************EXECUTES SUCCESSFULLY UNTIL THIS*********************************

------- spool no. of the spool generated -


s_spool = x_itcpp2-tdspoolid.

------- Fetching of the spool contents -


IF NOT s_spool IS INITIAL.

CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'

EXPORTING

rqident = s_spool

first_line = 1

last_line = 1000

desired_type = 'RAW'

  • IMPORTING

  • REAL_TYPE =

  • SP_LANG =

TABLES

buffer = it_spool_file "mail content

  • BUFFER_PDF =

  • EXCEPTIONS

  • NO_SUCH_JOB = 1

  • JOB_CONTAINS_NO_DATA = 2

  • SELECTION_EMPTY = 3

  • NO_PERMISSION = 4

  • CAN_NOT_ACCESS = 5

  • READ_ERROR = 6

  • TYPE_NO_MATCH = 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.

ENDIF.

CALCULATING THE NO OF RECORDS IN IT_SPOOL_FILE************

DESCRIBE TABLE it_spool_file LINES lin1.

*------ Filling the spool contents into internal table obtxt,-----

*------ whose contents will be displayed as the body of email -


*

CLEAR it_objtxt.

IF lin1 GT 0.

LOOP AT it_spool_file.

it_objtxt-line = it_spool_file-line.

APPEND it_objtxt.

CLEAR it_objtxt.

CLEAR it_spool_file-line.

ENDLOOP.

ENDIF.

DESCRIBE TABLE it_objtxt LINES tab_lines.

READ TABLE it_objtxt INDEX tab_lines.

*------ Calculating doc. size which is email -


*

x_docdata-obj_name = 'ZTEST_STD1'.

x_docdata-obj_descr = 'HAI TEST'.

x_docdata-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_objtxt ).

*THIS SET OF CODE IS TO UPDATE THE RECEIVER EMAIL ADDRESS

CLEAR it_reclist.

REFRESH it_reclist.

it_reclist-receiver = v_receiver.

it_reclist-rec_type = 'U'.

it_reclist-copy = 'X'.

it_reclist-blind_copy = ' '.

APPEND it_reclist.

*contains the document description

CLEAR it_packing_list.

REFRESH it_packing_list.

it_packing_list-transf_bin = space.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

DESCRIBE TABLE it_objtxt LINES it_packing_list-body_num.

*

it_packing_list-doc_type = 'RAW'.

APPEND it_packing_list.

*this is the function module which sends the mail

CALL FUNCTION 'SO_DOCUMENT_SEND_API1'

EXPORTING

document_data = x_docdata

put_in_outbox = 'X'

sender_address = v_sender "senders mail address

sender_address_type = 'INT'

commit_work = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

  • SENDER_ID =

TABLES

packing_list = it_packing_list

  • OBJECT_HEADER =

  • CONTENTS_BIN =

contents_txt = it_objtxt "this is the table which contains the content of the mail

  • CONTENTS_HEX =

  • OBJECT_PARA =

  • OBJECT_PARB =

receivers = it_reclist "contains the receivers mail id

  • 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.

*****************************************

check the links:

http://searchsap.techtarget.com/tip/0,289483,sid21_gci858658,00.html

http://searchsap.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid21_gci1027361,00.html

http://sap.ittoolbox.com/groups/technical-functional/sap-r3-dev/dev-abap-how-to-convert-sap-script-o...

hope this helps.