Sub topic 8
Loading data through staging tables
This chapter assumes you know the transfer approaches from the earlier chapter, can create a migration project, and are comfortable with basic SQL and CSV handling.
What staging tables are
With the staging tables approach, you don't upload a file for each migration object. The cockpit creates database tables in an SAP HANA schema, one for each source structure of the selected migration objects. You fill those tables with your own tools. The cockpit then reads from them in the same way it reads an uploaded file.
The approach is designed for large volumes and for sources that already pass through an ETL (extract, transform, load) tool. File uploads become slow and awkward at that scale.
Setting it up
- Create the migration project and choose the staging tables approach. This choice is made at project creation and fixes how the project receives data.
- Select the migration objects. The cockpit generates one staging table per source structure of each object.
- Check which database schema holds the tables. The schema is either in the S/4HANA system's own SAP HANA database or in a database connection that your administrator configured.
- Read the table and field definitions in the cockpit. They mirror the object's template structures, so field names, lengths, and mandatory fields carry over from the template.
Filling the tables
You can fill the tables with any tool that can write to SAP HANA tables. Common choices are SAP Data Services, SAP HANA smart data integration, other ETL tools, or plain SQL inserts. Each source structure has its own table. Rows that belong together, such as a header and its items, must share the same key values.
Because the cockpit checks the data later, clean it first. A cheap pre-check of an extract catches duplicate keys and over-long values before they reach the tables. The script below uses placeholder file and field names, 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)After the load
Once the tables are filled, the project continues as with files: validate the data, convert values, simulate, and migrate. The cockpit reports problems per migration object, but the fix belongs in the staging tables or in your source. Correct the data in the source or the ETL logic, reload the rows, and validate again. This keeps the source and the staging tables consistent.
Common errors
| Symptom | Likely cause |
|---|---|
| Objects show no data | The ETL job wrote to a different schema or table than the project uses |
| Duplicate-key messages | Rows were loaded twice without clearing the tables |
| Truncated or rejected values | Source values exceed the field length in the staging table |
| Child records not found | Header and item rows use different key values |
Exercise
You corrected a wrong plant code in the legacy system and re-ran your ETL job into the same staging tables. Validation now reports duplicate keys. What happened, and how do you fix it?
Show answer
The job appended the rows without removing the earlier load, so each record now exists twice. Clear the affected rows from the staging tables (or the whole load), run the ETL job again, and validate again.