Sub topic 10
Validating the data
This chapter assumes you have created a migration project, chosen migration objects, and loaded source data through a file upload, staging tables, or direct transfer. It also assumes you can read CSV and XML files.
What validation does
Validation is the step after data preparation and before value conversion. The cockpit reads the data you supplied for a migration object and checks it against the structure of that object. It does not post anything to the target system. Nothing is created in S/4HANA at this stage.
Typical checks cover:
- Mandatory fields that are empty.
- Values longer than the field length allows.
- Values with the wrong data type, such as text in a numeric field.
- Duplicate keys within the supplied data.
- Rows that refer to a parent row that is missing from the data.
Validation cannot catch everything. Checks that need the target system's configuration or existing data, such as whether a company code exists or whether a number is already taken, often appear only later, in value conversion and in the simulation run.
Running validation
Select the migration object in your project and start the validation step. The cockpit processes the data and reports a status for the object, usually with counts of records that passed, produced warnings, or failed. Open the messages to see which record and field caused each one.
Correct errors in the source, not in the cockpit result. For a file upload, edit the file and upload it again. For staging tables, change the rows in the table. For direct transfer, fix the data in the source system and read it again. Then validate again.
Errors and warnings differ. An error blocks the record from moving on. A warning tells you something looks unusual, but the record can continue. Review warnings anyway, because they often point to data you do not intend to migrate as it stands.
Checking before you upload
Large legacy extracts usually contain the same few mistakes. A short script run before upload saves validation cycles. The script below checks a CSV for duplicate keys and values that are too long. The file and field names are placeholders, not SAP template fields. Adapt them to your own extract.
import csv
from collections import Counter
def precheck(path, key_field, max_lengths):
"""Return a list of problems found in a source CSV before upload."""
problems = []
keys = Counter()
with open(path, newline="", encoding="utf-8") as f:
for line_no, row in enumerate(csv.DictReader(f), start=2):
keys[row[key_field]] += 1
for field, limit in max_lengths.items():
if len(row[field]) > limit:
problems.append(f"line {line_no}: {field} is longer than {limit} characters")
problems += [f"duplicate key {k}" for k, n in keys.items() if n > 1]
return problems
for problem in precheck("customers.csv", "CustomerId", {"Name": 40}):
print(problem)Line numbers start at 2 because line 1 holds the column headers.
Common errors
- Validating once and never again. Any change to the source data requires a new validation run.
- Fixing the same error type row by row. Group messages by type, find the cause, and fix it for all rows at once.
- Opening a CSV in a spreadsheet and saving it. This often strips leading zeros from keys or changes date formats, which then fail validation.
- Treating a successful validation as proof that the load will succeed. It only means the data is well-formed.
Exercise
After validation, 3 of 500 records show errors and 40 show warnings. You fix the 3 errors in the source file and upload it again. What should you do before moving on to value conversion, and why?
Show answer
Run validation again on the new data, and review the 40 warnings. The corrected file is new input, so earlier results no longer apply. Warnings do not block records, but they can reveal data you do not intend to migrate.