‎2013 Nov 15 9:01 AM
HI,
I am using user exit USEREXIT_SAVE_DOCUMENT_PREPARE for restricting user to save sales order VA01 if RV45A-KWMENG value greater then MARD-LABST only with VBAK-AUART = ZPBO. PLEASE HELP ME TO BUILD LOGIC.
I have to restrict user from being save sales order if order quantity is more then actual available quantity for sales document type ZPBO,ZCBO only please help me to build logic for the same. I am techno-functional consultant but I am more into functional please help.
‎2013 Nov 15 9:15 AM
Yes..the approach seems to be ok.
You need to populate an error message if your required condition does not meet.
If error message is raised,then system won't alllow user to save the order.
Regards
Ansumesh
‎2013 Nov 15 9:28 AM
Hey,
First check the structure available in USEREXIT_SAVE_DOCUMENT_PREPARE, because you need to access values of KWMENG, LABST and AUART.
If these field values are available, then do the below coding:
*Check sales document type ZPBO,ZCBO
IF ( VBAK-AUART = 'ZPBO' OR VBAK-AUART = 'ZCBO' )
*Check if order quantity is more then actual available quantity
IF ( RV45A-KWMENG > MARD-LABST )
" Raise error message
ENDIF.
ENDIF.
hope it helps. you just need to give correct structure name and message number with message class.
Thanks!
‎2013 Nov 15 11:41 AM
‎2013 Nov 15 9:34 AM
Hi,
Try this code in sales order user-exit.
| MV45AFZZ, |
FORM userexit_save_document_prepare.
If XVBAK-AUART = 'ZPBO' OR
XVBAK-AUART = 'ZCBO'
LOOP AT XVBAP WHERE UPDKZ = 'I' OR
| UPDKZ = 'U'. |
*get the Storage Loacation to read the MARD-LABST
IF xvbap-lgort IS INITIAL.
SELECT SINGLE l_lgort FROM t320
| WHERE werks = xvbap-werks. | |
else.
move xvbap-lgort to l_lgort.
endif.
select single l_labst from mard
| where matnr = xvbap-matnr and | |
| werks = xvbap-werks and | |
| lgort = l_lgort. |
if xvbap-kwmeng GE L_LABST.
L_ERROR = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF L_ERR = 'X'.
message E1xxx(z1) with vbap-posnr vbap-lgort. "CHECK RELAVENT MESSAGE IN z1 MESSAGE CLASS.
ENDIF.
‎2013 Nov 15 11:45 AM
thank you very much for your reply I am getting error as l_lgort is not defined
‎2013 Nov 15 11:48 AM
Hi,
Try now!
DATA: L_LGORT TYPE LGORT_D,
L_LABST TYPE MARD-LABST.
FORM userexit_save_document_prepare.
If XVBAK-AUART = 'ZPBO' OR
XVBAK-AUART = 'ZCBO'
LOOP AT XVBAP WHERE UPDKZ = 'I' OR
| UPDKZ = 'U'. |
*get the Storage Loacation to read the MARD-LABST
IF xvbap-lgort IS INITIAL.
SELECT SINGLE l_lgort FROM t320
| WHERE werks = xvbap-werks. | |
else.
move xvbap-lgort to l_lgort.
endif.
select single l_labst from mard
| where matnr = xvbap-matnr and | |
| werks = xvbap-werks and | |
| lgort = l_lgort. |
if xvbap-kwmeng GE L_LABST.
L_ERROR = 'X'.
EXIT.
ENDIF.
ENDLOOP.
IF L_ERR = 'X'.
message E1xxx(z1) with vbap-posnr vbap-lgort. "CHECK RELAVENT MESSAGE IN z1 MESSAGE CLASS.
ENDIF.
‎2013 Nov 15 11:50 AM
Hi,
If you are using Kiran's code,
declare as -
data : l_lgort type LGORT_D.
BR.
‎2013 Nov 15 11:58 AM
‎2013 Nov 15 12:08 PM
‎2013 Nov 15 12:17 PM
Hi,
use the below logic in the form save_document_prepare.
DATA: l_lgort TYPE lgort_d,
l_labst TYPE mard-labst,
l_error(1).
IF xvbak-auart = 'ZPBO' OR
xvbak-auart = 'ZCBO'.
LOOP AT xvbap WHERE updkz = 'I' OR
updkz = 'U'.
*get the Storage Loacation to read the MARD-LABST
IF xvbap-lgort IS INITIAL.
SELECT SINGLE lgort INTO l_lgort FROM t320
WHERE werks = xvbap-werks.
ELSE.
MOVE xvbap-lgort TO l_lgort.
ENDIF.
SELECT SINGLE labst INTO l_labst FROM mard
WHERE matnr = xvbap-matnr AND
werks = xvbap-werks AND
lgort = l_lgort.
IF xvbap-kwmeng GE l_labst.
l_error = 'X'.
EXIT.
ENDIF.
CLEAR: l_lgort,
l_error,
l_labst.
ENDLOOP.
if L_ERROR = 'X'.
MESSAGE e921(z1) WITH vbap-posnr .
ENDIF.
ENDIF.
‎2013 Nov 15 12:40 PM
thank you very much kiran I have done same as suggest by you and tested but I am able to save sales order. instead of getting error.
‎2013 Nov 15 12:43 PM
Do this way give an information message
MESSAGE i157(ABC) WITH sy-msgv1.
CLEAR sy-ucomm.
fcode ='ENT1'.
LEAVE TO SCREEN
sy-dynnr.
‎2013 Nov 15 12:49 PM
Hi,
Change the below statement and try .
from
LOOP AT xvbap WHERE updkz = 'I' OR
updkz = 'U'.
To
LOOP AT xvbap.
‎2013 Nov 18 4:54 PM
‎2013 Nov 19 12:05 PM
Not yet kiran i have got 2 high priority issue so i am working on it. i will update my soultion here and i tried your process but i am able to save sales order.
‎2013 Nov 15 9:39 AM
Hi Sameer,
The steps are -
1) Go to SE38 and give program as 'MV45AFZZ'.
2) Locate the exit USEREXIT_SAVE_DOCUMENT_PREPARE and create implicit enhancement. Throw error message suitably.
Ask further if you need any help.
BR.
‎2013 Nov 15 11:43 AM
‎2013 Nov 15 11:44 AM
‎2013 Nov 15 1:05 PM
Hi Sameer,
First write Select query to get the LABST value . After that Compare Kwmeng value with LABST.
Regards,
Hiriyappa