Register Login

Function module for sending SMS

Updated May 18, 2018

You have to use the below codes to send the SMS

FORM SENDMESSAGE USING   P_PA_MOBILE   

P_PA_TXT.

  DATA: send request       TYPE REF TO cl_bcs.

  DATA: text               TYPE bcsy_text.

  DATA: document           TYPE REF TO cl_document_bcs.

  DATA: sender             TYPE REF TO cl_sapuser_bcs.

  DATA: recipient          TYPE REF TO if_recipient_bcs.

  DATA: bcs_exception      TYPE REF TO cx_bcs.

  DATA: sent_to_all        TYPE os_boolean.

  Data lp_sms_num         type AD_PAGNMBR.

  TRY.

·             - Generate determined refer request -
      Send request = cl_bcs=>create persistent ( ).

·             -Generate and fix document --
·             Generate  document from internal table using text
      Add P_PA_TXT to text.

      Document = cl_document_bcs=>create document (

                      Type    = 'RAW'

                      Intent    = text

                      Length  = '12'

                      i_subject = '' ).


·             Append document to send request
      CALL METHOD send request->set document( document ).


·             -set -
      Sender = cl_sapuser_bcs=>create( sy-uname ).

      CALL METHOD send request->set_sender

        EXPORTING

          i_sender = sender.


·            - Append recipient (e-mail address) -
      lp_sms_num = P_PA_MOBILE.

      Recipient = cl_cam_address_bcs=>create_sms_address(

                                         lp_sms_num ).


·             Append recipient with its respective attributes to send request
      CALL METHOD send request->add recipient

        EXPORTING

          i_recipient = recipient

          i_express   = 'X'.


·             Fix  instant dispensation, as a substitute of queues
      Send request->set_send_immediately (‘X’).


·             -send document -
      CALL METHOD send request->send (

        DISSEMINATING

          i_with_error_screen = 'X'

          RECEIVING

          Result              = sent_to_all).

      IF sent_to_all = 'X'.


      ENDIF.

      OBLIGATE EFFORT.

    CATCH cx_bcs INTO bcs_exception.

      Increase SMS_SENDING_FAILED.

      EXIT.

  ENDTRY.

ENDFORM.

The below function module can also help you to send SMS

  • SO_NEW_DOCUMENT_ATT_SEND_API1
  • SO_OBJECT_SEND

Hope this article might help you to sort out the above issue


×