Sub topic 7
Preparing source data with templates
This chapter covers the file-based approach: how to turn legacy data into a template the migration cockpit accepts. It assumes you know what a migration object is and have a migration project that uses the file approach. It also assumes you can work with CSV files and spreadsheets.
What a template is
For each migration object, the cockpit offers a template that you download from the project. The template defines which structures (groups of fields) and fields the object accepts, which fields are mandatory, and in what format. Depending on release and object, the template is an XML spreadsheet file or a set of CSV files. Check which formats your release offers.
The template is the contract between your legacy data and the object. The cockpit does not interpret your source system's layout. It reads only what the template defines. The work of this chapter is therefore a mapping exercise: legacy fields on one side, template fields on the other.
Working model
Preparation follows a loop of extract, transform, fill, check, and upload.
Two points follow from this loop. The pre-check is your own, run before upload. The cockpit's validation comes after upload and is covered in a later chapter. Fixing a problem in the source is cheaper than finding it in the cockpit, because each upload cycle takes time and, for large files, the cockpit has to process the file again.
Reading the template
Open a downloaded XML template and you will normally find these parts:
- An instruction sheet that explains how to fill the file for this object.
- A field list that describes every field: its technical name, a description, whether it is mandatory, its type, and its length.
- One sheet per structure of the object. A structure is a group of related fields, such as general data and address data for a business partner.
Read the field list before you extract anything. It tells you which legacy fields you must find, which you may leave empty, and which have length limits you will need to enforce.
Structures and keys
A migration object usually has more than one structure, and the structures are linked by keys. The first structure holds one row per object instance. Dependent structures hold further rows that refer back to that instance with the same key value.
For example, a customer may have one general row and several address or bank rows. Each of those rows must carry the same key as the general row. If a dependent row has a key with no parent row, the data is inconsistent and the row will be rejected.
Keys in the template are file-internal identifiers. They are not always the number the object has in S/4HANA. The target number may be assigned by the system or by number-range rules, or you may supply it. The field list and the object's instructions say which applies.
Formatting rules that cause most errors
Most template problems come from a few causes. Check each of them before upload.
| Problem | Typical cause | What to do |
|---|---|---|
| Missing leading zeros | A spreadsheet treats `0000012345` as a number and stores `12345` | Format the column as text before pasting, or write CSV files with a script |
| Wrong date format | Locale-dependent dates such as `03/04/2026` | Use the format named in the field list for every date |
| Number and decimal separators | Local decimal comma instead of the expected separator | Normalize to the format in the field list |
| Over-long values | Legacy fields are longer than the S/4HANA field | Shorten or split the value in the source, not in the template |
| Duplicate keys | Same record extracted twice, or merged systems | Deduplicate before filling the template |
| Missing mandatory fields | Field exists in the template but not in the legacy system | Define a default or a derivation rule with the business |
| Encoding problems | Special characters corrupted by an export | Export and save as UTF-8 |
Another common error is editing the template's structure. Do not rename sheets, delete columns, reorder columns, or change header rows. The cockpit expects the template as downloaded. Fill only the data rows.
Master data, transactional data, and size
Master data objects, such as business partners and materials, are usually extracted in full. Transactional data, such as open items, needs a cutoff date and a rule for which documents are still open. Agree the cutoff with the business before extraction. Otherwise your numbers will not reconcile to the legacy system later.
For large volumes, a single spreadsheet file becomes slow to open and edit, and the cockpit has file size limits that depend on the release. If an object has too many rows for one file, split the data into several files by a sensible criterion such as company code or plant. Alternatively, consider the staging tables approach, which is covered in the next chapter.
Pre-checking a legacy extract
You can catch duplicates and over-long values with a short script before the data goes into the template. The following script reads a source CSV and reports both problems. The file and field names are placeholders, not SAP template fields.
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)Given this input in customers.csv:
CustomerId,Name
0000100001,Northwind Traders
0000100002,A Very Long Customer Name That Exceeds The Forty Character Limit
0000100001,Northwind Traders Ltdthe script prints:
line 3: Name is longer than 40 characters
duplicate key 0000100001Line numbers count the header as line 1, so the first data row is line 2. Because the script reads values as text, it keeps leading zeros. This is another reason to prepare data with scripts or text-formatted columns rather than opening a CSV in a spreadsheet and saving it again.
Take the limits from the template's field list, not from memory. The script checks only what you tell it to check. It does not replace the cockpit's validation, which also checks values against the system's configuration and master data.
Handling values that need conversion
Legacy codes often differ from S/4HANA codes. Examples are payment terms, units of measure, and country keys. You have two options. You can transform them during preparation, so the template already contains target values. Or you can leave source values in the template and convert them in the cockpit with value mapping, which a later chapter covers.
Choose one place for each field and document it. If you convert in the file and also map in the cockpit, you can end up converting twice, and the values will no longer match any rule.
Checklist before upload
- Template is the version downloaded for this object and project, with structure unchanged.
- Every mandatory field has a value or an agreed default.
- Keys are unique in the first structure, and every dependent row has a parent key.
- Values fit the field lengths and formats in the field list.
- Text-like numbers, such as account and material numbers, keep their leading zeros.
- Dates, decimals, and encoding follow the template's rules.
- Row counts match the extraction log.
Exercise
A colleague fills a business partner template by pasting from a spreadsheet. After upload, the cockpit rejects many rows because the partner numbers are too short. The legacy numbers were 0000012345. What most likely happened, and how do you prevent it?
Show answer
The spreadsheet treated the column as numbers and dropped the leading zeros, so 0000012345 became 12345. Format the column as text before pasting, or generate the file with a script that handles the values as text. Then compare a sample of numbers in the file with the source before upload.
Exercise
Why should you fix an over-long customer name in the legacy extract rather than shorten it by hand in the template?
Show answer
A manual edit in the template is not repeatable. The next test cycle starts from a fresh extract, and the same error returns. A rule applied in the extraction or transformation step is documented and runs every time, so every cycle gets the same result.