Skip to Content
Author's profile photo Bharat Rathod

Send SMS with more than 255 character from sap

Dear all,

If you want to send a SMS to your client or dealer or vendor for their payment or delivery etc. through SAP then you have to create a URL with less than 255 character but if your url has more than 255 character then you have to follow following procedure.

step1 : you have to make z class using foloowing class

CL_HTTP_CLIENT=>CREATE_BY_URL

step2 : make FM which call above class and method.

here I am giving sample code for the same.

CALL FUNCTION ‘ZSD_SMS_VF04’

EXPORTING

   VBELN         = BELNR

* TABLES

*   IT_VBRK       =

          .

FUNCTION ZSD_SMS_VF04.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     REFERENCE(VBELN) TYPE  VBELN OPTIONAL

*”  TABLES

*”      IT_VBRK STRUCTURE  VBRKVB OPTIONAL

*”———————————————————————-

  TABLES: VBRK.

*DATA: IT_VBRK TYPE STANDARD TABLE OF VBRK WITH HEADER LINE.

  DATA: WA_VBRK TYPE VBRK.

  DATA : gw_vbrp TYPE vbrp.

  DATA : gw_kna1 TYPE kna1.

  DATA : gw_vbrk TYPE vbrkvb.

  DATA : gw_adrc TYPE adrc.

  DATA : gw_adrc2 TYPE adr2.

*  DATA : gt_zsd_sms TYPE TABLE OF zsd_sms,

*         gw_zsd_sms TYPE zsd_sms.

*************ADD BY BHARAT RATHOD AS PER SUGGEST MR.MAHER

  DATA : GT_ZSD_SMS1  TYPE TABLE OF ZSD_SMS1,

         GW_ZSD_SMS1 TYPE ZSD_SMS1.

*************ADD END ***************************************

  DATA : lv_name1 TYPE name1_gp.

  DATA : lv_city TYPE ort01_gp.

  DATA : lv_kwert TYPE kwert.

  DATA : lv_kwert1 TYPE char10.

  DATA : lv_excnum TYPE j_1iexcnum.

  DATA : lv_exdat TYPE char10.

  DATA : lv_name2 TYPE name1_gp.

  DATA : lv_lrno TYPE bolnr.

  DATA : lv_billnum(30) TYPE c.

  DATA : lv_dealer(30) TYPE c.

  DATA : lv_billdt(30) TYPE c.

  DATA : lv_amt(30) TYPE c.

  DATA : lv_trans(30) TYPE c.

  DATA : TXT_MSG TYPE STRING.

  DATA: FRDAT TYPE STRING.

  DATA : NETWR TYPE KONV-KWERT.

  SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_VBRK WHERE VBELN EQ VBELN

                                                                AND FKART IN (‘G2’, ‘YG2’).

  IF SY-SUBRC EQ 0.

  READ TABLE IT_VBRK INTO WA_VBRK WITH KEY VBELN = VBELN.

  IF SY-SUBRC EQ 0.

    SELECT SINGLE DMBTR FROM BSID

      INTO NETWR

      WHERE BUKRS = ‘1000’

      AND   KUNNR = WA_VBRK-KUNAG

      AND   BELNR = VBELN.

    SELECT SINGLE * INTO gw_kna1

        FROM kna1

        WHERE kunnr = WA_VBRK-kunag.

    IF SY-SUBRC EQ 0.

      SELECT SINGLE * FROM adrc

   INTO gw_adrc

   WHERE addrnumber = gw_kna1-adrnr.

      IF SY-SUBRC EQ 0.

        GW_ZSD_SMS1-KUNNR = GW_KNA1-KUNNR.

        GW_ZSD_SMS1-PHONE_NO = GW_ADRC-TEL_NUMBER.

        APPEND  GW_ZSD_SMS1 TO GT_ZSD_SMS1.

      ENDIF.

      lv_name1 = gw_kna1-name1.

      lv_city  = gw_kna1-ort01.

    ENDIF.

    lv_excnum = WA_VBRK-VBELN.

    lv_exdat = WA_VBRK-FKDAT.

*    LV_KWERT1 = WA_VBRK-NETWR.

    LV_KWERT1 = NETWR.

    CLEAR: FRDAT.

    CONCATENATE LV_EXDAT+6(02) LV_EXDAT+4(02) LV_EXDAT+0(04) INTO FRDAT SEPARATED BY ‘.’.

    SHIFT lv_excnum LEFT DELETING LEADING ‘0’.

    SHIFT lv_kwert1 LEFT DELETING LEADING space.

IF WA_VBRK-FKART = ‘G2’.

    CONCATENATE ‘Dear Dealer, Your Atul Auto A/c is credited with Rs’ lv_kwert1

    ‘on’ frdat ‘via Credit note ref No:’ lv_excnum ‘against FSC and WRC settlement’ INTO

    txt_msg SEPARATED BY space.

ELSE.

    CONCATENATE ‘Dear Dealer, Your Atul Auto A/c is credited with Rs’ lv_kwert1

    ‘on’ frdat ‘via Credit note ref No:’ lv_excnum ‘against Warranty claim settlement’ INTO

    txt_msg SEPARATED BY space.

ENDIF.

BREAK BHARAT.

*MESSAGE ‘INSIDE ZSD_SMS_VF04’ TYPE ‘S’.

    CALL FUNCTION ‘ZSEND_SMS_LONG’

      EXPORTING

        mob_no        = GW_ZSD_SMS1-PHONE_NO

        tex_mes       = TXT_MSG

*       TABLES

*         RETURN        =

              .

  ENDIF.

ELSE.

  EXIT.

ENDIF.

ENDFUNCTION.

FUNCTION ZSEND_SMS_LONG.

*”———————————————————————-

*”*”Local Interface:

*”  IMPORTING

*”     VALUE(MOB_NO) TYPE  CHAR10

*”     VALUE(TEX_MES) TYPE  ZELE_MESS

*”  TABLES

*”      RETURN STRUCTURE  ZSMS OPTIONAL

*”———————————————————————-

  TABLES : zsms1.

  DATA: http_client TYPE REF TO if_http_client .

  DATA: wf_string TYPE string,

        result TYPE string ,

        r_str TYPE string .

  DATA : URL TYPE STRING,

         URL1 TYPE STRING,

         URL2 TYPE STRING.

  DATA: result_tab TYPE TABLE OF string.

  DATA : msg_typ TYPE  char1.

  DATA : msg_text TYPE char256.

  DATA : wa_result TYPE zsms.

  DATA : it_zsms1 TYPE TABLE OF zsms1,

         wa_zsms1 TYPE zsms1.

  SELECT SINGLE * FROM

                zsms1

                INTO

                wa_zsms1.

  CLEAR wf_string.

  CONCATENATE ‘method=sendMessage&send_to=’ mob_no ‘&msg=’ tex_mes ‘&userid=’ wa_zsms1-userid ‘&password=’ wa_zsms1-pass_wor ‘&v=1.0’

              INTO URL.

  URL1 =  ‘enterprise.smsgupshup.com’.

  URL2 = ‘/GatewayAPI/rest’.

  CALL METHOD ZCL_HTTP_CLIENT=>ZCREATE_BY_URL

    EXPORTING

      URL                = URL

      URL1               = URL1

      URL2               = URL2

*      PROXY_HOST         =

*      PROXY_SERVICE      =

*      SSL_ID             =

*      SAP_USERNAME       =

*      SAP_CLIENT         =

    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.

  CLEAR result .

  result = http_client->response->get_cdata( ).

  MESSAGE RESULT TYPE ‘S’.

  REFRESH result_tab.

  SPLIT result AT cl_abap_char_utilities=>cr_lf INTO TABLE result_tab .

  LOOP AT result_tab INTO r_str.

*    wa_result-msg_typ = ‘E’.

    wa_result-msg_text = r_str.

    APPEND wa_result TO return.

    CLEAR wa_result.

  ENDLOOP .

ENDFUNCTION.

method ZCREATE_BY_URL.

  data: client_obj type ref to Zcl_http_client.

  data: c_instance type ihttp_client_instance.

  data: scheme type string.

  data: service type string,

        host type string.

  data: path     type string,

        query    type string,

        userinfo type string.

  data: subrc    type sysubrc.

  if url is initial.

    raise argument_not_found.

  endif.

  pf_m_open c_statistic_state ‘HTTP Create By Url’.         “#EC *

* filter necessary information from URL

  pf_m_open c_statistic_state ‘HTTP Parse Url’.             “#EC *

  CALL FUNCTION ‘ZSWLWP_URI_PARSE’

    EXPORTING

      uri                 = url

      uri1                 = url1

      uri2                 = url2

*     PARSE_AUTHORITY     = ‘X’

    IMPORTING

      scheme              = scheme

*     AUTHORITY           =

      userinfo            = userinfo

*     HOSTPORT            =

      host                = host

      port                = service

      abs_path            = path

*     REL_SEGMENT         =

      query               = query

*     OPAQUE_PART         =

*     FRAGMENT            =

*     IS_RELATIVE         =

*     HAS_NET_PATH        =

*     HAS_REL_PATH        =

*     HAS_EMPTY_AUTHORITY =

*     HAS_IPV4_HOST       =

    EXCEPTIONS

      uri_no_path         = 1

      others              = 2.

  subrc = sy-subrc.

  pf_m_close c_statistic_state ‘HTTP Parse Url’.            “#EC *

  if subrc <> 0.

    pf_m_close c_statistic_state ‘HTTP Create By Url’.      “#EC *

    raise argument_not_found.

  endif.

*  call function ‘HTTP_PARSE_URL’

*      exporting

*           url      = url

*      importing

*           scheme   = scheme_str

*           hostname = host

*           service  = service

*           uri      = uri.

*

*  if host is initial.

*    raise argument_not_found.

*  endif.

  translate scheme to upper case.                           “#EC

  if scheme = ‘HTTP’.

    scheme = schemetype_http.

  elseif scheme = ‘HTTPS’.

    scheme = schemetype_https.

  else.

    pf_m_close c_statistic_state ‘HTTP Create By Url’.      “#EC *

    raise argument_not_found.

  endif.

  if service is initial.

    if scheme = schemetype_http.

      service = ’80’.

    else.

      service = ‘443’.

    endif.

  else.

* check validity of port number (16bit Integer)

    if ( strlen( service ) GT 5 )

    or ( service cn ‘0123456789’ ).

      raise argument_not_found.

    endif.

  endif.

* Is plugin available

  if scheme = schemetype_http and

     c_schemetype_http_active = 0.

    pf_m_close c_statistic_state ‘HTTP Create By Url’.      “#EC *

    raise plugin_not_active.

  elseif scheme = schemetype_https and

         c_schemetype_https_active = 0.

    pf_m_close c_statistic_state ‘HTTP Create By Url’.      “#EC *

    raise plugin_not_active.

  endif.

* Erzeuge der Interface-Referenz

  CREATE OBJECT client_obj

    EXCEPTIONS

      create_message_failed = 1.

  if sy-subrc <> 0.

    pf_m_close c_statistic_state ‘HTTP Create By Url’.      “#EC *

    raise internal_error.

  endif.

  client ?= client_obj.

  client_obj->m_host           = host.

  client_obj->m_target_host    = host.

  client_obj->m_service        = service.

  client_obj->m_target_service = service.

  if not proxy_host is initial.

    client_obj->m_is_special_proxy_configured = ABAP_TRUE.

    client_obj->m_proxy_host     = proxy_host.

* check validity of proxy port number (16bit Integer)

    if ( strlen( proxy_service ) GT 5 )

    or ( proxy_service cn ‘0123456789’ ).

      raise argument_not_found.

    endif.

    client_obj->m_proxy_service  = proxy_service.

  endif.

  client_obj->m_scheme         = scheme.

  client_obj->m_target_scheme  = scheme.

  client_obj->m_createtype     = createtype_url.

  pf_m_open c_statistic_state ‘HTTP Create TID’.            “#EC *

  CALL FUNCTION ‘ICF_CREATE_GUID’

    IMPORTING

      id = m_connection.

  pf_m_close c_statistic_state ‘HTTP Create TID’.           “#EC *

  if m_connection is initial.

    concatenate host ‘:’ service ‘@’ m_connection

                                       into client_obj->m_name.

    condense client_obj->m_name.

  else.

    client_obj->m_name = m_connection.

  endif.

*  len = strlen( client_obj->m_name ).

** — is name larger than the key space -> GUID first to build the key

*  if len > 60.

*    clear client_obj->m_name.

*    concatenate m_connection ‘@’ target

*                                      into client_obj->m_name.

*  endif.

  client_obj->m_state  = statetype_initial.

* Is secure communication, for transport of cookie data

  if scheme = schemetype_https.

    client_obj->m_is_secure = 1.

  else.

    client_obj->m_is_secure = 0.

  endif.

  client_obj->m_target_is_secure = client_obj->m_is_secure.

  client_obj->m_sslapplic    = ssl_id.

* Ermittlung des Filenamen bei SSL-Konfiguration

  if scheme = schemetype_https and

     not ( client_obj->m_sslapplic is initial ).

    if ( ‘ANONYM’ <> client_obj->m_sslapplic ).

*

* username and client numebr for mapping of client certificate at R/3

*

      client_obj->m_sap_username = sap_username.

      client_obj->m_sap_client   = sap_client.

    endif.

    pf_m_open c_statistic_state ‘HTTP PSE Parameter’.       “#EC *

    CALL FUNCTION ‘SSFPSE_PARAMETER’

      EXPORTING

        context         = ‘SSLC’

        applic          = client_obj->m_sslapplic

      IMPORTING

*       FALLBACK        =

*       KEY             =

*       HOST            =

*       INSTANCEID      =

*       PSENAME         =

        profile         = client_obj->m_x509filename

*       ID              =

*       SIGNED          =

*       DATALEN         =

      EXCEPTIONS

        pse_not_distrib = 1

        pse_not_found   = 2

        others          = 3.

    subrc = sy-subrc.

    pf_m_close c_statistic_state ‘HTTP PSE Parameter’.      “#EC *

    if subrc <> 0.

      pf_m_close c_statistic_state ‘HTTP Create By Url’.    “#EC *

      raise argument_not_found.

    endif.

  elseif scheme = schemetype_http.

*

* Remark: clear all HTTPS relevant fields in case of HTTP communication. This is necessary

*         since a redirect from HTTP to HTTPS protocol could mistakenly reuse the HTTPS

*         attributes, e.g. SSL context, ID.

*

    clear: client_obj->m_sslapplic, client_obj->m_x509filename.

  endif.

*  if not uri is initial.

*    cl_http_utility=>set_request_uri( request = client_obj->request

*                                      uri     = uri ).

*  endif.

* — set query string (form fields)

  if not query is initial.

* — store initial query for later use in CLOSE

    client_obj->m_query = query.

    Zcl_http_utility=>set_query( request = client_obj->request

                                query   = query ).

    client_obj->m_ecode = Zcl_http_utility=>get_last_error( ).

    if client_obj->m_ecode <> 0.

      pf_m_close c_statistic_state ‘HTTP Create By Url’.    “#EC *

      raise internal_error.

    endif.

  endif.

* — store initial path for later use in CLOSE

  client_obj->m_path = path.

*– set path

  client_obj->request->set_header_field( name  = ‘~request_uri’

                                         value = path ).

  client_obj->m_ecode = client_obj->request->get_last_error( ).

  if client_obj->m_ecode <> 0.

    pf_m_close c_statistic_state ‘HTTP Create By Url’.      “#EC *

    raise internal_error.

  endif.

*– set user:password

  if not userinfo is initial.

    split userinfo at ‘:’ into host service.

    client_obj->authenticate( username = host password = service ).

  endif.

  CREATE OBJECT c_instance-client

    EXPORTING

      oref = client_obj.

  c_instance-name   = client_obj->m_name.

  c_instance-state  = client_obj->m_state.

  append c_instance to http_client_instances.

  pf_m_close c_statistic_state ‘HTTP Create By Url’.        “#EC *

endmethod.


Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Hi Bharat Rathod


      First of all, thank you very much for your post

      Could you show the macro definitions, type-pools, constructor definition, atributes etc ... of ZCL_HTTP_CLIENT please

      thank you very much

      Author's profile photo Bharat Rathod
      Bharat Rathod
      Blog Post Author

      Dear,

      i just copy cl_htp_client and make z.