Skip to Content
Author's profile photo Reiner Markheiser

How to use String Functions in CBTA

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.

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 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)%

/wp-content/uploads/2014/10/split_577511.jpg

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

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 initial message text has been changed and the value populated as output parameter:

/wp-content/uploads/2014/10/log_577513.jpg

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

Assigned Tags

      21 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Claude ROSSI
      Claude ROSSI

      Hello Reiner,

      Your example is very interesting because it highlights the various possibilities that CBTA offers to evaluate VBScript expressions.

      It definitely makes sense for SAP GUI scenarios when a message is displayed in something else than the status bar (i.e.: the GuiStatusbar control).

      For Web applications the component CBTA_WEB_A_GETMESSAGEPARAMS can be used instead. This component has a built-in mechanism allowing the extraction of information from a text using patterns.

      The document providing a concrete example on how to use it can be found on the Test Management Wiki page at:

      SAP Solution Manager WIKI - Test Management - Solution Manager - SCN Wiki

      Direct link to CBTA 3.0 SP02 - Working with MessageParameters

      https://websmp107.sap-ag.de/~sapidb/011000358700000194852014E.PDF

      Best regards,

      Claude

      Author's profile photo Reiner Markheiser
      Reiner Markheiser
      Blog Post Author

      Thanks Claude for your comment. For sure in case of a web application this is much easier use that component. I updated the blog to make this more clear.

      Regards Reiner

      Author's profile photo Peter O'Leary
      Peter O'Leary

      HI Reiner

      A couple of more questions on CBTA

      How can we test a file upload scenario via CBTA (e.g Bulk Upload requirements for HR/PY scenarios we have for a specific customer)

      How can we find via CBTA script to take into a specific Work Item for the Universal  Work List?

      Really appreciate all your help....where is the location for all the How to Guides etc...

      Cheers

      Peter

      Author's profile photo Former Member
      Former Member

      Hello Reiner,

      Interesting article, thank you for sharing!

      We had a similar requirement with transaction MIRO (Post Vendor Invoice), which concatenates the invoice type with the invoice number in GETMESSAGEPARAMS.

      I must admit we struggled a bit before we found out how to use SET and GET IN EXECUTION CONTEXT components (in GUI).

      Funny you mention Fabien, he has been a VBscript guru for us as well. 🙂

      Best regards,

      Rémi.

      Author's profile photo Former Member
      Former Member

      Hi Reiner,

      It's very useful, thank you very much.

      Best regards,

      Darren

      Author's profile photo Former Member
      Former Member

      Hello Reiner,

      Thanks for your post. It's very useful.

      Could you please share some information on how to use the logical operators ( AND, OR etc ) inside the conditional statements ( IF...ELSE ) in CBTA.

      Best regards,

      Siva

      Author's profile photo Reiner Markheiser
      Reiner Markheiser
      Blog Post Author

      Hi Siva,

      the only operators that are supported here are:

       = for "Equal to"

       < for "Less than"

       > for "Greater than"

       <= for "Less than or equal to"

       >= for "Greater than or equal to"

       <> for "Not equal to"

       {contains} for "Contains"

       {startsWith} for "Starts with"

       {endsWith} for "Ends with"

       {matches} for checking whether the value matches a regular expression. The regular expressions are expressed using the .NET syntax.

      Further information can be found via this link:

      https://support.sap.com/content/dam/library/SAP%20Support%20Portal/support-programs-services/solution-manager/processes/Media%20Library/Test%20Management/CBTA%203.0%20SP05%20-%20Runtime%20Library%20and%20Default%20Components.pdf

      Regards Reiner

      Author's profile photo Former Member
      Former Member

      Hi Reiner,

      Thanks for this blog.

      I have a question for you or someone knows, I am trying to customize a composite test based on 2 targets component ( ECC / CRM ), how do you customize that to enable the execution on both environment.

      Thanks.

      Aminata.

      Author's profile photo Former Member
      Former Member
      Author's profile photo Former Member
      Former Member

      Hello Siva,

      Thanks, this guide was very helpful.

      Regards,

      Aminata.

      Author's profile photo Reiner Markheiser
      Reiner Markheiser
      Blog Post Author

      Hello Aminata,

      the answer from Siva is fully right and still works. The guide is based on an older Solution Manager Release. I just want to add a comment that in the current release you can also use the so called composite scripts as "master script" while the approach is exactly the same.

      @Siva: Thanks for your response.

      Regards Reiner

      Author's profile photo Former Member
      Former Member

      Hi Reiner,

      Actually, we create that "Master script" and we put on it some single ECC script  and a CRM composite script. It was easy to manage the parameters between the ECC and the CRM script.


      Thank you.


      Regards,

      Aminata

      Author's profile photo Former Member
      Former Member

      I have a question with CBTA. I saved multiple values in their own respective variables with the end of the variable incremented by 1. Example: VAR_1, VAR_2, VAR_3, VAR_4...., VAR_13.

      I want to be able to insert these values at a later step. Is there a quick way to do this using a loop? I have my DO LOOP set up using the following CBTA_GUI_SETTEXT where the value to insert into the text box is: %=VAR_$COUNTER$% but it is not working.

      Can this be done without creating a function?

      Author's profile photo Avijit Amitabh
      Avijit Amitabh

      Hi Bruce,

      Try using %VAR_$COUNTER$%

      We don't need an equal to (=) sign here since there is no operation involved. Please check and let me know if this works.

      Thanks,

      Avijit.

      Author's profile photo Claude ROSSI
      Claude ROSSI

      Hi,

      Avijit is right. The equal (=) is only used when you want to evaluate VBScript expressions.

      Hence, the 3 syntaxes below are equivalent:

      %VAR_$COUNTER$%

      %=InterpretToken( "VAR_" & $COUNTER$ )%

      %=InterpretToken( "VAR" & InterpretToken("COUNTER") )%

      The InterpretToken function is the one used internally by the runtime library to resolve the %token% and $token$ syntaxes.

      Please also keep in mind that we also have a #token# syntax which is helpful to manipulate numbers. This is explained in the documentation:

      "CBTA - Runtime Library and Default Components" chapter "Execution Context".

      Regards,

      Claude

      Author's profile photo Former Member
      Former Member

      This worked for me: %=InterpretToken( "VAR_" & $COUNTER$ )%

      Thank you very much as I was dealing with this for almost the whole day trying to figure it out. Much appreciated!

      Author's profile photo Claude ROSSI
      Claude ROSSI

      Hi,

      What about the first syntax? It should work properly as well.

      If this is not the case then, for sure, your Runtime Library is not up-to-date.

      To get the latest improvements you may have to implement the latest version of the SAP Note 2029868 on your SOLMAN system.

      2029868 - CBTA - Runtime Library - Fixes & Improvements

      Claude

      Author's profile photo Prasanth Nalam
      Prasanth Nalam

      HI Team,

       

      I am not able to use split function as suggested above, DO anyone tried split function is so can you add a screenshot of the script you recorded.

      Author's profile photo Dimple Bhangale
      Dimple Bhangale

      Hello Reiner,

      Thank you for sharing such an interesting article.

      I have done similar settings in my composite script but still output value is not getting exported to next script. Can anyone suggest here?

      Regards,

      Dimple

      Author's profile photo consultor Tebyon
      consultor Tebyon

      Hello Reiner,

      I was just needing to take a "reservation number"from MF60 result, and complete all the steps as is your example, but, in the field where put the result of split: NUMBER_ONLY, instead of keeping the result of the split, in NUMBER_ONLY I get the text of the instruction (in my case (% = [= Split ($ Msg- Full $, ”“) (3)]).
      Can you Help me  with what may be happening?

      Best regards

      Adriana

      Author's profile photo Janakiram Srinivasan
      Janakiram Srinivasan

      Hello,

      I have captured a cell value and it is in negative. I want the positive value. How should i perform this operation?

      But the string value returned is string.

      Amount = 2,00-

      i want to enter 2,00 in another field

      pls help me in this

       

      Regards

      Janakiram