Handling Messages

All messages that occur during the execution of a script are recorded in the log. However, you may want the script to react to certain classes of message, or even specific messages, during the execution of the test script. For this, you use MESSAGEENDMESSAGE blocks. These can capture messages resulting from the following commands: SAPGUI, TCD, LOGMSG, FUN, inline ABAP, CALLSTATIC and CALLMETHOD. The messages are stored in the command interface of the ENDMESSAGE command and can be accessed programmatically in the script. For example, you can loop through all the collected messages and process them as required:

MESSAGE ( MSG_1 ).

LOGMSG ( LOGMSG_1 ).

LOGMSG ( LOGMSG_2 ).

ENDMESSAGE ( E_MSG_1 ).

DO &TFILL.

IF ( E_MSG_1[&LPC]-MSGV1 = 'Test name' ).

LOG ( E_MSG_1[&LPC]-MSGV1 ).

ENDIF.

ENDDO.

Message Rules

In the MESSAGE command interface, you can specify rules so that eCATT knows how to react to various messages. In each rule, you can specify any combination of message type, number or ID. When a message occurs, it is checked against the rules in the order that they are specified in the command interface. If the message matches a rule, it is processed according to the rule and no further rules are checked for that particular message. If the message is not caught by one of the user-defined rules, the eCATT default rules are applied.

Because rules are processed in the order that they are specified in the command interface, the more specific a rule is, the higher it should be in the list. For example:

MODE

EXIT

MSGTYP

MSGID

MSGNR

‘F’

‘E’

007

‘A’

‘E’

Here, if error message 007 occurs, the script would be marked as a fail although all other error messages are allowed. If the rules in the above example were swapped, the general rule allowing all error messages would always be processed and the more specific rule that error message 007 should be a fail would never be reached.

Encapsulating Commands

Messages that would normally cause a script to fail can be specified as allowed in the MESSAGE command interface. Applications that terminate inside a MESSAGE…ENDMESSAGE block do not need to cause the execution of the script to end – the execution can jump to the ENDMESSAGE command and carry on from there. These functions allow you to build robust scripts by enclosing potentially problematic commands inside MESSAGE…ENDMESSAGE blocks and specifying the message rules accordingly.

Nesting MESSAGE…ENDMESSAGE Blocks

MESSAGE…ENDMESSAGE blocks can contain other MESSAGE…ENDMESSAGE blocks. Messages captured by an inner block are not captured by an outer block.

Learning Message Handling

To become familiar with the message handling rules, you can use the LOGMSG command to generate specific messages. For example:

MESSAGE ( MSG_1 ).

MESSAGE ( MSG_2 ).

LOGMSG ( LOGMSG_1 ).

LOGMSG ( LOGMSG_2 ).

ENDMESSAGE ( E_MSG_2 ).

LOGMSG ( LOGMSG_3 ).

ENDMESSAGE ( E_MSG_1 ).