Analysis will trigger an AfterRedisplay callback (if you've registered a callback procedure) after a wide array of events, and you might think that some of those events shouldn't cause a redisplay, but they do. For example, viewing the help file, the about dialog or cancelling the prompts dialog all trigger an AfterRedisplay callback.
One of the actions that triggers an AfterRedisplay callback is the SAPAddMessage API method, and it will trigger the callback every time you call SAPAddMessage, so if you're adding multiple messages, Analysis will execute the callback multiple times.
Analysis does recognise when you've called SAPAddMessage from within the AfterRedisplay callback stack, and will stop the AfterRedisplay procedure from triggering itself.... So you won't inadvertantly cause an infinite loop by calling SAPAddMessage from within the AfterRedisplay procedure stack.
However, in other parts of your code, you could potentially trigger AfterRedisplay multiple times. So, how do you add multiple messages without triggering AfterRedsiplay multiple times? I've solved this problem by setting a global VBA variable. You could possibly use Application.Run("SAPExecuteCommand", "PauseVariableSubmit", "Off"), or temporarily deregister the callback using Application.Run("SAPExecuteCommand", "UnregisterCallback", "AfterRedisplay") to achieve similar results.
Here's my global variable approach:
1. Define a global VBA variable named bSkipCallBack:
Public bSkipCallBack as Boolean 'This will default to False
2. In your AfterRedisplay callback procedure, make the code execution depend upon the global variable:
Public Sub callback_AfterRedisplay()
If bSkipCallBack Then
Exit Sub
Else
'Do AfterRedisplay actions here
'.....
End If
End Sub
3. Elsewhere in your code, when you need to call SAPAddMessage multiple times, set the global variable to True, add your messages, and then revert the variable to false
Private Sub AddMessages()
bSkipCallback = True
Application.Run("SAPAddMessage", "First of many messages", "INFORMATION")
'More messages here
'...
bSkipCallback = False
End Sub
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
10 | |
5 | |
5 | |
4 | |
4 | |
4 | |
3 | |
3 | |
3 |