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: 

MV45AFZZ cancel document saving process

MichiFr
Participant
0 Kudos

Hi,

I'm investigating an option on how to cancel the saving process of a document in user-exit include MV45AFZZ from within transaction VA01/VA02.

Currently I've tried to do some MESSAGE E in FORM USEREXIT_SAVE_DOCUMENT_PREPARE or FORM USEREXIT_SAVE_DOCUMENT w/o any success so far.

Of course MESSAGE A is possible but does a hard break and is not the best solution at all.

Setting any screen like SET SCREEN 0 or LEAVE TO SCREEN 0 or any similar things did not work either.

What am I trying to do? I would like to check some VBAP/VBAK fields if certain conditions are met and cancel the saving process if necessary - of course without dropping the complete document.

I've already searched the forum here and only found hints like those already mentioned above - but nothing really specific.

Another thing which came into my mind is what about storing some a line into the incomplete log of the transaction to prevent from saving? However, I did not found any function module to add some lines to the log in user-exit MV45AFZZ so far.

Any hints on how to accomplish this?

1 ACCEPTED SOLUTION

tamas_hoznek
Product and Topic Expert
Product and Topic Expert

I used this code snippet to achieve your goal:

MESSAGE Sxxx. "to tell the user what's the problem

PERFORM FOLGE_GLEICHSETZEN(SAPLV00F).

FCODE = 'ENT1'.

SET SCREEN SYST-DYNNR.

LEAVE SCREEN.

This will display a message about the problem or the reason for not saving the document, and stay on the same screen where the user was when clicking on 'Save'.

This should theoretically work in either USEREXIT_SAVE_DOCUMENT_PREPARE or USEREXIT_SAVE_DOCUMENT as far as I remember. USEREXIT_SAVE_DOCUMENT_PREPARE is a better location to do something like this though.

18 REPLIES 18

marcin_milczynski
Contributor
0 Kudos

Hi,

You should achieve it by calling message type E in user-exit USEREXIT_SAVE_DOCUMENT_PREPARE - I've done it many times and it worked.

Best regards,

Marcin

0 Kudos

Marcin,

thanks for your reply!

I've tried this already, however the problem is after confirming the red error message by pressing ENTER, the transaction immediately enters FORM USEREXIT_SAVE_DOCUMENT_PREPARE again and shows this error again - this continues unless I switch to another transaction.

The user is not able to change the field values which caused the error message to appear anymore.

So basically I'm searching for a way to cancel document saving with e.g. an error message or similar and let the user, after confirming the message, modify the document again to get rid of this error.

Michael

0 Kudos

Michael, Why don't you try the exit FORM userexit_move_field_to_vbak.in MV45AFZZ

0 Kudos

Why don't you use USEREXIT_CHECK_VBAK, VBAP, VBKD or VBEP, those exits exist for that... Which data are you checking, which is not editable after USEREXIT_SAVE_DOCUMENT_PREPARE ?

Regards,

Raymond

0 Kudos

Hi..

I  am using USEREXIT_SAVE_DOCUMENT_PREPARE it is giving the error message as I wanted but after the message even I press enter also it is not moving to the editable mode can you help me

naimesh_patel
Active Contributor

You can try like this in user exit USEREXIT_SAVE_DOCUMENT_PREPARE. NEVER try to trigger error from the USEREXIT_SAVE_DOCUMENT.


      fcode = 'ENT1'.
      message e999(Z1) with 'Error occurred, press enter to continue...'.

Regards,

Naimesh Patel

tamas_hoznek
Product and Topic Expert
Product and Topic Expert

I used this code snippet to achieve your goal:

MESSAGE Sxxx. "to tell the user what's the problem

PERFORM FOLGE_GLEICHSETZEN(SAPLV00F).

FCODE = 'ENT1'.

SET SCREEN SYST-DYNNR.

LEAVE SCREEN.

This will display a message about the problem or the reason for not saving the document, and stay on the same screen where the user was when clicking on 'Save'.

This should theoretically work in either USEREXIT_SAVE_DOCUMENT_PREPARE or USEREXIT_SAVE_DOCUMENT as far as I remember. USEREXIT_SAVE_DOCUMENT_PREPARE is a better location to do something like this though.

0 Kudos

Hi Tamas,

that's the best solution ever- Thanks for this! This solved my problem at the end - points awarded!

Michael

0 Kudos

Hi Tamas,

I am using MV45AFZB for doing my changes.If error message occured then I have to raise an error message and user should not be allowed to save the sales order.

I have written my logic in USEREXIT_CHECK_VBAP .But after the error message if I press enter again I am able to change the sales order.

Could you please let me know the solution how to avoid the editing of sales order after the error message occured.

Thanks,

Komal Bhutada.

0 Kudos

Dear Tamas

Thanks for the solution, it worked well.

I just want to give another hint:

When the saving process is stopped, a warning is often not apropriate. But changing to message type "E" isn't an alternative , caused to the influence to the screen handling.

Use the following:

MESSAGE iXXX(X) DISPLAY LIKE 'E'.

instead of


MESSAGE wXXX(X).

Kind regards

Damian

Former Member
0 Kudos

Hi,

I got the same problem and the solution posted here has some major drawbacks: the user exit is also performed by several BAPIs which will not work as they should anymore!

The reason for that is that is because the BAPI doesn't terminate with an error as it should. The code after calling the BAPI cannot be reached anymore and if the BAPI is called within a loop you terminate this to. And last but not least you cannot handle this error in your code so the user just won't know what just happened.

Has anyone got an better solution? Maybe use another userexit to fill a message table and stop the Fuba from saving the sales document?

/chris

0 Kudos

Christian,

you may be right that this will cause some troubles when the User-Exit has been called from a previous BAPI call.

In my case I would like to stop the saving process when the user has entered some values into the material configuration which are not allowed. This condition, too, depends on some more conditions and cannot be caught elsewhere.

In my specific case, I don't execute this check (and hence the cancellation of the saving process) when the user-exit was called from within a BAPI.

Michael

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

I'm not exactly sure why is this a problem... when your transaction is called from a BAPI, just issue an error message instead of a success message. That should end up in the BAPIRET* structure of the BAPI, or am I wrong?

Then you can handle the error in the calling program and inform the user etc.

0 Kudos

The problem is not in the "MESSAGE" portion of it, it's in the "SET SCREEN", "LEAVE".

Former Member
0 Kudos

Michael,

how do you achieve that the check/cancellation is not performed in a BAPI call?

in my case the check/cancellation should always be performed so that the same restrictions are valid for all transactions on the system. why would you like to prevent the creation of faulty sales documents in VA01/VA02 but not in other transactions.

in my case i implemented the check before calling the BAPI as a work around till i find a better solution.

still other developers have will have trouble with these codings either the will wonder why the desired check does not work or they will wonder why their BAPI call leads to a leave to screen.

0 Kudos

>

> how do you achieve that the check/cancellation is not performed in a BAPI call?

Currently I'm using a coding like

 IF CALL_BAPI IS INITIAL.  MESSAGE... 

CALL_BAPI is available at least in MV45AFZB and MV45AFZZ, if I create a sales order from e.g. SD_SALESDOCUMENT_CREATE or SD_SALESDOCUMENT_MAINTAIN.

Better would be of course to show the warning/error message only when the user-exit is called from online processing and when called from batch or BAPI or similar it should write a message into the BAPIRET* structures or perhaps into the incompletion log of the document. So far I could not figure out how to do logging.

Michael

former_member184504
Participant
0 Kudos

Hi Tamas,

I have the same requirement but I am using that User Exit MV45AFZZ for VA41 (Contract Creation).

So will the snippet you have given will going to work for this VA41 as well??

Regards,

Paavan

0 Kudos

Hi,

I have also the same problem; I am trying to cancel the saving process of the ETM document by raising an error message in USEREXIT_SAVE_DOCUMENT_PREPARE(MJ3GFFZZ).

The error was successfully displayed. However, when you press enter the document is saved.

I tried the solution here but it does not solve my problem. Hope you can help me.

TIA,

Paul More