Quantcast
Channel: SCN : All Content - SAP on Oracle
Viewing all articles
Browse latest Browse all 2104

System copy of change documents with some Datapump magic

$
0
0


Client copy process does not include change documents since version 4.5B as the 70 characters long field OBJECTID of table CDHRDR might sometime contain the client number (see OSS note 180949 - CC-INFO: Change documents for a client copy).

I've been asked many times to copy the change documents and I did perform some checks, it appears than most of the time OBJECTID field does not contain the client number.

Even if the tool I'm using is supported by SAP, copying change documents is not supported… but it should not hurt.

 

I've always like playing with oracle import/export tool but they are not recommended anymore on 11g (note 1712612 - Oracle 11g: Usage of exp with 11.2 / 11g). It's successor, datapump did bring some very interesting features.

  • The remapoption can be used to apply a specific function to a field of the table imported/exported. I've created a dummy function (REMAP_MANDANT.chg_cli) to use remap function for modifying the client field (MANDANT) of the change documents tables.
  • The network_linkoption allows to perform an import from a remote DB over a database link. This does allow to directly import data from a remote DB without needing to perform an export and move/share the data with the target system.
  • The query option did already exist on exp/imp, it allows to filter the data you are willing to export.

 

I'm combining these options to be able in one command to

  • export filtered records from one specific client of a source system,
  • copy into the target system,
  • change the content of the MANDANT field.


The here under procedure should be run from the target system where you wish to import change doc.  It could/should be used right after a client copy while user & batch activity is supposed to be suspended in both source and target client.

 

When the 3 imports are done you will need to reset table buffers on all the instances of the target SAP system (/$tab)

 

Performance is not that high, but as far as it is doing both the copy and the BDLS it can be considered faster than client copy.

On a medium size system it took 1.5 hours to copy a 4.5 GB CDLS table, at a speed of around 1 MB / sec.

I'm not sure that with network_link option datapump is fully using the requested level of parallelism. I've checked during import and Oracle did only open 3 TCP connections when I did set the parallelism to a degree of 4.


I hope this could help you if you are requested to copy change documents.

I'm sure these nice datapump functions demonstrated here could be helpful for many other usages.


 

 

Export the original tables as a backup

 

set des_SID=DES

set des_cli=500

set des_opwd=try2guess

setschema=SAPSR3

 

Cd /d D:\Script\cli_cop & mkdir %des_cli%\chg_doc & cd %des_cli%\chg_doc

 

echo CREATEORREPLACEDIRECTORY datapump_directory AS'D:\Script\cli_cop\%des_cli%\chg_doc';> pre.sql

echo GRANTREAD,WRITEONDIRECTORY datapump_directory TOsystem;>> pre.sql

echo Exit>> pre.sql

sqlplus"/as sysdba" @pre.sql

 

::Export tables to flat files with a parallelism degree of 4

For/D %Tin(CDPOS_UID CDHDR CDCLS)do  (

expdp system/%des_opwd% Tables=%schema%.%Tdirectory=datapump_directory dumpfile=%T^%U.dmp logfile=exp_%T.logPARALLEL=4

)

 

Delete all entries from change document tables for the target client

If your target system do only have one client you can use the truncate command that is faster

 

For/D %Tin(CDPOS_UID CDHDR CDCLS)do  (

Echo deletefrom %schema%.%Twhere MANDANT ='%des_cli%';>> trunk.sql

Echo --truncate table %schema%.%T; >> trunk.sql

)

echo exit>> trunk.sql

sqlplus"/as sysdba"  @trunk.sql

 


Perform direct import over DB link

 

set src_SID=SRC

set des_SID=DES

set des_cli=500

set src_cli=230

set src_opwd=2hard2guess

set des_opwd=try2guess

set src_host=src-host

setschema=SAPSR3

 

:: sql script to create the directory for datapump

echo CREATEORREPLACEDIRECTORY datapump_directory AS'D:\Script\cli_cop\%des_cli%\chg_doc';> pre.sql

echo GRANTREAD,WRITEONDIRECTORY datapump_directory TOsystem;>> pre.sql

echo Connectsystem/%des_opwd%>> pre.sql

:: create the DB link

echo CREATEDATABASELINK src_link CONNECTTOsystemIDENTIFIEDBY %src_opwd% >> pre.sql

echo USING'(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST =%src_shost%)(PORT = 1527))) (CONNECT_DATA = (SID = %src_SID%) ) )';>> pre.sql

:: create the remap package

echo CREATEORREPLACEPACKAGE REMAP_MANDANT AS>> pre.sql

echo FUNCTION chg_cli(ori_cli VARCHAR2)returnVARCHAR2;>> pre.sql

echo END REMAP_MANDANT;>> pre.sql

echo />> pre.sql

:: create the remap function

echo CREATEORREPLACEPACKAGEBODY REMAP_MANDANT AS>> pre.sql

echo FUNCTION chg_cli(ori_cli VARCHAR2)returnVARCHAR2IS>> pre.sql

echo new_cli VARCHAR2(9);>> pre.sql

echo BEGIN>> pre.sql

echo new_cli :='%des_cli%';>> pre.sql

echo RETURN new_cli;>> pre.sql

echo END;>> pre.sql

echo END REMAP_MANDANT;>> pre.sql

echo />> pre.sql

echo Exit>> pre.sql

 

sqlplus"/as sysdba" @pre.sql

 

:: Loop on the list of tables to refresh

For/D %Tin(CDPOS_UID CDHDR CDCLS)do(

impdp system/%des_opwd%@%Des_SID% Tables=%schema%.%Tdirectory=datapump_directory REMAP_DATA=%schema%.%T.MANDANT:SYSTEM.REMAP_MANDANT.chg_cli logfile=imp_%T.logPARALLEL=4 table_exists_action=appendcontent=data_only network_link=src_link query="' where MANDANT = ''%src_cli%'''"

)

 

Cleanup created objects


sqlplus"/as sysdba"

revokeREAD,WRITEONDIRECTORY datapump_directory fromsystem;

DropDIRECTORY datapump_directory;

DROPPACKAGEBODYSYSTEM.REMAP_MANDANT;

DROPPACKAGESYSTEM.REMAP_MANDANT ;

DropDATABASELINK src_link;

Exit


Viewing all articles
Browse latest Browse all 2104

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>