Example: PDM Custom Check

You enter the script of the custom check in the Check Script tab using VBScript. In this example, we will write a script to verify that SAP® Sybase® IQ indexes of type HG, HNG, CMP, or LF are not linked with columns with a data type of VARCHAR with a length higher than 255.

The script is initialized with the following line, which must not be altered:
Function %Check%(obj)
At run-time the variable %Check% is replaced by concatenating the names of the resource file, metaclass, any stereotypes or criteria, and the name of the check itself from the General tab, with any spaces replaced by an underscore. The parameter obj contains the object being checked.
We begin by defining a certain number of variables after the default function definition:
Dim c 'temporary  index column
Dim col 'temporary column
Dim position
Dim DT_col
Next, we enter the function body, which starts by setting the %Check% to true (meaning that the object passes the test) and then iterates over each of the columns associated with the index and tests their datatype. If a column has a varchar longer than 255, the script outputs a message and sets the check to false (the object fails the test:
%Check%= True

if obj.type = "LF" or obj.type = "HG" or obj.type = "CMP" or obj.type ="HNG" then
 for each c in obj.indexcolumns
  set col = c.column
  
   position = InStr(col.datatype,"(") 
   if position <> 0 then
    DT_col = left(col.datatype, position -1) 
   else 
    DT_col = col.datatype
   end if
if ucase(DT_col) = "VARCHAR" and col.length > 255 then
     output "Table " & col.parent.name & " Column " & col.name & " : Data type is not compatible with Index " & obj.name & " type " & obj.type
     %Check% = False
  end if

For more information about using VBScript in PowerDesigner, see Scripting PowerDesigner.