Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

STOP SAVING SALES ORDER

Former Member
0 Likes
4,801

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.

19 REPLIES 19
Read only

Former Member
0 Likes
3,275

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

Read only

Former Member
0 Likes
3,275

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!

Read only

0 Likes
3,275

hi,

I tried this not working.

Read only

Former Member
0 Likes
3,275

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.

Read only

0 Likes
3,275

thank you very much for your reply I am getting error as l_lgort is not defined

Read only

0 Likes
3,275

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.

Read only

0 Likes
3,275

Hi,

If you are using Kiran's code,

declare as -

data : l_lgort type LGORT_D.

BR.

Read only

0 Likes
3,275

unknown coloumn name l_lgort in field list error

Read only

0 Likes
3,275

its already defined and I am doing through enhancement.

Read only

0 Likes
3,275

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.

Read only

0 Likes
3,275

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.

Read only

0 Likes
3,275

Do this way give an information message

 

MESSAGE i157(ABC) WITH sy-msgv1.
CLEAR sy-ucomm.
fcode =
'ENT1'.
LEAVE TO SCREEN

sy-dynnr.

Read only

0 Likes
3,275

Hi,

Change the below statement and try .

from

LOOP AT xvbap WHERE updkz = 'I' OR
                         updkz = 'U'.

To
LOOP AT xvbap.

Read only

0 Likes
3,275

hi

have u resolved the the issue?

Read only

0 Likes
3,275

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.

Read only

Former Member
0 Likes
3,275

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.

Read only

0 Likes
3,275

hii

this I know I need logic to be written in program

Read only

0 Likes
3,275

Hi,

Check the logic above and implement it.

Thanks,

Kiran

Read only

0 Likes
3,275

Hi Sameer,

First write Select query to get the LABST value . After that Compare Kwmeng value with LABST.

Regards,

Hiriyappa