SMS are use, for different type of communication between company and other parties like, customer, vendor, employee etc.
In sap we can integrate sms api, which first we have to purchase from service provider.
SMS API comes into 2 types, like free text API and template base API.
In this example, I am sharing the code for free text sms api.
We have to pass mobile number and message from screen, remaining parameters will be fix , as per given from service provider.
REPORT ZSMS_API.
DATA: HTTP_CLIENT TYPE REF TO IF_HTTP_CLIENT,
STRING TYPE STRING,
STRING1(1000),
W_RESULT TYPE STRING.
PARAMETERS : p_mobile(10),
p_msg type char100 LOWER CASE.
START-OF-SELECTION.
perform send_sms.
end-of-SELECTION.
*&---------------------------------------------------------------------*
*& Form SEND_SMS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM SEND_SMS.
if P_MOBILE is NOT INITIAL and P_MSG is NOT INITIAL.
CONCATENATE 'http://www.winsms.in/api/mt/SendSMS?user=blogger&password=sms_api&senderid=ABAP&channel=Trans&DCS=0&flashsms=0'
'&number=' P_MOBILE
'&text=' P_MSG
'&route=1&peid=875325600000010654' into string.
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = string
IMPORTING
client = http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.
CALL METHOD http_client->send
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2.
CALL METHOD http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3.
if sy-SUBRC = 0.
CLEAR : w_result.
w_result = http_client->response->get_cdata( ).
CONDENSE w_result.
write : W_RESULT.
else.
STRING1 = STRING.
CALL FUNCTION 'HR_URL_CALL_BROWSER'
EXPORTING
URL = string1
EXCEPTIONS
BROWSER_START_FAILED = 1
NO_BATCH = 2
URL_IS_EMPTY = 3
OTHERS = 4
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
endif.
else.
message 'Please enter the mobile no. and Message' TYPE 'I'.
endif.
ENDFORM.
3 Comments
username and password invalid
ReplyDeleteRecieve method is failing
ReplyDeletehow to send SMS using proxy?
ReplyDeletebecause in RISE server this code is not working getting 'http_communication_failure' message.