.foreach_part Macro

The .foreach_part macro allows an iteration on each part of an expression. The part separators will be specified into a pattern expression.

This macro is very useful when dealing with inter-model generation, as models can have very different naming conventions. For example a Java class attribute code may be "customerName" whereas a PDM table column code may be "CUSTOMER_NAME".

Syntax

. foreach_part (<Expression> [, <Separator Pattern>[,<Head> [, <Tail>]]])
[<Block>]
.next[(<Separator>)]

Parameters

Parameter

Description

<Expression>

Designates the expression scanned by the part iterator. This part iterator will stop on each character specified into the <PartSeparatorPattern>

<Separator Pattern> (optional)

Defined into a double quoted string. Any character specified into the pattern will be used as a part separator.

See below

<Block>

Encompasses the following variables:

%CurrentPart%: Current part value,

%IsFirst%: Determines if the current part is the first part of the expression,

%IsLast%: Determines if the current part is the last part of the expression

<Separator> (optional)

A <separator> can be concatenated between each part. If you defined a character separator in the <PartSeparatorPattern>, the value of the <separator> will replace the character separator. If you defined a range separator in the <PartSeparatorPattern>, the table conversion you selected will return the corresponding value to replace the range separator

<Head> or <Tail> (optional)

Expressions that can be added respectively at the beginning or at the end of the generated expression

Separator

There are two types of separator:


  • A character separator that must be defined into an additional simple quote and writes as follows: (%Name,"'<char>'")

  • A range separator that must be used with a conversion table and writes as follows: (%Name,"[<c1>-<c2>]")

Both can also be combined: (%Name,"'<char>',[<c1>-<c2>]"). '<char>' can be any character specified into the pattern for example: a, b , c, 0, 9.

[<c1> - <c2>] specifies a character taken into the range defined between the two characters <c1> and <c2>. For example, [A-Z], [a-z] or [0-9]" can be used as part separators.

By default, the <PartSeparatorPattern> is initialized by the pattern " -_,\t". If the specified pattern is empty the pattern is initialized using the default value.

Examples


  • Script 1: Convert a name into a class code (JAVA naming convention)

    .foreach_part(%Name%, "' _-'")
    %.FU:CurrentPart%
    .next

    The conversion script will output:

    Name = Employee shareholder => Code = EmployeeShareholder

  • Script 2: Convert a name into a class attribute code (JAVA naming convention)

    .set_value(_First, true, new)
    .foreach_part(%Name%, "' _-'")
    .if (%_First%)
    %.L:CurrentPart%
    .set_value(_First, false, update)
    .else
    %.FU:CurrentPart%
    .endif
    .next

    The conversion script will output:

    Name = Employee shareholder => Code = employeeShareholder


Created October 7, 2009. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com