Start of Content Area

Process documentation Using Surveys in Activity Management  Locate the document in its SAP Library structure

Purpose

In many Activity Management scenarios, the use of surveys (surveys) is enabled by the callback modules CRM_SVY_ACTIVITY_PBO and CRM_SVY_ACTIVITY_PAI. This document uses the different scenarios in Activity Management that use surveys to describe the structure of the function modules CRM_SVY_ACTIVITY_PBO and CRM_SVY_ACTIVITY_PAI.

The function module and the supplementary function modules can be found in the function group CRM_ACTIVITY_SURVEY. This function group is in the package CRM_SURVEY.

The following documentation should help you to understand the coding in the function modules described below. The function modules contain partially commented example coding. This can be copied and the copies can then be adapted accordingly.

 

Surveys are used in the following cases:

     Processing of existing activities using a survey

This option is provided in the SAP standard system.

 

The activity processing interface can be used alone or together with the Interaction Center for creating or changing activities. The Questionnaire tab page allows you to fill out a survey.

When you choose the Submit button in the survey (“Qualify” or “Save”), the survey runtime calls function module CRM_SVY_ACTIVITY_PAI at exit time PAI.

The function module CRM_SVY_ACTIVITY_PBO is run before the survey is displayed.

·        Creation of new activities using surveys

This option is provided in the SAP standard system.

During campaign execution, an e-mail is sent which contains a link (URL) to a survey (GUID). A parameter MIG (Mail Identifier GUID) is attached to the end of this URL string during execution of the e-mail. This parameter identifies the sent e-mail, the campaign and the business partner.

The recipient of the e-mail clicks on the link and the survey is displayed in a Web browser. This survey can be a marketing or activity survey.

When you choose the Submit button in the survey (“Qualify” or “Save”), the survey runtime calls the assigned function module at exit time PAI.

For a marketing survey, the function module CRM_MKTCA_SURVEY_MKT_PAI is called. This function module calls the Business Add-In CRM_MKTCA_SVY_PAI. In the default implementation of this Business Add-In, the activity attributes are filled and the function module CRM_SVY_ACTIVITY_PAI is then called.

For an activity survey, the function module CRM_SVY_ACTIVITY_PAI is called. In the SAP standard, a new activity is not created, as this is in the code. If you wish to use activity surveys within campaign automation, you either need to copy or enhance the code from the function module CRM_SVY_ACTIVITY_PAI, or you need to create an implementation for the Business Add-In CRM_MKTCA_SVY_PAI, in which you set the activity attributes and assign the function module CRM_MKTCA_SVY_PAI to the activity survey.

Before the survey is displayed, either the function module CRM_SVY_ACTIVITY_PAI or CRM_MKTCA_SVY_PBO is run.

·        Creating new leads using a Web survey

This option is not provided in the SAP standard system. The coding for the callback function module is, however, prepared for this option. This means, it contains code examples with which the scenario can be implemented quickly.

 A survey can, for example, be made available in an Internet shop or HTML e-mail. The business partner fills out the survey. When he/she chooses the Submit button, the survey is sent back to the Survey Tool. When the Survey Tool processes the survey, function module CRM_SVY_ACTIVITY_PAI is called at exit time PAI. A new activity object is created for the specified business partner and the completed survey is attached to the activity object.

·        Import of surveys using External List Management

This option is provided in the SAP standard system.

External List Management is used to import answers for externally executed campaigns. These answers are stored in an external text file in a CSV (Comma Separated Value) format. The text file contains information on the business partners who have been contacted, and on leads and activities which have been filled out.

External List Management enables you to import external data in order to create business partners and create activities or leads for these business partners. These activities or leads can be linked to a filled out survey if this is part of the external file.

The survey questions and answers are stored in the file in separate columns. This file is imported using External List Management, and the contents are converted correspondingly. The survey questions and answers are converted to the XML string. During this conversion, the function module CRM_SVY_ACTIVITY_PAI is run, for example, in order to set the marketing attributes for the business partner.

Prerequisites

The Survey Tool provides two exit times at which the application can intervene during survey processing. Callback function modules, provided by the application, provide the interface between survey and application. The interface for the function modules is predefined by the Survey Tool.

The callback function modules can defined for each survey, under its attributes. This makes it possible to enter special function modules for each survey, which were implemented especially for this survey.

For more information, see the documentation on the Survey Tool.

Process Flow

...

       1.              Determining the scenario

Function module CRM_SURVEY_GET_SCENARIO is used to determine the scenario. The following scenarios are differentiated from each other:

·        Testing of a survey within Survey Suite

·        Processing existing activities using surveys on the activity processing interface

·        Generation of new activities using surveys within campaign automation

·        Generation of new activities using surveys on the website

·        Import of surveys using External List Management

***** determine the scenario

  DATA lv_scenario  TYPE crmt_survey_scenario.

 

  CALL FUNCTION 'CRM_SURVEY_GET_SCENARIO'

    EXPORTING

      iv_application_id = i_application_id

      iv_survey_id      = i_survey_id

      iv_survey_version = i_survey_version

      iv_language       = i_language

      iv_valueguid      = i_valueguid

      iv_valueversion   = i_valueversion

      ir_survey_values  = ir_survey_values

      it_survey_params  = it_survey_params

    IMPORTING

      ev_scenario       = lv_scenario.

       2.      Filling of scenario-specific variables

The specific variables are filled once the scenario has been determined.

·        Testing of survey within Survey Suite

If the survey is tested in the Survey Suite, the callback function module is also called. In this case, you must not carry out any further processing during this time (for example, create or change an activity). Otherwise, the corresponding function modules will produce an error.

·        Processing of existing activities using surveys on the activity processing interface

The GUID of the activity and of the current activity item are defined using the function modules CRM_INTLAY_GET_HEADER_GUID and CRM_INTLAY_GET_ITEM_GUID. These function modules only send back a GUID if the survey is processed during activity processing. In addition, the business partners assigned to the activity are read using the function module CRM_ORDER_READ. The business partners are necessary for updating the marketing attributes.

·        Generation of new activities using surveys within Campaign Automation

In this scenario, a parameter MIG is attached to the end of the survey URL. This parameter identifies the sent e-mail, the campaign and business partner. The business partners who have been contacted are determined for the marketing attribute update.

·        Generation of new activities using surveys on a website

The values of the variables, for example, business partners, need to transferred via the URL. These URL parameters are then transferred from the Survey Tool to the interface table IT_SURVEY_PARAMS to the function module CRM_SVY_ACTIVITY_PBO. They must follow a naming convention which is described in the description of the function module CRM_SVY_ACTIVITY_PAI. The business partners are necessary for the update of the marketing attributes.

·        Import of surveys using External List Management

The values of the variables, for example, business partners, are transferred from External List Management, using the interface table IT_SURVEY_PARAMS to the function module CRM_SVY_ACTIVITY_PBO. The partners are necessary for the update of the marketing attributes.

 

***** get business partner + additonal data

* GUID of HEADER

  DATA lv_header_guid    TYPE crmt_object_guid.

* GUID of ITEM

  DATA lv_item_guid      TYPE crmt_object_guid.             "#EC NEEDED

* GUID of One-Order-Object

  DATA lv_object_guid    TYPE crmt_object_guid.

* given URL parameters

  DATA ls_survey_params  TYPE crm_svy_api_parameter.

* business partners given in URL

  DATA lv_bp_id          TYPE bu_partner.

  DATA lv_bp_id_cp       TYPE bu_partner.

  DATA lv_bp_guid        TYPE bu_partner_guid.

  DATA lv_bp_guid_cp     TYPE bu_partner_guid.

 

  DATA lt_header_guid    TYPE crmt_object_guid_tab.

  DATA lt_partner        TYPE crmt_partner_external_wrkt.

  DATA ls_partner        TYPE crmt_partner_external_wrk.

 

  INCLUDE com_partner.

 

  CASE lv_scenario.

    WHEN gc_survey_scenario-test.

*   leave the call because we run in test mode in survey suite

      RETURN.

 

 

    WHEN gc_survey_scenario-one_order_ui.

*     get GUID of header from interaction layer

      CALL FUNCTION 'CRM_INTLAY_GET_HEADER_GUID'

        IMPORTING

          ev_header_guid = lv_header_guid.

 

*     get GUID of item from interaction layer

      CALL FUNCTION 'CRM_INTLAY_GET_ITEM_GUID'

        IMPORTING

          ev_item_guid = lv_item_guid.

 

*     NOTE:

*     every One-Order-Object has to decide whether the survey is

*     assigned to header or item;

*     we know that ACTIVITY has surveys which are assigned to header

      lv_object_guid = lv_header_guid.

 

*     get the business partner of the object

      INSERT lv_object_guid INTO TABLE lt_header_guid.

 

      CALL FUNCTION 'CRM_ORDER_READ'

        EXPORTING

          it_header_guid       = lt_header_guid

        IMPORTING

          et_partner           = lt_partner

        EXCEPTIONS

          document_not_found   = 1

          error_occurred       = 2

          document_locked      = 3

          no_change_authority  = 4

          no_display_authority = 5

          no_change_allowed    = 6

          OTHERS               = 7.

 

      IF sy-subrc = 0.

*       find the contact partner (e.g. sales prospect)

        READ TABLE lt_partner INTO ls_partner

             WITH KEY mainpartner = 'X'

                      partner_pft = gc_partner_pft-contact_partner.

        IF sy-subrc = 0.

          lv_bp_guid = ls_partner-bp_partner_guid.

        ENDIF.

 

*       find the contact person (e.g. of sales prospect)

        READ TABLE lt_partner INTO ls_partner

             WITH KEY mainpartner = 'X'

                      partner_pft = gc_partner_pft-contact_person.

        IF sy-subrc = 0.

          lv_bp_guid_cp = ls_partner-bp_partner_guid.

        ENDIF.

      ENDIF.

 

    WHEN gc_survey_scenario-ca_survey.

*     Mail Item GUID

      DATA lv_mig                   TYPE crmt_im_guid.

*     GUID of URL (for multiple link tracking)

      DATA lv_url_guid              TYPE crmt_im_url_guid.

*     outbound tracking table

      DATA ls_item_info             TYPE crmd_im_ml_item.

      DATA ls_head_info             TYPE crmd_im_ml_head.

 

      DATA lv_campaign_guid         TYPE cgpl_task_guid.

      DATA lv_campaign_bpartner     TYPE bu_partner.

 

*     search for MIG in Parameter list

      READ TABLE it_survey_params INTO ls_survey_params

           WITH KEY name = 'MIG'.

*     get the MIG

      lv_mig = ls_survey_params-value.

 

*     search for URL-GUID in Parameter list

      READ TABLE it_survey_params INTO ls_survey_params

           WITH KEY name = 'URLGUID'.

*     get the URL-GUID

      lv_url_guid = ls_survey_params-value.

 

*     get the relevant data out of contact tracking table via MIG

      IF lv_mig IS NOT INITIAL.

        CALL FUNCTION 'CRM_MKTCT_GET_HEAD_ITEM_LINE'

          EXPORTING

            iv_mail_item_guid = lv_mig

          IMPORTING

            es_head_info      = ls_head_info

            es_item_info      = ls_item_info

          EXCEPTIONS

            no_entry_found    = 1

            OTHERS            = 2.

 

        IF sy-subrc = 0 AND

           ( ls_head_info-project_guid IS NOT INITIAL OR

             ls_head_info-task_guid    IS NOT INITIAL ).

 

*       mapping to distinguish between B2B and B2C scenario

          CALL FUNCTION 'CRM_MKTCA_BP_CP_MAPPING_INV'

            EXPORTING

              iv_partner_guid     = ls_item_info-partner_guid

              iv_add_partner_guid = ls_item_info-add_partner_guid

            IMPORTING

              ev_bp_guid          = lv_bp_guid

              ev_cp_guid          = lv_bp_guid_cp

            EXCEPTIONS

              no_partner_guid     = 1

              illegal_bp_category = 2

              OTHERS              = 3.

          IF sy-subrc <> 0.

          ENDIF.

 

*         map campaign guid to target object parameter CAMPAIGN

          IF ls_head_info-task_guid IS INITIAL.

            lv_campaign_guid = ls_head_info-project_guid.

          ELSE.

            lv_campaign_guid = ls_head_info-task_guid.

          ENDIF.

 

*         map bpartner guids to target object parameter BPARTNER

*         B2B case

          IF lv_bp_guid IS NOT INITIAL.

            CALL FUNCTION 'BUPA_NUMBERS_READ'

              EXPORTING

                iv_partner_guid = lv_bp_guid

              IMPORTING

                ev_partner      = lv_campaign_bpartner.

*         B2C case

          ELSE.

            CALL FUNCTION 'BUPA_NUMBERS_READ'

              EXPORTING

                iv_partner_guid = lv_bp_guid_cp

              IMPORTING

                ev_partner      = lv_campaign_bpartner.

          ENDIF.

        ENDIF.

      ENDIF.

 

 

    WHEN gc_survey_scenario-icwc1.

      LOOP AT it_survey_params INTO ls_survey_params.

        CASE ls_survey_params-name.

          WHEN 'appl_bupa'.

*           contact partner (e.g. sales prospect)

            lv_bp_id = ls_survey_params-value.

          WHEN 'appl_bupa_contact'.

*           contact person (e.g. contact person of sales prospect)

            lv_bp_id_cp = ls_survey_params-value.

        ENDCASE.

      ENDLOOP.

 

 

    WHEN gc_survey_scenario-icwc2.

      LOOP AT it_survey_params INTO ls_survey_params.

        CASE ls_survey_params-name.

          WHEN 'appl_guid'.

*           GUID of the one order object

*           parameter name is in lower case

            lv_object_guid = ls_survey_params-value.

        ENDCASE.

      ENDLOOP.

 

*     get the business partner of the object

      INSERT lv_object_guid INTO TABLE lt_header_guid.

 

      CALL FUNCTION 'CRM_ORDER_READ'

        EXPORTING

          it_header_guid       = lt_header_guid

        IMPORTING

          et_partner           = lt_partner

        EXCEPTIONS

          document_not_found   = 1

          error_occurred       = 2

          document_locked      = 3

          no_change_authority  = 4

          no_display_authority = 5

          no_change_allowed    = 6

          OTHERS               = 7.

 

      IF sy-subrc = 0.

*       find the contact partner (e.g. sales prospect)

        READ TABLE lt_partner INTO ls_partner

             WITH KEY mainpartner = 'X'

                      partner_pft = gc_partner_pft-contact_partner.

        IF sy-subrc = 0.

          lv_bp_guid = ls_partner-bp_partner_guid.

        ENDIF.

 

*       find the contact person (e.g. of sales prospect)

        READ TABLE lt_partner INTO ls_partner

             WITH KEY mainpartner = 'X'

                      partner_pft = gc_partner_pft-contact_person.

        IF sy-subrc = 0.

          lv_bp_guid_cp = ls_partner-bp_partner_guid.

        ENDIF.

      ENDIF.

 

 

    WHEN gc_survey_scenario-web.

      LOOP AT it_survey_params INTO ls_survey_params.

        CASE ls_survey_params-name.

          WHEN 'appl_bupa'.

*           contact partner (e.g. sales prospect)

            lv_bp_id = ls_survey_params-value.

          WHEN 'appl_bupa_contact'.

*           contact person (e.g. contact person of sales prospect)

            lv_bp_id_cp = ls_survey_params-value.

        ENDCASE.

      ENDLOOP.

 

 

    WHEN gc_survey_scenario-mic.

      LOOP AT it_survey_params INTO ls_survey_params.

        CASE ls_survey_params-name.

          WHEN 'appl_bupa'.

*           contact partner (e.g. sales prospect)

            lv_bp_id = ls_survey_params-value.

          WHEN 'appl_bupa_contact'.

*           contact person (e.g. contact person of sales prospect)

            lv_bp_id_cp = ls_survey_params-value.

        ENDCASE.

      ENDLOOP.

  ENDCASE.

       3.      Defaulting the marketing attributes for business partners

In the Survey Suite editor, questions and answer options can be linked with marketing attributes and their values. When the survey is filled out for the first time, the business partner marketing attributes valid at this point in time are merged into the corresponding answers. This defaulting of answer options takes place in the function module CRM_SURVEY_MKTATTR_PRESELECT.

Example:

The survey contains a question about the business partner’s hobbies: What are your hobbies? Possible answer options are: drawing; sport; music; gardening.

The survey is first filled out by a business partner. The business partner marketing attributes valid at this point in time are merged into the answer options, that is, sport and music, because these are the business partner’s current hobbies.

***** convert IDs into GUIDs of business partner
***** check BP type
***** preset marketing attributes in survey

* NOTE
* We preset the marketing attributes of the given business partners
* ONLY if we run in CREATE MODE. This means only if the survey PBO is
* called for the first time we preset the marketing attributes.
* If the survey PBO is called for the second time (value GUID was
* created) we don't preset the marketing attributes because in this case
* we want to show the survey document as it was created/changed at last
* (in this case the survey is a snapshot).

  
IF i_valueguid IS INITIAL.
    
CALL FUNCTION 'CRM_SURVEY_MKTATTR_PRESELECT'
      
EXPORTING
        iv_bp_id         = lv_bp_id
        iv_bp_id_cp      = lv_bp_id_cp
        iv_bp_guid       = lv_bp_guid
        iv_bp_guid_cp    = lv_bp_guid_cp
        ir_survey_values = ir_survey_values
        it_survey_params = it_survey_params.
  
ENDIF.

The defaulting of answer options with the currently valid business partner marketing attributes takes places only the first time a survey is filled out. If the survey has already been filled out, and is only edited a second time, the answer option values set the last time the survey was filled out are displayed for all survey questions. That means, for question and answer options that do not refer to the marketing attributes, the currently valid business partner marketing attributes are NOT merged.

       4.      Copying variables for campaign automation

Several necessary variables are set as hidden fields in the survey for the generation of new activities using surveys within campaign automation.

*//// SPECIAL for Campaign Automation
  
IF lv_scenario = gc_survey_scenario-ca_survey.
***** Add Hidden fields
    
DATA lt_hidden_fields  TYPE crm_svy_api_parameter_t.
    
DATA ls_hidden_fields  TYPE crm_svy_api_parameter.

*   Add new hidden fields
    
CLEAR lt_hidden_fields[].

*   CAMPAIGN
    ls_hidden_fields-name  =  
'appl_CAMPAIGN'.
    ls_hidden_fields-
value =  lv_campaign_guid.
    
APPEND ls_hidden_fields TO lt_hidden_fields.

*   BPARTNER
    ls_hidden_fields-name  =  
'appl_BPARTNER'.
    ls_hidden_fields-
value =  lv_campaign_bpartner.
    
APPEND ls_hidden_fields TO lt_hidden_fields.

*   MIG
    ls_hidden_fields-name  =  
'MIG'.
    ls_hidden_fields-
value =  lv_mig.
    
APPEND ls_hidden_fields TO lt_hidden_fields.

*   URL-GUID
    ls_hidden_fields-name  =  
'URLGUID'.
    ls_hidden_fields-
value =  lv_url_guid.
    
APPEND ls_hidden_fields TO lt_hidden_fields.

    
CALL METHOD ir_survey_values->hidden_fields_add
      
EXPORTING
        it_hidden_fields = lt_hidden_fields.
  
ENDIF.

Function module CRM_SVY_ACTIVITY_PAI

     Defining the XML string and rating values

The survey XML string, the maximum number of points for the survey, the number of points achieved for the currently filled survey, and the percentage of the points achieved are defined using the function module CRM_SURVEY_GET_RATING.

The XML string is needed to save the contents of the filled survey when the activity is saved.

***** get the value XML string + the rating values
* survey value
  
DATA lv_svy_value_xml      TYPE crm_svy_db_svs_xml.
* optimum survey value
  
DATA lv_svy_value_optimum  TYPE f.                        "#EC NEEDED
* archieved survey value
  
DATA lv_svy_value_achieved TYPE f.                        "#EC NEEDED
* reached survey value as percentage
  
DATA lv_svy_percentage     TYPE crmt_survey_percentage.

  
CALL FUNCTION 'CRM_SURVEY_GET_RATING'
    
EXPORTING
      ir_survey_values      = ir_survey_values
    
IMPORTING
      ev_svy_value_xml_hex  = lv_svy_value_xml
      ev_svy_value_optimum  = lv_svy_value_optimum
      ev_svy_value_achieved = lv_svy_value_achieved
      ev_svy_percentage     = lv_svy_percentage
    
EXCEPTIONS
      error_occured         = 
1
      
OTHERS                = 2.

  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    
EXIT.
  
ENDIF. 

     Defining the scenario

The scenario is defined using function module CRM_SURVEY_GET_SCENARIO. The following scenarios exist:

     Test survey within Survey Suite

     Process existing activities using surveys on activity interface

Here, the activity is first created, then processed on the activity interface.

     Create new activities using surveys within campaign automation

Here, the survey is the starting point of processing. An e-mail is sent with a URL. The URL links to a survey. The survey is displayed and filled out in a Web browser. When the user chooses the Submit button in the survey, the survey is processed. An activity is then created in function module CRM_SVY_ACTIVITY_PAI and the filled survey is linked to the activity.

     Create new activities using surveys on a Web site

Here, the survey is the starting point of processing. The survey is displayed and filled out in a Web browser. When the user chooses the Submit button, the survey is processed. An activity is then created in function module CRM_SVY_ACTIVITY_PAI and the filled survey is linked to the activity.

     Import surveys using External List Management

The survey questions and answers are in a file. External List Management is used to import these files and the contents is converted. The survey questions and answers are converted to an XML string. The function module CRM_SVY_ACTIVITY_PAI is run during this conversion, in order to set the business partner marketing attributes.

 

***** determine the scenario
  
DATA lv_scenario  TYPE crmt_survey_scenario.

  
CALL FUNCTION 'CRM_SURVEY_GET_SCENARIO'
    
EXPORTING
      iv_application_id = i_application_id
      iv_survey_id      = i_survey_id
      iv_survey_version = i_survey_version
      iv_language       = i_language
      iv_valueguid      = i_valueguid
      iv_valueversion   = i_valueversion
      ir_survey_values  = ir_survey_values
      it_survey_params  = it_survey_params
    
IMPORTING
      ev_scenario       = lv_scenario.

     Filling the scenario specific variables

Once the scenario has been defined, the specific variables are filled.

     Test survey within Survey Suite

If the survey is tested in the Survey Suite, the callback function module is also called. In this case, no further processing (create or change an activity) can be carried out, as the corresponding function modules will otherwise display an error.

     Process existing activities using surveys on the activity interface

The activity GUID and the current activity item are defined using the function modules CRM_INTLAY_GET_HEADER_GUID and CRM_INTLAY_GET_ITEM_GUID.  These function modules only return a GUID if the survey is processed during activity processing on the activity interface. In addition, the partners assigned to the activity are read using function module CRM_ORDER_READ. The partners are needed to update the marketing attributes.

     Create new activities using surveys within campaign automation

In the standard delivery, the variable values (for example, description of new activity; transaction type of new activity; business partner) are filled in method PROCESS_SVY_PAI_FOR_CA in Business Add-In CRM_MKTCA_SVY_PAI. These values are copied to the function module CRM_SVY_ACTIVITY_PAI using interface table IT_SURVEY_PARAMS.

     Create new activities using surveys on a Web site

The variable values (for example, description, transaction type of new activity, business partner) must be copied using the URL. These URL parameters are copied from the Survey Tool to function module CRM_SVY_ACTIVITY_PAI via interface table IT_SURVEY_PARAMS. They must follow a naming convention. This is described later.

     Import surveys using External List Management

The variable values (for example, new activity GUID, business partner) are copied from External List Management to function module CRM_SVY_ACTIVITY_PAI via interface table IT_SURVEY_PARAMS.

If the survey is processed on a Web site, the application must attach the following parameters to the survey URL:

      appl_id

This parameter has the value WEB for the Web scenario

      appl_bupa

This parameter contains the business partner ID, for example, organization in B2B, person in B2C, entered as a contact person in the activity.

      appl_bupa_contact

This parameter contains the business partner ID, for example, person entered as contact person in the activity.

      appl_transaction_type

This parameter contains the activity transaction type. This is necessary if a new activity is to be created.

The URL parameters are copied to the callback function module in the import parameter IT_SURVEY_PARAMS. The parameters are used to define the scenario in which the survey is being processed.

 

* processing mode
  
DATA lv_process_mode   TYPE crmt_mode.
* GUID of HEADER
  
DATA lv_header_guid    TYPE crmt_object_guid.
* GUID of ITEM
  
DATA lv_item_guid      TYPE crmt_object_guid.             "#EC NEEDED
* GUID of One-Order-Object
  
DATA lv_object_guid    TYPE crmt_object_guid.
* given URL parameters
  
DATA ls_survey_params  TYPE crm_svy_api_parameter.
* business partners given in URL
  
DATA lv_bp_id          TYPE bu_partner.
  
DATA lv_bp_id_cp       TYPE bu_partner.
  
DATA lv_bp_guid        TYPE bu_partner_guid.
  
DATA lv_bp_guid_cp     TYPE bu_partner_guid.
* GUID of campaign
  
DATA lv_campaign_guid  TYPE cgpl_project_guid.
* GUID of campaign element
  
DATA lv_task_guid      TYPE cgpl_task_guid.
* process type of the object (needed for the CREATE mode)
  
DATA lv_process_type   TYPE crmt_process_type.
* description
  
DATA lv_description    TYPE crmt_process_description.
* language key of description of one order object
  
DATA lv_description_language  TYPE crmt_process_description_langu.
* direction
  
DATA lv_direction      TYPE crmt_direction.
* category
  
DATA lv_category       TYPE crmt_activity_category.
* date
  
DATA ls_date           TYPE bapibus20001_appointment_ins.
* status (user status)
  
DATA ls_status         TYPE crmt_status_com.
* reason
  
DATA ls_reason         TYPE bapibus2000110_reason_ins.
* result
DATA ls_result         TYPE bapibus2000110_outcome_ins.
* document flow (link campaign with object)
  
DATA lt_doc_flow       TYPE crmt_doc_flow_comt.

  
DATA lt_header_guid    TYPE crmt_object_guid_tab.
  
DATA lt_partner        TYPE crmt_partner_external_wrkt.
  
DATA ls_partner        TYPE crmt_partner_external_wrk.

  
INCLUDE com_partner.

  
CASE lv_scenario.
*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-test.
*   leave the call because we run in test mode in survey suite
      
RETURN.
*   -----------------------------------------------------------------

*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-one_order_ui.
      lv_process_mode = gc_mode-
change.

*     get GUID of header from interaction layer
      
CALL FUNCTION 'CRM_INTLAY_GET_HEADER_GUID'
        
IMPORTING
          ev_header_guid = lv_header_guid.

*     get GUID of item from interaction layer
      
CALL FUNCTION 'CRM_INTLAY_GET_ITEM_GUID'
        
IMPORTING
          ev_item_guid = lv_item_guid.

*     NOTE:
*     every One-Order-Object has to decide whether the survey is
*     assigned to header or item;
*     we know that ACTIVITY has surveys which are assigned to header
      lv_object_guid = lv_header_guid.

*     get the business partner of the object
      
INSERT lv_object_guid INTO TABLE lt_header_guid.

      
CALL FUNCTION 'CRM_ORDER_READ'
        
EXPORTING
          it_header_guid       = lt_header_guid
        
IMPORTING
          et_partner           = lt_partner
        
EXCEPTIONS
          document_not_found   = 
1
          error_occurred       = 
2
          document_locked      = 
3
          no_change_authority  = 
4
          no_display_authority = 
5
          no_change_allowed    = 
6
          
OTHERS               = 7.

      
IF sy-subrc = 0.
*       find the contact partner (e.g. activity partner)
        
READ TABLE lt_partner INTO ls_partner
             
WITH KEY mainpartner = 'X'
                      partner_pft = gc_partner_pft-contact_partner.
        
IF sy-subrc = 0.
          lv_bp_guid = ls_partner-bp_partner_guid.
        
ENDIF.

*       find the contact person (e.g. of activity partner)
        
READ TABLE lt_partner INTO ls_partner
             
WITH KEY mainpartner = 'X'
                      partner_pft = gc_partner_pft-contact_person.
        
IF sy-subrc = 0.
          lv_bp_guid_cp = ls_partner-bp_partner_guid.
        
ENDIF.
      
ENDIF.
*   -----------------------------------------------------------------

*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-ca_survey.
      lv_process_mode = gc_mode-
create.

*     NOTE:
*     The following parameters are filled into the IT_SURVEY_PARAMS
*     table in the default implementation of BAdI CRM_MKTCA_SVY_PAI.
*     This means in the CA survey scenario a Marketing survey template
*     is processed. In the PAI logic of this Marketing survey template

template
*     the BAdI is called. In that BAdI the CA specific parameters are
*     determined (via MIG - Mail Item GUID) and appended to the
*     table IT_SURVEY_PARAMS. Then the object specifiy PAI (e.g.
*     CRM_SVY_ACTIVITY_PAI) is called.
*
*     If you want to use an Activity survey template directly in the
*     CA survey scenario you can copy the function module
*     CRM_SVY_ACTIVITY_PAI and change the following coding (see BEGIN
*     and END blocks):
*     Mail Item GUID
      
DATA lv_mig                   TYPE crmt_im_guid.
      
DATA lv_mig_char32            TYPE crmt_object_guid32.
*     GUID of URL (for multiple link tracking)
      
DATA lv_url_guid              TYPE crmt_im_url_guid.
      
DATA lv_url_guid_char32       TYPE crmt_object_guid32.
*     outbound tracking table
      
DATA ls_item_info             TYPE crmd_im_ml_item.
      
DATA ls_head_info             TYPE crmd_im_ml_head.


*     search for MIG in Parameter list
      
READ TABLE it_survey_params INTO ls_survey_params
           
WITH KEY name = 'MIG'.
*     get the MIG
      lv_mig = ls_survey_params-
value.

*     search for URL-GUID in Parameter list
      
READ TABLE it_survey_params INTO ls_survey_params
           
WITH KEY name = 'URLGUID'.
*     get the URL-GUID
      lv_url_guid = ls_survey_params-
value.

***/// BEGIN activate coding lines
**     get the relevant data out of contact tracking table via MIG
*      IF lv_mig IS NOT INITIAL.
*        CALL FUNCTION 'CRM_MKTCT_GET_HEAD_ITEM_LINE'
*          EXPORTING
*            iv_mail_item_guid = lv_mig
*          IMPORTING
*            es_head_info      = ls_head_info
*            es_item_info      = ls_item_info
*          EXCEPTIONS
*            no_entry_found    = 1
*            OTHERS            = 2.
*
*        IF sy-subrc = 0 AND
*           ( ls_head_info-project_guid IS NOT INITIAL OR
*             ls_head_info-task_guid    IS NOT INITIAL ).
*
**       mapping to distinguish between B2B and B2C scenario
*          CALL FUNCTION 'CRM_MKTCA_BP_CP_MAPPING_INV'
*            EXPORTING
*              iv_partner_guid     = ls_item_info-partner_guid
*              iv_add_partner_guid = ls_item_info-add_partner_guid
*            IMPORTING
*              ev_bp_guid          = lv_bp_guid
*              ev_cp_guid          = lv_bp_guid_cp
*            EXCEPTIONS
*              no_partner_guid     = 1
*              illegal_bp_category = 2
*              OTHERS              = 3.
*          IF sy-subrc = 0.
*            CALL FUNCTION 'BUPA_NUMBERS_GET'
*              EXPORTING
*                iv_partner_guid = lv_bp_guid
*              IMPORTING
*                ev_partner      = lv_bp_id.
*
*            CALL FUNCTION 'BUPA_NUMBERS_GET'
*              EXPORTING
*                iv_partner_guid = lv_bp_guid_cp
*              IMPORTING
*                ev_partner      = lv_bp_id_cp.
*          ELSE.
**           do nothing
*            RETURN.
*          ENDIF.
*
**         fill additional parameters:
**            change the process type if you don't use the given one
*          lv_process_type         = '0000'.
*          lv_description          = 'enter your description'.
*          lv_description_language = sy-langu.
*          lv_campaign_guid        = ls_head_info-project_guid.
*          lv_task_guid            = ls_head_info-task_guid.
*          lv_direction            = '0'.    " INBOUND
*          lv_category             = 'URL'.  " URL
*          ls_date-appt_type       = 'enter your type'.
*          ls_date-timestamp_from  = 'enter your time stamp'.
*          ls_date-timestamp_to    = 'enter your time stamp'.
*          ls_date-timezone_from   = 'enter your time zone'.
*          ls_date-timezone_to     = 'enter your time zone'.
*          ls_status-status        = 'enter your user status'.
*          ls_status-activate      = true.
*          ls_reason-code_group    = 'enter your code group here'.
*          ls_reason-code          = 'enter your code here'.
*          ls_result-code_group    = 'enter your code group here'.
*          ls_result-code          = 'enter your code here'.
*           ..........
*        ENDIF.
*      ENDIF.
***/// END activate coding lines

***/// BEGIN de-activate coding lines
      
LOOP AT it_survey_params INTO ls_survey_params.
        
CASE ls_survey_params-name.
          
WHEN 'CA_bp_id'.
*           activity partner
            lv_bp_id = ls_survey_params-
value.
          
WHEN 'CA_cp_id'.
*           contact person of activity partner
            lv_bp_id_cp = ls_survey_params-
value.
          
WHEN 'CA_campaign_guid'.
            lv_campaign_guid = ls_survey_params-
value.
          
WHEN 'CA_task_guid'.
            lv_task_guid = ls_survey_params-
value.
          
WHEN 'CA_process_type'.
*           transaction type
            lv_process_type = ls_survey_params-
value.
          
WHEN 'CA_description'.
*           description of newly created object
            lv_description = ls_survey_params-
value.
          
WHEN 'CA_description_language'.
*           language of description of newly created object
            lv_description_language = ls_survey_params-
value.
          
WHEN 'CA_ACT_direction'.
*           direction of newly created object
            lv_direction = ls_survey_params-
value.
          
WHEN 'CA_ACT_category'.
*           category of newly created object
            lv_category = ls_survey_params-
value.
          
WHEN 'CA_ACT_date_appt_type'.
*           date
            ls_date-appt_type = ls_survey_params-
value.
          
WHEN 'CA_ACT_date_timestamp_from'.
*           date
            ls_date-timestamp_from = ls_survey_params-
value.
          
WHEN 'CA_ACT_date_timestamp_to'.
*           date
            ls_date-timestamp_to = ls_survey_params-
value.
          
WHEN 'CA_ACT_date_timezone_from'.
*           date
            ls_date-timezone_from = ls_survey_params-
value.
          
WHEN 'CA_ACT_date_timezone_to'.
*           date
            ls_date-timezone_to = ls_survey_params-
value.
          
WHEN 'CA_ACT_status'.
*           user status of newly created object
            ls_status-status = ls_survey_params-
value.
*           set status to active
            ls_status-activate = true.
          
WHEN 'CA_ACT_reason_code_group'.
*           reason of newly created object
            ls_reason-code_group = ls_survey_params-
value.
          
WHEN 'CA_ACT_reason_code'.
*           reason of newly created object
            ls_reason-
code = ls_survey_params-value.
          
WHEN 'CA_ACT_result_code_group'.
*           reason of newly created object
            ls_result-code_group = ls_survey_params-
value.
          
WHEN 'CA_ACT_result_code'.
*           reason of newly created object
            ls_result-
code = ls_survey_params-value.
        
ENDCASE.
      
ENDLOOP.
***/// END de-activate coding lines

*     fill doc flow to link campaign with object
      
CALL FUNCTION 'CRM_SURVEY_FILL_1O_DOCFLOW'
        
EXPORTING
          iv_campaign_guid = lv_campaign_guid
          iv_task_guid     = lv_task_guid
        
IMPORTING
          et_doc_flow      = lt_doc_flow.
*   ------------------------------------------------------------

-----------------------------------------------------------------

*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-icwc1.
      lv_process_mode = gc_mode-
create.

      
LOOP AT it_survey_params INTO ls_survey_params.
        
CASE ls_survey_params-name.
          
WHEN 'appl_bupa'.
*           activity partner
            lv_bp_id = ls_survey_params-
value.
          
WHEN 'appl_bupa_contact'.
*           contact person of activity partner
            lv_bp_id_cp = ls_survey_params-
value.
          
WHEN 'appl_transaction_type'.
*           transaction type
            lv_process_type = ls_survey_params-
value.
          
WHEN 'appl_transaction_descr'.
*           description of newly created object
            lv_description = ls_survey_params-
value.
        
ENDCASE.
      
ENDLOOP.
*   -----------------------------------------------------------------

*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-icwc2.
      lv_process_mode = gc_mode-
change.

      
LOOP AT it_survey_params INTO ls_survey_params.
        
CASE ls_survey_params-name.
          
WHEN 'appl_guid'.
*           GUID of the one order object
*           parameter name is in lower case
            lv_object_guid = ls_survey_params-
value.
        
ENDCASE.
      
ENDLOOP.

*     get the business partner of the object
      
INSERT lv_object_guid INTO TABLE lt_header_guid.

      
CALL FUNCTION 'CRM_ORDER_READ'
        
EXPORTING
          it_header_guid       = lt_header_guid
        
IMPORTING
          et_partner           = lt_partner
        
EXCEPTIONS
          document_not_found   = 
1
          error_occurred       = 
2
          document_locked      = 
3
          no_change_authority  = 
4
          no_display_authority = 
5
          no_change_allowed    = 
6
          
OTHERS               = 7.

      
IF sy-subrc = 0.
*       find the contact partner (e.g. activity partner)
        
READ TABLE lt_partner INTO ls_partner
             
WITH KEY mainpartner = 'X'
                      partner_pft = gc_partner_pft-contact_partner.
        
IF sy-subrc = 0.
          lv_bp_guid = ls_partner-bp_partner_guid.
        
ENDIF.

*       find the contact person (e.g. of activity partner)
        
READ TABLE lt_partner INTO ls_partner
             
WITH KEY mainpartner = 'X'
                      partner_pft = gc_partner_pft-contact_person.
        
IF sy-subrc = 0.
          lv_bp_guid_cp = ls_partner-bp_partner_guid.
        
ENDIF.
      
ENDIF.
*   -----------------------------------------------------------------

*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-web.
      lv_process_mode = gc_mode-
create.

      
LOOP AT it_survey_params INTO ls_survey_params.
        
CASE ls_survey_params-name.
          
WHEN 'appl_bupa'.
*           activity partner
            lv_bp_id = ls_survey_params-
value.
          
WHEN 'appl_bupa_contact'.
*           contact person of activity partner
            lv_bp_id_cp = ls_survey_params-
value.
*           transaction type
          
WHEN 'appl_transaction_type'.
            lv_process_type = ls_survey_params-
value.
        
ENDCASE.
      
ENDLOOP.
*   -----------------------------------------------------------------

*   -----------------------------------------------------------------
    
WHEN gc_survey_scenario-mic.
      lv_process_mode = 
space.

*     get the given business partners
*     (needed for an update of Marketing Attributes)
      
LOOP AT it_survey_params INTO ls_survey_params.
        
CASE ls_survey_params-name.
          
WHEN 'appl_bupa'.
*           activity partner
            lv_bp_id = ls_survey_params-
value.
          
WHEN 'appl_bupa_contact'.
*           contact person of activity partner
            lv_bp_id_cp = ls_survey_params-
value.
          
WHEN 'appl_transaction_guid'.
*           GUID of object
            lv_object_guid = ls_survey_params-
value.
        
ENDCASE.
      
ENDLOOP.
*     at the bottom of this fctn mod the Marketing Attributes are filled
*   -----------------------------------------------------------------
  
ENDCASE.

     Filling ORDER_MAINTAIN import tables for survey data

The import tables IT_SURVEY and LT_INPUT_FIELDS are filled for the function module call CRM_ORDER_MAINTAIN using the function module CRM_SURVEY_FILL_1O_SURVEY.

 

***** put the Survey-Data into input structure of ORDER_MAINTAIN
* table with changed fields for ORDER_MAINTAIN
  
DATA lt_input_fields       TYPE crmt_input_field_tab.

* input structure of SURVEY for ORDER_MAINTAIN
  
DATA lt_survey              TYPE crmt_survey_comt.
  
DATA ls_survey              TYPE crmt_survey_com.

  
IF lv_process_mode IS NOT INITIAL.
*   fill input structure
*   ....................................................................
    ls_survey-ref_kind         = gc_object_kind-orderadm_h.
    ls_survey-surveyid         = i_survey_id.
    ls_survey-surveyversion    = i_survey_version.
    ls_survey-valueguid        = i_valueguid.
    ls_survey-valueversion     = i_valueversion.
    ls_survey-valuexml         = lv_svy_value_xml.
    ls_survey-evaluation_infos = cs_evaluation_infos.
*   ....................................................................

    
CALL FUNCTION 'CRM_SURVEY_FILL_1O_SURVEY'
      
EXPORTING
        iv_process_mode = lv_process_mode
        iv_object_guid  = lv_object_guid
        is_survey       = ls_survey
      
IMPORTING
        et_survey       = lt_survey
      
CHANGING
        ct_input_fields = lt_input_fields.
  
ENDIF.

 

      Filling of ORDER_MAINTAIN import tables for activity data

The import tables IT_ACTIVITY_H and LT_INPUT_FIELDS are filled for the function module call CRM_ORDER_MAINTAIN using routine BUILD_LT_ACTIVITY_H.

 

*//// special for ACTIVITY
*//// set attributes of activity
* input table for lead header structure
  
DATA lt_activity_h         TYPE crmt_activity_h_comt.
  
DATA ls_activity_h         TYPE crmt_activity_h_com.

* fill the following only if we run in CA
  
IF lv_scenario = gc_survey_scenario-ca_survey.
    ls_activity_h-direction  = lv_direction.
    ls_activity_h-category   = lv_category.

    
PERFORM build_lt_activity_h
      
USING    lv_process_mode
              lv_scenario
               lv_object_guid
      
CHANGING lt_input_fields
               ls_activity_h
               lt_activity_h.
  
ENDIF.

     Copying products from survey to activity

The Survey Editor is used to define a survey template in the Survey Suite. This editor has an expert mode (can be activated via the menu). In export mode, an ID can be assigned to each question and answer.

The following code example shows how to copy products from the survey. Only table LT_ORDERADM_I must be filled. The import table CT_INPUT_FIELDS of function module CRM_ORDER_MAINTAIN is built in function module CRM_SVY_ACTIVITY_PAI_CREATE or CRM_SVY_ACTIVITY_PAI_CHANGE.

 

*//// get the products
*
* NOTE
* The following commented coding is an example how you can use the
* survey in order to fill the Lead positions with products.
* Requirement:
* You have defined in the survey for some questions a special
* question ID. Here in that example you have defined product_1 for
* a question and PRODUCT_2 for another question (please remember:
* case sensitive).
* In the survey you have defined for that special questions the answer
* IDs in such a way that every answer ID represents a product ID.


  
DATA lt_values      TYPE survy_t_all_values.              "#EC *
  
DATA ls_values      TYPE survy_s_all_values.              "#EC *
  
DATA ls_orderadm_i  TYPE crmt_orderadm_i_com.             "#EC *
  
DATA lt_orderadm_i  TYPE crmt_orderadm_i_comt.            "#EC *

*  CALL METHOD ir_survey_values->values_get_all
*    IMPORTING
*      et_all_values = lt_values.
*
*  LOOP AT lt_values INTO ls_values.
*
*    IF ls_values-question_id = 'product_1'.
*      ls_orderadm_i-ordered_prod = ls_values-value.
*      INSERT ls_orderadm_i INTO TABLE lt_orderadm_i.
*    ENDIF.
*
*    IF ls_values-question_id = 'PRODUCT_2'.
*      ls_orderadm_i-ordered_prod = ls_values-value.
*      INSERT ls_orderadm_i INTO TABLE lt_orderadm_i.
*    ENDIF.
*
*  ENDLOOP. 

     Create new activity

A new activity can be created using function module CRM_SVY_ACTIVITY_PAI_CREATE.

 

*//// create new activity
  
IF lv_process_mode = gc_mode-create.
    
CALL FUNCTION 'CRM_SVY_ACTIVITY_PAI_CREATE'
      
EXPORTING
        iv_process_type           = lv_process_type
        iv_description            = lv_description
        iv_description_language   = lv_description_language
        iv_bp_id_activity_partner = lv_bp_id
        iv_bp_id_contact_person   = lv_bp_id_cp
        it_activity_h             = lt_activity_h
        it_survey                 = lt_survey
        it_orderadm_i             = lt_orderadm_i
        is_date                   = ls_date
        is_status                 = ls_status
        is_reason                 = ls_reason
        is_result                 = ls_result
      
IMPORTING
        ev_object_guid            = lv_object_guid
      
CHANGING
        ct_input_fields           = lt_input_fields
        ct_doc_flow               = lt_doc_flow
      
EXCEPTIONS
        error_occured             = 
1
        
OTHERS                    = 2.

    
IF sy-subrc <> 0.
*   we raise the message as X message because an error here
*   is a reason to stop
      
MESSAGE ID sy-msgid TYPE 'X' NUMBER sy-msgno
              
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    
ENDIF.

  
ENDIF.

     Change existing activity

An existing activity can be changed using function module CRM_SVY_ACTIVITY_PAI_CHANGE.

*//// change Activity
*//// call ORDER_MAINTAIN with SURVEY data + ACTIVITY data
  
IF lv_process_mode = gc_mode-change.
    
CALL FUNCTION 'CRM_SVY_ACTIVITY_PAI_CHANGE'
      
EXPORTING
        iv_object_guid  = lv_object_guid
        it_activity_h   = lt_activity_h
        it_survey       = lt_survey
        it_orderadm_i   = lt_orderadm_i
        is_status       = ls_status
      
CHANGING
        ct_input_fields = lt_input_fields
      
EXCEPTIONS
        error_occured   = 
1
        
OTHERS          = 2.

    
IF sy-subrc <> 0.
*   we raise the message as X message because an error here
*   is a reason to stop
      
MESSAGE ID sy-msgid TYPE 'X' NUMBER sy-msgno
              
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    
ENDIF.

  
ENDIF.

     Update business partner marketing attributes

In the Survey Suite editor, questions and answers can be linked to marketing attributes and their values. Once these questions have been answered, the marketing attributes can be changed for the business partners in LV_BP_ID and LV_BP_ID_CP via function module CRM_SURVEY_MKTATTR_UPDATE.

The changed marketing attributes are only saved when the function module CRM_ORDER_SAVE and a COMMIT WORK has been executed.

If the business partner marketing attributes are to be saved immediately (not using the function module CRM_ORDER_SAVE), the function module code CRM_SURVEY_MKTATTR_UPDATE must be copied. At the end of this function module, the function module CRM_SVY_MKTATTR_UPDATE is called. To save marketing attributes immediately, the import parameter SAVE must be set to X. A COMMIT WORK finally saves the data in the database.

 

***** convert IDs into GUIDs of business partner
***** check BP type
***** update marketing attributes for given business partner(s)
  
CALL FUNCTION 'CRM_SURVEY_MKTATTR_UPDATE'
    
EXPORTING
      iv_object_guid   = lv_object_guid
      iv_bp_id         = lv_bp_id
      iv_bp_id_cp      = lv_bp_id_cp
      iv_bp_guid       = lv_bp_guid
      iv_bp_guid_cp    = lv_bp_guid_cp
      ir_survey_values = ir_survey_values
      it_survey_params = it_survey_params
    
EXCEPTIONS
      parameter_error  = 
1
      error_occurred   = 
2
      
OTHERS           = 3.

  
IF sy-subrc <> 0.
    
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  
ENDIF.

     Saving the activity

The activity must be saved when creating new activities using surveys within campaign automation and creating new activities using surveys on a Web site. To do so, the function module CRM_ORDER_SAVE is called.

A COMMIT WORK finally saves the data in the database.

The GUID of the activity created is returned via parameter appl_ActivityGuid in the export table ET_SURVEY_PARAMS.

 

*//// save the object
* Note:
* We aren't allowed to call CRM_ORDER_SAVE and COMMIT WORK if we run in
* the One-Order. If we would do this the One-Order would dump during
* save because of duplicate records in CRMD_ORDERADM_H.

  
IF lv_scenario = gc_survey_scenario-ca_survey OR
     lv_scenario = gc_survey_scenario-icwc1     
OR
     lv_scenario = gc_survey_scenario-web.
    
DATA lt_objects_to_save  TYPE crmt_object_guid_tab.

*   build save table
    
INSERT lv_object_guid INTO TABLE lt_objects_to_save.

*   save object
    
CALL FUNCTION 'CRM_ORDER_SAVE'
      
EXPORTING
        it_objects_to_save = lt_objects_to_save
      
EXCEPTIONS
        document_not_saved = 
1
        
OTHERS             = 2.

    
IF sy-subrc <> 0.
*   we raise the message as X message because an error here
*   is a reason to stop
      
MESSAGE ID sy-msgid TYPE 'X' NUMBER sy-msgno
              
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      
EXIT.
    
ELSE.
      
IF lv_mig IS NOT INITIAL.
*       casting: HEX16 -> CHAR32
        lv_mig_char32      = lv_mig.
        lv_url_guid_char32 = lv_url_guid.
*       fill multiple link tracking table
        
CALL FUNCTION 'CRM_IM_UPD_CLICK_CNTR'
          
EXPORTING
            iv_url_guid     = lv_url_guid_char32
            iv_mig          = lv_mig_char32
            iv_upd_old_cntr = 
'X'
          
EXCEPTIONS
            no_update       = 
1
            
OTHERS          = 2.
*     we don't care about the return code
      
ENDIF.

*     bring data to database
      
COMMIT WORK AND WAIT.
*     deliver back the activity guid for Web scenarios
*     (e.g. IC web client with interactive scripting)
      
DATA application_param TYPE crm_svy_api_parameter.
      application_param-name  = 
'appl_ActivityGuid'.
      application_param-
value = lv_object_guid.
      
APPEND application_param TO et_survey_params.
    
ENDIF.
  
ENDIF.

 

End of Content Area