Beruflich Dokumente
Kultur Dokumente
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Abstract
After this lab you will know the difference between model and table level scripts, attached and unattached scripts, when to use what type of script, and how you can make all your scripts work together. Starting with an easy Hello World script to get the hang of it, we will switch to some simple iteration through tables and columns, followed by more complex iterations using relations, subroutines and nesting.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Biography
Theo van Westrienen Martinair Holland
Working with ERwin since 1999 President and founding member of eBUG (ERwin BeNeLux User Group) since 2004 Working in IT since 1987, in various industries such as telecom, banking, car industry, Dutch flower, fruit and vegetables auctions Currently as Data Manager for airliner Martinair
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Agenda - Exercises
1. Sample Model
Traditional Forward Engineering
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Agenda - Exercises
7. Iteration 8. More Iteration 9. Nested Iteration 10.Selection 11.Iteration + Selection 12.Subroutines 13.Filtering 14.Finale A Complete Script
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
but without:
Scripts yet
Note that FE using Scripts only produces no output yet try again after next exercise!
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Select New and type a name: Exercise2 Type Hello World (under Code) Click on Expanded for result
Note that you can just type the macro i.s.o. using the macro toolbox for the same result
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Ex. 4: Apply FE
Use script Exercise3
Select SA Flight, open the Script editor and select tab General Select Model-Level, Generate and PostCreation FE using the 3 option sets, check the differences Select Pre-Creation and FE again, check the differences Deselect Generate and FE again, check the differences
Note that with these settings you can control if and where the output is produced
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Note that ERwin needs to know for what object it should generate output
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Switch to SA Locations Now FE again, check differences for tables and views
Note that Table can be Table or View, while a view is only a View
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Ex. 7: Iteration
Create script Exercise7
Select SA Locations Select Model-Level, Generate and PostCreation Type %ForEachTable() Type {this is %TableName}
Now FE again Note that the output is on a separated line for each table / view Note that the output order is alphabetical
Note that %ForEachXxxx macros expand exactly what you tell them between the {}
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Now FE again
Note that you can use a %ForEachXxxx macros for exact navigation
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Now FE from SA Locations, and check the output for tables and views
Now FE again and check the output for tables and views Note the output for %AttName for
View columns Physical only columns
Note that %ForEachColumn does expand for Views, and that %AttName always expands
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Note the difference in navigation between Model level and Table-level scripts
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Now check the expanded code Vary the Comparison Operators: ==,>=,>,<=,<,!=,<> Vary the condition
Note that what you type between { and } is expanded exactly except leading spaces
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Note how the number of brackets }} grows using the wrong amount leads to errors easily
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Create Exercise12Sub
Any Level, Not Generated, Pre or Post Type This is table %TableName
Create Exercise12SubSub
Any Level, Not Generated, Pre or Post Type Col: %ColName
Now FE
Note that the subroutine does NOT know the current column / attribute anymore
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Note that object selection for scripts follows the standard FE method
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Note that reversing the order offers you Insert logic i.s.o. Delete logic
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Note that Model level scripts offer more control and flexibility than table level scripts
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Script SubGetChildLevel
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Parameters needed
MaxChildLevel: holds the number of loops TblChildLevel: holds the ChildLevel for a specific table. Determined at the lowest level, used in the mid level
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Within this loop: the table loop in which you call the subroutine Now you can build script Main
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Within a %ForEachParentRel() {} context you can use specific macros like %Parent, %Child to navigate
%ForEachEntity(%Child) {zzz} Replace zzz by the same logic Repeat this nesting as many times as you need!
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Summary
A few words to review Sequention, Selection, Iteration Build it step by step Design the structure to keep it maintainable Keep it simple For Advanced Use: apply an editor like PSPad to keep track of {}() etc. An then: start generating! Result: 100% code generation, no manual coding of SQL statements needed
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.
Copyright 2007 CA. All rights reserved. All trademarks, trade names, service marks and logos referenced herein belong to their respective companies.