• No results found

Expressions and condition operators

In document PSProfDeveloperManualEnglish (Page 85-95)

Return statement

Chapter 12 Expressions and condition operators

Operators

When using operators, it must be noted that a && link has a higher priority than ||. It may be necessary to use parentheses to achieve the required interpretation.

|| = Or

&& = And

! = Not

The new functions which do not exclusively return TRUE or FALSE can also be used in loops.

Examples

If loop where the status is Released or the group Administrator:

If ( comp ("00003","#(STATUSKEY)") || wcomp("ADMINISTRATORS","$(ALL_GROUPS)") ) {

<Sourcecode: TRUE>

}

If loop; whether Field1 and Field2 exist:

If ( fieldexist ("FELD1") || fieldexist ("FELD2") ) {

<Sourcecode: TRUE>

}

While loop; as long as fields are found, they are read out to a text file:

___Environment ( Num=0 );

while ( fieldexist( INT("$Num") ) ) {

___Shell ( wr(fields.txt:a)@(=field( INT("$Num"))) @(=fieldtype ( INT("$Num"))) );

___Environment ( Num=$(Num:++) );

}

General

#( <FieldName or Function> )

Returns the value of a field or a function. The case used for the field names must be compliant (always UPPER-CASE by default).

Example

IDENT query using a field length of 15:

"@(IDENT)"= "ENG-0000001 "

"@(IDENT:t)"= "ENG-0000001"

"#(IDENT)"= "ENG-0000001"

@( <FieldName or Function> )

Same as '#'. However, here all the field contents are returned, and are therefore complemented with spaces if necessary.

General 72

$( <Variable> )

All expressions including a $ sign are variables. These have no relationship to the actual context. Variable values never end with a space. These are trimmed automatically.

The following variables are available by default when Productstream Professional is launched:

ALL_GROUPS: All the assigned groups of the current user ACTIVE_GROUP: Active group of the current user FULL_USERNAME: Full name of the current user USERID: Login name of the current user

All variables from COMPASS.INI [Path]>

<All environment variables of the operating system>

(See also: ___CmpUtility WriteSyspar)

#( ( <Expression> ) [<SubstitutionDepth>] [:<Format>] )

Version 5.3.0

The character string between the inner round parentheses is substituted as an expression.

The general syntax used previously was:

#(<Expression> [<Affix>] [:<Format>] )

A new, slightly differently phrased handle is now used: (...). The syntax in this case is now:

#(( <Expression> ) [<SubstitutionDepth>] [:<Format>] )

@ or $ together with the appropriate characteristics can always be used in place of #. In particular: $((...)) only substitutes $ variables, but not # or @ variables.

Parameters

<SubstitutionDepth>

A number between 1 and 16 is given here. This represents the maximum number of substitutions performed with the respective result returned the expression. 16 is entered by default unless given otherwise. The expres-sion is not interpreted if it no longer contains the character #, @ or $, or if it has not changed as a result of the substitution.

<Format>

The same format definition used for all expressions applies.

Example

An object contains the following fields::

DES = designation for the number #IDENT IDENT=47110815

The following substitutions are performed on this object:

"#(DES)" returns"Designation for the number #IDENT"

"#((#(DES)))"returns"Designation for the number 47110815"

General 73

#(= <Expression with FieldNames> )

All functions which return field or variable values can be given here. These have already been described in the documentation.

Expressions can also be arithmetic operations. The supported operations are:

+: Addition -: Subtraction

*: Multiplication /: Division Example

Addition of fixed values:

#(= 2 + 5)

Addition of variables:

___Environment ( Number1 = 5 );

___Environment ( Number2 = 2 );

#(= strprep("$(Number1)") + strprep("$(Number2)") )

#(== <Conditions> )

Conditions which are interpreted immediately can be given here. This allows the result of a condition to be saved in a variable.

Example

Information about whether a primary document (#DOCNAME0) exists is saved in a variable.

___Environment ( DocExist=#(== docexist(0) ) );

#(Tx...)

Text variables

This form can be used as soon as a string is given. If a language identifier is used in the variable LangPostFix (configurable in COMPASS.INI), the corresponding language text files are loaded from the different directo-ries.

If multiple languages are to be used, the appropriate files containing valid line IDs must be provided in each directory.

All texts in Productstream Professional are language-neutral. This means that variables which are interpreted during runtime are used instead of definitive texts. These variables are stored in text files in the directory <Prg-Path>\etc\txt.<LangPostFix> (<PrgPath>=server directory; <LangPostFix>=language).

Parameters

#Tx<TexFile><LineID>

#Tx: Fixed handle

<TexFile>: File name, four characters (extension is always *.tex)

<LineID>: Number at the beginning of the line (1 to 3 figures)

These are ASCII files, and the lines are numbered from 1-999. Only one line may be used for each variable.

Each line begins with a number.

Example

Content of the myFi.tex file in the <PrgPath>\etc\txt.<LangPostFix> folder:

000 Version 1.0.1 002 Folder name

003 Logged on as: "$(USERID)" on "#(SYSDATE:D10)"

Usage and output of text

#Txmyfi000 = Version 1.0.1

#Txmyfi002 = Folder name

#Txmyfi003 = Logged on as: "Administrator" on "05.07.2004"

Functions 74

#( Symbol:<SymbolName> )

Symbols can be defined for the record buffer of the current context. They are handled as virtual fields, allowing freely defined virtual fields to be appended to a record buffer. They are addressed just like normal fields. It is only necessary to give the key word Symbol: as well. Symbols do not have any effect on operations performed directly on the database, either.

Example

Redefining a symbol for a current record buffer:

___Recordbuffer ( set __CURRENT__ Symbol:myFunc="New record" );

Reading out a symbol from a current record buffer:

___Recordbuffer ( call __CURRENT__ ___Environment Func=#(Symbol:myFunc) );

#( RecID [:<Format>] )

In Productstream Professional, RecID is used to unambiguously identify an object within a Folder object. This internal number only applies during the Productstream Professional runtime.

@(\n)

Contains an ENTER (carriage return). Is used for texts in messages and dialogs.

$(_DS)

Contains a backslash ("\"). Is used for texts in messages and dialogs, as well as when compiling directories.

Functions

#( call <Function> [<Parameter>] [:<Format>] )

This function starts <Function> and returns the value last saved in <Function> using ___ReturnString. The parameters given here are substituted for the current context and passed on to the <Function>. The product can be formatted using<Format>.

Example

Calling a function which builds up a Where clause according to a switch set by the user:

Public myWhere,AIM_myWhere Procedure AIM_myWhere If ( !empty("$(arg)") ) {

___ReturnString ( ENTITY_TYPE='AIM.DOC.ENG' AND CATEGORY='$(arg)');

} Else {

___ReturnString ( ENTITY_TYPE='AIM.DOC.ENG' );

} Endproc

The following expressions can now be used in this context:

#(call myWhere Buch)

−> ENTITY_TYPE='AIM.DOC.ENG' AND CATEGORY='$(arg)'

#(call myWhere)

−> ENTITY_TYPE='AIM.DOC.ENG'

Functions 75

#( KeyGen <Action> )

Generates keys.

An unique value is generated for the field given. The colon does not have to be entered. Quotation marks ("..."), as well as single inverted commas ('...') can be used for the values.

Syntax

#( KeyGen[:]<GenField>="<StartValue>"[,<GenType>]

[<Field>="<Value1>"][<Field2>="<Value2>"])

Parameters

<GenField>

A unique value is sought for the field and returned.

<StartValue>

<StartValue> can be used to define the number to be started with. If the start value is already unambiguous, it is returned again.

[, <GenType>]

How a key is generated can be influenced using the parameter <GenType>. Valid values are:

A: Upper-case letters only from A-Z a: Letters from a-z only

X: Only upper-case letters from A-Z and numbers from 0-9

x: All letters from a-z and numbers from 0-9 (= default value unless stated otherwise) 0: Numbers from 0-9 only

D: Only figures from 0-9 (is used for the variable generation of the incrementation; syntax see below) Specifying the generating type defines how the incrementation continues. The start value is therefore not con-verted as an overall value.

Example

StartValue = ENG-0000001 GenType = 0

Generated value = ENG-0000012 ("ENG-..." is retained) [<Field1>="<Value1>"]

If <Field1> is given as well, the unambiguity is determined using the generating field <GenField> and

<Field1>.

[<Field2>="<Value2>"]

If <Field2> is given as well, the unambiguity is determined using the generating field <GenField> and <Field1>

and <Field2>.

Note

• Keys can be generated using a maximum of 3 fields (generating field and 2 offset fields). Temporary fields are necessary if a key i ! has to be generated using more than 3 fields.

• Errors are documented in the file errlog.err with the error number 02082.

• The function #(FileNameGen) can be used for the file name (field FILE_NAME).

Functions 76

Example

Generating a document number taking into account the page (new field PAGE):

#(KeyGen IDENT=#(IDENT),0 BLATT="00") )

Variable generation of the incrementation

The value D has been added to the parameter <GenTyp> for the variable generation of the incrementation.

The following syntax is used for this type:

D[0][:Offset[:Length[:Increment]]]

Examples:

From these examples, it can be seen that a key can only be generated without leading zeros in the first example with a purely numerical value as it is not possible to define how positions are expanded dynamically. Here, the numerical sub-string must always be completely filled, as otherwise there will be a conflict with the length.

Example of a function call:

NewElementKeyGen= "IDENT=#(KeyGen:IDENT='DOC-00000',D0:4:5:10 REVISION='A')" […]

The next number is generated from position 4 over 5 characters with an incrementation of 10. The next value would therefore be DOC-00010.

#(GetMaxKey…)

Optimized performance for generating keys

The DBP function #(GetMaxKey…) for generating keys #(KeyGen…) allows an optimized value to be deter-mined when generating keys. The search for an optimized value supports classified keys (with prefix/postfix).

This is controlled using the parameters Offset and Length.

General Syntax for generating keys:

#(KeyGen[:] <GenField>="<Start value>"[,<GenType>] [<Field>="<Value1>"]

[<Field2>="<Value2>"])

Syntax for the determination of the ideal start value:

#(GetMaxKey Fieldname="<Value>" "<Offset>" "<Length>")

Syntax for the combined call:

#(KeyGen[:] <GenField>=#(GetMaxKey Fieldname="<Value>" "<Offset>" "<Length>")[…]

0 Optional and describes whether leading zeros are to be retained (0) or omitted (no entry).

This is only of significance with purely numerical fields, and not with classified fields. In the case of classified fields, the value together with the length represent the field that is to be filled. Missing significant positions are always padded with zeros (left padding)

Call options:

: Leading zeros are neither taken into consideration nor returned 0: Leading zeros are returned up to the defined length

Offset Starting point (index) of the prefix. Index is a so-called 0 index, i.e. it starts with 0.

Length Length of the variable numerical sub-character string that is to be generated Increment Incrementation for the generation (only positive integer values are allowed)

D

Internal: :0:0:0

Generation over the entire field without leading zeros and an incrementation of 1.

Positions are carried over and expanded if necessary.

D0

Internal: 0:0:0:0

Generation over the entire field with leading zeros and an incrementation of 1. The entire field is padded with leading zeros if any are missing.

D0:3

Internal 0:3:0:0

Generation over the entire field from position 4 to the end of the field with leading zeros and an incrementation of 1.

D0:4:6 Internal 0:4:6:0

Generation over the entire field from position 5 to length 6 with leading zeros and an incrementation of 1.

D0:4:4:10 Internal 0:4:4:10

Generation over the entire field from position 5 to length 4 with leading zeros and an incrementation of 10.

Functions 77

ObligatoryField

Obligatory fields (mandatory fields) can be defined in the configuration of the list view and the datasheet. This document describes the procedures and whether the attribute ObligatoryField was filled in or not at the time the check was run.

The function ObligatoryFieldViolation() is always called by the ListView object or the DataSheetView object if the user leaves a field defined as a mandatory field empty after editing it. 3 arguments are handed over to the function:

• CaptionName: this value is used from the configuration

• FieldName: field name of the field left empty after editing.

• OldValue: the value in the field prior to editing. The field can also have been empty if the attribute Obliga-toryField was only changed subsequently.

Caution!

This function must not change the program's input focus! The only action which can be performed is to write error messages to a file or in the status bar. A message dialog may not be used either, as this would also change the input focus!

Chkobligatory() function

This function can be called in the in Save function of the New record dialog window. It triggers a check of all the editable fields in the dialog to determine whether there have been any violations of the ObligatoryField condition. If no violation is detected, the value 0 is returned instead of >0.

If this check does detect a violation of the ObligatoryField condition, the function ObligatoryFieldViolation() is called within the function chkobligatory(). This enables the field name (or other permitted information) to be stored in global variables following the interpretation of chkobligatory() as well allowing an error message to be issued.

Example

If ( chkobligatory() > 0 ) {

___Shell ( read()#TxMSG1610 );

Return ( 100 );

} ...

Public ObligatoryFieldViolation, AIM_ObligatoryFieldViolation Procedure AIM_ObligatoryFieldViolation

___Environment ( OFV_Caption=$(arg:v1) );

___Environment ( OFV_Field=$(arg:v2) );

___Environment ( OFV_OldValue=$(arg:v3) );

___StatusBar ( #TxSTBA200 );

Endproc

Strings 78

Strings

comp ( "<String1>" , "<String2>" )

String comparison: The result is TRUE if the two specified strings within a comparison length are identical.

The comparison length is the length of <String1>. All the other characters in <String 2> are not compared.

Important: The strings are case-sensitive!

Caution!

The condition is always TRUE if <String1> is empty.

ncomp ( "<String1>" , "<String2>" , "<Length>" )

String comparison of the length: The result is TRUE if <String1> is identical to <String2> regarding the length

<Length> of the strings

wcomp ( "<String1>" , "<String2>" )

Part string comparison: The result is TRUE if <String1> is contained in <String2>. The strings are funda-mentally case-sensitive. Lower-case letters in <String1> are an exception. They are regarded as identical to the upper and lower-case letters in <String2>.

empty ( "<String>" )

String comparison: The result is TRUE if <String> is empty, i.e. the length is either 0 or is made up of spaces only.

isdefined ( "<String>" )

The result is TRUE if <String> is an environment variable which is not empty.

isknown ( "<String>" )

The result is TRUE if <String> is a known condition name.

eq ( "<Number1>" , "<Number2>" )

Comparison of two numerical values: The result is TRUE if <Number1> is equal to <Number2>.

aeq ( "<Char1>" , "<Char2>" )

Like eq, but an ASCII comparison is performed. The given values are compared on the basis of their ASCII codes, therefore making comparisons of letters also possible, e.g. "a" = "a".

le ( "<Number1>" , "<Number2>" )

Comparison of two numerical values: The result is TRUE if <Number1> <= <Number2> (less than or equal to).

ale ( "<Char1>" , "<Char2>" )

Like le, but a ASCII comparison is performed. The given values are compared on the basis of their ASCII co-des, therefore making comparisons of letters also possible, e.g. "a" <= "s".

lt ( "<Number1>" , "<Number2>" )

Comparison of two numerical values: The result is TRUE if <Number1> < <Number2> (less than).

alt ( "<Char1>" , "<Char2>" )

Like lt, but an ASCII comparison is performed. The given values are compared on the basis of their ASCII codes, therefore making comparisons of letters also possible, e.g. "a" < "s".

Strings 79

ge ( "<Number1>" , "<Number2>" )

Comparison of two numerical values: The result is TRUE if <Number1> >= <Number2> (greater than or equal to).

age ( "<Char1>" , "<Char2>" )

Like ge, but an ASCII comparison is performed. The given values are compared on the basis of their ASCII codes, therefore making comparisons of letters also possible, e.g. "s" >= "a"..

gt ( "<Value1>","<Value2>" )

Comparison of two numerical values: The result is TRUE if Value1 > Value2 (greater than).

agt ( "<Value1>","<Value2>" )

Like gt, but an ASCII comparison is performed. See the condition function aeq for details.

ne ( "<Value1>","<Value2>" )

The opposite of eq (not equal). See the condition function eq for details.

ane ( "<Value1>","<Value2>" )

Like ne, but an ASCII comparison is performed. See the condition function aeq for details.

#(= strlen ( "<String>" ) )

Returns the string length as an integer.

The expressions are not substituted!

#(= strchr ( "<String>" , "<SearchCharacter>" ) )

Searches for the <SearchCharacter> in the <String> and returns the <String> from the <SearchCharacter>.

Parameters

<String>: Character string in which the search is run

<SearchCharacter>: Character string whose first character is being sought in <String>

Return value

<Sub-String>:Character string <String> from (incl.) the found first character of <SearchCharacter>. The return value is an empty string ("") if the search character cannot be found.

The expressions are not substituted!

#(= substr ( "<String>" , <Start> , <Length> ) )

Returns the part of <String> from the position <Start> in the length <Length>.

Parameters

<String>: Character string whose part string is to be returned

<Start>: Value is returned from the defined position (1st character = 0)

<Length>: Length, how many values are to be returned The expressions are not substituted!

#(= strprep ( "<String>" ) )

Substitutes all the expressions ($, #, @) contained in the given <String>.

#(= envprep ( "<String>" ) )

Substitutes all the variables ($) contained in the given <String>.

Fields 80

#(= INT ( "<String>" ) )

The given string is converted into an integer (actually a long integer).

The expressions are substituted!

#(= INT ( <Number> ) )

The given number is converted into an integer (actually a long integer). The number can also be a condition.

The expressions are substituted!

#(= DOUBLE ( "<String>" ) )

The given string is converted into a double.

The expressions are substituted!

#( subst: <Variable> )

A second substitution of the given variables is forced. This is given without the character $. The return value is the substituted content of the variable.

Example

___Environment ( MyVar=Designation = $tempDesignation );

The substituted value is now given in the variable MyVar. If the variable $tempDesignation in turn contains a variable, the content of this variable is not substituted.

___Environment ( MyVarNew=#(subst: MyVar) );

The content of the variable MyVar is now given in the variable MyVarNew. Even the content of $tempDesi-gnation is substituted.

Fields

#(= field ( "<FieldName>" ) ), #( field ( <FieldNumber> ) )

The field number or field name is returned.

Return value

"<FieldName>": Name of the field or an empty string ("") if the field number does not exist

<FieldNumber>: Number of the field, or -1 if the field does not exist

#(= fieldexist ( "<FieldName>" ) ), #(= fieldexist ( <FieldNumber> ) )

Condition whether <FieldName> or <FieldNumber> exists.

Return value

TRUE: Field name or field number exists FALSE: Field name or field number does not exist

#(= fieldlen ( "<FieldName>" ) ), #(= fieldlen ( <FieldNumber> ) )

The field length is returned as an integer.

Return value

<Integer>: Field length of the given field -1: Field name or field number does not exist

#(= fielddec ( "<FieldName>" ) ), #(= fielddec ( <FieldNumber> ) )

The decimal positions are returned as integers.

Return value

<Integer>: Decimal positions of the given field

0: Field name or the field number does not exist, or does not have any decimal positions

In document PSProfDeveloperManualEnglish (Page 85-95)