Application Development 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: 

How to make validations before saving a Sales Order?

Former Member
0 Kudos

Hi All,

I have tried to make some validations to header data captured when creating/changing Sales Order(VA01/VA02), especially to Plant Field.

Sample code :

I have tried to modify the User Exit (MV45AFZZ) Under teh form "userexit_field_modification" like below.

IF sy-tcode = 'VA01' OR

sy-tcode = 'VA02'.

DATA : v_werks like xvbap-werks,

v_flag1 type c.

  • LOOP AT SCREEN.

  • CHECK screen-name EQ 'VBAP-WERKS'.

READ TABLE xvbap INDEX 1.

v_werks = xvbap-werks.

LOOP AT xvbap.

IF v_werks <> xvbap-werks.

v_flag1 = 'Y'.

ENDIF.

  • ENDLOOP.

IF v_flag1 = 'Y'.

MESSAGE i990(v1) WITH 'Multiple plants Exist.'

'ZP Partner not auto determined.'.

ELSEIF NOT v_werks IS INITIAL.

MESSAGE i990(v1)

WITH 'ZP Partner is auto determined.'.

ENDIF.

ENDLOOP.

ENDIF.

Due to the above code the system response is dead slow.

please help me !!

Thanks in advace.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

if sy-tcode = 'VA01' OR

sy-tcode = 'VA02'.

DATA : v_werks like xvbap-werks,

v_flag1 type c.

READ TABLE xvbap INDEX 1.

v_werks = xvbap-werks.

if NOT v_werks IS INITIAL.

MESSAGE i990(v1)

WITH 'ZP Partner is auto determined.'.

ENDIF.

LOOP AT xvbap where werks <> v_werks .

MESSAGE i990(v1) WITH 'Multiple plants Exist.'

'ZP Partner not auto determined.'.

exit.

ENDLOOP.

ENDIF.

try like this..

6 REPLIES 6

Former Member
0 Kudos

if sy-tcode = 'VA01' OR

sy-tcode = 'VA02'.

DATA : v_werks like xvbap-werks,

v_flag1 type c.

READ TABLE xvbap INDEX 1.

v_werks = xvbap-werks.

if NOT v_werks IS INITIAL.

MESSAGE i990(v1)

WITH 'ZP Partner is auto determined.'.

ENDIF.

LOOP AT xvbap where werks <> v_werks .

MESSAGE i990(v1) WITH 'Multiple plants Exist.'

'ZP Partner not auto determined.'.

exit.

ENDLOOP.

ENDIF.

try like this..

0 Kudos

I would also recommend to move the code from USEREXIT_FIELD_MODIFICATION as it is called from within LOOP AT SCREEN to the form USEREXIT_SAVE_DOCUMENT_PREPARE which used generally for checks before saving sales document.

0 Kudos

Hi Sergei,

Initially, I have written under form USEREXIT_SAVE_DOCUMENT_PREPARE only, but as per requirement if they hit the Enter Button they need a Popup message.That's why I am trying in the from USEREXIT_FIELD_MODIFICATION .

Is there any way to do this...

Regards,

Raja

0 Kudos

Venkat,

Thanks for your reply. But we will get two times popup message when we have multiple plants.

Regards,

Raja

0 Kudos

I would use MV45AFZB, Form USEREXIT_CHECK_VBAP


*&---------------------------------------------------------------------*
*                                                                     *
*       This Userexit can be used to add addtional logic for          *
*       checking the position for completeness and consistency. 

Kind regards

Matthias Kabel

Former Member
0 Kudos

hi,

Normally subroutine userexit_field_modification is used for enable/disalble/active/input the particular fields for some creteria.

for validataion use the routine userexit_save_document_prepare

the logic also need to modify (

as per this logic

READ TABLE xvbap INDEX 1.

v_werks = xvbap-werks.

LOOP AT xvbap.

IF v_werks <> xvbap-werks.

v_flag1 = 'Y'.

ENDIF.

the flag always 'Y'

i guess you try to find out any duplicate plants in the item, for that

data xtemp like xvbap occurs 0.

xtemp[] = xvbap.

delete adjacent duplicates from xtemp by comparing werks.

if sy-subrc = 0.

duplicates

else.

no duplicates

endif.