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: 

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

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

VeselinaPeykova
Active Contributor

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

5 REPLIES 5

raymond_giuseppi
Active Contributor

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?

0 Kudos

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'.
ENDIF.
endif.
ENDIF.

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.

0 Kudos

Thanks Raymond,

Your suggestions solved my problem.

VeselinaPeykova
Active Contributor

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