Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Adding Shopping Cart lines through BBP_DOC_CHANGE_BADI

Folks,

I had a requirement where there is a need to split the line with multiple quantities.

I'm doing this change in DOC CHANGE BADI. This should be similar to a "copy" functionality performed through Shopping cart GUI. But this one is done inside the badi as opposed to user clicking on "copy" button.

As you know, the BADI contains the following structures.

Import -- > Header, Item, Account, Partner, Org data, Header Custom fields, Item custom fields.

Export --> Header, Item, Account, Partner, Org data, Header Custom fields, Item custom fields.

I'm creating a new item and also creating associated objects like account, partner and org data.

I've also looked at the logic for copy function in SRM FM "BBP_SC_APP_EVENT_DISPATCHER".....I believe I've taken care of all the steps.

<b>But it still doesnt WORK.</b> Pls. look at the code and help me if there are any obvious flaws. Points would be awarded for helpful answers.

I've also debugged this BADI and found that if the export structure is populated with

the new item. But GUI neither shows any error nor adds the new item to the cart.

When it errors out, I can atleast look at it. In this case, no clue why it is not being added although I believe I've done the necessary steps.

<b>code:</b>

LOOP AT it_item INTO ls_item_data_wa WHERE del_ind = ''.

if ( ls_item_data_wa-category_id = '40000001' OR

ls_item_data_wa-category_id = '40000002' OR

ls_item_data_wa-category_id = '40000003' )

AND ( ls_item_data_wa-quantity > 1 ).

append ls_item_data_wa to lt_item_data_multiple.

ls_item_data_wa-quantity = 1.

MODIFY it_item FROM ls_item_data_wa.

endif.

ENDLOOP.

CLEAR ls_item_data_wa.

DATA: lv_lines TYPE i,

lv_max_item_no TYPE i,

ls_partner_count1 type i,

ls_partner_count2 type i,

ls_partner_count3 type i.

DESCRIBE TABLE it_item LINES lv_lines.

READ TABLE it_item INTO ls_item_data_wa INDEX lv_lines.

IF sy-subrc EQ 0.

lv_max_item_no = ls_item_data_wa-number_int.

ENDIF.

CLEAR ls_item_data_wa.

if NOT lt_item_data_multiple IS INITIAL.

DATA: lv_item_guid_16 TYPE GUID_16,

lv_acct_guid_16 TYPE GUID_16,

lv_partner_guid_16 TYPE GUID_16,

lv_orgdata_guid_16 TYPE GUID_16.

loop AT lt_item_data_multiple INTO ls_item_data1.

ls_current_item_guid = ls_item_data1-guid.

CALL FUNCTION 'MDM_GET_NEXT_GUID'

IMPORTING

E_GUID_16 = lv_item_guid_16.

.

ls_item_data1-guid = lv_item_guid_16.

ls_item_data1-quantity = 1.

lv_max_item_no = lv_max_item_no + 1.

ls_item_data1-number_int = lv_max_item_no.

ls_item_data1-created_at = sy-datum.

ls_item_data1-changed_at = sy-datum.

append ls_item_data1 to it_item.

READ TABLE it_account INTO ls_acct_data1

WITH KEY p_guid = ls_current_item_guid.

CALL FUNCTION 'MDM_GET_NEXT_GUID'

IMPORTING

E_GUID_16 = lv_acct_guid_16.

ls_acct_data1-guid = lv_acct_guid_16.

ls_acct_data1-p_guid = lv_item_guid_16.

ls_acct_data1-acc_no = lv_max_item_no.

append ls_acct_data1 TO it_account.

LOOP AT it_partner INTO ls_partner_wa WHERE p_guid =

ls_current_item_guid.

CALL FUNCTION 'MDM_GET_NEXT_GUID'

IMPORTING

E_GUID_16 = lv_partner_guid_16.

ls_partner_wa-partner_guid = lv_partner_guid_16.

ls_partner_wa-p_guid = lv_item_guid_16.

append ls_partner_wa TO lt_temp_partner.

clear: ls_partner_wa , lv_partner_guid_16.

ENDLOOP.

append lines of lt_temp_partner TO it_partner.

LOOP AT it_orgdata INTO ls_orgdata_wa WHERE p_guid =

ls_current_item_guid.

CALL FUNCTION 'MDM_GET_NEXT_GUID'

IMPORTING

E_GUID_16 = lv_orgdata_guid_16.

ls_orgdata_wa-guid = lv_orgdata_guid_16.

ls_orgdata_wa-p_guid = lv_item_guid_16.

append ls_orgdata_wa TO lt_temp_orgdata.

ENDLOOP.

append lines of lt_temp_orgdata TO it_orgdata.

endloop.

endif.

endif.

es_header = ls_header.

et_item[] = it_item[].

et_account[] = it_account[].

et_partner[] = it_partner[].

et_orgdata[] = it_orgdata[].

Former Member
Not what you were looking for? View more on this topic or Ask a question