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: 

Automatic Mail generation

Former Member
0 Kudos

Hi all,

I need to Send a mail to the Purchase reuisition Creator if the Purchaser order is Released

IF the field VSTAT in the table NAST is "1" then we can say that the PO is released.

How can we do this.

Please suggest me if any Userexit or BADI exists for this requirement or haw can we achieve this

Regards

Ajay

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

For using SAP we can send the mail to the correspodning user...

Iam sending code for that..

If u need any further information plz let me know.

***mail

lwa_docu_data-obj_name = 'TEXT'.

lwa_docu_data-obj_descr = 'TEXT'.

lt_attach1-line = 'See the attachment'.

APPEND lt_attach1.

CLEAR lt_attach1.

lt_attach1-line = 'S-> Success'.

APPEND lt_attach1.

CLEAR lt_attach1.

lt_attach1-line = 'E-> Error'.

APPEND lt_attach1.

DESCRIBE TABLE lt_attach1 LINES lv_lines.

READ TABLE lt_attach INDEX lv_lines.

lwa_docu_data-doc_size = ( lv_lines - 1 ) * 255 + STRLEN( lt_attach1 ).

lt_obj_header-head_start = 1.

lt_obj_header-head_num = 0.

lt_obj_header-body_start = 1.

lt_obj_header-body_num = lv_lines.

lt_obj_header-doc_type = 'RAW'.

APPEND lt_obj_header.

CLEAR lt_obj_header.

LOOP AT gt_mail INTO gs_mail.

CONCATENATE gs_mail-no_rec

gs_mail-no_sap

gs_mail-no_suc

gs_mail-no_err

gs_mail-status

gs_mail-regid

gs_mail-bpnum

gs_mail-desc INTO lt_attach SEPARATED BY con_tab.

CONCATENATE con_cret lt_attach INTO lt_attach.

APPEND lt_attach.

CLEAR: gs_mail, lt_attach.

ENDLOOP.

GET PARAMETER ID 'ZMAIL' FIELD gv_code.

SELECT zzmailid

FROM zweb_codes

INTO TABLE lt_mail

WHERE zzcode EQ gv_code.

LOOP AT lt_mail INTO lwa_mail.

lv_mail = lwa_mail-mailid.

lt_rec_list-receiver = lv_mail.

lt_rec_list-rec_type = 'U'.

APPEND lt_rec_list.

clear: lwa_mail, lv_mail.

ENDLOOP.

DESCRIBE TABLE lt_attach LINES lv_lines.

  • Object Attachment detail

lt_obj_header-transf_bin = 'X'.

lt_obj_header-head_start = 1.

lt_obj_header-head_num = 1.

lt_obj_header-body_start = 1.

lt_obj_header-body_num = lv_lines.

DESCRIBE TABLE lt_attach LINES lt_obj_header-body_num.

lt_obj_header-obj_name = 'TEXT'.

lt_obj_header-doc_type = 'XLS'.

lt_obj_header-obj_descr = 'TEXT'.

lt_obj_header-doc_size = lt_obj_header-body_num * 255.

APPEND lt_obj_header.

CLEAR lt_obj_header.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_docu_data

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = lt_obj_header

contents_bin = lt_attach

contents_txt = lt_attach1

receivers = lt_rec_list

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.

.

5 REPLIES 5

Former Member
0 Kudos

use workflow for same....

use PO Release method of BUS2012

Former Member
0 Kudos

Hi,

For using SAP we can send the mail to the correspodning user...

Iam sending code for that..

If u need any further information plz let me know.

***mail

lwa_docu_data-obj_name = 'TEXT'.

lwa_docu_data-obj_descr = 'TEXT'.

lt_attach1-line = 'See the attachment'.

APPEND lt_attach1.

CLEAR lt_attach1.

lt_attach1-line = 'S-> Success'.

APPEND lt_attach1.

CLEAR lt_attach1.

lt_attach1-line = 'E-> Error'.

APPEND lt_attach1.

DESCRIBE TABLE lt_attach1 LINES lv_lines.

READ TABLE lt_attach INDEX lv_lines.

lwa_docu_data-doc_size = ( lv_lines - 1 ) * 255 + STRLEN( lt_attach1 ).

lt_obj_header-head_start = 1.

lt_obj_header-head_num = 0.

lt_obj_header-body_start = 1.

lt_obj_header-body_num = lv_lines.

lt_obj_header-doc_type = 'RAW'.

APPEND lt_obj_header.

CLEAR lt_obj_header.

LOOP AT gt_mail INTO gs_mail.

CONCATENATE gs_mail-no_rec

gs_mail-no_sap

gs_mail-no_suc

gs_mail-no_err

gs_mail-status

gs_mail-regid

gs_mail-bpnum

gs_mail-desc INTO lt_attach SEPARATED BY con_tab.

CONCATENATE con_cret lt_attach INTO lt_attach.

APPEND lt_attach.

CLEAR: gs_mail, lt_attach.

ENDLOOP.

GET PARAMETER ID 'ZMAIL' FIELD gv_code.

SELECT zzmailid

FROM zweb_codes

INTO TABLE lt_mail

WHERE zzcode EQ gv_code.

LOOP AT lt_mail INTO lwa_mail.

lv_mail = lwa_mail-mailid.

lt_rec_list-receiver = lv_mail.

lt_rec_list-rec_type = 'U'.

APPEND lt_rec_list.

clear: lwa_mail, lv_mail.

ENDLOOP.

DESCRIBE TABLE lt_attach LINES lv_lines.

  • Object Attachment detail

lt_obj_header-transf_bin = 'X'.

lt_obj_header-head_start = 1.

lt_obj_header-head_num = 1.

lt_obj_header-body_start = 1.

lt_obj_header-body_num = lv_lines.

DESCRIBE TABLE lt_attach LINES lt_obj_header-body_num.

lt_obj_header-obj_name = 'TEXT'.

lt_obj_header-doc_type = 'XLS'.

lt_obj_header-obj_descr = 'TEXT'.

lt_obj_header-doc_size = lt_obj_header-body_num * 255.

APPEND lt_obj_header.

CLEAR lt_obj_header.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = lwa_docu_data

put_in_outbox = 'X'

commit_work = 'X'

TABLES

packing_list = lt_obj_header

contents_bin = lt_attach

contents_txt = lt_attach1

receivers = lt_rec_list

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.

.

Former Member
0 Kudos

Plz tell whether you want internal mail or external of SAp

rgds

rajesh

0 Kudos

Hi,

I want internal mail only not external mail.

Regards

Ajay

0 Kudos

then you should go for workflow... which will send mail to SAP Internal mail box.. as work item