cancel
Showing results for 
Search instead for 
Did you mean: 

How to prevent line item net value from being negative in sap

Pankaj_M
Participant
0 Kudos

Hello Experts,

The requirement is to prevent line item net value from being negative in sales orders.

For example by mistake, there are more discounts and the net value is being negative, in that case, we need to block the sales order or show the order in the incompletion log.

Please check and suggest.

Thanks and Regards,

Pankaj

Accepted Solutions (0)

Answers (3)

Answers (3)

Lakshmipathi
Active Contributor
0 Kudos

Did you try with incompletion log ?

Kartik_Dua
Contributor
0 Kudos

Hi Pankaj,

Have you tried the "Plus/Minus" field on the Condition Type configuration in V/06 (under control data 1 section)? I am thinking on the lines of making that field "Positive" for the primary condition on the sales order. Lets try it out and see if it works for your requirement.

Thank you.

Kartik

Pankaj_M
Participant
0 Kudos

Thanks for the reply. I am looking for the Net value and not the condition type value.

Thanks and Regards,

Pankaj

Kartik_Dua
Contributor
0 Kudos

You can add logic to calculation type 2 which is used for Net Total on the pricing procedure. But in my opinion, a complete solution should include the config in my previous comment to make sure even condition value is not negative (unless you have a business reason to have a negative value for a primary condition type).

Thank you

Kartik

aoyang
Contributor
0 Kudos

Technical but more flexible solution will be to implement a user exit with ABAP. In user exit, we add logic to check each item's net value and if it's minus we can display error message/add to incomplete log/block the item.

Below is my sample code and please follow the steps to implement it. The result will look like my screenshot. When the user click save button, the exit is triggered, the error message displayed and save action disallow. The user have to go back once to main screen and go into the item's condition tab to fix the price.

Steps: Go to SE38, go into program MV45AFZZ, find FORM USEREXIT_SAVE_DOCUMENT_PREPARE. Enable implicit exit and create a new custom enhancement at the first line of that form.

Add the following code and activate the enhancement.

You can ask your ABAPer if you have any questions, or you can let me know in the comment.

Similarly, you can add logic to add the message to incompletion log, which you can do by adding message row in XVBUV internal table in the exit.

    "Check every sales items for the net value
LOOP AT XVBAP[] ASSIGNING FIELD-SYMBOL(<LW_XVBAP>).
IF <LW_XVBAP>-NETWR < 0. "If net value is minus
MESSAGE 'Negative net value not allowed' TYPE 'E'.
ENDIF.
ENDLOOP.

Pankaj_M
Participant
0 Kudos

Thank you for providing a detailed explanation. I will check and update you.

Thanks and Regards,

Pankaj

Pankaj_M
Participant
0 Kudos

Thank you for the details.

We are planning to do with the incompletion log so that the order will save and not be blocked for delivery. It's only blocked for Billing.

Please suggest how we can add this code for the incompletion procedure.

Thanks and Regards,

Pankaj

aoyang
Contributor
0 Kudos

mahajan_pankaj If you want to add the check to incompletion log, just add below code in the same enhancement spot(program MV45AFZZ, find FORM USEREXIT_SAVE_DOCUMENT_PREPARE.) It's working for me.

    DATA:ls_tvuvf TYPE tvuvf.
"Check every sales items for the net value
LOOP AT XVBAP[] ASSIGNING FIELD-SYMBOL(<LW_XVBAP>).

IF <LW_XVBAP>-NETWR < 0. "If net value is minus
"Get incomplete procedure for net value
SELECT SINGLE *
FROM tvuvf
INTO ls_tvuvf
WHERE fehgr = tvap-fehgr
AND tbnam = 'VBAP'
AND fdnam = 'NETWR'.

IF sy-subrc = 0.
"Add to incompletion log
APPEND INITIAL LINE TO xvbuv[] ASSIGNING FIELD-SYMBOL(<xvbuv>).
<xvbuv>-mandt = sy-mandt.
<xvbuv>-vbeln = <LW_XVBAP>-vbeln.
<xvbuv>-posnr = <LW_XVBAP>-posnr.
<xvbuv>-tbnam = ls_tvuvf-tbnam.
<xvbuv>-fdnam = ls_tvuvf-fdnam.
<xvbuv>-fehgr = tvap-fehgr.
<xvbuv>-statg = ls_tvuvf-statg.
<xvbuv>-msgkz = ls_tvuvf-msgkz.
<xvbuv>-sortf = ls_tvuvf-sortf.
ENDIF.
ENDIF.
ENDLOOP.