cancel
Showing results for 
Search instead for 
Did you mean: 

How to add Shopping Cart lines programatically in SRM?

Former Member
0 Kudos

Folks,

We have a requirement in EBP where we need to add shopping cart line items programmatically AFTER a line item is added by the requistioner for certain conditions.

Supposing, if the requisitioner enters a shopping cart item through EBP "Shopping Cart - Full functionality" link with a quantity = N ( where N > 1). Then, our requirement is that, for certain product category, we need to split one item with qty = N into N different line items with qty = 1.

To do that, I'm looking at the possibility of adding shopping cart lines programatically through one of the BADI's. (doc change, create req back, sc transfer etc..)

I've tried to develop a prototype by implementing BBP_APPEND_ITEM BADI to see if any change is taking place. But it seems like the control doesnt get into the above BADI while adding an item to the cart.

If you have any suggestions or ideas, pls. pass it on. It would be highly helpful.

Thanks in advance,

Seyed

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Kim Rao,

Check this thread that I opened for this issue. That could solve our issue.

-Seyed

Former Member
0 Kudos

Need more details to be marked as answered.

Former Member
0 Kudos

Sure.. wl reply on your email. )

Regards

- Atul

Former Member
0 Kudos

Atul,

Thank you! Pls. have a look at the code in my earlier post to see if I'm missing anything obvious! Hope to hear from you soon!

Regards,

-Seyed

Former Member
0 Kudos

One obvious thing from the code you posted is the absence of any exporting structures. You only use the IT* tables which are only used for importing data. Use the ET* tables for further processing.

And the other thing is that there is no way to see how many 1 quantity line items should be made if you reset the quantity before you append that line in the first part of your code.

BTW for guid creation you can use... FM GUID_CREATE.

So a general setup would be:

1. LOOP over the IT_ITEM table and select all those items that you need.

2. Append these as is to a local table (to preserve the quantity).

3. LOOP over the local table and retrieve the quantity

3b. Use a DO or a WHILE loop to generate items and append these to the ET_ITEM table using the value from the quantity (assuming this is a whole number).

Don't forget to add all the other items to the ET_ITEM table as well.

Former Member
0 Kudos

Hi Robin,

First, Thanks much for your reply.

"BTW for guid creation you can use... FM GUID_CREATE."

FM "MDM_GET_NEXT_GUID" in turn calls "GUID_CREATE"

"And the other thing is that there is no way to see how many 1 quantity line items should be made if you reset the quantity before you append that line in the first part of your code."

Thanks for pointing out the above flaw. I'd correct it.

I believe I also use the logic that you mentioned except that I'm just trying to create one new line now. When this works, I'd have the do-while loop to add (n-1) new lines assuming the initial line had n quantity.

The last part of the code that I didn't paste is below.

After all the chnages are made in it_* structures, they are assigned to corresponding et_* structures.

es_header = is_header.

et_item[] = it_item[].

et_account[] = it_account[].

et_partner[] = it_partner[].

et_orgdata[] = it_orgdata[].

At this point, I create new lines only for item and account structure. Havent created one for partner and orgdata. Would that present an issue?

Regards,

Seyed

Former Member
0 Kudos

Seyed,

I went through your code for creating multiple line items in SC for that many of SC line item quantities...Can't I use the same logic for PO in BBP_doc_change_badi...so as in your case line item quantities are splitted in multiple line items, in my case it will be in SRM purchase order, line items getting created for that many SC line item quantities and then this purchase order getting replicated to PO ( we are using EXTENDED CLASSIC) the reason we have this scenario of splitting while creation of PO, is because we want to have a single asset record for single quantity, and we are triggering asset creation immediately after PO, so PO has to be broked down into line items with 1 quantity, so that we can create single asset records from those PO line items...Can you keep me posted about your development..My development will start next month, but still want to have everything clarified before going there....

Here is my email id:

kkim_14@yahoo.co.in

Former Member
0 Kudos

HI SEYED, did you get any success so far, regarding adding items with quantity 1?

K. rao

Former Member
0 Kudos

Seyed are you making use of function module 'BBP_ITEM_CREATE' or following sort of same logic for creating new items with quantity 1. in your bbp_doc_change_badi.

Please let me know.

Thanks,

K. rao

Former Member
0 Kudos

Hi Kim,

I was away and couldnt reply sooner.

I'm using BBP_DOC_CHANGE_BADI.

It was put on hold. I started to work on this this week. Will let you know

of the progress.

-S

Former Member
0 Kudos

Hi

<u>This is very much possible in BBP_DOC_CHANGE_BADI in SE18 transaction, but you need to take care a lot of conditions.

We have done similar requirements, long back in our previous SRM implementations.

For customer messages, you can use, BBP_DOC_CHECK_BADI.

For example, each line item in the shopping cart is having a unique guid number, various partner associated with it, company code, plant data, location, etc.

In case you add some thing more than once, then you might end up in getting errors like</u> <b> Enter partner of type location only once ...

Enter partner of type goods recipient only once ...</b>

Incase you need further details, please send me detailed business requirement on my email id.

atul.kant@gmail.com

I will try to guide you how to about it in detail (with code).

Hope this will help.

Please reward full points, incase it suits your requirements.

Regards

- Atul

Former Member
0 Kudos

Atul,

Thanks for the real quick response.

We've already implemented DOC CHANGE BADI and I'd add my current requirements there as you suggested.

I was looking for someone to say "Yes, this is possible and we have done it". Thanks for giving a direction there. Yes, I understand that we need to take care of lots of condition.

One challenge I figured out was to generate the GUID's. Here I plan to use the FM

"MDM_GET_NEXT_GUID" to generate GUID. Pls. let me know if it is OK to use this FM to get next GUID.

If I have questions while implementing this, I'll shoot you an email. Your response would be highly helpful there.

Thanks,

Seyed

Former Member
0 Kudos

Hi

) Thanks.

Sure, any time. Do let me know.

Regards

- Atul

Former Member
0 Kudos

Hi Atul,

Thanks again for answering my question about adding a SHC line programatically in EBP. I've a follow up question if you can kindly spare few minutes.

Per your suggestion, I added the logic in DOC CHANGE BADI to implement the above requirements. I'm able to modify the quantity for the item currently in the cart. But when I try to add a new line, I dont get any errors but it is not adding as well.

Could you pls. take a look into it and let me know if there are any obvious issues that I missed? Thanks in advance for your help.

              • Start of POC

DATA: ls_item_data1 type bbp_pds_sc_item_d,

ls_acct_data1 type bbp_pds_acc,

lt_item_data_multiple type bbpt_sc_item_badi,

ls_item_data_wa type bbp_pds_sc_item_d.

  • loop over the it_item table to examine each item line in the cart

LOOP AT it_item INTO ls_item_data_wa.

  • verify it_item to check if SHC lines with category ID 4X1, 4X2 and 4X3

  • have quantities above 1.

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 ).

  • res-set the quantity to 1.

ls_item_data_wa-quantity = 1.

*modify the incoming structure it_item so that above

*change is reflected in it_item structure

MODIFY it_item FROM ls_item_data_wa.

  • append this line to a new structure to be used later.

*Idea is to collect all lines that have multiple quantities in

  • one structure

append ls_item_data_wa to lt_item_data_multiple.

endif.

endloop.

CLEAR ls_item_data1.

  • check is multiple-quantity lines are there

if lt_item_data_multiple IS NOT INITIAL.

DATA: lv_item_guid_32 TYPE GUID_32,

lv_acct_guid_32 TYPE GUID_32.

*loop at the new structure for further processing

loop AT lt_item_data_multiple INTO ls_item_data1.

  • we would setup ls_item_data1 to be the new line and assign

  • it to it_item

  • also read the corresponding accounting structure

READ TABLE it_account INTO ls_acct_data1

WITH KEY p_guid = ls_item_data1-guid.

*generate a new GUID

CALL FUNCTION 'MDM_GET_NEXT_GUID'

IMPORTING

E_GUID_32 = lv_item_guid_32.

.

  • assign the generated guid above to the new line.

ls_item_data1-guid = lv_item_guid_32.

*modify the quantity to 1. For time being, just set the qty value = 1.

ls_item_data1-quantity = 1.

  • append the modified line to it_item structure.

append ls_item_data1 to it_item.

  • generate a second guid to be used for accounting structure

CALL FUNCTION 'MDM_GET_NEXT_GUID'

IMPORTING

E_GUID_32 = lv_acct_guid_32.

  • set acct guid to the second guid generated above

ls_acct_data1-guid = lv_acct_guid_32.

  • set acct parent guid to the first guid generated for the item.

ls_acct_data1-p_guid = lv_item_guid_32.

  • append the ls_acct_data1 structure to it_account.

  • and check if these changes work!

append ls_acct_data1 TO it_account.

endloop.

endif.

              • End of POC

Thanks,

Seyed