cancel
Showing results for 
Search instead for 
Did you mean: 

BADI: Purchase order Workflow restart, Order Confirmation entered

Stephen_Niemann
Participant
0 Kudos
1,017

Hi there,

I´m new to the "BADI World", but I have an issue I´m trying to solve:
My Procurement Team wants a PO-Workflow, which only will be triggered AGAIN, when the price rises. I therefore implemented this code in BADI MMPUR_PO_WORKFLOW_RESTART:

   DATA newPoValue TYPE P.<br>    DATA newNetPriceAmount TYPE P.<br>    DATA oldPoValue TYPE P.<br>    DATA oldNetPriceAmount TYPE P.<br><br>    workflowrestarttype = 'N'.<br><br><br>    LOOP AT PURCHASEORDERITEM INTO DATA(N_PO_ITEM).<br>        newPoValue = newPoValue + N_PO_ITEM-netamount.<br>        newNetPriceAmount = newNetPriceAmount + N_PO_ITEM-NetPriceAmount.<br>    ENDLOOP.<br><br><br>    LOOP AT PURCHASEORDERITEM_DB INTO DATA(O_PO_ITEM).<br>        oldPoValue = oldPoValue + O_PO_ITEM-netamount.<br>        oldNetPriceAmount = oldNetPriceAmount + N_PO_ITEM-NetPriceAmount.<br>    ENDLOOP.<br><br><br>   IF newPoValue GT oldPoValue.<br>       workflowrestarttype = 'R'.<br>       RETURN.<br>   ELSEIF newNetPriceAmount GT newNetPriceAmount. "If Net Amount for line item 1 is changed then Conditional Restart<br>       workflowrestarttype = 'R'.<br>   RETURN.<br>ENDIF.

The code itself works quite well. The Idea was: If the price rises, trigger again the workflow, in any other case --> proceed.

I also already tried to just put

    DATA newPoValue TYPE P.<br>    DATA newNetPriceAmount TYPE P.<br>    DATA oldPoValue TYPE P.<br>    DATA oldNetPriceAmount TYPE P.<br><br>    workflowrestarttype = 'N'.<br>

as the only code, to see if it is the right BADI to achieve my goal, well, it didnt work.

Question:
We now have the issue, when the procurement manager enters the Order Confirmation for the PO, the Workflow will be triggered again.
How can I adjust that the Workflow of the PO will only be triggered (in case a OC is entered) when the price of the OC rises, but not in any other case?

View Entire Topic
Stephen_Niemann
Participant

Hi there I now found the solution.
First, these are my settings

And this is my code which solved it:

DATA newPoValue TYPE P.
    DATA newNetPriceAmount TYPE P.
    DATA oldPoValue TYPE P.
    DATA oldNetPriceAmount TYPE P.


CASE workflowrestarttype.
    WHEN 'R'.
        LOOP AT PURCHASEORDERITEM INTO DATA(N_PO_ITEM)."loop all PO Items from the new state
        IF N_PO_ITEM-purchasingdocumentdeletioncode <> 'L'."process item if not deleted
            newPoValue = newPoValue + N_PO_ITEM-netamount."add the values of the position up
            newNetPriceAmount = newNetPriceAmount + N_PO_ITEM-NetPriceAmount."save value of total order value
        ENDIF.
        ENDLOOP.


        LOOP AT PURCHASEORDERITEM_DB INTO DATA(O_PO_ITEM). "loop all PO Items from the prior state
        IF O_PO_ITEM-purchasingdocumentdeletioncode <> 'L'. "process item if not deleted
            oldPoValue = oldPoValue + O_PO_ITEM-netamount. "add the values of the position up
            oldNetPriceAmount = oldNetPriceAmount + N_PO_ITEM-NetPriceAmount. "save value of total order value
        ENDIF.
        ENDLOOP.

        IF newPoValue GT oldPoValue. "If the total Purchase order has risen, than restart the workflow
            workflowrestarttype = 'R'.
        RETURN.
        ELSEIF newNetPriceAmount GT newNetPriceAmount. "If the total NetPrice has risen, than restart the workflow
            workflowrestarttype = 'R'.
        ELSE.
            workflowrestarttype = 'N'.
        RETURN.
ENDIF.
ENDCASE.

I hope this helps others aswell

KjetilKilhavn
Active Contributor
0 Kudos

In our system I've found that the _DB parameters are supplied only with data for changed items, so your old PO value will only be correct if all items were changed.

I've resorted to a local class which selects from the database and then replaces/supplies with data supplied to the Business Add-In. I wish I had a better solution, but I haven't come up with one yet. Since there is no distinction (as far as I have been able to find) between an unchanged item and a new item in PURCHASEORDERITEM etc the _DB parameters can't be initialized from the other parameters.