30.11.
2020 SAP S/4HANA migration cockpit – Creating and using synonyms for renaming staging tables | SAP Blogs
Follow RSS feed Like
Community
Ask a Question Write a Blog Post
Technical Articles
Udo Matthias Sommer
April 15, 2020 3 minute read
SAP S/4HANA migration cockpit – Creating and using
synonyms for renaming staging tables
5 Likes 998 Views 0 Comments
In this blog, I will brie y explain the use of synonyms for staging tables and will also provide sample code on
how to create synonyms for renaming the staging tables of the SAP S/4HANA migration cockpit. These
synonyms can be later used in other ETL Tools such as SAP Data Services.
As mentioned in the blog from Markus Andres: “Using SAP Data Services to load data to the staging tables“,
you can use SAP Data Services to populate the migration cockpit´s staging tables. An overview of the SAP
S/4HANA migration cockpit and further details about the migration approach “Transfer Data Using Staging
Tables” are explained in Blog: Part 1: SAP S/4HANA migration cockpit – Migrating data using staging tables
and methods for populating the staging tables.
When moving (i.e. import/exporting) the SAP S/4HANA migration cockpit projects from the development
environment to a quality environment, the generated names of the staging tables will be di erent in the
di erent environments. Consequently, you have to adjust the data ows in your ETL tool and update the
names of the staging tables. You can avoid these adjustments if you de ne synonyms for the staging tables
and use the synonyms in the data ows. Synonyms are references or aliases for a table or other database
objects, so it’s just another name you can use to refer to the table in SQL statements. For more details about
synonyms you can refer to:
SAP HANA Developer Guide – Synonyms
SAP HANA Developer Guide – Create a Synonym
SAP HANA Academy – Web IDE for HANA: Synonyms – Create Synonym [2.0 SPS 00]
For the SAP S/4 HANA migration cockpit, synonyms can be used to obtain identifying names from the
system, project, object and structure instead of having consecutive numbers in the table name. Synonyms
https://blogs.sap.com/2020/04/15/sap-s-4hana-migration-cockpit-creating-and-using-synonyms-for-renaming-staging-tables/ 1/5
30.11.2020 SAP S/4HANA migration cockpit – Creating and using synonyms for renaming staging tables | SAP Blogs
have the format S_<sid>__<object>__<structure>, for example
Follow RSS feed Like
S_ABC__Z_CUSTOMER2_US8__S_CUST_GEN.
The names of the staging tables are stored in mapping table /1LT/DS_MAPPING in the schema of the
staging tables. Users can use table /1LT/DS_MAPPING to recreate the synonyms. This means that even
though the names of the staging tables will change, the destinations used for data export stored procedures
or scripts in the extraction tools (for example SAP Data Services) will not change.
The example stored procedure below shows how to create the synonyms for the staging tables. For
example, the name of the staging table for source structure S_CUST_SALES_DATA in the staging schema of
the development system might be /1LT/DSDEV10001234 and /1LT/DSQAS20004321 in the staging
schema of the quality system. In the case below, the SID of the S/4HANA system is used in the synonym.
However, you can remove this SID (i.e. <sid> & ABC, sample name which represents this SID) to make the
stored procedure system independent and get static synonym names across the landscape (simply
comment and uncomment the respective line in the script).
……………………………………………………………………………………………….
Stored procedure for all staging tables of a migration project
Important Notes:
The procedure and synonyms are created in the current schema using SQL console in SAP HANA Studio.
Input of the stored procedure is the system id <sid> and the project id <mtid>. There is no output.
A synonym will be created for each staging table in a migration project.
If a synonym already exists but is assigned to another table name, it will be dropped and created with the
current staging table name.
The naming convention used for the synonym is: S_<sid>__<object>__<structure>, e.g.
S_ABC__Z_CUSTOMER2_US8__S_CUST_GEN
The scripts and stored procedures are examples that should be adjusted to your requirements.
1. Create procedure
--drop procedure create_staging_synonyms;
CREATE PROCEDURE create_staging_synonyms(
IN SYS_ID NVARCHAR(8),
IN MT_ID NVARCHAR(3))
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
AS
https://blogs.sap.com/2020/04/15/sap-s-4hana-migration-cockpit-creating-and-using-synonyms-for-renaming-staging-tables/ 2/5
30.11.2020 SAP S/4HANA migration cockpit – Creating and using synonyms for renaming staging tables | SAP Blogs
BEGIN Follow RSS feed Like
DECLARE CNT INTEGER;
DECLARE SYNONYM_NAME NVARCHAR(60);
DECLARE STAGING_TAB NVARCHAR(30);
DECLARE CURSOR c_cursor ( SYSID NVARCHAR(8), MTID NVARCHAR(3)) FOR
select *
from "/1LT/DS_MAPPING"
where SYS_ID = :SYSID
and MT_ID = :MTID;
--
FOR wa AS c_cursor(:SYS_ID, :MT_ID)
DO
STAGING_TAB = :wa.STAGING_TAB;
-- synonym name with SID
SYNONYM_NAME = 'S_' || :wa.SYS_ID || '__' || :wa.COBJ_IDENT || '__' || :wa.STRUCT_
-- synonym name without SID
-- SYNONYM_NAME = 'S_' | :wa.COBJ_IDENT || '__' || :wa.STRUCT_IDENT;
-- drop synonym if already exists with another staging table
SELECT count(*) into CNT FROM SYNONYMS WHERE SYNONYM_NAME = :SYNONYM_NAME;
if CNT > 0 then
SELECT OBJECT_NAME into STAGING_TAB FROM SYNONYMS WHERE SYNONYM_NAME = :SYNONYM_
if STAGING_TAB <> :wa.STAGING_TAB then
EXEC 'DROP SYNONYM "' || :SYNONYM_NAME || '"';
STAGING_TAB = :wa.STAGING_TAB;
EXEC 'CREATE SYNONYM "' || SYNONYM_NAME || '" for "' || STAGING_TAB || '"';
end if;
else
https://blogs.sap.com/2020/04/15/sap-s-4hana-migration-cockpit-creating-and-using-synonyms-for-renaming-staging-tables/ 3/5
30.11.2020 SAP S/4HANA migration cockpit – Creating and using synonyms for renaming staging tables | SAP Blogs
EXEC 'CREATE SYNONYM "' || SYNONYM_NAME || '" for "' || STAGING_TAB || '"';
Follow RSS feed Like
end if;
END FOR;
END;
2. Call procedure for a system and project
In SQL console you can call the procedure as follows e.g. for system QKX and project id US8:
CALL create_staging_synonyms(SYS_ID => 'QKX', MT_ID => 'US8');
3. You can display all synonyms for your system and project like this
Replace <MTID> with the project id and <SID> with the system id:
SELECT * FROM SYNONYMS WHERE SYNONYM_NAME LIKE 'S_<SID>%<MTID>%' order by SYNONYM_NAM
If you follow the steps above you will get synonyms with static names that are independent from the
generated staging table names and you can use these names in your ETL tools.
Alert Moderator
Assigned tags
SAP S/4HANA migration cockpit | SAP Data Services | SAP S/4HANA | SAP S/4HANA Cloud |
Related Blog Posts
Part 1: SAP S/4HANA migration cockpit - Migrating data using staging tables and methods for populating the staging tables
By Iliana Olvera , Dec 02, 2019
https://blogs.sap.com/2020/04/15/sap-s-4hana-migration-cockpit-creating-and-using-synonyms-for-renaming-staging-tables/ 4/5
30.11.2020 SAP S/4HANA migration cockpit – Creating and using synonyms for renaming staging tables | SAP Blogs
SAP S/4HANA Migration Cockpit - New Fiori App in CE2008
By Sybille Lackermeier , Jul 31, 2020 Follow RSS feed Like
SAP S/4HANA Migration Cockpit – tips&tricks
By Sybille Lackermeier , Dec 04, 2017
Related Questions
How to connect tables in Migration Cockpit?
By chandra koduri , Mar 12, 2018
S/4HANA MIgration Cockpit: Delta load from staging tables
By Adriaan van der Bank , Sep 12, 2019
The entries in the SAP S/4 HANA staging tables aren't visible in SAP S/4 HANA Migration Cockpit.
By Bogdan Popescu-Miclosanu , Dec 12, 2019
Be the rst to leave a comment
Add Comment
Find us on
Privacy Terms of Use
Legal Disclosure Copyright
Trademark Настройки параметра cookie
Newsletter Support
https://blogs.sap.com/2020/04/15/sap-s-4hana-migration-cockpit-creating-and-using-synonyms-for-renaming-staging-tables/ 5/5