Skip to Content
avatar image
Former Member

REG : Sample code for BADI : BBP_GROUP_LOC_PO


Can anyone provide the sample code for the implementation of the BADI - BBP_GROUP_LOC_PO.

We have requirement to create multiple PO from SC line items using a custom field present in the shopping cart item details as the spliting criteria.

I am not getting the reference number logic.

Hence please do send the code, where in the BADI is used to split the shopping cart using a custom field.

Please do help me with this as this is a priority issue.
Any help will be appreciated.


Aakash Awasthi

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jun 04, 2015 at 07:03 PM

    Hi Aakash,

    I do not have sample code doing what you Need but I can extract something from our super complicated logic that might help.
    First of all customer fields are not part of the structure passed to the grouping BADI. So the only Chance is to read the Shopping Cart Details within the BADI:

      loop at item_data into ls_badi_split.

        lv_index = sy-tabix.

        SELECT single * into ls_crmd_item

                FROM  CRMD_ORDERADM_I

                WHERE  GUID  = ls_badi_split-guid.

        check sy-subrc = 0.

        SELECT single * into ls_crmd_header

                FROM  CRMD_ORDERADM_H

                WHERE  GUID  = ls_crmd_item-header.

        check sy-subrc = 0.

        clear ls_item.

        refresh lt_items_sc.


          EXPORTING        I_GUID                        = ls_crmd_header-guid

          TABLES        E_ITEM                        = lt_items_sc

            E_ACCOUNT                    = lt_account.

        read table lt_items_sc into ls_items_sc

              with key guid = ls_crmd_item-guid.

        check sy-subrc = 0.

        move-corresponding ls_items_sc to ls_item.

    Now that you have the SC Details incl. customer fields you can move the value you want to group by into one of the generic fields SAP has provided (CUST_FIELD1 to CUST_FIELD5) of internal table ITEM_DATA.

    Next is to sort the internal table by the exact list of group fields. If it is really just the customer field just sort by that one but please bear in mind that some splits are mandatory (e.g. by purchasing organization, Company code, purchasing group, currency target document type and so on) because These fields are PO Header fields.

    Now define a Counter field and run a Loop on the sorted item list. Whenever the customer field or better the the grouping criteria changes add 1 to the Counter field and write it back to field REFNUMBER of field ITEM_DATA. All the items having the same value in REFNUMBER at the end will go into the same PO and (of course) items having different values in that field will be split into different POs.

    An example from a PO Conversion Setup:

    * New sort order taking care of the old PO Number (which is in Customer Field 1

       SORT item_data BY cust_field5 logsys_fi line.

    * --- Now run the simple Split logic for Converted POs

      lt_split_copy[] = item_data[].

      loop at item_data into ls_badi_split.

        lv_index = sy-tabix.

        clear lv_split.

    *   check if there are different split criterias

        split_field cust_field5    'Old PO Number'.

        split_field logsys_fi      'FI logical System'.

        IF lv_split = c_on.

          start_number = start_number + 1.


        ls_badi_split-refnumber = start_number.

        modify item_data from ls_badi_split index lv_index.

    *   always save current line for next round

        ls_badi_split_save = ls_badi_split.


    The Macro SPLIT_FIELD just checks if the field value of the given field is the same as in save-structure ls_badi_split_save:

    define split_field.

      if lv_split is initial.

         if ls_badi_split-&1 <> ls_badi_split_save-&1.

            lv_split = 'X'.




    Hope that helps.



    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Thanks Oliver,

      You were great.

      My issue is resolved, and I used the logic similar to this one.

      Currently stucked with multiple issues.

      Posted in SCN, waiting to get replies on those.

      Thank you once again.