[ Update UME data via CUA using web services ]

The purpose of this enhancement is to show how CUA can be used to automatically update the UME without using the portal.
This example scenario is to automatically assign the company to a vendor within the portal by passing the vendor number in CUA. This means that all user administration can be completed via CUA on the ABAP stack without having a need to log into the portal, in particular the UME administration page.

The new process will be a follows:

User is created/changed using SU01:

The save button is pressed:



You are prompted for the vendor number.
At this point if a vendor number is entered and the green tick is pressed the UME web service will be triggered to save the correct company (SUPXXXXX) against the user.

 

This enhancement is made up of the following components:

Z_SEC_ASSIGN_AG_CLEANUP - SU01 user exit

Z_UME_WEBSERVICE - UME web service function module

Z_READ_COMPANY - Supplier External ID function module

 

What does each component do?

Z_SEC_ASSIGN_AG_CLEANUP

  1. Checks if a Vendor Bidder ID is being created/modified by checking that the ID starts with BD.
  2. Requests the Vendor Number
  3. Obtains the correct Company ID from the Portal system via RFC
  4. Executes the UME web service “modifyUser” to add the Company ID
* If a Vendor Bidder is found
      IF <fcuaname>(2) EQ 'BD'.
        CALL SCREEN 4010 STARTING AT 2 10.
        CASE g_fcode.
          WHEN 'OPTIONS_SET'.
            IF vendorid IS NOT INITIAL.

              CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                EXPORTING
                  input  = vendorid
                IMPORTING
                  output = vendorid.

              call function 'Z_READ_COMPANY'DESTINATION 'BE0100'
                EXPORTING
                  vendorid = vendorid
                IMPORTING
                  company  = lv_company.


              lv_logonid = <fcuaname>.


              call function 'Z_UME_WEBSERVICE'
                EXPORTING
                  logonid = lv_logonid
                  company = lv_company
                IMPORTING
                  success = lv_success.

              IF lv_success EQ 'X'.
                MESSAGE 'Company Updated Successfully' TYPE 'I'.
              ELSE.
                MESSAGE 'Company Update Failed' TYPE 'W'.
              ENDIF.

            ENDIF.

          WHEN 'OPTIONS_ESCAPE'.

        ENDCASE.

      ENDIF.

 

Z_READ_COMPANY

  1. Read JAVA stack stable using the VENDORID field
  2. Return the SUPPLIER_PK field which is the company ID number
  3. Append SUP to the Company ID number

 

Important note:
If the above function module does not return any values check the contents of the LV_EXEC_REF structure in the SQLMSG field. If the following message appears:

SQL0551N  "SAPBE0" does not have the privilege to perform operation "SELECT" on object "SAPBE0DB.SRM_SUP_EXTERNALID".

The logon to UNIX as db2be0 and perform the following command:

db2 grant DBADM on database to user SAPBE0

 

Z_UME_WEBSERVICE

  1. Build SOAP Envelope
  2. Build Header
  3. Call Web Service operation/method modifyUser
  4. Return success/failure result
FUNCTION z_ume_webservice.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(LOGONID) TYPE  STRING
*"     VALUE(NEWEMAIL) TYPE  STRING OPTIONAL
*"     VALUE(FIRSTNAME) TYPE  STRING OPTIONAL
*"     VALUE(LASTNAME) TYPE  STRING OPTIONAL
*"     VALUE(TITLE) TYPE  STRING OPTIONAL
*"     VALUE(LOCALE_LANGUAGE) TYPE  STRING OPTIONAL
*"     VALUE(LOCALE_COUNTRY) TYPE  STRING OPTIONAL
*"     VALUE(LOCALE_VARIANT) TYPE  STRING OPTIONAL
*"     VALUE(COMPANY) TYPE  STRING OPTIONAL
*"  EXPORTING
*"     VALUE(SUCCESS) TYPE  BOOLEAN
*"----------------------------------------------------------------------

*       Global data declarations


  DATA:
     http_client TYPE REF TO if_http_client,
     lv_length TYPE i,
     lv_txlen TYPE string,
     lv_con_string TYPE string,
     lv_out_string TYPE string.

  CLEAR lv_con_string .


* Build SOAP envelope
  CONCATENATE
  `<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" `
  `xmlns:prt="prt:service:com.sapportals.portal.prt.webservice.usermanagement.UMWebService">`
     `<soapenv:Header/>`
     `<soapenv:Body>`
        `<prt:modifyUser soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">`
           `<modifyUser_9_param5 xsi:type="xsd:string">` logonid `</modifyUser_9_param5>`
           `<modifyUser_9_param6 xsi:type="xsd:string">` newemail `</modifyUser_9_param6>`
           `<modifyUser_9_param7 xsi:type="xsd:string">` firstname `</modifyUser_9_param7>`
           `<modifyUser_9_param8 xsi:type="xsd:string">` lastname `</modifyUser_9_param8>`
           `<modifyUser_9_param9 xsi:type="xsd:string">` title `</modifyUser_9_param9>`
           `<modifyUser_9_param10 xsi:type="xsd:string">` locale_language `</modifyUser_9_param10>`
           `<modifyUser_9_param11 xsi:type="xsd:string">` locale_country `</modifyUser_9_param11>`
           `<modifyUser_9_param12 xsi:type="xsd:string">` locale_variant `</modifyUser_9_param12>`
           `<modifyUser_9_param13 xsi:type="xsd:string">` company `</modifyUser_9_param13>`
        `</prt:modifyUser>`
     `</soapenv:Body>`
  `</soapenv:Envelope>`
    INTO lv_con_string .

* get length of message
  CLEAR :lv_length , lv_txlen .
  lv_length = STRLEN( lv_con_string ) .
  MOVE: lv_length TO lv_txlen .



* Create HTTP client
  CALL METHOD cl_http_client=>create_by_destination
    EXPORTING
      destination    = 'BED_HTTP'
    IMPORTING
      client = http_client.


* Set the required header fields
  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~request_method'
      value = 'POST'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~server_protocol'
      value = 'HTTP/1.1'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = '~request_uri'
      value = '/irj/servlet/prt/soap/UMWebService?style=rpc_enc'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = 'Content-Type'
      value = 'text/xml;charset=UTF-8'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = 'User-Agent'
      value = 'Jakarta Commons-HttpClient/3.0.1'.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = 'Content-Length'
      value = lv_txlen.

  CALL METHOD http_client->request->set_header_field
    EXPORTING
      name  = 'SOAPAction'
      value = 'prt:service:com.sapportals.portal.prt.webservice.usermanagement.UMWebService.UMWebService/modifyUser'.

* Set the data
  CALL METHOD http_client->request->set_cdata
    EXPORTING
      data   = lv_con_string
      offset = 0
      length = lv_length.

* Send Data
  CALL METHOD http_client->send
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2.

* Receive Data
  CALL METHOD http_client->receive
    EXCEPTIONS
      http_communication_failure = 1
      http_invalid_state         = 2
      http_processing_failed     = 3.

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

  SEARCH lv_out_string FOR '<response xsi:type="xsd:boolean">true</response>'.
  IF sy-subrc EQ 0.
    success = 'X'.
  endif.

ENDFUNCTION.

 

Important note:
The following RFC must exist:

Code extract
* Create HTTP client
  CALL METHOD cl_http_client=>create_by_destination
    EXPORTING
      destination    = 'BED_HTTP'
    IMPORTING
      client = http_client.

RFC destination