Back to

Advanced mapping

Setting conditions: IF statements

Conditional Run statements can provide additional control over the way data is uploaded into SAP. Conditional Run perform at a field level to set conditions for executing the selected portions of the TRANSACTION script. Conditional Run statements can be inserted around a single row or a block of rows. You may add multiple Conditional Run blocks, as long as they do not interfere with any other existing Conditional Run blocks.

Every cell belonging to the specified column is checked against the specified constant value. When the Conditional Run is performed, TRANSACTION executes only the row for which the given condition holds true.

For example, when column H is compared to the word “Credit”, then TRANSACTION perform the actions contained within the IF condition only when the condition is true. In this case, a value of H is uploaded to the D/C Column of the FB50 transaction.

NOTE: The comparison of the constant value specified in the Conditional Run statement with the value in an Excel column depends upon the Data read preferences Microsoft Excel defaults. See “Application Defaults” for more information.

For example, suppose column D of your Excel worksheet contains a decimal value and TRANSACTION needs to execute only those rows that contain the value 3.141 (value of PI) in column D. In this case, column D is formatted to show numbers only up to one decimal place, but internally column D stores up to three decimal places. If the Data read preferences is set to As stored, the condition required will be "D=3.141". However, if this option is set to As displayed, the condition required will be "D=3.1".

A Conditional Run command in the Mapper is equivalent to using a +IF SHUTTLEScript command.

Adding Conditional Run statements

The If Conditional Properties dialog box settings are:

Start Row/End Row: Type the Start Row and End Row you want to use, if other than the row or range of rows you initially selected on the Expert Tab: Recording Preview.

Else Row: Type the Else row where you want to store the If-Else row value.

IF first transaction: This setting is used to address SAP transactions in which dialog boxes, for example, occur only once on the first transaction record. Click this setting to execute the rows specified for the IF first transaction condition on the first record in the data source. For example, when the Classification View for a material is being changed, the Class Type dialog box pops up on the first record only, but not on any subsequent records.

IF NOT first transaction: Similar to the IF first transaction setting, this condition is used to address SAP transactions in which dialog boxes, for example, occur after the first transaction. Click this setting to execute the rows specified for the IF NOT first transaction condition on all records after the first record in the data source.

IF on SAP field: Similar to IF condition. Condition applies only to SAP fields that are enabled. It can apply to disabled fields only if their corresponding screen is enabled in the mapper. However, IF on SAP cannot apply to SAP input fields. IF on SAP is not available in batch mode recording.

IF on Index Field: IF on Index Field is available only for scripts that were recorded in GUI scripting mode. Use IF on Index Field with regular loops (NOT indexed loops) to search and update multiple rows based on one field’s value. With IF on Index Field, you can find a row based on a value in a given column. Map only those fields that need to be updated.

In the IF Condition Properties box, select If on Index Field. If you want to update multiple rows based on the search field, check the Find All box. In the Select box, select the field or SAP line that you want to search on, select the operator, and then specify the update value or the Excel column from which the update value will be read.

Note: IF on Index Field supports text values only.

IF on verify text: Available for imported A1 Dataloader scripts and for TRANSACTION scripts recorded with GUI scripting. Confirms that a value in Excel corresponds to a value in SAP. It does not change or remove data.

IF: Click the IF setting to base the condition on an Excel column, or Access table/column, or in version 10.6.1, the XML field that you specify for the condition. When IF is selected, the Select Column, Operator, and Value fields are displayed near the bottom.

The allowed operators are:

=, >, <, >=, <=, <>, {BLANK}, {NOT BLANK}, {STARTS WITH}, {CONTAINS}, {ENDS_WITH}, {BETWEEN}

Select Column, Operator, Value: When the IF condition is selected, select the Excel column or Access table/column that you want to use for the condition, select the Operator for the condition, and then type the Value (text or number) for this comparison. When you select a column, the screen field and condition appear in a tool tip.

Compare with Column: Select this check box to compare the Select Column (Excel column or Access table/column) to the column you select. If you mark the Compare with Column check box, the Value field displays a selection list of the columns available for this comparison. The following operators are allowed:

<> and =

When you complete the If Conditional Properties dialog box, the Mapper displays your changes using two  Conditional Run icons connected by a line.

IF statements in .txr files for web services (available in version 10.6 Update 1)

You can include IF statements in web services. For example, you might add an IF statement so that when a certain value is entered in that form, a script runs.

When you add the IF condition to the script, you create the field where the condition applies. All operators are available and you can also select to compare the entered value to another field value. If during the run the IF condition is not met, a message similar to "No message returned from SAP" or "No batch returned" appears.

Only the IF statement can be used when the data source is XML. If the data source is an SAP value, use an IF on SAP statement.

Adding conditional fields in loops

In a loop, you can add the same IF condition custom field in the header and inside the loop and the field is treated as two different fields. The IF condition field added in the header section will be a single value field, whereas the one defined within a loop will be a repeating values field. To use the same field value in both the header section and the loop, you should bind the values together in the form designer.

To add an IF condition in a web service

  1. In Transaction, create a new script or open an existing script.
  2. In the Mapper, select the fields where the condition should apply, and click the Conditional Run button.
  3. In the IF Condition Properties box, select IF.
  4. In the Enter field name box, type a name for the field. Note that special characters and spaces are not allowed in custom field names, and it is helpful to use a name that differs from any SAP field name. Alternatively, you can also add a field that has been used in another IF condition.

    The condition field does not appear in the Mapper, but only when the web service is published as a form.

  5. From the list select an operator.
  6. Do one of the following:
    • In the Value box, type a value for the condition.

      -or-

    • To compare the field value to another field, click Compare to field, and then enter the name of the field to compare. Click OK. It is not possible to compare a custom field to a column in a web service.
  7. Many any other required mapping changes, and then publish the script to the web service.

    The custom field is added to the published form as another column in a table

IF statements in .txr files distilled from BAPIs

Adding notes

You can add notes in the Mapper Notes column to IF condition rows. However, notes cannot be seen if the script is opened in an earlier version of the product.

Also in this section

Editing in the Mapper

Filtering mapper settings

Advanced looping capability

Validating data

Validate by list

Compensating for missing SAP screens and fields

Undo and Undo All

Mapping long text

Attaching documents

Auto mapping

Downloading from SAP

Editing a TRANSACTION script