Question Mikhail (VetsEZ) Akselrod · 1 hr ago

Failure to use multi-line code in *inc file macro definition

What is wrong with the *inc file code below:

#define ArrayToString(%array,%out,%del)      set %out="" for { ##continue
                                                                                   set key=$order(%array("")) quit:key="" ##continue
                                                                                   set %out=%out_%del_key ##continue
                                                                               } quit

Compilation at calling classmethod as : Set tQStr = $$$ArrayToString(pQArray,tQStr,"##") brings error as:

Product version: IRIS 2022.1
$ZV: 2022.1.2 Build 574 Server IRIS for Windows (x86-64) 2022.1.2

Comments

Julius Kavay · 1 hr ago

I would say, a little bit to much "set" command.

Instead   of: Set tQStr = $$$ArrayToString(pQArray,tQStr,"##") 

try this  one: $$$ArrayToString(pQArray,tQStr,"##") 

Your version gives something like: Set tQStr = set %out="" for { ...

as you see, %out isn't a command (and set would be undefined, but that isn't the problem)

By the way, the second line of your macro should be:

set key=$order(%array(key)) quit:key="" ##continue

else you have the perfect endless loop

0
Mikhail (VetsEZ) Akselrod  5 min ago to Julius Kavay

Upon change:

set %out="" for { ##continue
         set key=$order(%array(key)) quit:key="" ##continue
        set %out=%out_%del_key}

ERROR #5002: ObjectScript error: <UNDEFINED>zTrans+22^HS.Local.VA.Util.SQLHub.1 *key

0
Julius Kavay · 1 hr ago

One more comment, I'm not sure about the "quit" command after the closing curly brace,  I think you don't need it (because it's outside of the FOR loop, hence it will stop the flow of your application)!

0
Robert Cemper · 30 min ago
  1. With your #define, you create a sequence of lines. NOT a method !!
  2. So the final quit is wrong. 
    But this works:
  3. #define ArrayToString(%array,%out,%del) ##continue 
     set %out="" for { ##continue 
     set key=$order(%array("")) quit:key="" ##continue 
     set %out=%out_%del_key ##continue 
     } 
    a 
     $$$ArrayToString(pQArray,tQStr,"##") 
     zw
  4. // the generated int code:
     
  5. a 
     set tQStr="" for { 
     set key=$order(pQArray("")) quit:key="" 
     set tQStr=tQStr_"##"_key 
     } 
    zw     
    
0
Mikhail (VetsEZ) Akselrod  1 min ago to Robert Cemper

Upon change:

set %out="" for { ##continue
         set key=$order(%array("")) quit:key="" ##continue
        set %out=%out_%del_key}

Just for 3 rows array, it creates infinitive string ending in MAXSTRING error

0