CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
faisal_pc
Active Contributor

Hi All,

I have seen that we have very less topics which are discussing about loyalty management and questions related to them are hardly answered. I would like to share a document which I have recently worked and is about the membership creation. This is about how can we create a membership with an FM when your requirement is to create a membership for a member which is a common requirement.

First thing is that, we have to check whether a membership already exists for the member and that can be done by the FM CRM_LOY_MSH_READ_SINGLE. You can pass the member guid as below.

* Check whether the membership is already created for this member.

    CALL FUNCTION 'CRM_LOY_MSH_READ_SINGLE'

      EXPORTING

        iv_member_guid            = l_v_member_guid

      IMPORTING

        et_membership             = l_is_membership

      EXCEPTIONS

        loy_system_failure        = 1

        loy_communication_failure = 2

        OTHERS                    = 3.

Now, if the membership is not already created for the member we go ahead with the creation of membership. There are three FMs for this purpose out of which one is an RFC.

1) CRM_LOY_MEMBERSHIP_CREATE

2) CRM_LOY_MSH_CREATE_SINGLE

3) LOY_MEMBERSHIP_CREATE_RFC


Out of above 3, CRM_LOY_MSH_CREATE_SINGLE doesn't have a field USAGE (purpose of use in table LOYD_MSH_MEMS). So if your requirement doesn't have usage field you can use this and is an easy way of creating membership.


Example code below:


CALL FUNCTION 'CRM_LOY_MSH_CREATE_SINGLE'

        EXPORTING

          IV_MEMBERSHIP_TYPE   =      'STD21MEM'

          iv_member_guid                 =      lv_guid

          iv_program_guid                 =      lv_program_guid

          iv_campaign_code              =      lv_cpg_guid

       EXCEPTIONS

         LOY_SYSTEM_FAILURE              = 1

         LOY_COMMUNICATION_FAILURE  = 2

         OTHERS                                       = 3

If in case you need the field usage also needs other fields (any fields of table LOYD_MSH_MEMS), then go for FM CRM_LOY_MEMBERSHIP_CREATE or LOY_MEMBERSHIP_CREATE_RFC. Both of them are having same inputs. A sample code for the creation of membership with the FM is below. We have to call FM CRM_LOY_MEMBERSHIP_SAVE/LOY_MEMBERSHIP_SAVE_RFC after the call of above FMs for the save of memberships.



*Fill the work area with the data to be passed to the internal table of function module to create membership.

    l_wa_mem_data-memb_guid       = l_v_member_guid.        "Member GUID

    l_wa_mem_data-loy_prog_guid   = l_v_program_guid.       "Program GUID

    l_wa_mem_data-application        = l_c_application.        "Application as Membership (MSH)

    l_wa_mem_data-mems_type       = l_c_mem_type.           "Membership type as standard membership (STDMEM)

    l_wa_mem_data-status               = l_c_status.             "Status E0002

    l_wa_mem_data-purpose_of_use  = l_v_usage.              "Usage field (Purpose_of_use field in table)

    l_wa_mem_data-memb_id           = l_v_partner. "Member ID as BP id

    l_wa_mem_data-contact_id          =  l_v_partner. "Contact ID as BP ID

    l_wa_mem_data-start_date         = sy-datum.                "Start date as current date

    l_wa_mem_data-end_date          = l_c_end_date.            "End date

    l_wa_mem_data-created_via       = l_v_origin.              " Origin(Created_via field of table)

    INSERT l_wa_mem_data INTO TABLE l_is_mem_data.

* Calling the function module to create the membership with above data

    CALL FUNCTION 'CRM_LOY_MEMBERSHIP_CREATE'

      EXPORTING

        iv_create_key             = l_c_true

        iv_fill_attributes        = abap_true

      IMPORTING

        ev_success                = l_v_success           "Membership creation is success or not

      CHANGING

        ct_data                   = l_is_mem_data         "Membership creation data

      EXCEPTIONS

        loy_system_failure        = 1

        loy_communication_failure = 2

        OTHERS                    = 3.

    IF sy-subrc <> 0.                                     

*Exception handling code

    ENDIF.

* Save the membership

    IF l_v_success EQ abap_true.                          "If create FM is success only call the save FM.

      CLEAR:l_v_success.                                  "Clear the success flag to use in below FM.

* Calling in update task by passing iv_update_task as abap_true.

      CALL FUNCTION 'CRM_LOY_MEMBERSHIP_SAVE'

        EXPORTING

          iv_update_task            = abap_true               "If you write in BADI

        IMPORTING

          ev_success                = l_v_success        "This will return the save of membership is success or not.

        EXCEPTIONS

          loy_system_failure        = 1

          loy_communication_failure = 2

          OTHERS                    = 3.

                .

ENDIF.


Please let me know if you have any queries.


Thanks,

Faisal