Quantcast
Channel: SAP Solution Manager
Viewing all articles
Browse latest Browse all 230

How to use String Functions in CBTA

$
0
0

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 message parameters in the status bar (e.g. MESSAGEPARAMETER1). But for some other transactions / applications and especially in the situation of custom code or Web Applications the number might not be available via dedicated screen property 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 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. This requires 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

 

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

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.

add checkpoint.jpg

and select the option ‘Get Data’:

get data.jpg

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’:

Target field.jpg

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 first string operation.

set context 1.jpg

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

%=replace($COMPLETE_TEXT$,"Standard Order ","")%

 

This command replaces the text ‘Standard Order ‘ with an empty value ‘’ (so it actually deletes this left part of the string) and writes it to the token RIGHT_PART.

 

To do the same for the right text next to the number you need to add another default component CBTA_A_SETINEXECUTIONCTXT, set the Usage to Fixed for both parameters and enter the name ‘NUMBER_ONLY’ as well as the parameter value

%=replace($RIGHT_PART$," has been saved","")%

set context 2.jpg

 

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

get context.jpg

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

OUTPUT.jpg

If you now execute the script you can see in the log how the 3 steps are changing the initial message text and populating the value as output parameter:

log.jpg

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


Viewing all articles
Browse latest Browse all 230

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>