Advanced Looping - Automate_Studio - Latest

Automate Studio with Evolve User Guide

Product type
Product family
Automate > Automate Studio
Product name
Automate Studio
Automate Studio with Evolve User Guide
Topic type
How Do I
First publish date

The way that you record line items depends on the transaction code. Find details for the t-code that you are recording in the Step-by-step guides or on the Automate Support site.

Multiple-line transactions

Some SAP transactions require multiple rows of data to be processed at the same time—for example, FB50, F-65, ME21, VA01, CS01, CA01, and FB70.

For many of these transactions, SAP separates the data into two parts:

  • A header section: The header contains data that remains constant for the entire transaction, such as a date.
  • One or more line item or detail sections: Each line item section typically contains reiterative data, which is entered in a grid-like area of the SAP transaction, such as journal entry line items.
    Note: It's good to record two line items, so that you can see the repeatable pattern. Some t-codes, such as ME21N, require two line items, because the Filter function is not available until you complete the first line item.

After you record the script, including the line items, you create a loop around the line items. Then you set up your data file for the loop.

data layout for data and loop id column

The value in the Loop ID column tells Transaction whether the data in the row is part of the header section or a line of details.

Step-by-step instructions for adding basic loops are in Add a loop in Excel and Add a loop in Access.

Indexed loops

An indexed loop is useful when there is no position, search, or filter option in an SAP grid.

The index loop will imitate a scrolling action until it finds a blank row in the grid, ensuring that entries do not overwrite existing data. This is particularly helpful when there is no action in SAP that could be used in a normal loop.


Indexed loops can be inserted only in scripts that were recorded in GUI Scripting mode.

You can't use an indexed loop to perform a find or select an action. Instead, you can use an Index Field condition on a regular loop.

To use an indexed loop, you must specify an index field. Studio 12.x will base the indexed loop on that column in the grid.

  1. When you're setting up the loop in the Loop box, check Index Based Loop.
  2. Choose a field in the Index Field box.

    index loop check box index field drop down menu

When the script runs, Studio will look for a row where that field does not contain a value in SAP and then upload the data to that row.

Multiple loops


For best results when you use multiple loops in Transaction to upload data, do the following:While recording the transaction, enter more than one line item in the transaction to create a visible pattern of repetition in the Mapper. After you add the loops, disable the extra item's rows from the Mapper.If you use the same identifier column for different loops, use different identifier values for each loop—for example, D1 for the first loop and D2 for the second loop. You can use the same identifier if the loops refer to different identifier columns.

If the transaction includes separate sets of line items that are at the same level, you can create multiple loops at the same level in the same sheet. Because some rows will contain information for both loops, you will have a separate loop ID column for each loop, with a different loop identifier value for each loop.


No indentation is needed for loops that are at the same level.

For example, here are the values in the Loop ID columns for a script that includes three loops at the same level.

header in first row line item identifier in each column

Nested loops

Note: The data for nested loops should be in the same order as the loops appear in the Mapper. For nested loops, the data must be indented in the data file even if you are using a separate identifier column.

Map nested loops

Transaction does not automatically map scripts that contain additional line-item data.

To map the script, click a column in the Excel data file and drag it to the field in the Mapper. Repeat for each field that you want to map. Or click Auto Map.

auto map command in sheet headers group


In scripts with nested loops, you must insert at least one field between the two nested loops (the field may be anything with the exception of the BDC Cursor). This will ensure that your script is validated.

Prepare your workbook for running nested loops

When you upload nested loops, the header data and the details or line-item data in your Excel workbook must be placed on different rows. It looks similar to a simple loop, but you have extra rows for the nested loop.

Loop data layout for column-based mapping

data entered in different rows for nested loops

H - Header row D - multiple line items for loop 1 D1- multiple line items for loop 2 DD1 D1 

Using loops, conditions, and Else blocks in the Mapper

Copying and cutting rows with loops and conditions; adding Else blocks to If conditions

You can cut, copy, and paste rows that contain loops and conditions. To edit a loop or a condition, select all parts of it. You cannot paste a loop or a condition into a log column.

You can cut, copy, and paste a complete loop block.

You can cut, copy, and paste a complete If block.

You can copy and paste just the header row of a loop.

You can also copy and paste just the header row of an If condition block.

Below are the pasted header rows of the loop and the If condition block.

You can paste the copied rows at the ends of the Mapper rows, and you can insert fields and screens in the last row.

You can also Paste After the last field of any screen for a BAPI-based script.

In addition to Paste Before and Paste After options, you can Add a Blank Row.


Else blocks can be added to If conditions that are defined inside a loop.

Loop data on multiple sheets

To create a clearer presentation of data when multiple loops are present in a script, you can place the data for different loops on different Excel data sheets.

  • Master sheet: The Excel sheet containing the header data corresponding to the loop applied
  • Loop identifier column: The column on the header sheet that contains the join key
  • Line item sheet: The Excel sheet containing the line item data corresponding to the loop applied
  • Loop identifier column: The column on the line item sheet that contains the join key

You can assign the join key to any column that appears on all of the sheets.

Map multiple-sheet loops

  1. On the Map tab, in the Data Set panel, add as many new sheets as you need.
  2. Click the first sheet. In the Mapper, select the items for the first loop.
  3. Click the Create Loop button.
    Note: Define all loops that are at the same level before you define any nested loops.
  4. For Loop type, click Multiple sheet loop.
  5. Select the appropriate sheets for the header and line items, and specify the corresponding join key columns.
    Note: When a script file is published, the published sheet must contain the same sheet names that are in the script.
  6. Map the fields to their respective Excel worksheets.
  7. If the data source is changed, the preview reverts to Untitled. Either add the sheets manually or open a sheet that contains the appropriate names.
  8. Save the data file preview before you close Studio, or data sheets might be deleted.
Note: As a limitation from SAP, when any skip screen error returns from SAP during runtime, only skip screen name and screen number are returned which is common for all the skip screen line items. Therefore, in case of skip screens within loop we cannot identify for which line item this error has been returned from SAP.

Invalid mapping

  • You cannot map a loop to a column that is not part of that loop.
  • You cannot validate when multiple sheets are present.
  • If conditions are validated as sheets are processed.
  • You can use only column-based mapping.
  • Extended logs are not available. Only regular logs are written to the header sheet.