Steps to Publish Web Service in R/3, Consume Web Service in R/3 and Adobe Flex

By Rajkumar Shanmuganthan, Kaar Technologies

Publishing a Web Service:

Create a RFC enabled Function module that will send Email to the person based on the input parameters.

Check whether your mail is being sent in SOST transaction. Once SAP BASIS Team configures mail connections in SCOT transaction, all the mails in the Queue will be sent to the external world.

Source code for the Function module is as follows:

FUNCTION ZKAAR_PUBLISH_WEB_SERVICE.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(FROM) TYPE  STRING
*"     VALUE(TO) TYPE  STRING
*"     VALUE(MESSAGE) TYPE  STRING
*"     VALUE(SUBJECT) TYPE  STRING
*"  EXPORTING
*"     VALUE(RETURN) TYPE  STRING
*"----------------------------------------------------------------------

*----------------------------------------------------------------------*
* CLASS-DEFINITIONS                                                    *
*----------------------------------------------------------------------*
  
DATA: SEND_REQUEST       TYPE REF TO CL_BCS.
  
DATA: DOCUMENT           TYPE REF TO CL_DOCUMENT_BCS.
  
DATA: SENDER             TYPE REF TO IF_SENDER_BCS.
  
DATA: RECIPIENT          TYPE REF TO IF_RECIPIENT_BCS.
  
DATA: EXCEPTION_INFO     TYPE REF TO IF_OS_EXCEPTION_INFO,
        BCS_EXCEPTION      
TYPE REF TO CX_BCS.

*----------------------------------------------------------------------*
* INTERNAL TABLES                                                      *
*----------------------------------------------------------------------*
  
DATA: L_MAILTEXT TYPE SOLI_TAB.

  
TRY.
* Create persistent send request
      SEND_REQUEST = CL_BCS=>CREATE_PERSISTENT( ).

* Move the Subject from string to BCS subject type
      
DATA: L_SUBJECT TYPE SO_OBJ_DES.
      L_SUBJECT = SUBJECT.

* Move the message from string to internal table
      
CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
        
EXPORTING
          
TEXT      = MESSAGE
        
TABLES
          FTEXT_TAB = L_MAILTEXT.

* Create the Document
      DOCUMENT = CL_DOCUMENT_BCS=>CREATE_DOCUMENT(
                          I_TYPE    = 
'RAW'
                          I_TEXT    = L_MAILTEXT
                          I_SUBJECT = L_SUBJECT ).

* Add document to send request
      
CALL METHOD SEND_REQUEST->SET_DOCUMENT( DOCUMENT ).

* Get sender object
      
DATA: L_SENDER TYPE AD_SMTPADR.
      L_SENDER = 
FROM.
      SENDER = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( L_SENDER ).

* Add sender
      
CALL METHOD SEND_REQUEST->SET_SENDER
        
EXPORTING
          I_SENDER = SENDER.

* Get Recipient Object
      
DATA: L_RECIPIENT TYPE AD_SMTPADR.
      L_RECIPIENT = 
TO.
      RECIPIENT = CL_CAM_ADDRESS_BCS=>CREATE_INTERNET_ADDRESS( L_RECIPIENT

).

* Add recipient with its respective attributes to send request
      
CALL METHOD SEND_REQUEST->ADD_RECIPIENT
        
EXPORTING
          I_RECIPIENT = RECIPIENT.

* Set that you don't need a Return Status E-mail
      
CALL METHOD SEND_REQUEST->SET_STATUS_ATTRIBUTES
        
EXPORTING
          I_REQUESTED_STATUS = 
'E'
          I_STATUS_MAIL      = 
'E'.

* set send immediately flag
      SEND_REQUEST->SET_SEND_IMMEDIATELY( 
'X' ).

* Send document
      
CALL METHOD SEND_REQUEST->SEND( ).

      
COMMIT WORK.

      
IF SY-SUBRC EQ 0.
        
RETURN = 'Message Sent Successfully'.
       
ELSE.
        
RETURN = 'Error in Sending Email'.
      
ENDIF.
    
CATCH CX_BCS INTO BCS_EXCEPTION.
*      data: l_message type string.
*      l_message = bcs_exception->GET_TEXT( ).
  
ENDTRY.

ENDFUNCTION.

Now this Function module has to be published as a Web service.

Click here to continue...

Please send us your feedback/suggestions at webmaster@SAPTechnical.COM 

HomeContribute About Us Privacy Terms Of Use • Disclaimer • SafeCompanies: Advertise on SAPTechnical.COM | Post JobContact Us  

Graphic Design by Round the Bend Wizards

footer image footer image