cancel
Showing results for 
Search instead for 
Did you mean: 

User Exits in prog SAPMV45A - how to abort save? (VA41, VA42)

Former Member
0 Kudos

Hi everyone,

When creating or changing a contract using VA41/VA42 I want to check if a z-field of VBAK is filled or not. For certain Sales Document Types I want to abort saving if the field is initial. But how do I do that?

I've tried Include MV45AFZZ form USEREXIT_SAVE_DOCUMENT_PREPARE.

I check for sy-tcode, vbak-auart and my z-field. Then I've tried to output a message (using MESSAGE 'my message' TYPE 'E' and 'W') if the field is empty. But that ended up in an endless-display-message-loop:

1) user changes/creates a contract

2) user saves

3) the z-field is empty but should be filled

4) message is displayed

5) user presses enter

6) back to 4)

Then I've tried Include MV45AFZB form USEREXIT_CHECK_VBAK. I only check when sy-ucomm is 'SICH' (which is the saving ok-code) because only then the check should be performed. But also here happens the exact same as described above.

I've done some searching around and found that there shoulnd't be any message outputs in the user exits. Is that correct? So how else can I abort the saving and tell the user why it was aborted?

Do I have to put my coding somewhere else? Where?

Or how else can I abort saving?

Thanks for your help!

Best regards,

Melanie

View Entire Topic
Jelena
Active Contributor
0 Kudos

Melanie, why don't you just use an incompletion procedure? It can be assigned to the specific document types and does not require any programming whatsoever.

If you insist on going through a user exit, I have to warn you that it's not quite right to check the sy-tcode and sy-ucomm. The same user exits are used when, for example, a document is created by BAPI and then none of this will work. SAP recommends to use t180-trtyp field instead - it's 'H' when a document is created and I think 'V' is for Display, but I might be wrong - check in the debugger.

USEREXIT_CHECK_VBAK user exit in MV45AFZB seems like the correct place. I've used messages with type E there myself without any problems.

USEREXIT_SAVE_DOCUMENT_PREPARE in MV45AFZZ is usually the last resort. I found that adding this line before the error message helps, although I have no reasonable explanation for it:

fcode = 'ENT1'.

Former Member
0 Kudos

Thanks everyone for the answers!

Thanks Jelena for the tip with the function code; that did the trick. I wasn't anymore in an endless loop.

Also I considered your hints concerning sy-ucomm and sy-tcode and I do my checks without them now and it seems to work fine.

About using "incompletion procedure". I unfortunately havn't used them before and I was told to check this z-field before saving so the only way to go which I knew was user exits. But thanks for pointing it out!

Regards,

Melanie