Sending SMS to the Customer on Delivery Order using 3rd party API!
Sending SMS to the Customer on Delivery Order using 3rd party Application Program Interface.
I’m sure many of us came across the similar requirement where there’s a need to send SMS or Email to the customers through integration with ERP system. Since we’ve implemented SMS sending through HTTP with 3rd party API server so thought of sharing a document which I believe will explain well how to follow major procedure by using Standard SAP configuration for SMS generation.
There was a business requirement to send an SMS to the Customer on the creation of Delivery Order in SD Sale Process. Reason behind this was that Customers should be aware as how much Qty. of which product has been dispatched from the warehouse to them which we’ve catered in SAP by using 3rd party API server. Moreover, Email functionality has also been implemented in order to intimate about delivery orders creation to our Branch Managers, Accountants and Warehouse In-charges.
We have implemented automatic SMS generating functionality on transactions VL01N (Delivery Order Creation at the time of PGI) and VL09 (Delivery Order Reversal) where system will initiate SMS via ABAP Program for the customer against their cell numbers which have been maintained in Customer Master record. Before this we’ve re-verified Customer Master Record (maintenance of Mobile No. under General Data Tab in Mobile Phone Text Box i.e. TELF2 field in CMR) for all the Customers which will be picked by KNA1 Table against LIKP-KUNNR.
We’ve defined a Z* table in order to pass necessary Parameters for SMS sending after getting the response data (i.e. URL building through HTTP request) via class method like KUNNR, TELF2, MESSAGE TEXT, SENT FLAG, ERDAT and TIME against which we’ll receive back response from 3rd party API server.
After retrieving the HTTP response by utilizing 3rd party API we will update the Z* table accordingly by setting SENT flag to ‘X‘ if API’s server back response is successful. In case SMS hasn’t been sent from DB due to any reason system will retry sending it via background job and it will send all the SMS that have been pending in a queue.
Message Text has been defined based on Movement Type logic as if there’s a Stock Out from Inventory system will send Dispatch SMS to the Customer. If it’s Return, it will give the intimation that Stock has been Returned to warehouse. In case of Delivery Order Reversal, system will send an SMS to the Customer that Delivery Order has been cancelled due to ___ Reason. Attaching snapshots for better understanding which shows the Message Content that have been delivered to the customer.
We’ve implemented the coding in BADI LE_SHP_DELIVERY_PROC at method IF_EX_LE_SHP_DELIVERY_PROC~SAVE_AND_PUBLISH_BEFORE_OUTPUT via class method
1st we need to build the URL string based on the input parameters (A valid account ID of 3rd party server, Text Msg, SMS masking, Language, Valid mobile number to whom you want to send SMS number and valid password to request API) that will be dynamically created (SMS TEXT) and (MOBILE NUM).
3rd Party Mobile Number will be maintained after building the URL via HTTP request from Z* Table after which we’ll pass this corresponding field to our Internal Table and concatenate the URL as mentioned below.
After the URL creation, we will prepare HTTP Client request to 3rd party’s API server using the classes.
1. IF_HTTP_CLIENT OBJECT CREATION
This class CL_HTTP_CLIENT is used to call a Web Service which will generate the Request Data and Post the Returned Data as a result of which the request will be converted to a HTTP Data Stream.
2. SENDING REQUEST
The system will use this Header Field to submit a Request to 3rd party’s API server after which we’ll receive the Response transmitted back to our Application Server.
3. RETRIEVE THE RESULT
This call method HTTP_CLIENT->RECEIVE will be used to get the Response back from the API server however there’s a need to make sure as if HTTP Requests are going fine through a proxy server and after that they should have been set on your Application Server for e.g. If Message Sending is Successful or Unsuccessful due to Incomplete or Missing Parameters, Account Expiry, Invalid API Password, Special Characters in SMS etc.
Finally we need to get the Response data in STRING format from and we need to make sure that String type should be as CHAR.
In order to send email to our Branch Managers, Accountants and Warehouse In-charges we’ve created a separate Z* table in which every Branch Common Email Address Group has been maintained based on the Sales District. After appending the desired Parameters like Mail Group etc. We’ve used a call function CALL FUNCTION ‘SO_DOCUMENT_SEND_API1’ in order to send Email to an External Email Addresses. Also, we need to make sure that Address Declarations should be correct.
SMTP NODE CONFIGURATION:
SMTP node is necessary to send Mails to an External Mail System. From the Settings Menu you need to Define Domain, just type your Company’s Email Domain.
The SAP system will transfer the Outbound Mails to a Single Mail Server where we can set its Host Address and Mail Port Number.
In Mail host field name we will write an SMTP (outgoing mail) address and in the Mail port field we need to give the correct port which will be used to connect to an SMTP server.
Under Supported address types option, click on Set button next to the Internet check-box. Here give an address area as * as that will be used for a routing decision.
MONITORING IN SOST:
We can Monitor and view the Status of Outgoing Emails sent from SAP depending upon the selection criteria given in order to execute. This Transaction displays the relevant Send Status for all the Send Requests. Status String displays number of Send Requests, Warning, Waiting, Errors etc.
Send Method in our case is via Internet, Document Title will display complete details about the send request. Sender/Recipient will show the detailing about the Sender or Recipient. Send Date/Send Time will be the Date and Time at which the User sent the Message. Msg will show the Current Status Code of the Send Request. If Status is Green that means Email has been delivered. Also, you can view the Message Contents by going to the Display Document Option in Send Request Menu.
This step by step Document will be helpful from Functional and Technical perspective as I’ve tried my best to cover every possible Scenario one can encounter via doing this development. Please post your valuable comments if you feel that it’s worthwhile. Thanks