Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi Experts
I want to conditionally load the table based on values in variable.
I have the below variable that contain the list of values.
LET vSegTypes = chr(39) & Peek('Customers') & chr(39);
I want to compare the above values with below variables.
SET vVar1 = No1;
SET vVar2 = No2;
SET vVar3 = No3;
if ($(vSegTypes) = $(vVar1)) or ($(vSegTypes) = $(vVar2)) or ($(vSegTypes) = $(vVar3)) then
load ....from;
end if
The above if condition is not working. Please help.
On seeing your error, it looks like you are concatenating multiple values in to a variable 'vSegTypes'
in that case I prefer to use Match function
Try something like this
IF Match('$(vVar1)', $(vSegTypes)) or Match('$(vVar2)', $(vSegTypes)) or Match('$(vVar3)', $(vSegTypes)) then
load ....from;
end if
Try this may be:
IF $(vSegTypes) = '$(vVar1)' or $(vSegTypes) = '$(vVar2)' or $(vSegTypes) = '$(vVar3)' then
//On peek you need to write the row number and table.
LET vSegTypes = Peek('Customers',NumberOfReg,'Table');
SET vVar1 = No1;
SET vVar2 = No2;
SET vVar3 = No3;
//On IF, put your vars into string
if '$(vSegTypes)' = '$(vVar1)' or '$(vSegTypes)' = '$(vVar2)' or '$(vSegTypes)' = '$(vVar3)' then
load ....from;
end if
Other option is load table with where condition:
Customers:
Load
....
RESIDENT YourTable
WHERE Customers = '$(vVar1)' or Customers= '$(vVar2)' or Customers = '$(vVar3)';
Kind regards
If you want to access variables which contain string-values you need to wrap them with single-quotes like:
'$(vVar)'
beside them VSegType will be return NULL because peek is applied outside from a load and needs further parameter like: Peek('Customers', RecordNumber, 'Tablename' ) and then it would be only contain a single value and not a list of values. Here you would need to loop through these field and then probably rather in this way:
for i = 0 to fieldvaluecount('Customers')
let vSegTypes = fieldvalue('Customers', $(i));
....
- Marcus
You can also try,
LET vSegTypes = Peek('Customers') ;
SET vVar1 = 'No1';
SET vVar2 = 'No2';
SET vVar3 = 'No3';
if vSegTypes = vVar1 or vSegType = vVar2 or vSegTypes = vVar3 then
load ....from;
end if
Hi Sunny, Thanks for the reply.
I got the Error: Script line error. I see that the variable has null in 3rd condition.
if 'Field1','Field2' = 'Field5' or
'Field1','Field2' = 'Field8' or
'Field1','Field2' = '' or
'Field1','Field2' = 'Field10' then
Error: Script line error:
Would you be able to share the table form which Customer is coming from?
On seeing your error, it looks like you are concatenating multiple values in to a variable 'vSegTypes'
in that case I prefer to use Match function
Try something like this
IF Match('$(vVar1)', $(vSegTypes)) or Match('$(vVar2)', $(vSegTypes)) or Match('$(vVar3)', $(vSegTypes)) then
load ....from;
end if
Thanks everyone for the support.