This page is not a part of an official Int4 documentation.
Knowledge Articles

2. SAP Backend Validation- Variable creation to dynamically change the value to unique one

How to Create a Dynamic Variable for Unique Purchase Order Numbers

Hands-on tutorial - Part 2 of 5: SAP Backend Validation Series

This guide shows you how to make each simulated message uniquely identifiable by adding a variable and a number range to an existing Automation Object. After this setup, every test execution will generate a unique Purchase Order number, which makes messages easy to trace in middleware and the SAP backend.


Overview

When you simulate the same message, for example Purchase Order message many times, every run produces an identical payload - making it hard to trace individual executions in the middleware monitor or the SAP backend or even prevents it from posting in the backend.

The solution is to introduce a variable that replaces a chosen field in the payload with a value generated from an Int4 Suite number range. This makes each simulated message unique while keeping the rest of the test data stable.

At the end of this guide you will have:

  • A PO variable on your Automation Object that replaces the Purchase Order number at runtime

  • A number range that generates unique values

  • A working test execution that produces a different Purchase Order number on every run

More info about variables: https://help.int4.com/int4-suite-knowledge-center-library/3.15/variables-variable-processing


Step-by-step instructions

1. Open the Automation Object for the test case

  1. Navigate to the Automation Object assigned to your test case.

  2. Open it in edit mode so you can configure variables and number ranges.

  3. Expand the Variables section.

  4. Click Create to add a new variable.

  5. Fill in:

    • Variable name: PO

    • Description: PurchaseOrder

  6. Set the action type to Read and Replace.

  7. Choose the appropriate scope for the variable.

💡 Tip: Use a short, meaningful variable name. The same name will be reused later to wire the variable into a database validation rule set - consistency saves time.


image-20260512-100003.png


2. Configure the variable to replace the payload value

  1. Click the pencil / edit icon next to the variable.

  2. In the Read area, choose Read variable from saved message

  3. In the Expression area, open the search help and choose Import payload from test case.

    image-20260512-100111.png
  4. Click Go - the test cases assigned to the Automation Object will be displayed.

    image-20260512-100141.png
  5. Select the relevant test case.

  6. In the Select Payload section, chosse Input Message and then go to Xpath tab and choose the field you want to change before the message is sent to middleware.

  7. In this example, the target field is under attributes → purchaseOrderNumber.

    image-20260512-100312.png

3. Choose how the value should be generated

  1. From the available actions in Replace, select Generate value from number range.

    image-20260512-100400.png
  2. The system will prompt for a number range assigned to the Automation Object.

  3. Since no number range exists yet, save the variable setup and move on to the next step to create one.

4. Create a number range for the variable

Step 6 - Create number range
  1. Navigate to the Number Ranges section.

  2. Click Create.

  3. Fill in the number range details:

    • Name: PO_test

    • Prefix: workshop_<X>

    • Low value: 1

    • High value: any suitable upper limit

    • Enable Add zeros so the generated values include leading zeros

  4. Save the number range.

    image-20260512-100459.png


  1. Return to the Variables section.

  2. Open the PO variable again.

  3. In the Number Range field, select the number range you just created (PO_test).

  4. Click OK and then Save to finalize the configuration.

    image-20260512-100526.png


💡 Tip: In this example we created the local number range that is assigned to the Automation Object. You can create also global number range, that can be used in multiple AOs. You can do this in Configuration-> Define Global Number Ranges

6. Run the test and verify the variable value changes


  1. Go back to Int4 API Tester.

  2. Select the test case and send it to the test environment.

  3. Open the test case execution details.

  4. Confirm that the PO / Purchase Order variable was created.

  5. Check the Before / After value:

    • Original: e.g. INT4_test_221

    • Generated: e.g. workshop_10001

7. Understand the benefit of the setup

Every time you execute the test case, a new unique value is generated. Benefits include:

  • Easy identification of each message in the middleware monitor

  • Easy traceability in the SAP backend (e.g. the resulting Sales Order)

  • Reliable repeated test runs without duplicate-document errors

  • A reusable variable that downstream validations (DB rules, IDoc output) can reference


Troubleshooting

Issue

Likely cause

Resolution

Variable does not appear after execution

Action type is not set to Read and Replace

Re-open the variable and switch the action type

XPath does not resolve

XPath points to a node that does not exist in this payload

Re-open the test case input message and copy the path again

Value does not change between runs

Variable not linked to a number range or doesn’t have any other Replace action

Assign proper action in the replace step


What's next


References

🎥 Full walkthrough on Loom: https://loom.com/share/af9cccd8dc5049deb080652093559c75

Variables and Variable processings: https://help.int4.com/int4-suite-knowledge-center-library/3.15/variables-variable-processing