11.07.2015 Views

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

Caché ObjectScript Reference - InterSystems Documentation

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

1. Evaluates occurrences of indirection or subscripts to the left of the equal sign in a leftto-rightorder to determine the variable name(s). For more information, refer to Indirectionin Using <strong>Caché</strong> <strong>ObjectScript</strong>.2. Evaluates the expression to the right of the equal sign.3. Assigns the expression to the right of the equal sign to the variable name or referencesto the left of the equal sign.Defined and Undefined VariablesMost <strong>Caché</strong> commands and functions require that a variable be defined before it is referenced.Attempting to reference an undefined variable generates an error.Attempting to reference an undefined object generates a or error. Refer to $ZERROR for further details on theseerror codes.The READ command and the $INCREMENT function can reference an undefined variableand assign a value to it. The $DATA function can take an undefined or defined variable andreturn its status. The $GET function returns the value of a defined variable; optionally, it canalso assign a value to an undefined variable.SET with $PIECE and $EXTRACTYou can use the $PIECE and $EXTRACT functions with SET on either side of the equalssign. For detailed descriptions, refer to $PIECE and $EXTRACT.When used on the right side of the equals sign, $PIECE and $EXTRACT extract a substringfrom a variable and assign its value to the specified variable(s) on the left side of the equalssign. $PIECE extracts a substring using a specified delimiter, and $EXTRACT extracts asubstring using a character count.For example, assume that variable x contains the string "HELLO WORLD". The followingcommands extract the substring "HELLO" and assign it to variables y and z, respectively:SET x="HELLO WORLD"SET y=$PIECE(x," ",1)SET z=$EXTRACT(x,1,5)WRITE "x=",x,!,"y=",y,!,"z=",zSETWhen used on the left side of the equals sign, $PIECE and $EXTRACT insert the valuefrom the expression on the right side of the equals sign into the specified portion of the targetvariable. Any existing value in the specified portion of the target variable is replaced by theinserted value.<strong>Caché</strong> <strong>ObjectScript</strong> <strong>Reference</strong> 131

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!