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

Accepted Solutions (1)

Accepted Solutions (1)

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

Answers (2)

Answers (2)

Jelena
Active Contributor
0 Kudos

The configuration for an incompletion procedure is very simple. I'm an ABAPer myself, but I've done it once. It is located in SPRO, under Sales and Distribution -> Basic Functions -> Log of Incomplete Items. First step is to define the procedure (i.e. what fields should be included and how it should behave). The second step is to assign the procedure to the document type. I would first check if there is a procedure assigned already and if it could be simply modified to add a new field.

The advantage of using an incompletion procedure (apart from no programming) is that the document may still be saved and the required field may be filled in later. The incomplete document won't be processed any further, so there is no risk. With the user exit it's "all or nothing", which may be frustrating to the users.

Former Member
0 Kudos

Dear friend,

Please try the abort function with in MV45AFZZ (USEREXIT_SAVE_DOCUMENT).

hope this will help.

regards

ravi k

Former Member
0 Kudos

Has noone an idea how it's done?

I would appreciate help a lot because we need this quite urgently.

Thanks again,

Regards,

Melanie

Shiva_Ram
Active Contributor
0 Kudos

Hi,

I think you can provide message output in the user exit.

What I suggest you is to put your coding in the ABAP forum, then some one can help you resolve the issue.

Regards

Former Member
0 Kudos

Hi,

you can use userexit MV45AFZB FORM userexit_check_vbak. There you can also include an error message.

I just saw that you are using it, sorry I was just answering to quick... Try instead MV45AFZZ USEREXIT_SAVE_DOCUMENT_PREPARE called at save time.

When you get the error message you can click it away and continue processing (in your case filling the field) but without it you will not be able to save.