How to create Limit/Non-Limit shopping cart using FM in SRM
This blog is result of my 2 days struggle on finding a way to create a SC using only FMs, particularly to create Limit SCs. I saw lot of threads asking and discussing this topic, but no concrete solution. I would like to post the sample code for this.
Assume that you are having a program where you already have the required data to create SCs i.e., item data, accounting data, partner data etc., The you create a FORM like I have shown below. Pass all the required data to the below form. I am not giving here the details of how to fill these tables as the data might vary from case to case.
The important point to note here is to not populate the P_GUID in Accounting, partner, attachment, organisation data, etc tables. Basically where ever there is a need to fill in item guid just leave it as blank. we will fill those details in the below form.
FORM create_limit_sc TABLES pt_item STRUCTURE bbp_pds_sc_item_icu
pt_account STRUCTURE bbp_pds_acc
pt_partner STRUCTURE bbp_pds_partner
pt_longtext STRUCTURE bbp_pds_longtext
pt_limit STRUCTURE bbp_pds_limit
pt_orgdata STRUCTURE bbp_pds_org
pt_item_out STRUCTURE bbp_pds_sc_item_icu
pt_messages_out STRUCTURE bbp_pds_messages
USING
pt_attachment TYPE bbpt_pds_att_t
CHANGING ps_header TYPE bbp_pds_sc_header_ic
ps_header_out type bbp_pds_sc_header_d.
FIELD-SYMBOLS: <fs_item> TYPE bbp_pds_sc_item_icu,
<fs_account> TYPE bbp_pds_acc,
<fs_partner> TYPE bbp_pds_partner,
<fs_orgdata> TYPE bbp_pds_org,
<fs_longtext> TYPE bbp_pds_longtext,
<fs_attachment> TYPE bbp_pds_att_t,
<fs_limit> TYPE bbp_pds_limit.
DATA: lv_guid_item_tmp TYPE bbp_guid,
lv_tmp TYPE bbp_guid,
ls_header_out TYPE bbp_pds_sc_header_d,
lv_guid_limit_tmp TYPE bbp_guid,
lv_error_found TYPE xfeld,
ls_header_u TYPE bbp_pds_sc_header_u,
lv_changed TYPE xfeld.
CLEAR: ls_header_out, ls_header_u, lv_error_found.
*Create header data of SC
CALL FUNCTION ‘BBP_PD_SC_CREATE’
EXPORTING
i_header = ps_header
IMPORTING
e_header = ps_header_out
TABLES
e_messages = pt_messages_out.
MOVE-CORRESPONDING ps_header_out TO ls_header_u.
*Fill in the item GUID in each of the table
LOOP AT pt_item ASSIGNING <fs_item>.
lv_tmp = <fs_item>-guid.
lv_guid_item_tmp = lv_guid_item_tmp + 1.
<fs_item>-guid = lv_guid_item_tmp.
<fs_item>-parent = ls_header_u-guid.
LOOP AT pt_limit ASSIGNING <fs_limit> WHERE p_guid EQ lv_tmp.
lv_guid_limit_tmp = lv_guid_item_tmp * 2.
<fs_limit>-guid = lv_guid_limit_tmp.
<fs_limit>-p_guid = lv_guid_item_tmp.
lv_guid_limit_tmp = lv_guid_limit_tmp + 1.
ENDLOOP.
LOOP AT pt_account ASSIGNING <fs_account> WHERE p_guid EQ lv_tmp.
<fs_account>-p_guid = lv_guid_item_tmp.
ENDLOOP.
LOOP AT pt_partner ASSIGNING <fs_partner> WHERE p_guid EQ lv_tmp .
<fs_partner>-p_guid = lv_guid_item_tmp.
ENDLOOP.
LOOP AT pt_orgdata ASSIGNING <fs_orgdata> WHERE p_guid EQ lv_tmp.
<fs_orgdata>-p_guid = lv_guid_item_tmp.
ENDLOOP.
LOOP AT pt_attachment ASSIGNING <fs_attachment> WHERE p_guid EQ lv_tmp.
<fs_attachment>-p_guid = lv_guid_item_tmp.
ENDLOOP.
LOOP AT pt_longtext ASSIGNING <fs_longtext> WHERE guid EQ lv_tmp.
<fs_longtext>-guid = lv_guid_item_tmp.
ENDLOOP.
CLEAR: lv_guid_limit_tmp, lv_tmp.
ENDLOOP.
*Create item data, accounting data, partnner data. limit data etc.,
CALL FUNCTION ‘BBP_PD_SC_UPDATE’
EXPORTING
i_header = ls_header_u
i_save = ‘X’
it_attach = pt_attachment
IMPORTING
e_changed = lv_changed
TABLES
i_item = pt_item
i_account = pt_account
i_partner = pt_partner
i_longtext = pt_longtext
i_limit = pt_limit
i_orgdata = pt_orgdata
e_messages = pt_messages_out.
LOOP AT pt_messages_out WHERE msgty = ‘A’ OR msgty = ‘E’.
lv_error_found = ‘X’.
ENDLOOP.
*
*If there are no errors save the SC
IF lv_error_found NE ‘X’.
CALL FUNCTION ‘BBP_PD_SC_SAVE’
EXPORTING
iv_header_guid = ls_header_u-guid.
COMMIT WORK.
ENDIF.
ENDFORM. ” CREATE_LIMIT_SC
I hope this will be helpful to all SRM techies
Thanks
sankar.
Hi Sankar,
Instead of calling BBP_PD_SC_CREATE and then BBP_PD_SC_UPDATE. Did you try this.?
CALL FUNCTION 'BBP_PD_SC_CREATE'
EXPORTING
i_header = ps_header
IMPORTING
e_header = ps_header_out
TABLES
TABLES
i_item = pt_item
i_account = pt_account
i_partner = pt_partner
i_longtext = pt_longtext
i_limit = pt_limit
i_orgdata = pt_orgdata
e_messages = pt_messages_out.
COMMIT WORK.
I mean, pass all the item, account, partner, longtext, limit and org data to CREATE BAPI.
That should be a simple way.
Note: the structure types differ for both create and update bapis.
BBP_PD_SC_CREATE does not work for limit items. That is the whole point of this blog
oh sorry. Thanks Sankara. 🙂
Hi sankar,
I have a requirement to create a PO using BBP_PD_PO_CREATE FM.
Any idea does the same way work there?
Regards,
Ashish Shah
Hi Ashish,
Sorry..I never worked with that FM.
thanks,
sankar.
Hello Sankara,
I also have a requirement where i need to create normal SC using FMs. I tried the way you described. But it still gives error from FM BBP_PD_SC_UPDATE that - Enter at least one item or one limit. I am unable to understand what am i missing as i can see the shopping cart in BBP_PD transaction but only with header data. No other information is getting created. Could you please tell me what i might be missing?
Regards,
Yayati Ekbote
Hi,
when you debug the program, when the control comess to FM BBP_PD_SC_UPDATE check what you are passing PT_ITEM. Here the parent GUID should be the new GUID that gets created when calling BBP_PD_SC_CREATE' (i.e., ps_header_out-guid and ). Also make sure when you call BBP_PD_SC_SAVE, you should pass new GUID.
thanks,
sankar.
Hello Sankara,
There is a new problem. The Shopping cart is getting created and i can see it in BBP_PD transaction. But in SRM portal the requester cannot find the shopping cart using monitor and queries. When i enter shopping cart number in query or quick search, i don't get the shopping cart. The shopping cart has errors in it which are supposed to be corrected by requester. Could you please tell me what information do i need to pass exactly so that i can see the new shopping cart in portal. I think there is no role issue because requester can see shopping carts created in portal with normal process.
Regards,
Yayati Ekbote
open the SC in bbp_pd and see the partner details for requestor. The details should match with the user who is logging into portal.