Copying data from one system to another
Veröffentlicht von Shortcut IT in Sc4SAP · 8 Juni 2023
Tags: SAP automation;SAP system copy;SAP system refresh
Tags: SAP automation;SAP system copy;SAP system refresh
Sometimes it is useful to copy a table or a bunch of tables from one system to another. For example, to update data in the Quality system, in a test client on the development system or in a sandbox with data from the Production system.
Doing this would either be a task to be done on database level or - to keep moving on the SAP level - you will be referred to the possibility with a "Transport of copies" and use the Transport Management System. For one-time use, this may be sufficient. Doing this with a "Transport of copies" is a task to be done manually, it can not be automated.
If the copy is to take place on a regular basis, possibly daily, the procedure with a "Transport of copies" is out of the picture. Do not expect anyone to be willing to bother with this.
Among others "Shortcut for SAP systems" (Sc4SAP) offers also for this problem a solution. In this article you will find a description how easy it can be to update some data on your Quality / sandbox / training system with data from the Production system - fully automated and on a regular basis.
We can use the "Process table data using R3trans" function in Shortcut for SAP systems (Sc4SAP). In this example we are going to distribute the contents of an own-developed table 'ZCUST_BLACKLIST' from the Production system PX1 to the Quality system QX1. The advantage is better possibilities in solving problems, troubleshooting, debugging, testing, etc.
Doing it one-time, by using the GUI, it is a quite clear thing:
1.: Export the data into a file
2.: Clear the table in QX1
3.: Import the data into QX1
We received a warning, so let's have a look what was the reason for it.
Ok, let's have a look into the log file:
This warning was given as we specified the table to be imported. R3trans can do an import also without any table specification, in that case all data of all tables in the R3trans file will be imported - and then no warning will be given. However, we can ignore it, the result in the database is the same.
I used a file on the frontend in this example. Using a server file would be also possible, but this would require that both systems, PX1 and QX1, have access to the directory. This can not be taken as granted, and unless this is not implemented, I am on the safe side using a directory accessible on my frontend. But of course in this case a user with dialog capabilites has to be used in the connection (type 'A' or 'S').
So, after doing these 3 steps - Export from PX1 > Remove in QX1 > Import in QX1 the data of the table in QX1, client 100 is exactly the same as in PX1, client 100. If the requirement is to do this one-time, we have finished it. But in our case the requirement is to do a daily synchronisation of the table from PX1 to QX1, therefore it is about automation - as I already mentioned we can do this fully automated and on a regular basis.
Sc4SAP comes with a command line tool (Sc4SAPCmd.exe), which allows to do nearly every function on OS level with a one-liner. There are 2 methods to use the command line tool:
- Calling sc4sapcmd.exe with function and variant as arguments (variant = variant in Sc4SAP)
Assumed we have saved variants for the 3 steps, the calls would look like this:
sc4sapcmd.exe r3trans "PX1 export ZCUST_BLACKLIST"
sc4sapcmd.exe r3trans "QX1 remove ZCUST_BLACKLIST"
sc4sapcmd.exe r3trans "QX1 import ZCUST_BLACKLIST"Putting these 3 calls in a simple file, let's name it 'Copy Customer blacklist from PX1 to QX1.cmd', and scheduling this file to execute it regularly (e.g. with the Windows Task Scheduler) does the job. A recommendation at this point when using variants with the command line tool: make a note in the variant about this, it might prevent you from changing or deleting if one day you get the urge to clean up the variants. - Calling sc4sapcmd with an XML file as argument, containing all information of the function to be executed
This offers more flexibility than using variants. We don't have to specify a variant, the XML file can be created either with a text editor or also by another application (for example a Chatbot can create an XML file for unlocking a user as a result from a chat with him).
<ExecutionChain>
<Comment>Copy customer blacklist from PX1 to QX1</Comment>
<Task>
<R3trans StopOnError="true">
<Comment>Extract customer blacklist from PX1</Comment>
<Connection>PX1/100, SRV_SC4SAP</Connection>
<Export>
<Table>ZCUST_BLACKLIST</Table>
<Client>100</Client>
<LocalFile>E:\\SAP\\Transfer\\PX1 Customer Blacklist.r3trans.bin</LocalFile>
</Export>
</R3trans>
</Task>
<Task>
<R3trans StopOnError="false">
<Comment>Remove customer blacklist in QX1</Comment>
<Connection>QX1/100, SRV_SC4SAP</Connection>
<Remove>
<Table>ZCUST_BLACKLIST</Table>
<Client>100</Client>
<LocalLogFile>E:\\SAP\\Transfer\\QX1 Customer Blacklist remove.log</LocalLogFile>
</Remove>
</R3trans>
</Task>
<Task>
<R3trans StopOnError="false">
<Comment>Import customer blacklist from PX1 into QX1</Comment>
<Connection>QX1/100, SRV_SC4SAP</Connection>
<Import>
<Table>ZCUST_BLACKLIST</Table>
<Client>100</Client>
<LocalFile>E:\\SAP\\Transfer\\PX1 Customer Blacklist.r3trans.bin</LocalFile>
</Import>
</R3trans>
</Task>
</ExecutionChain>
If you have seen XML files before (or HTML files, which have a similar structure using this <tag> ... </tag> notation), it is not so difficult to understand it, isn't it? The root element is the ExecutionChain, in it is at least one Task (here there are three) with their specific tags. For using R3trans we used the task type R3trans tag with its specific tags Export, Remove and Import.
After calling the command line tool with such an XML file (let's name it 'Copy Customer blacklist from PX1 to QX1.xml')
sc4sapcmd.exe "Copy Customer blacklist from PX1 to QX1.xml"
the XML file will be enriched with some information in Result tags, on task level as well as on the level of the whole execution chain - similar to what we can see using the GUI.
<ExecutionChain>
<Comment>Copy customer blacklist from PX1 to QX1</Comment>
<Task>
<R3trans StopOnError="true">
<Comment>Extract customer blacklist from PX1</Comment>
<Connection>PX1/100, SRV_SC4SAP</Connection>
<Export>
<Table>ZCUST_BLACKLIST</Table>
<Client>100</Client>
<LocalFile>E:\\SAP\Transfer\\PX1 Customer Blacklist.r3trans.bin</LocalFile>
</Export>
<Result>
<Processed>2023-06-01T11:56:50.444</Processed>
<ReturnCode>0</ReturnCode>
<Message>1st step (preparation) finished.</Message>
<Message>Now execute R3trans and afterwards download data and log file...</Message>
<Message>2nd step (execution of R3trans) finished. Have a look into the log file, please.</Message>
</Result>
</R3trans>
</Task>
<Task>
<R3trans StopOnError="false">
<Comment>Remove customer blacklist in QX1</Comment>
<Connection>QX1/100, SRV_SC4SAP</Connection>
<Remove>
<Table>ZCUST_BLACKLIST</Table>
<Client>100</Client>
<LocalLogFile>E:\\SAP\Transfer\\QX1 Customer Blacklist remove.log</LocalLogFile>
</Remove>
<Result>
<Processed>2023-06-01T11:56:53.227</Processed>
<ReturnCode>0</ReturnCode>
<Message>1st step (preparation) finished.</Message>
<Message>Now execute R3trans and afterwards download the log file...</Message>
<Message>2nd step (execution of R3trans) finished. Have a look into the log file, please.</Message>
</Result>
</R3trans>
</Task>
<Task>
<R3trans StopOnError="false">
<Comment>Import customer blacklist from PX1 into QX1</Comment>
<Connection>QX1/100, SRV_SC4SAP</Connection>
<Import>
<Table>ZCUST_BLACKLIST</Table>
<Client>100</Client>
<LocalFile>E:\\SAP\\Transfer\\PX1 Customer Blacklist.r3trans.bin</LocalFile>
</Import>
<Result>
<Processed>2023-06-01T11:56:53.804</Processed>
<ReturnCode>4</ReturnCode>
<Message>1st step (preparation) finished.</Message>
<Message>Now upload the data file, afterwards execute R3trans, then download the log file...</Message>
<Message>R3trans execution done with warning!</Message>
<Message>See following information</Message>
<Message>>>> Using R3trans <<<</Message>
<Message>R3trans location:</Message>
<Message>/usr/sap/NPL/D00/exe/R3trans</Message>
<Message>Datafile :</Message>
<Message>/tmp/080027B7210A1EEE808C5455D6B0FA0A.tmp</Message>
<Message>Now calling R3trans:</Message>
<Message>/usr/sap/NPL/D00/exe/R3trans -w /tmp//080027B7210A1EEE808C5454D465DA0A.log /tmp//080027B7210A1EEE808C5454D465DA0A.tmp</Message>
<Message>R3trans call ended with RC 4</Message>
<Message>-> see log file for details.</Message>
<Message>R3trans execution ( Import ) successful!</Message>
<Message>Downloaded (bytes): 3.148</Message>
<Message>Uploaded (bytes): 421</Message>
<Message>2nd step (execution of R3trans) finished. Have a look into the log file, please.</Message>
</Result>
</R3trans>
</Task>
<Result>
<Processed>2023-06-01T11:56:53.804</Processed>
<ReturnCode>4</ReturnCode>
</Result>
</ExecutionChain>
The XML schema is also provided in the 'xml' subfolder of Sc4SAP (file 'Sc4SAPCmd.xsd'). A huge advantage of the possibility using XML files with the command line tool is its flexibility. XML files can be created either with a text editor or by any application. This makes it possible to use Sc4SAP e.g. by a user self service for unlocking the own user or by a Chatbot, creating an XML file as a result of the users input that he/she is locked.
So finally, depending on which method we prefer to use, we have a either a command file with 3 calls of the command line tool (using the variants for Export, Remove, Import) or a single XML file with 3 tasks. Both can be used to execute it periodically. For scheduling it the Windows Task Scheduler can be used or a more complex product for process automation (like Automatic Automation, former UC4).
Scheduling of the table data copy via Windows Task Scheduler - here by using an XML file
Whatever you choose - the method using the variants or the method with the XML file -, in both cases the data can be easily copied from one system to another, fully automated and on a regular basis. Isn't this a nice way to avoid such tedious and time-consuming tasks as banging around with a Transport of copies, day after day?
Es gibt noch keine Rezension.