## How to set or get attributes in SAP elements using SAP blocks

You can get or set the attributes of SAP elements in Leapwork by using the **SAP Action** block.

The available attributes depend on the type of SAP element you capture.

Use **Get Attribute** to read a value from the element, and **Set Attribute** to write a value to it.

Common attributes include **Name**, **Type**, **Id** and **Text**.

**Getting attributes**

To retrieve text from an SAP element:

1. Capture the element in an **SAP Action** block.
2. Select **Get Attribute** as the action.
3. Choose **Text** in the Attribute Name dropdown.
4. Use the **Value** connector to pass the retrieved text to other blocks.

**Setting attributes**

To set a value, such as text:

1. Capture the SAP element in an **SAP Action** block.
2. Select **Set Attribute**.
3. If the element supports text, **Text** will appear in the Attribute Name list.
4. Enter the value you want to set in the field provided.

## How to perform SAP data validation using SAP building blocks

In Leapwork, you may need to validate data across SAP transactions. For example, checking that a created sales order number matches the expected value. This can be done using two blocks:

**Validate SAP block**

The **Validate SAP** block allows you to compare the text captured from an SAP element with the text specified in the block’s **Validate text** field.

This is useful for simple equal-to validations.

**SAP Action block**

The **SAP Action** block can retrieve values using **Get Attribute**.

You can pass the retrieved value to a **Compare** block to perform more advanced validations, such as:

- A contains B
- A is greater than B
- A is less than B
- Other logical comparisons

This method offers more flexibility than the Validate SAP block.

## How to handle drop-downs in SAP

Leapwork can select SAP dropdown values in two ways:

### Select by Args

This method selects a dropdown value using the **Args** attribute.

**Get the Args value**

1. Add an **SAP Action** block.
2. Capture the dropdown element.
3. Choose **Get Attribute** as the action.
4. Select **Args** as the attribute name.

**Set the dropdown using Args**

1. Add another **SAP Action** block.
2. Choose **Set Attribute**.
3. Select **Args** as the attribute name.
4. Enter the Args value you want to select.

### Select by Key

SAP dropdowns often show only descriptions, while each option also has a **Key** value.

If keys are not visible, enable them:

1. In SAP GUI, click **Customize Local Layout** or press **ALT + F12**.

2. Go to **Interaction Design > Visualization 1**.
3. Enable **Show keys within dropdown lists**.
4. Click **Apply**.

**Get the Key value**

1. Use an **SAP Action** block.
2. Capture the dropdown element.
3. Select **Get Attribute**.
4. Choose **Key** as the attribute.

**Set the dropdown using Key**

1. Add an **SAP Action** block.
2. Select **Set Attribute**.
3. Choose **Key** as the attribute.
4. Enter the key you want (for example **44**).
