Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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

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

Former Member
replied

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

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question