Purpose
The onmessage() command triggers actions when messages are received from SAP. This command behaves as an independent screen block, similar to the onscreen command.
Syntax
onmessage
Options
The onmessage() command does not take any options.
Example
The following example demonstrates the onmessage() command on VA01 transaction.
Create a function that will execute when the user hits Enter key. We will use the onUIEvents command to trigger the function and we will use the message command to display it. If an incorrect code is entered, the onmessage() command will capture that and display the message on the screen as following:
Enter an incorrect value in the Sold-to field and press Enter key. The specified error message appears, as shown in above figure.
Script
Go to the VA01 script file and create a new inputfield with the following code:
//SAPMV45A.E0101.sjs
inputfield([3,1],"Sold-to",[3,22],{"name":"z_va01_soldto","size":10}); onUIEvents['Enter'] = va01_entersoldto; function va01_entersoldto(){ onscreen 'SAPMV45A.4001' set("F[Sold-to party]","&V[z_va01_soldto]"); enter(); onmessage message("E:" + _message); enter("/nva01"); }