cancel
Showing results for 
Search instead for 
Did you mean: 

Remove Top Line Residual Quantity from Delivery

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

I'm sorry to trouble you but this issue is still not completely solved. The current issue i am having is that I need to update 3 completion statuses for Sales Order Item i.e. at VBUP table.

For that I need to set the Update Indicator (UPDKZ) in XVBUP for the modified item to 'U' for Update.

But as soon as the transaction gets over, i.e. the delivery gets saved, i get a message saying "Update was terminated"

The details of this error when viewed through SM13 Transaction are as follows.

Function module     RV_DELIVERIES_SAVE

Status              Update was terminated

Report              LV05IFAP

Line                40

Error text 

VI 200: Item status (document ************** , item 000010 ) is missing.

I NEED to update those 3 completion statuses for VBUP for the Sales Order to work correctly.

Please suggest.

Former Member
0 Kudos

I have tried to make all internal tables status like they would in standard SAP as you suggested Nabheet but there i am facing a problem.

In the standard SAP working, when i am removing residual delivery quantity from the delivery. Two flags are set to 'C' status in VBUP for the Delivery Line item (UVALL and UVWAK).

So i tried to mimick the Standard SAP working and set the status to C when i set the Residual Quantity to zero. I was able to successfully change the status to C for both the fields UVALL and UVWAK.

After coming out of the transaction, i even checked the VBUP table entries and found that the field values had reflected in the database as well.

BUT when i opened the Delivery again using VL02N, i checked the internal table XVBUP and the status would be recalculated by the SAP System and would now be 'A' both. This is something that is better avoided as in this state when we try to PGI the Delivery it gives an error such as "Batches / valuation types not completely allocated".

Now, as soon as i visit the Batch Split tab once, this error gets corrected.

I checked why this was happening and found that UVALL and UVWAK had been set to C in XVBUP internal table by the SAP Standard flow when I visit the Batch Split subscreen.

Edited by: Omkar J Danke on Jan 11, 2012 4:03 PM

So, how should i change the VBUP statuses UVALL and UVWAK such that they always remain "C" ?

Edited by: Omkar J Danke on Jan 11, 2012 4:08 PM

nabheetscn
Active Contributor
0 Kudos

What i mean in my last post was to make your changes in performs in user exit where its nothing but simply moving the data...you ahould try playing with the values there only as after that sap standard will handle it..

Thanks

Nabheet

Former Member
0 Kudos

I will try that and let you know. I'm sure i did try it earlier but i will try again.

Former Member
0 Kudos

Hi

It was not feasible for me to try out the earlier perform that you mentioned Nabheet.

But I found a temporary solution that I used a standard perform to recalculate the internal incompletion statuses.

That seems to have worked.

The perform I used was PERFORM uc_complete_recalc(sapfv50u).

If my changes successfully work. I will close this topic.

nabheetscn
Active Contributor
0 Kudos

Okie so you basically called standard sub routine to recalculate..got it

Thanks

Nabheet

Former Member
0 Kudos

Let me try and explain this issue again.

Residual Qty Issue

Reason for residual Qty - The batch determination required by the Business is that only complete batches are to be assigned. The left over from the Original Qty becomes the residual Qty. And this residual sits in the main line item above the batches.

Workaround Solution:

As per the above error message we understand that to proceed with the PGI process we have to remove the residual qty manually. Once the residual Qty is removed, PGI is done successfully.

However as the creation of deliveries and PGI are done through batch jobs many of the deliveries gets stuck up because of the residual issue as explained above.

Users have to go and find such deliveries and remove the residual manually for each and every delivery which is a very tedious and time consuming work for the Business.

Business Requirement:

Business needs an automated way to remove the residual Qty from the Delivery.

Please note that we have proposed the solution to modify a User-Exit (Include: MV50AFZ1, Form : USEREXIT_SAVE_DOCUMENT_PREPARE) such that the Residual Qty is deleted when the delivery is saved.

However we are facing a lot of issues in updation of statuses in standard tables like VBUK, VBUP and some other fields in standard tables like LIPS, VBFA etc. Also please note that this updation is done perfectly when the residual is removed manually.

Please help to us to know if there is any alternate User-Exit where we can write the code to delete this residual Qty so that the standard behavior of the delivery updates the required standard tables.

Or else let us know if there is any standard code, function module, perform, etc., which we can include in the existing User-Exit which will help update the standard tables.

Former Member
0 Kudos

Will someone please help me with this ?

nabheetscn
Active Contributor
0 Kudos

Hi,

The place where you are trying to make the change is correct. But i guess it will be good thing if you debug in parallel both the case one is manual and other through your exit and compare the entries in table for the same.

In case you find any difference make the corresponding changes and i believe it will work.

Nabheet

Former Member
0 Kudos

Yes Nabheet, what you say is true. If i can make the XLIPS, XVBUP and XVBFA tables just like they were to behave in Standard Code, then it would work fine.

There are many scenarios and the tables have different statuses for each scenario. In many cases the standard also changes the Sales Order Item Statuses in XVBUP.

Should I also set those like the standard code would ?

(Setting statuses manually like the standard code is very tedious, is there any short cut ? )

Edited by: Omkar J Danke on Dec 15, 2011 5:06 PM

nabheetscn
Active Contributor
0 Kudos

I will say what you can do is you can modify the line in another perform which is like move data etc as after sAP standard will do its process and hence all status will get updated automativally.

Nabheet

Former Member
0 Kudos

Continuing from the last code

* Capture index
                v_sy_tabix_vbup = sy-tabix.
* If reference document type is Sales Order or Return Order
                IF xlips-vgtyp = c_c OR xlips-vgtyp = c_h.
* Copy current xvbfa header values to be restored later
                  CLEAR v_xvbfa_copy.
                  v_xvbfa_copy = xvbfa.
* Get VBFA Entry Respective to the current entry
                  CLEAR xvbfa.
                  READ TABLE xvbfa WITH KEY
                  vbeln = xlips-vbeln
                  posnn = xlips-posnr.
                  IF sy-subrc = 0.
* Capture index
                    v_sy_tabix_vbfa = sy-tabix.

* Update Status overview for Sales Order and Return order
               CLEAR: xvbfa-rfmng,          "Referenced quantity in BUOM
               xvbfa-rfmng_flo, "Referenced quantity in sales unit float
               xvbfa-rfmng_flt.       "Referenced quantity in BUOM float

* Set update flag depending on mode. Create or Change.
                    IF t180-trtyp = c_h.            "Create
                      xvbfa-updkz = c_i.            "Insert
                    ELSE.                           "Change
                      xvbfa-updkz = c_u.            "Update
                    ENDIF.

                    MODIFY xvbfa INDEX v_sy_tabix_vbfa TRANSPORTING
                    rfmng rfmng_flo rfmng_flt updkz.
* Restore xvbfa header values
                    CLEAR xvbfa.
                    READ TABLE xvbfa FROM v_xvbfa_copy.
                    IF sy-subrc = 0.
* Do nothing
                    ENDIF.
                  ENDIF.
                ENDIF.  "VBFA
* Batch not assigned. Hence this is a top level delivery item
                CLEAR: xlips-lfimg,     "Residual Quantity
                xlips-ntgew,            "Residual Qty Net weight
                xlips-brgew,            "Residual Qty Gross weight
                xlips-volum,            "Residual Qty Volume
                xlips-lgmng,            "Actual quantity delivered
                xlips-lfimg_flo,        "Residual Qty Float
* Make item not relevant for picking
                xvbup-kosta.            "Top item picking status

* Set update flag depending on mode. Create or Change.
                IF t180-trtyp = c_h.            "Create
                  xvbup-updkz = c_i.              "Insert
                ELSE.                            "Change
                  xvbup-updkz = c_u.              "Update
                ENDIF.
                MODIFY xvbup INDEX v_sy_tabix_vbup TRANSPORTING
                kosta updkz.

                MODIFY xlips INDEX v_sy_tabix TRANSPORTING
                lfimg ntgew brgew volum lgmng lfimg_flo.
              ENDIF.   "VBUP
* Restore xvbup header values
              CLEAR xvbup.
              READ TABLE xvbup FROM v_xvbup_copy.
              IF sy-subrc = 0.
* Do nothing
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
* Reset sy-tabix
      IF sy-tabix NE v_sy_tabix.
        READ TABLE xlips INDEX v_sy_tabix.
        IF sy-subrc = 0.
* Do nothing
        ENDIF.
      ENDIF.

Now a part of the code is to apply flag logic(so that the code only runs for some shipping points and sales organisations) so you can ignore that.

But the main gist of it is that i have tried to change the internal tables XLIPS, XVBUP and XVBFA to get my job done. But all things are not getting corrected.

Please let me know if i am doing it wrong. or if there is a better way or i have missed anything.

Thanks a lot in advance!!

Former Member
0 Kudos

And the main logic of the code is as follows

* Get Sales Organisation and Shipping Point values from YGV_FLAGS table
* for FLAG477
    REFRESH  it_ygvflags.
    SELECT vkorg vstel FROM ygv_flags
    INTO TABLE it_ygvflags
    WHERE flag = c_flag477.
    IF sy-subrc = 0.
      SORT it_ygvflags.
    ENDIF.

    LOOP AT xlips.
* Capture index
      CLEAR v_sy_tabix.
      v_sy_tabix = sy-tabix.
* Changes to remove residual quantity from header level item in delivery
      CLEAR: wa_ygvflags, v_apply_flag.
* Check if Delivery's Sales Organisation and Shipping Point matches
* with any of the corresponding values mentioned in YGV_FLAGS table.
      READ TABLE it_ygvflags INTO wa_ygvflags WITH KEY
      vkorg = xlikp-vkorg
      vstel = xlikp-vstel
      BINARY SEARCH.
      IF sy-subrc = 0.
        v_apply_flag = c_x.
      ELSE.
* Check if Delivery's Sales Organisation matches
* with any of the Sales Org values mentioned in YGV_FLAGS table.
        READ TABLE it_ygvflags INTO wa_ygvflags WITH KEY
        vkorg = xlikp-vkorg
        vstel = space
        BINARY SEARCH.
        IF sy-subrc = 0.
          v_apply_flag = c_x.
        ELSE.
* Check if Delivery's Shipping Point matches
* with any of the Shipping Point values mentioned in YGV_FLAGS table.
          READ TABLE it_ygvflags INTO wa_ygvflags WITH KEY
          vkorg = space
          vstel = xlikp-vstel
          BINARY SEARCH.
          IF sy-subrc = 0.
            v_apply_flag = c_x.
          ENDIF.
        ENDIF.
      ENDIF.
      IF v_apply_flag = c_x.
* Sales Org and/or Shipping Point matches
        IF NOT xlips-kcmeng IS INITIAL.
* Cumulative Batch Split Quantity is not zero. Hence batch split item.
          IF xlips-charg IS INITIAL.
* If residual exits
            IF NOT xlips-lfimg IS INITIAL.
* Copy current xvbup header values to be restored later
              CLEAR v_xvbup_copy.
              v_xvbup_copy = xvbup.
* Get VBUP Entry Respective to the current entry.
              CLEAR xvbup.
              READ TABLE xvbup WITH KEY
              vbeln = xlips-vbeln
              posnr = xlips-posnr.
              IF sy-subrc = 0.