Monday 29 September 2014

Slowly Changing Dimension 2(SCD2) - Flag Control

Slowly Changing Dimension 2(SCD2) - Flag Control


Process :

Step 1: Create Source Table & Data
  1. We can use Scott Schema EMP table
  2. Import table using source analyzer

Step 2: Create Target Table

  1. Create target table in target database
 
CREATE TABLE EMP_SCD2_FLAG
  ( EMPKEY NUMBER(5,0) PRIMARY KEY,
EMPNO NUMBER(5,0),
ENAME VARCHAR2(20 BYTE),
JOB VARCHAR2(20 BYTE),
SAL NUMBER(10,2),
DEPTNO NUMBER(5,0),
FLAG VARCHAR2(1)
  )

  1. Import table using Target Designer

Step 3: Create mapping with transformations

  1. Create a mapping with the name m_SCD2_FLAG
  2. Drag and drop source and target into work area
  1. Introduce  Lookup transformation and select lookup table as EMP_SCD2_FLAG
  2. Drag and drop EMPNO from Source Qualifier to Lookup and rename it as EMPNO_in
  3. Click on condition tab of lookup provide join condition as shown below
  1. Click on properties tab and select multiple match property as last value
  1. Introduce Expression transformation into work area and name it as exp_INSERT_UPDATE_NOCHANGE
  2. Drag and drop ports EMPNO,ENAME,JOB,SAL,DEPTNO from source qualifier to expression
  3. Drag and drop ports EMPKEY,JOB,SAL  from Lookup to expression and rename job,sal as job_previous ,sal_previous respectively
  4. Add one new port in expression and name it as INSERT_UPDATE_NOCHANGE_FLAG
  5. Develop expression using below formula

IIF(
ISNULL(EMPKEY),'I',
IIF(
(JOB != JOB_previous) OR
      (SAL != SAL_previous),'U','NC' ) )

  1. Introduce ROUTER transformation → Drag and drop EMPKEY,EMPNO,ENAME,JOB,SAL,DEPTNO and INSERT_UPDATE_NOCHANGE_FLAG from expression to router
  1. Double click on ROUTER header → click on groups tab → add two groups as shown

  1. Introduce Expression transformation→ from INSERT section of router drag and drop ports EMPNO1,ENAME1,JOB1,SAL1,DEPTNO1and INSERT_UPDATE_NOCHANGE_FLAG1
  2. Create two new ports EMPKEY1 ,FLAG
  3. Introduce Sequence generator transformation and connect NEXTVAL with EMPKEY1
  4. Provide constant value ‘Y’ in FLAG port
  5. Overall it looks like below
  1. Introduce update strategy transformation and connect as shown
  1. Connect ports from update strategy transformation to target as shown
  1. Introduce Expression and update strategy transformations
  2. Duplicate target table and connect all as shown
  1. Double click on update strategy transformation → provide Update Strategy Expression as 1
  1. Save it .



Step 4: Create Workflow and Session
  1. Create workflow and session as shown below
  1. Double click on session task provide source and target connection accordingly
  1. Save the workflow
Step 5: Run workflow and Observe output
  1. Observe source data in my case
  1. Select Start task → click on run
  2. observe target data
  1. Observe target table output
  1. Update any one existing record in my case iam updating RAM REDDY sal from 10000 to 12000
  1. Run Workflow again


Step 6: Download workflow XML Code and observe it

https://drive.google.com/file/d/0B6mKqi53iP-NOWdtaDFvRW1zMEU/edit?usp=sharing

No comments:

Post a Comment