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.
cancel
Showing results for 
Search instead for 
Did you mean: 

PREREQUISITES

The looping capability are planned to be shipped with SAP Solution Manager 7.1 SP13

Alternatively you can implement following notes in advance:

  • 2088536 - Downport CBTA Default Components
  • 2088525 - IF and LOOP Default Components for CBTA
  • 2029868 - CBTA - Runtime Library - Fixes & improvements

USE-CASE FOR LOOP FUNCTIONALITY:

A test script may need to perform actions against an unknown number of entries in a table. The script may therefore need to:

  • Start at first row and check if there is an entry
  • If entry exists perform one or more actions on the current row
  • Continue with next row

REQUIRED DEFAULT COMPONENTS: DO, EXIT_DO, LOOP

Keyword: DO

It can be used to iterate over several steps. It defines where the loop starts.

  • It must be used together with the LOOP keyword which defines where the loop ends.
  • The EXIT_DO keyword must be used as well to determine when to stop the loop.

The CounterName parameter provides the name of the iteration counter. This counter is incremented automatically at runtime while iterating over the included steps. The actual value of the counter can be retrieve using the regular token syntax.

For instance, when CounterName is set to "COUNTER" its value can be reused in the subsequent steps using %COUNTER% (or $COUNTER$ for specific situations where the percent character is ambiguous).

If you plan to use nested loops please make sure to declare a different counter names.

Component Parameters

CounterName: Specifies the the name of the iteration counter.

Keyword: EXIT DO

It must be used within a loop that has been defined using the DO and the LOOP keywords. The EXIT_DO keyword interrupts the loop as soon as the condition is met.

A typical use case is to check the value of iteration counter that has been declared via the CounterName parameter of the DO keyword.

For instance, when CounterName is set to "COUNTER" its value can be checked using the %COUNTER% token.

Component Parameters

LeftOperand

  • Specifies the value of the left operand that is to be checked.

Operator

  • Specifies the boolean operator to use.

The operators supported are the ones below:

    • = 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"

An additional operator is supported when testing WEB applications (i.e.: applications running in the browser):

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

RightOperand

  • Specifies the value of the right operand that is to be compared with the left operand.

Options

The options parameter lets you perform some adaptations or conversions of both the left and right operand before comparing them.

The supported options are:

  • /u (for uppercase) - Both values are converted to upper-case before being compared
  • /t (for trimmed) - Both values are trimmed before being compared
  • /i (integer) - Both values are converted to an integer before being compared
  • /f (float) - Both values are converted to a float (or double) before being compared
  • /b (bool) - Both values are converted to a Boolean before being compared

Keyword: LOOP

It defines the end of the loop and must be used together with the DO keyword which defines where the loop starts.

EXAMPLE – PROCESS LINE ITEMS IN SALES ORDER

The following scripts was created for transaction VA02 (Change Sales Order) to add shipping information for each line item of an existing sales order.

With DO Keyword the loop starts and the counter is set to ‘1’.

To be able address the row number starting at ‘0’ we take the counter number minus ‘1’ using the CBTA_A_SETINEXECUTIONCTXT component.

Then the scripts reads the value of the first row in the first column to check if an entry exists.

If the value is empty we exit the loop with the EXIT_DO keyword.

Otherwise the scripts performs the required actions for the current row

  • Select row

  • Menu Goto --> Item --> Shipping
  • Enter the required shipping information using the related screen component
  • Go back to main screen

With the LOOP keyword the script goes back to the DO keyword while increasing the counter and processing further line items of that sales order.

18 Comments