Skip to Content

I have a requirement in my project for adding validation for tcode VA01

Nov 07, 2017 at 05:46 AM


avatar image
Former Member

I have a requirement in my project..For the tcode = VA01 or VA02, for sales org = 'mxco',distribution channel = 20, division = tv,order type = zsf2 and order reason = zar,

as I click on the save button, I have to check that order field (aufnr) in account assignment tab at item level is blank or not, if it is blank then I have to display the error. I am new to user exits and I am not able to find the correct userexit where I can write my code. Any help will be appreciated.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Veselina Peykova
Nov 07, 2017 at 06:57 AM

On top of what Raymond said, you really need to get back to your functional consultant for clarifications to understand what is the idea behind, because AUFNR is on header and on item level.

From the details that you provided I would say that the solution design is rather poor and it would not work well in real life situations.

Seriously, validation for AUFNR on order type+sales area+order reason is not very intuitive and once the users figure out that the easiest way to get rid of the the error is by changing the order reason you can imagine what will be the end result. Raising an error in the exit that Raymond suggested may be right from technical perspective, but it is not immensely helpful to business users, who would be more willing to comply with rules if they were presented with a screen where they can correct their mistake - like standard document incompletion is designed. #justmy2cents

10 |10000 characters needed characters left characters exceeded
Raymond Giuseppi
Nov 07, 2017 at 06:29 AM

During your search didn't you find the good old SD user-exit (USEREXIT_SAVE_DOCUMENT_PREPARE) there are already so many threads on this kind of question?

Show 3 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Raymond,

I tried putting my code in the above mentioned userexit but my code didn't run successfully.

Below is my code which i have written inside an include and have called this inlcude in the userexit_save_document_prepare.

DATA: wa_vbap1 TYPE vbap.
if sy-tcode = 'VA01' or sy-tcode = 'VA02'.
IF vbak-vkorg = 'MXCO' AND vbak-vtweg = '20' AND vbak-spart = 'TV'
AND vbak-auart = 'ZSF2' AND vbak-augru = 'ZAR' .

READ TABLE xvbap INTO wa_vbap1 INDEX 1.
IF wa_vbap1-aufnr IS INITIAL.
MESSAGE s000(zsd) WITH 'ORDER field cannot be blank' DISPLAY LIKE 'E'.

Please let me know if i am writing anything wrong.


Use an actual error message type 'E', your current code wont stop the save. Put your customer form(s) in include MV45AFZZ to get acess to main program data. Don't hesitate to debug. Also provide more information to user in the error message like item number xvbap-posnr and a 'why' the field is mandatory.

  • You could also remove the check of sy-tcode, this exit wont be called in display mode (or better check t180-trtyp value) but check, for example, that the item is not cancelled.
  • You could trigger incompletion log modifying table XVBUV. (to complete Veselina Peykova answer) in this case don't raise any message.

Former Member
Raymond Giuseppi

Thanks Raymond,

Your suggestions solved my problem.