PreviousNextIndex

{ } Preprocessor name reference

References the value of a preprocessor name in any ABL or preprocessor expression.

Syntax

{ &preprocessor-name } 

Enter the braces ({}) as shown; they do not represent syntax notation in this description.

&preprocessor-name
Examples

The r-prprc1.p procedure shows how you can reference a built-in preprocessor name and include it in a character string.

r-prprc1.p
MESSAGE "The current operating system is" "{&OPSYS}."  
  VIEW-AS ALERT-BOX. 

The procedure r-prprc2.p shows how to capture the value of a {&SEQUENCE} reference. In this example, {&SEQUENCE} is referenced three times, once each to assign its value to wvar (0) and xvar (1) at run time. The third reference defines the preprocessor name Last-Value with the value 3. As shown, Last-Value is assigned unchanged to both yvar and zvar, each of which take the value 3 at run time.

r-prprc2.p
DEFINE VARIABLE wvar AS INTEGER NO-UNDO. 
DEFINE VARIABLE xvar AS INTEGER NO-UNDO. 
DEFINE VARIABLE yvar AS INTEGER NO-UNDO. 
DEFINE VARIABLE zvar AS INTEGER NO-UNDO. 
ASSIGN 
  wvar = {&SEQUENCE} 
  xvar = {&SEQUENCE}. 
&GLOBAL-DEFINE Last-Value {&SEQUENCE} 
ASSIGN 
  yvar = {&Last-Value} 
  zvar = {&Last-Value}. 
MESSAGE "wvar =" wvar SKIP "xvar =" xvar SKIP 
        "yvar =" yvar SKIP "zvar =" zvar VIEW-AS ALERT-BOX. 

The procedure r-prprc3.p shows how preprocessor names override compile-time arguments. In this example, r-prprc3.p defines the preprocessor name My-Name as "Daniel". It then passes the compile-time argument My-Name, with the value "David", to the include file r-prprc3.i, which in turn defines a preprocessor name My-Name as "Donald".

r-prprc3.p
&SCOPED-DEFINE My-Name "Daniel" 
{r-prprc3.i &My-Name = "David"} 
MESSAGE "My-Name preprocessed in r-prprc3.p is" {&My-Name} + "." 
  VIEW-AS ALERT-BOX. 

r-prprc3.i
MESSAGE "My-Name argument in r-prprc3.i is" "{&My-Name}" + "."  
  VIEW-AS ALERT-BOX. 
&SCOPED-DEFINE My-Name "Donald" 
MESSAGE "My-Name preprocessed in r-prprc3.i is" {&My-Name} + "."  
  VIEW-AS ALERT-BOX 

During execution, the first message included by r-prprc3.i displays the value of the My-Name argument, "David". The second message included by r-prprc3.i displays the value of the following My-Name preprocessor name, defined as "Donald", permanently overriding "David" passed by the My-Name argument. Finally, the message in r-prprc3.p displays the value of the My-Name preprocessor name that was initially defined there, "Daniel", because the value from My-Name established in r-prprc3.i ("Donald") went out of scope during compilation.

Note also that the reference to the My-Name compile-time argument in r-prprc3.i is inside double-quotes, because ABL passes string constant values for compile-time arguments without the surrounding double-quotes.

You can encounter compilation problems mixing preprocessor names with compile-time argument names. The following example, a variation of r-prprc3.i, does not compile, even when passed a My-Name argument as an include file. This is because the preprocessor My-Name value overrides the argument My-Name value, as shown:

&SCOPED-DEFINE My-Name "Donald" 
MESSAGE "My-Name preprocessed in r-prprc3.i is" {&My-Name} + "." 
  VIEW-AS ALERT-BOX. 
MESSAGE "My-Name argument in r-prprc3.i is" "{&My-Name}" + "." 
  VIEW-AS ALERT-BOX. 

Because the preprocessor My-Name defines a quoted "Donald" value, ABL replaces "{&My-Name}" in the fourth line with ""Donald"". This appears to the compiler as two empty strings and an unknown variable reference (Donald). Although you can do it with care, in general, avoid using the same names for compile-time arguments and preprocessor names.

Notes
See also

&GLOBAL-DEFINE preprocessor directive, &SCOPED-DEFINE preprocessor directive, { } Argument reference, { } Include file reference, ; Special character


OpenEdge Release 10.2B
Copyright © 2009 Progress Software Corporation
PreviousNextIndex