cancel
Showing results for 
Search instead for 
Did you mean: 

Dump when adding marketing permissions

sascha_roehm
Explorer
0 Kudos

Hello everybody,

we are having a problem with the function modules CRM_BUPA_MKT_PERM_ADD and CRM_BUPA_MKT_PERM_SAVE_TABS. The problem is very similar to this post:

We have implemented function module CRM_BUPA_MKT_PERM_ADD in the BAdI ORDER_SAVE. This BAdI implementation of ours is adding marketing permissions contact persons of leads.

Here is the process of how we are using the function modules:

  1. User saves a lead and triggers BAdI ORDER_SAVE
  2. BAdI ORDER_SAVE uses function module CRM_BUPA_MKT_PERM_ADD to add marketing permissions to contact person of lead
  3. In update process function module CRM_BUPA_MKT_PERM_SAVE_TABS is triggered

For saving the first lead everything is working great because internal table it_but_mktperm_insert[] of function module CRM_BUPA_MKT_PERM_SAVE_TABS contains only one entry (step 3).

When the user saves every next lead the internal table it_but_mktperm_insert[] of function module CRM_BUPA_MKT_PERM_SAVE_TABS in step 3 has more than one entry. In addition to the new entry it also contains the previous ones which will result in the following dump on executing the INSERT statement:

Runtime Error              DBSQL_DUPLICATE_KEY_ERROR

Exception                    CX_SY_OPEN_SQL_DB

Terminated Program     SAPLCRM_BUPA_MKTPERM_SAVE

I also created a small program in order to easily repeat this issue:

*&---------------------------------------------------------------------*

*& Report Y09_MKT_PERMS_DUMP

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT y09_mkt_perms_dump.

TABLES: but050.

SELECT-OPTIONS:

o_but050 FOR but050-partner2.

START-OF-SELECTION.

  DATA:

  lv_partner2  TYPE bu_partner,

  ls_data  TYPE crmt_but_mktperm_data,

  lv_record_guid TYPE crmt_bu_mktperm_guid,

  lv_error  TYPE crmt_boolean,

  lt_return  TYPE bus_bapiret2_t.

  BREAK-POINT.

  LOOP AT o_but050 INTO DATA(ls_but050).

   CLEAR: lv_partner2, ls_data, lv_record_guid, lv_error, lt_return.

   SELECT SINGLE partner1 INTO lv_partner2 FROM but050 WHERE partner2 = ls_but050-LOW.

   CHECK sy-subrc = 0.

   SELECT SINGLE partner_guid INTO ls_data-contpguid FROM but000 WHERE partner = ls_but050-LOW.

   CHECK sy-subrc = 0.

   SELECT SINGLE partner_guid INTO ls_data-partnerguid FROM but000 WHERE partner = lv_partner2.

   CHECK sy-subrc = 0.

  ls_data-channel = 'INT'.

  ls_data-permission = '002'.

  ls_data-origin = 'YBO'.

  ls_data-valid_from = sy-datum.

   CALL FUNCTION 'CRM_BUPA_MKT_PERM_ADD'

   EXPORTING

  is_data  = ls_data

  iv_x_save  = 'X'

   IMPORTING

  ev_record_guid = lv_record_guid

  ev_error  = lv_error

  et_return  = lt_return.

   CHECK lv_error IS INITIAL.

   CHECK lt_return IS INITIAL.

* COMMIT WORK AND WAIT.

   "COMMIT inside the loop will cause dump DBSQL_DUPLICATE_KEY_ERROR

   "during update process in function module CRM_BUPA_MKT_PERM_SAVE_TABS

  ENDLOOP.

  COMMIT WORK AND WAIT.

  "COMMIT outside the loop will work properly because update process and therefore function

  "module CRM_BUPA_MKT_PERM_SAVE_TABS is only triggered once and all entries of internal

  "table it_but_mktperm_insert[] will be inserted into db table CRMM_BUT_MKTPERM at once

  BREAK-POINT.

How do I solve this situation within the BAdI call of ORDER_SAVE? Putting the COMMIT inside or outside the loop is easy, but how do I do that when it comes to ORDER_SAVE BAdI?

Any help will be appreciated.

Best regards

Sascha

Accepted Solutions (1)

Accepted Solutions (1)

hakan_kose
Contributor
0 Kudos

Hi Sascha,

I worked for Marketing Permissions before and used the function module CRM_BUPA_MKT_PERM_ADD and BAPI_TRANSACTION_COMMIT respectively in order to add marketing permissions to business partners in a custom report.. However I didn't encounter any error whatsoever.


If you want to use them in ORDER_SAVE BAdI, I'd use only CRM_BUPA_MKT_PERM_ADD function module.


In order to get a handle on the issue, is there anyway you can attach the whole .txt file for the dump?

sascha_roehm
Explorer
0 Kudos

Hello Hakan,

thank you for your reply.

I created a small Y-program where the error can easily be replicated (code can be found in my first post). Within this program I can get rid of the error with no problem at all. It is a matter of when the COMMIT is executed.

I corrected all the places where we are using marketing permissions in our Y-coding. The only place left is this ORDER_SAVE BAdI call that I am not able to fix.

Using CRM_BUPA_MKT_PERM_ADD in ORDER_SAVE BAdI is however a completely different story. because the commit is automatically executed after the BAdI and you cannot influence it, or can you?

I attached the dump as a .txt file.

Best regards

Sascha Röhm

hakan_kose
Contributor
0 Kudos

Hi Sascha,

I examined the .txt file. It appears that the reason for the dump is that the system is trying to insert a record into the table "CRMM_BUT_MKTPERM" with a record guid that already exits. Could you check the table "CRMM_BUT_MKTPERM" please for this message?

And yes, database commit already occurs after Order_Save BAdI, hence you don't need to speficially commit the changes. I assume that you're only using CRM_BUPA_MKT_PERM_ADD alone in the BAdI method (Without BAPI_TRANSACTION_COMMIT or any other statement related to commit). Do you use function module CRM_BUPA_MKT_PERM_ADD alone in the BAdI method, right?

sascha_roehm
Explorer
0 Kudos


Hello Hakan,

yes, in the BAdI call I only use CRM_BUPA_MKT_PERM_ADD (without any additional commit).

I know that the dump occurs because of a duplicate record in DB table CRMM_BUT_MKTPERM. This is because the first time of call to the BAdI only one entry is in internal table it_but_mktperm_insert[] of function module CRM_BUPA_MKT_PERM_SAVE_TABS, but the second time there are two entries, the third time three entries and so on...

The first time with just one entry everything gets saved properly. The second time where there are two entries it already dumps because the first of those two entries is already in DB table CRMM_BUT_MKTPERM and therefore a duplicate record dump is produced.

These screenshots may explain it a little better:

Best regards

Sascha

hakan_kose
Contributor
0 Kudos

Hi Sascha,

I'm sorry for taking your time to give further information, but since I don't have access to source codes and can't check them myself, I wanted to make sure that everything is just as I expected.

Thanks for the screenshots. There are last two questions I wanted to ask about the BAdI and then I'm suggesting another solution. But first let's make sure about the BAdI first:

1 - In ORDER_SAVE BAdI, in which method you wrote your code? I hope it's CHANGE_BEFORE_UPDATE.

2- If you have your codes in CHANGE_BEFORE_UPDATE and all the other methods are either empty or just working fine, would you mind share the codes in all methods of that BAdI? If it's not appropriate to share it here, you can send it to em via private message.

If we even can't make out after we try these two questions, I'll suggest you to use action profile for adding marketing permissions. If you're already experienced in action in transactions, you just need to adjust schedule/start conditions according to your requirements. If you're not experienced with actions and action profiles, I can share some documents to assist you

Best Regards,

sascha_roehm
Explorer
0 Kudos

Hi Hakan,

1 - We implemented only the PREPARE method of ORDER_SAVE BAdI. The other methods (CHANGE_BEFORE_UPDATE, CHECK_BEFORE_SAVE) are empty and we only have this one implementation of ORDER_SAVE.

Do you think moving the code from PREPARE to CHANGE_BEFORE_UPDATE will solve this issue? I will move the coding to CHANGE_BEFORE_UPDATE method in our development system. Unfortunately I think I will only be able to test it in January.

Best regards

Sascha

hakan_kose
Contributor
0 Kudos

Hi Sascha,

Well, since all your other methods are empty, I can't guarantee that this will certainly solve the issue.

I don't know your business requirement and conditions that marketing permissions should be added to business partners, but I really wonder how come the ORDER_SAVE BAdI has to be called more than once in case save checks are all OK. If your business process is all fine and this multiply callings are inevitable, firstly I suggest you to do some validations for marketing permissions beforehand so that the system doesn't try to add same records over and over again. If there's no validation you can set as you don't know exactly when this occurs, try to elliminate duplicate entries in import tables of the function modules if you can.

If you cannot do any of above, I highly suggest you to customize an action profile and actions in order to add marketing permission(s) in the BAdI (in this case your processing type will be methods) of the specified action. If you have any questions regarding actions in transactions or actions generally, I will try to help as much as I can. I can even share some sample ABAP codes for processing methods.

I hope this helps.

sascha_roehm
Explorer
0 Kudos

Hi Hakan,

thank you for your detailed answers.

The ORDER_SAVE BAdI is correctly called in our system. It is not the case that it gets called several times for the same transaction. The problem is that the user works with one transaction, saves it (first time ORDER_SAVE triggered) and takes the next one. When the user is finished with the this next transaction, again the save is used (second time ORDER_SAVE triggered).

After the first ORDER_SAVE call the system's update process calls function module CRM_BUPA_MKT_PERM_SAVE_TABS which at that point just has one entry in itab it_but_mktperm_insert[].

After the second ORDER_SAVE call the system's update process calls function module CRM_BUPA_MKT_PERM_SAVE_TABS which now has two entries in itab it_but_mktperm_insert[] and that leads to a dump.

Since the call of the BAdI is fine and still this SAP function module CRM_BUPA_MKT_PERM_SAVE_TABS can have several entries, I don't think using actions will solve the problem. What would prevent the same situation from happening with the actions? So one action to add a marketing permission is executed which in the end calls CRM_BUPA_MKT_PERM_SAVE_TABS with this one entry. When the next actions adds a marketing permission again CRM_BUPA_MKT_PERM_SAVE_TABS is called and now has two entries?

When I will use actions to add marketing permissions I will use custom methods in the action execution if I understood correctly. So I would use the same SAP function module to add permissions as in the already present implementation of ORDER_SAVE BAdI.

Do you think trying with actions is worth a shot?

Best regards

Sascha

hakan_kose
Contributor
0 Kudos

Hi Sascha,

OK, now that sounds very odd! Last thing I can think of as a question regarding this issue: Do you use an interaction web client role or just a normal business role for your users? In interaction webclient roles, the ORDER_SAVE BAdI gets called one more time at the end when agents use "End" button to end the interaction session. If this is not the case, please ignore here.

Do you have any kind of check you can implement before you add marketing permissions in ORDER_SAVE BAdI? For instance, checking related permission has been already added to the business partner(s).

If you cannot implement a comprehensive check, then I suggest you to open up a SAP Note regarding this issue with explanation abvoe and supported screenshots. Because as far as I can remember, there's no SAP Note related to this kind of issue now.

Best Regards

sascha_roehm
Explorer
0 Kudos

Hi Hakan,

in this case this is not an interaction web client role. We are using a customized version of standard role marketingpro.

Implementing a check before or directly after ORDER_SAVE BAdI will not help because the issue is not yet present there and at first happens when this update function module is called. A check would only be helpful directly in this function module to check for already existing entries in db table.

To implement a check in this update function module I would have to do a modifiation, which we don't do in our SAP CRM environment.

When I started researching I looked for issues in our code and didn't find any. Then I started looking for an SAP Note and wasn't successful. After that I created this post because I find it more helpful than creating a ticket to SAP.

Now I will raise a ticket to SAP explaining the situation and ask for a solution.

Thank you for all your effort 🙂

Best regards

Sascha

hakan_kose
Contributor
0 Kudos

Sascha,

Normally, before I open up a ticket to SAP, I would undergo almost same procedure as yours. However, I think, I asked all my questions that came to my mind about the possibilities. I have truly run out of them

Please enlighten us on how this issue will get resolved

Good luck

sascha_roehm
Explorer
0 Kudos

Solution of my SAP Incident was, that SAP suggested to call function module CRM_BUPA_MKT_PERM_CLEAR_BUFFER right before calling function module CRM_BUPA_MKT_PERM_ADD.

Best regards

Sascha Röhm

hakan_kose
Contributor
0 Kudos

I'm really glad you solved it.

So, they acknowledge this was a buffer problem.

Best Regards,

Answers (0)