| Author | 
		  Message
		 | 
		
		  | petervh1 | 
		  
		    
			  
				 Posted: Fri Sep 17, 2021 5:58 am    Post subject: Dynamically constructed IF statement | 
				     | 
			   
			 
		   | 
		
		
		   Centurion
 
 Joined: 19 Apr 2010 Posts: 140
  
  | 
		  
		    
			  
				Hi
 
 
IIB 10.0.0.14
 
 
I'm trying to dynamically build an IF statement and then execute it.
 
 
I've managed to build 
 
   
	| Code: | 
   
  
	| 'IF Environment.item.Costcentre <> 00001 AND IF Environment.item.Costcentre <> 00002 AND IF Environment.item.Costcentre <> 00003' | 
   
 
 
as a string inside 
 
   
	| Code: | 
   
  
	| Environment.COSTCENTRECHECK | 
   
 
 
 
and tried to execute it using
 
   
	| Code: | 
   
  
	| IF EVAL('(Environment.COSTCENTRECHECK)') THEN ... | 
   
 
 
 
I get:
 
   
	| Code: | 
   
  
	| BIP2474 A Search condition must produce a boolean result | 
   
 
 
 
Can someone assist me with the required format of the EVAL?
 
 
TIA | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | timber | 
		  
		    
			  
				 Posted: Fri Sep 17, 2021 6:57 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand Master
 
 Joined: 25 Aug 2015 Posts: 1292
  
  | 
		  
		    
			  
				| Using EVAL is usually a terrible idea. What is the technical task that you are trying to accomplish? | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | petervh1 | 
		  
		    
			  
				 Posted: Fri Sep 17, 2021 7:03 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Centurion
 
 Joined: 19 Apr 2010 Posts: 140
  
  | 
		  
		    
			  
				| I need to check whether a cost centre element that is part of an input XML structure is represented or is not represented in a list of cost centres. The list of cost centres is supplied to the IIB flow by means of a JSON array which I need to parse and then construct a an IF statement. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | timber | 
		  
		    
			  
				 Posted: Fri Sep 17, 2021 3:16 pm    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Grand Master
 
 Joined: 25 Aug 2015 Posts: 1292
  
  | 
		  
		    
			  
				This is a very common task, and you do not need EVAL.
 
 
You should 
 
- store the values from the JSON list in the Environment
 
- use the IN operator to see whether the XML value is in that list.
 
 
Give it a try, and post again if you cannot get it to work. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | petervh1 | 
		  
		    
			  
				 Posted: Mon Sep 20, 2021 1:34 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Centurion
 
 Joined: 19 Apr 2010 Posts: 140
  
  | 
		  
		    
			  
				I got it to work using "IN".
 
 
Thanks for your help. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | bruce2359 | 
		  
		    
			  
				 Posted: Mon Sep 20, 2021 3:52 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		    Poobah
 
 Joined: 05 Jan 2008 Posts: 9486 Location: US: west coast, almost. Otherwise, enroute. 
  | 
		  
		    
			  
				Please share your successful code for the benefit of others. _________________ I like deadlines. I like to wave as they pass by.
 
ב''ה
 
Lex Orandi, Lex Credendi, Lex Vivendi. As we Worship, So we Believe, So we Live. | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | petervh1 | 
		  
		    
			  
				 Posted: Mon Sep 20, 2021 4:09 am    Post subject:  | 
				     | 
			   
			 
		   | 
		
		
		   Centurion
 
 Joined: 19 Apr 2010 Posts: 140
  
  | 
		  
		    
			  
				The purpose of checking whether a cost centre is in a list was to determine whether a flag should be set to TRUE or FALSE.
 
 
Here's the code:
   
	| Code: | 
   
  
	
 
DECLARE CostCentreExists BOOLEAN;
 
SET Environment.item.[] = InputRoot.XMLNSC.item.[];
 
        
 
        IF InputRoot.XMLNSC.item.Costcentre IN(
 
          Environment.item.costcentrelist[]) THEN
 
            SET CostCentreExists = TRUE;
 
         ELSE
 
            SET CostCentreExists = FALSE;
 
         END IF; | 
   
 
 | 
			   
			 
		   | 
		
		
		  | Back to top | 
		  
		  	
		   | 
		
		
		    | 
		
		
		  | 
		    
		   |