Skip to Content

Scenario:Automatic plant determination for sales order line item with respect to distance between customer location and production plant.


Over view:

  • Plant will be determined automatically while creating sales order.
  • Plant determination will be a zone level. A zone details will be maintained based on Zip code.
  • ZIP/PIN code and its details will be captured through the web services or look-up table (Web Service – Free ZIP Code Web Services or using google api’s or collect the zip/pin code and its details details and load into look-up tabe (ZTable Because distance will be remain same )

Flow Logic:

Plant 1 is in Rajasthan (Jaipur) – Zip code = 303329

Plant 2 is in Karnataka (Bangalore) – Zip code = 560062

/wp-content/uploads/2013/11/indian_map_317910.jpg

Case 1:

If customer (Cust – 3 )is booking order from Jammu and Kashmir system has to check which is nearest plant to customer location below image obviously Jaipur plant is near to customer place so system will choose Plant – 2 for particular line item of sales order.

Case 2:

If customer (Cust – 1 )is booking order from Chennai (Tamil Nadu) system has to select Bangalore plant which is nearer to Chennai.

Note: Before selecting plant system will check whether material produce in multiple plant or not if not system will choose the plant where the material is produced.

Case 3:

If Sales order have multiple line item and Customer is booking order from Madya Pradesh (Cust – 2) so Plant – 1 is near to Cust – 2 , but order have some material which is not produced in Plant1, so in this case system has to select Bangalore plant (Plant – 2)

* system has to check before selecting plant Whether material is produced in respective plant or not.

indian_map2.JPG

Followed below steps for achieving above scenario :

1. Collected all the zip codes and mapped to plant maintained in Look up Table – ‘zcustomer_zone’.


Z Table : zcustomer_zone, Customer zip(Pin) code is Primary Key


Customer Zip (Pin) code Respective Production plant
560001 – BNG (Karnataka) 560062 – Plant 2
577202 – SMG (Karnataka) 560062 – Plant 2
577101 – CKM (Karnataka) 560062 – Plant 2
500001 – HYD (Andhra Pradesh) 560062 – Plant 2
382010 – GNR (Gujarat) 303329 – Plant 1
208001 – ANA (Uttar pradesh) 303329 – Plant 1


2. Used user exit SOURCE_DETERMINATION (‘Sales order enhancement’  – MV45AFZB)


FORM USEREXIT_SOURCE_DETERMINATION.
“$”””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””””$

“$\SE:(1) Form USEREXIT_SOURCE_DETERMINATION, Start                                                                                         
*$*$-Start: (1)———————————————————————————$*$*

ENHANCEMENT 1  ZSD_PLANT_DETERMINATION.    “active version

DATA: BEGIN OF ty_werks,

        werks  TYPE werks_d,

END OF ty_werks.

DATA: it_werks  LIKE TABLE OF ty_werks,

      wa_werks  LIKE ty_werks.

DATA: lv_count  TYPE i.

DATA: lv_pstlz  TYPE pstlz.

DATA: wa_vbpa    TYPE vbpa.

TYPES: BEGIN OF ty_zone .

        INCLUDE STRUCTURE zcus

tomer_zone.
TYPES: END OF ty_zone .

DATA : lt_zone TYPE STANDARD TABLE OF ty_zone,
            wa_zone TYPE ty_zone.

*———————————————————————-*

* Check that the product exist in more than one plant

*———————————————————————-*
SELECT werks INTO TABLE it_werks
              FROM marc
            WHERE matnr = vbap-matnr.

CLEAR: lv_count.
DESCRIBE TABLE it_werks LINES lv_count.

IF lv_count = 1.
* do Nothing…. No plant determination
ELSE.

*———————————————————————-*
* Get the Postal code of Ship-to from line item

*———————————————————————-*

  READ TABLE xvbpa INTO wa_vbpa WITH KEY parvw = ‘WE’
                            posnr = vbap-posnr.
*———————————————————————-*
* Get the Postal code of Ship-to from Header

*———————————————————————-*
  IF sy-subrc <> 0.
    READ TABLE xvbpa INTO wa_vbpa WITH KEY parvw = ‘WE’
                              posnr = ‘000000’.
  ENDIF.

*———————————————————————-*

* If ship-to party found

*———————————————————————-*
  IF wa_vbpa-kunnr IS NOT INITIAL.
    SELECT SINGLE pstlz INTO lv_pstlz
              FROM kna1
            WHERE kunnr = wa_vbpa-kunnr.

*———————————————————————-*
* Zone table by Zipcode – Getting plant from

* look up table with respect to Customer zip code

*———————————————————————-*
    SELECT * FROM zcustomer_zone
              INTO TABLE lt_zone
            WHERE zipcode = lv_pstlz.

*———————————————————————-*

* Sort internal table by Transit time

*———————————————————————-*
    SORT lt_zone ASCENDING  BY zzone transit_time.

*———————————————————————-*

* Assign the production plant

*———————————————————————-*
    READ TABLE lt_zone INTO wa_zone INDEX 1.
    vbap-werks = wa_zone-plant.
  ENDIF.

ENDIF.

ENDENHANCEMENT.

To report this post you need to login first.

3 Comments

You must be Logged on to comment or reply to a post.

Leave a Reply