| Home • Tips • Tutorials • Forums • Certification Q's • Interview Q's • Jobs • Testimonials • Contact Us | ||
Document Categories:
What's New?
Contribute?Sample SpecsWhat's Hot? |
Developing a Web Service to send an emailBy Joffy John, Collabera Web service- Basics Web services are application
components that communicate using open protocols. They are
self-contained and self-describing. They can be discovered using UDDI. They can
be used by other applications .XML is the basis for Web services. How Does it Work? The basic Web services
platform is XML + HTTP. XML
provides a language which can be used between different platforms and
programming languages and still express complex messages and functions. The HTTP
protocol is the most used Internet protocol. Web services platform
elements:
Advantages: 1) By using Web services,
your application can publish its function or message to the rest of the world.
Web services use XML to code and to decode data, and SOAP to transport it (using
open protocols). 2) Reusable
application-components: Web services can offer application-components like:
currency conversion, weather reports, language translation, credit card number
check etc as services. 3) Connect existing
software: With Web services you can exchange data between different applications
and different platforms. Example: Web service to send
mail: I) Create table types in Tcode: SE11. 1)
ZTT_RECIPEINT of line type: SALRTSCOMM
2)
ZTP_TT_MESSAGE of line type SOLISTI1
II) Now
create function module: ZJO_WEB_INTEGRATION
I_MESSAGE
is the table type to store messages to send mail. I_RECIPIENT
is the list of the recipients.
E_RETURN
is the return message after sending the mail. Add the
following code: FUNCTION zjo_web_integration.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_MESSAGE) TYPE ZTP_TT_MESSAGE OPTIONAL
*" VALUE(I_RECIPIENT) TYPE ZTT_RECIPEINT OPTIONAL
*" EXPORTING
*" VALUE(E_RETURN) TYPE BAPIRET2_TAB
*"----------------------------------------------------------------------
INCLUDE <cntn01>. "----------- Include multiline container specifications
DATA: it_message TYPE STANDARD TABLE OF solisti1 INITIAL SIZE 0
WITH HEADER LINE.
DATA: t_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
t_contents LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_receivers LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
t_attachment LIKE solisti1 OCCURS 0 WITH HEADER LINE,
t_object_header LIKE solisti1 OCCURS 0 WITH HEADER LINE,
w_cnt TYPE i,
w_sent_all(1) TYPE c,
w_doc_data LIKE sodocchgi1,
gd_error TYPE sy-subrc,
gd_reciever TYPE sy-subrc.
DATA: ld_error TYPE sy-subrc,
ld_reciever TYPE sy-subrc,
ld_mtitle LIKE sodocchgi1-obj_descr,
ld_email LIKE somlreci1-receiver,
ld_format TYPE so_obj_tp ,
ld_attdescription TYPE so_obj_nam ,
ld_attfilename TYPE so_obj_des ,
ld_sender_address LIKE soextreci1-receiver,
ld_sender_address_type LIKE soextreci1-adr_typ,
ld_receiver LIKE sy-subrc.
* swc_container notice. "Declaration
*===============================================================*
DATA:
it_return TYPE TABLE OF bapiret2,
wa_recipient TYPE salrtscomm.
*-->> for Message content ------------------------------->>
it_message[] = i_message[].
READ TABLE it_message INDEX 1.
SHIFT it_message-line LEFT DELETING LEADING space.
IF it_message-line IS INITIAL.
PERFORM error_process
USING
'E' '/OBIZ/ALM_MSG' '047'
'No message to send1'
space
space
space
CHANGING
e_return.
EXIT.
ENDIF."it_message-string
*-- Send Alert---------------------------------------------------*
ld_mtitle = 'mail' .
ld_sender_address = 'abc@xxxx.com'. "Sender email address
ld_sender_address_type = 'INT'.
* Fill the document data.
w_doc_data-doc_size = 1.
* Populate the subject/generic message attributes
w_doc_data-obj_langu = sy-langu.
w_doc_data-obj_name = 'saprpt'.
w_doc_data-obj_descr = ld_mtitle .
w_doc_data-sensitivty = 'F'.
* Describe the body of the message
CLEAR t_packing_list.
REFRESH t_packing_list.
t_packing_list-transf_bin = space.
t_packing_list-head_start = 1.
t_packing_list-head_num = 0.
t_packing_list-body_start = 1.
DESCRIBE TABLE it_message LINES t_packing_list-body_num.
t_packing_list-doc_type = 'RAW'.
APPEND t_packing_list.
* Add the recipients email address
CLEAR t_receivers.
REFRESH t_receivers.
LOOP AT i_recipient INTO wa_recipient.
t_receivers-receiver = wa_recipient-value.
t_receivers-rec_type = 'U'.
t_receivers-com_type = 'INT'.
t_receivers-notif_del = 'X'.
t_receivers-notif_ndel = 'X'.
APPEND t_receivers.
ENDLOOP.
CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
document_data = w_doc_data
put_in_outbox = 'X'
sender_address = ld_sender_address
sender_address_type = ld_sender_address_type
commit_work = 'X'
IMPORTING
sent_to_all = w_sent_all
TABLES
packing_list = t_packing_list
* contents_bin =
contents_txt = it_message
receivers = t_receivers
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.
* Populate zerror return code
ld_error = sy-subrc.
* Populate zreceiver return code
LOOP AT t_receivers.
ld_receiver = t_receivers-retrn_code.
ENDLOOP.
*-->> Check status of mail ------------------------------------>>
IF sy-subrc = 0.
PERFORM error_process
USING
'S' '/OBIZ/ALM_MSG' '047'
'mail send'
space
space
space
CHANGING
e_return.
ENDIF.
ENDFUNCTION. *----------------------- error_processing-----------------------------*
*----------------INCLUDE LZJO_WEBF01 ------------------------*
*----------------------------------------------------------------------*
form error_process
using us_msgty
us_msgid
us_msgno
us_msgv1
us_msgv2
us_msgv3
us_msgv4
changing p_return type bapiret2_tab.
DATA:
return TYPE bapiret2,
da_msgv1 LIKE sy-msgv1,
da_msgv2 LIKE sy-msgv2,
da_msgv3 LIKE sy-msgv3,
da_msgv4 LIKE sy-msgv4.
da_msgv1 = us_msgv1.
da_msgv2 = us_msgv2.
da_msgv3 = us_msgv3.
da_msgv4 = us_msgv4.
CLEAR return.
CLEAR return.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = us_msgty
cl = us_msgid
number = us_msgno
par1 = da_msgv1
par2 = da_msgv2
par3 = da_msgv3
par4 = da_msgv4
IMPORTING
return = return.
APPEND return TO p_return.
ENDFORM. "error_processing |
|
|
Please send us your feedback/suggestions at webmaster@SAPTechnical.COM Home • Contribute • About Us • Privacy • Terms Of Use • Disclaimer • Safe • Companies: Advertise on SAPTechnical.COM | Post Job • Contact Us ©2006-2007 SAPTechnical.COM. All rights reserved. All
product names are trademarks of their respective companies. SAPTechnical.COM
is in no way affiliated with SAP AG. Graphic Design by Round the Bend Wizards |
||