Skip to Content
0
Former Member
Nov 08, 2011 at 03:49 PM

Remove Top Line Residual Quantity from Delivery

584 Views

Hi,

I need to remove residual quantity from a Delivery when a delivery is Saved.

For e.g. I have one Delivery with 1 line item 10 for Quantities 20. This line items is split in 2 batches 90001 and 90002.

The delivery quantity of the batches is 10 and 5.

Hence a residual of 5 is getting left over which is not yet allocated a batch and is seen in the Quantity column in the Item 10 line.

This needs to get removed automatically through an enhancement whenever the delivery is saved.

I already have a partially working solution which i will mention below.

When I say partially, i mean it removes the Residual Quantity updates the Picking Status and the Quantities are Reflected in Sales Order Overview in case the Delivery is created from a Sales Order. But we are still getting issues as everything that the standard code updates is not getting updated by us. [In case you feel the latest issue has relevance, please ask]

It would be very helpful if someone can shed some light on this. I would like to know whether what I am doing is the right way to do it.

Here's how i went about it. I searched for a userexit where i can make alter the Quantity in Deliveries. Though many are available, one of them was the best suggest I thought. Particularly interesting was an SAP Note number 415716.

I chose the following form to write my code.

Include: MV50AFZ1

Form : USEREXIT_SAVE_DOCUMENT_PREPARE

The description of this form is as follows

This userexit can be used for changes or checks, before a document is saved. If field T180-TRTYP contents 'H', the document will be created, else it will be changed. This form is called at the beginning of form BELEG_SICHERN.

Now the following is my code.

The data declaration

* Structure to get ygv_flag entries for removing residual quantity
* from Batch Split Delivery Item
    TYPES: BEGIN OF ty_ygvflags,
          vkorg TYPE ygv_flags-vkorg,    "Sales Org
          vstel TYPE ygv_flags-vstel,    "Plant
          END OF ty_ygvflags.
    DATA: it_ygvflags TYPE STANDARD TABLE OF ty_ygvflags,
          wa_ygvflags TYPE ty_ygvflags,
          v_sy_tabix TYPE sy-tabix,
          v_sy_tabix_vbup TYPE sy-tabix,
          v_sy_tabix_vbfa TYPE sy-tabix,
          v_xvbup_copy LIKE xvbup,
          v_xvbfa_copy LIKE xvbfa,
          v_apply_flag TYPE c.
* Constants to get ygv_flags entries for removing residual quantity
* from Batch Split Delivery Item
    CONSTANTS: c_flag477(7) TYPE c VALUE 'FLAG477',  "FLAG Number
         c_h TYPE c VALUE 'H',   "Value for "Create" in T180-TRTYP
         c_c TYPE c VALUE 'C', "Value for Sales order in XLIPS-VGTYP
         c_u TYPE c VALUE 'U'.                "Update Flag