cancel
Showing results for 
Search instead for 
Did you mean: 

Is there any Function Module available to send SMS (Short Message Service)?

Former Member
0 Kudos

Hi,

Is there any Function Module available to send SMS (Short Message Service)?

Regards,

Surjith

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Hi,

You can refer to the following code lines 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.

  • -------- create persistent send request ------------------------

send_request = cl_bcs=>create_persistent( ).

  • -------- create and set document -------------------------------

  • create document from internal table with text

append P_PA_TXT to text.

document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = text

i_length = '12'

i_subject = '' ).

  • add document to send request

CALL METHOD send_request->set_document( document ).

  • --------- set sender -------------------------------------------

sender = cl_sapuser_bcs=>create( sy-uname ).

CALL METHOD send_request->set_sender

EXPORTING

i_sender = sender.

  • --------- add recipient (e-mail address) -----------------------

lp_sms_num = P_PA_MOBILE.

recipient = cl_cam_address_bcs=>create_sms_address(

lp_sms_num ).

  • add recipient with its respective attributes to send request

CALL METHOD send_request->add_recipient

EXPORTING

i_recipient = recipient

i_express = 'X'.

  • set immediate processing, instead of queues

send_request->set_send_immediately( 'X' ).

  • ---------- send document ---------------------------------------

CALL METHOD send_request->send(

EXPORTING

i_with_error_screen = 'X'

RECEIVING

result = sent_to_all ).

IF sent_to_all = 'X'.

ENDIF.

COMMIT WORK.

CATCH cx_bcs INTO bcs_exception.

raise SMS_SENDING_FAILED.

EXIT.

ENDTRY.

ENDFORM.

Srisap
Participant
0 Kudos

Hello Ramanath,

Can you tell me what is format you are sending the number? Are you using your cell phone number for this. I am getting an error when I put in my cell phone number.

Can anybody else hepl me out with this?

recipient = cl_cam_address_bcs=>create_sms_address( i_number = p_number ).

What should p_number contain? I am currently working on ECC 6.0 system.

Regards,

Sridhar Karra.

Former Member
0 Kudos

Hi,

Tyr this..

receivers-receiver = '0...0 SMS Y...YX...X'.

receivers-rec_type = 'K'. " Pager/SMS

APPEND receivers.

X...X - Mobile phone's number

Y...Y - Country's code number

0...0 - You must write as 0 as numbers have the country code.

Example Spanish mobile phone:

Country code = 0034

Phone's number = 123456789

receivers-receiver = '0000 SMS 0034123456789'.

Former Member
0 Kudos

hello Srinivas S,

can you send the code which sends SMS using

FM : so_new_document_att_send_api1,

as i am also using this FM only to send SMS

regards

Mohit

Former Member
0 Kudos

method SEND_SMS_NOTIF.

**----------------------------------------------------------------------*

** TYPE DECLARATIONS                                                    *

**----------------------------------------------------------------------*

  TYPES :  BEGIN OF ty_doc_row,

               type TYPE so_obj_tp,

               subject TYPE so_obj_des,

               content_text TYPE soli_tab,

               content_hex TYPE solix_tab,

           END OF ty_doc_row.

  TYPES :  BEGIN OF ty_rec_row,

              uname TYPE syuname,

              c_address TYPE ad_smtpadr,

              i_express TYPE os_boolean,

              i_copy TYPE os_boolean,

              i_blind_copy TYPE os_boolean,

              i_no_foward TYPE os_boolean,

           END OF ty_rec_row.

*----------------------------------------------------------------------*

*INTERNAL TABLES AND WORK AREAS                                       *

*----------------------------------------------------------------------*

  DATA: documents TYPE TABLE OF ty_doc_row.

  DATA: send_request       TYPE REF TO cl_bcs.

  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: message_tab TYPE soli_tab.

  DATA: message_line LIKE LINE OF message_tab.

  DATA: documents_line LIKE LINE OF documents.

  DATA: l_oref TYPE REF TO cx_root.

  DATA: it_message TYPE STANDARD TABLE OF  zzpi_msg_notify(**** table for email address).

  DATA: wa_message LIKE LINE OF it_message.

*----------------------------------------------------------------------*

* CLASS-DEFINITIONS                                                    *

*----------------------------------------------------------------------*

  CLASS cl_cam_address_bcs DEFINITION LOAD.

  CLASS cl_abap_char_utilities DEFINITION LOAD.

*----------------------------------------------------------------------*

* LOCAL VARIABLES                                                      *

*----------------------------------------------------------------------*

  DATA: lv_subject TYPE so_obj_des.

  DATA: firstline(1) TYPE c.

  DATA: lv_mail_address TYPE adr6-smtp_addr.

*----------------------------------------------------------------------*

* LOCAL CONSTANT DECLARATIONS                                          *

*----------------------------------------------------------------------*

  CONSTANTS lc_txt TYPE so_obj_tp VALUE 'RAW'.

  TRY.

* Create send request

      send_request = cl_bcs=>create_persistent( ).

        message_line = ' '.

        APPEND message_line TO message_tab.

        message_line = 'Hi,'.

        APPEND message_line TO message_tab.

        message_line = ''.

        APPEND message_line TO message_tab.

      IF i_msgtab-type EQ 'E'.

        message_line = i_msgtab-message.

        APPEND message_line TO message_tab.

        lv_subject  = i_msgtab-ID.

      ENDIF.

      documents_line-type =  lc_txt.

      documents_line-content_text = message_tab.

      documents_line-subject = lv_subject.

      APPEND documents_line TO documents.

      LOOP AT documents INTO documents_line.

        IF firstline IS INITIAL.

          MOVE 'X' TO firstline.

* Build the Main Document

          IF documents_line-content_hex[] IS INITIAL.

            document = cl_document_bcs=>create_document(

                                i_type    = documents_line-type

                                i_text    = documents_line-content_text

                                i_subject = documents_line-subject ).

          ELSE.

            document = cl_document_bcs=>create_document(

                                i_type    = documents_line-type

                                i_hex     = documents_line-content_hex

                                i_subject = documents_line-subject ).

          ENDIF.

        ENDIF.

      ENDLOOP.

* Add document to send request

      CALL METHOD send_request->set_document( document ).

* Get sender object

      sender = cl_sapuser_bcs=>create( sy-uname ).

* Add sender

      CALL METHOD send_request->set_sender

        EXPORTING

          i_sender = sender.

* pull the recepients list from Variant table.

      SELECT * FROM zzpi_msg_notify INTO TABLE it_message WHERE process_code = i_proc_code AND sms_flag = 'X'.

      IF sy-subrc = 0.

        LOOP AT it_message INTO wa_message.

          MOVE wa_message-sms_addr TO lv_mail_address.

          recipient = cl_cam_address_bcs=>create_internet_address( lv_mail_address ).

* Add recipient with its respective attributes to send request

          CALL METHOD send_request->add_recipient

            EXPORTING

              i_recipient = recipient.

        ENDLOOP.

* set send immediately flag

        send_request->set_send_immediately( 'X' ).

* Send document

        CALL METHOD send_request->send( ).

        COMMIT WORK.

        e_out_return-message = 'SMS Notification sent successfully'.

        e_out_return-type = 'S'.

      ELSE.

        e_out_return-message = 'No recipients found as variant'.

        e_out_return-type = 'E'.

      ENDIF.

    CATCH cx_root INTO l_oref.                     "#EC

      e_out_return-message = l_oref->get_text( ).

      e_out_return-type = 'E'.

ENDTRY.

endmethod.

Former Member
0 Kudos

i am really thankful to your reply and concern,

but i want to send the SMS using FM only.

FM : so_new_document_att_send_api1,

so i would really appreciate your reply

if you u could tell through FM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

you can use function module

SO_NEW_DOCUMENT_ATT_SEND_API1

SO_OBJECT_SEND

Regards,

Roberto