$GET; $GET

Returns the data value of the specified variable.

The outline

$GET(variable,default)
$G(variable,default)
Copy the code

Parameters

  • Variable Subscripted or unscripted local variable, global variable, or process-specific global variable. The variable may be undefined. You can useobj.propertyThe syntax specifies variables as multidimensional object properties.
  • Default Optional – The value returned if the variable is not defined. If it is a variable, it must be defined.

describe

$GET returns the data value of the specified variable. Processing of undefined variables depends on whether a default parameter is specified.

  • $GET(variable)Returns the value of the specified variable, or an empty string if the variable is undefined. A variable parameter value can be the name of any variable, including array elements with subscripts (local or global variables).
  • $GET(variable,default)Provides a default value that is returned if the variable is not defined. If a variable is defined, then$GETReturns its value.
DHC-APP>w $g(a,"asc")
asc
Copy the code

parameter

variable

The variable whose data value is to be returned.

  • Variables can be local, global, or process-specific global (PPG) variables. It can be subscript or not subscript.

This variable need not be a defined variable. $GET returns an empty string of undefined variables; It does not define the variable. You can define variables and set them to an empty string (” “). If it is a global variable, it can contain an extended global reference. If it is a global variable with a lower index, you can specify it using a bare global reference. Even when referencing an undefined subscript global variable, the variable resets the naked indicator, affecting future naked global references, as described below.

  • Variables can be multidimensional object attributes, not non-multidimensional object attributes. Try using it on non-dimensional object properties$GETCan lead to<Object Dispatch>Error.

$GET cannot return the property value of the proxy object property. Instead, the Cache issues a message indicating that the specified attribute does not exist. This property access restriction is unique to the class % zent.proxyObject, which is defined in the InterSystems class Reference.

default

The data value to return when a variable is not defined. It can be any expression, including local or global variables, with or without subscripts. If it is a global variable, it can contain an extended global reference. If it is a global variable with a lower index, you can specify it using a bare global reference. If so, DEFAULT resets the bare indicator, affecting future bare global references, as described below.

If DEFAULT is an UNDEFINED variable, then by DEFAULT $GET emits a

error, even if the variable is defined. By setting the % system.process.unpay () method, you can change the Cache behavior so that it does not generate a

error when referring to UNDEFINED variables. If the un25th () method is set to not generate a

error, then $GET will return the variable if the default value is UN25th.


The sample

In the following example, the variable test is defined, but the variable xtest is not. (The ZWRITE command is used because it explicitly returns a NULL string value.)

/// d ##class(PHA.TEST.Function).Get()
ClassMethod Get(a)
{
	KILL xtest
	SET test="banana"SET tdef=$GET(test),tundef=$GET(xtest) ZWRITE tdef ; $GET Returns ZWRITE tundef; $GET returns the empty string WRITE! For xtest ,$GET(xtest,"none"); $GET returns the default value of the undefined variable "None"}Copy the code
DHC-APP>d ##class(PHA.TEST.Function).Get(a)tdef="banana"
tundef=""
 
none
Copy the code

In the following example, multidimensional attributes are used as variable values. This example returns the names of all defined namespaces:

/// d ##class(PHA.TEST.Function).Get1()
ClassMethod Get1(a)
{
	SET obj = ##class(%ResultSet%).New(" %SYS.Namespace:List")
	DO obj.Execute(a)WRITE! , $GET(obj.Data,"none/ / ")returns "none"
	SET x=1
	WHILE x'="" { DO obj.Next() SET x=$GET(obj.Data("Nsp")) IF x'=""{ WRITE ! ."Namespace: ",x } } WRITE ! ."Done!"
}
Copy the code
DHC-APP>d ##class(PHA.TEST.Function).Get1(a)none
Namespace: %SYS
Namespace: DHC-APP
Namespace: DHC-CHSSWEB
Namespace: DHC-CSM
Namespace: DHC-DATA
Namespace: DHC-DWR
Namespace: DHC-EKG
Namespace: DHC-HEIS
Namespace: DHC-HR
Namespace: DHC-LISDATA
Namespace: DHC-LISSRC
Namespace: DHC-MEDSRC
Namespace: DHC-MRQ
Namespace: DOCBOOK
Namespace: FDBMS
Namespace: PACS
Namespace: PIS
Namespace: RIS
Namespace: SAMPLES
Namespace: USER
Done!
Copy the code

Similar programs use the $DATA function to return the same information.

Pay attention to


G E T with The GET and
Compared with the DATA

$GET provides an alternative to the $DATA test for undefined variables ($DATA = 0) and array nodes ($DATA = 10) that are Pointers down for no DATA. If the variable is undefined or a pointer array node with no data, $GET returns an empty string (” “) without an undefined error. For example, the following lines could be recoded:

   IF $DATA(^client(i))=10{ WRITE !! ."Name: No Data" 
      GOTO Level1+3
   }
Copy the code

or

   IF $GET(^client(i))=""{ WRITE !! ."Name: No Data" 
      GOTO Level1+3
   }
Copy the code

Note that the $DATA tests are more specific than the $GET tests, because they enable the distinction between undefined elements and elements that are just downward Pointers. For example, these lines:

    IF $DATA(^client(i))=0 { QUIT }
    ELSEIF $DATA(^client(i))=10{ WRITE !! ."Name: No Data" 
    GOTO Level1+3 
    }
Copy the code

Could not be recoded as:

    IF $GET(^client(i))="" { QUIT }
    ELSEIF $GET(^client(i))=""{ WRITE !! ."Name: No Data" 
      GOTO Level1+3
    }
Copy the code

These two lines perform different operations depending on whether an array element is undefined or a downward pointer with no data. If $GET is used here, only the first action (QUIT) will be performed. You can use $DATA for the first test and $GET for the second, but not the other way around ($GET for the first test and $DATA for the second test).

The default value is
G E T and GET and
SELECT

$GET(variable,default) allows the default value to be returned if the specified variable is not defined. You can perform the same operation using the $SELECT function.

However, unlike $SELECT, the second argument in $GET is always evaluated.

If both variables and defaults use global references to subscripts and therefore both modify the bare metric, the fact that $GET will always evaluate its two parameters is important. Because the arguments are evaluated from left to right, the bare metric is set to the default global reference whether or not $GET returns the default value.

Handle undefined variables

If the specified variable is not defined, $GET defines the processing behavior. If the specified variable is not defined, the basic form of $GET returns an empty string (” “).

$DATA tests whether the specified variable is defined. If the variable is not defined, 0 is returned.

You can use% SYSTEM. The ProcessOf the classUndefined ()Method defines the processing behavior of all undefined variables for each process. You can do that by settingConfig.MiscellaneousOf the classUndefinedProperty to establish system-wide default behavior. Sets undefined values for the specified variable$GETor$DATAProcessing has no impact.