Spend Management Blogs by Members
Check out community member blog posts about spend management and SAP Ariba, SAP Fieldglass, and SAP Concur solutions. Post or comment about your experiences.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member184741
Active Contributor

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.

9 Comments