I'm doing some work with &define's, and I've got a scenario which I think _should_ work but doesn't.
This is the code:
&scoped-define test "integer"
&if defined(test) &then
message "hello1".
&endif
&if {&test} = "integer" &then
message "hello2".
&endif
/* this works */
&if defined(test) &then
&if {&test} = "integer" &then
message "hello3".
&endif
&endif
defined() returns an integer and should be used as such.
Example:
if defined(test) <> 0 &then
I do not really know why your code works when this is the only expression, but it is probably not doing what you expect or want.
That did it - thx!
DEFINED returns 0 (not defined), 1 (scoped) or 2 (global). &IF DEFINED (foo) &THEN without a comparison returns false if the value of DEFINED is 0, otherwise true - this short cut does shortly bite you if you want to add operators to the condition and you will need to add the > 0 (I dislike <> when > is sufficient).
Depending on your actual case it can help to /not/ put the quotes around the defined value since you can then use it in more places - for example in the definition of a variable.
&SCOPED-DEFINE test integer
&IF "{&test}" = "integer" &THEN
DEFINE VARIABLE foo AS {&test} NO-UNDO.
&ENDIF
&SCOPED-DEFINE datatype integer
&IF DEFINED( datatype ) > 0 &THEN
DEFINE VARIABLE foo AS {&datatype} NO-UNDO.
MESSAGE foo "{&datatype}".
&ENDIF
If you are only using the values as strings then definitely keep the quotes as you will trap typing errors in the preprocessor name with compile errors.