Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
Showing results for 
Search instead for 
Did you mean: 

Use Case Description

Select a value from a message text to be used as output parameter

During test automating you might face the challenge that only a part of a string is required as output parameter for subsequent steps to be used as input parameter.

Example: Let’s assume when creating a sales order with VA01 you just get the message ‘'Standard Order 12695 has been saved' and you would like to use only the number for subsequent steps, e.g. create delivery.

For most SAP standard transactions like VA01 you can capture the value directly from the standard message parameters in the status bar (e.g. MESSAGEPARAMETER1) via default components CBTA*GETMESSAGEPARAMS. But for some other transactions / applications and especially in the situation of custom code a number might not be available as an dedicated screen element but only as part of the complete message string. In this case the following procedure will help you to select the number and put it into an output parameter.

Although the better option for VA01 would be to use the message parameter directly via CBTA_GUI_SB_GetMessageParams I would like to use this as an example to outline the procedure.

A further requirement to this use case was that the number of digits of the output value should be flexible.

There is one option to change the string in 2 steps:

  1. Deleting the left part next to the number with VBScript Replace Function
  2. Deleting the right part next to the number with VBScript Replace Function

Another and simpler option is to use the VBScript Split Function, which can do the same in one step. (Thanks to Fabien Graille for the valuable input).

If the target value has a fixed number of characters the VBScript Mid Function could be used to do the same also in just one step.

For web applications there is an easier way to use the default component CBTA_WEB_A_GetMessageParams to extract parts of a message via message patterns.

For further VBSript Functions and Operators please check: VBScript Language Reference

To be able to follow this description I recommend to check the Standard How-To Guide for CBTA as well as the CBTA Default Component Reference in advance.

Reading the text message from screen

When ever you intend to check values or read values from the screen I recommend to use the Test Creation Wizard to capture the String from the screen via ‘Add Checkpoint’ during initial recording.

and select the option ‘Get Data’:

After finishing the recording and saving the script to SAP Solution Manager you need to edit the script in the Test Composition Environment (TCE).

Adjustment of Script after recording

In the TCE select the relevant Default Component that captures the text from the screen e.g. CBTA_GUI_GETPROPERTY. In the Parameters section select ‘Fixed’ in the Usage column and enter a meaningful name in the Value column for the Parameter ‘TARGETFIELD’:

With this action you provide the text string to the execution context as a token with name COMPLETE_TEXT.

Now you need to add new default component CBTA_A_SETINEXECUTIONCTXT to perform the string operation.

To do so please set both parameters to ‘Fixed’ and enter a new name of a token e.g. NUMBER_ONLY and the following VBScript command for value of the parameter ‘THEVALUE’:

%=Split($COMPLETE_TEXT$," ")(2)%

This command splits the text into several parts (sub strings) using space (" ") as delimiter and returns the 3rd sub string. As the first sub string starts at count (0), (2) is required for this example.

As final step you need to add the default component CBTA_A_GETFROMEXECUTIONCTXT to read the number from the token in execution context and write to an output parameter which can be used as import parameter in subsequent scripts.

Set usage of parameter NAME to Fixed and for OUTPUT to Exposed

For better transparency you should rename the generated parameter ‘OUTPUT’ to a more ‘speaking’ name like ORDER_NUMBER in Parameter tab strip:

If you now execute the script you can see in the log how the initial message text has been changed and the value populated as output parameter:

Now you can use the TCE to create a composite script and map this output parameter to the subsequent script as input parameter.