return

The return command is used to return values or messages from actions.

The return command enables users to return values or messages from actions and then display those values or messages on a SAP screen. The most common usage is to send an error message to a user when an invalid action occurs and then to end the script. The return command can be executed in WS to perform any of the following actions:

Note: When screen combinations are done, the return command should be used before any screen blocks.

The syntax for using return is as follows:

return("string");

Variables can also be used in return commands. To use a variable, such as a user-created variable or a system variable, the syntax would be as follows:

return(_variable);

Variables and strings can also be combined. To combine a variable and a string, the following syntax would be used:

return("string" +_variable);

Options

The return command does not take any options.

Example

In the following examples, we will demonstrate how the return command can be used in SAP screens.

Conveying Users to a SAP transaction

As previously stated, the return command is almost always used to throw an error message and then end the script. In this example, we will return a message and take users back to the initial SAP Easy Access screen, if no tcode is entered in the GuiXT field. Otherwise, we will take users to the transaction selected.

  1. On the Easy Access screen, create a pushbutton and a process call. use the following code:

     pushbutton([2,1], "Execute Return", "/n&V[fcode]", {"process":z_return, "size":[1,30]});
    inputfield([2,32], {"name":"fcode", "size":10, "nolabel":true}); 
    					
  2. Create a function that will be called by the pushbutton. The code is shown below:

    function z_return()  {
    	if(fcode == "")  {
    		return("E: Please enter a transaction code - ex. va01, mm01...");
    	}
    	onscreen 'SAPLSMTR_NAVIGATION.0100'
    	enter("/n&V[fcode]");
    } 
    					
  3. Save your changes and refresh the Easy Access screen. It now appears as shown below:



  4. Do not enter any transaction codes and click the pushbutton. You should see the following message on the statusline: