4gl string parsing
Posted in 2011
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I need to parse a comma separated list of strings in 4gl. If there is a number less than 290000 in the list i need to return a true value, otherwise false. I have something like: let topix = "300000,310010,420011,650934,280000" let top_loop = 0 while (top_loop < length(topic)) if (topix[top_loop, top_loop + 6] < 290000) then return 1 end if end while return 0
On Jan 26, 12:01 pm, monkeys paw <mon...@joemoney.net> wrote:
> I need to parse a comma separated list of strings
> in 4gl. If there is a number less than 290000 in the
> list i need to return a true value, otherwise false.
> I have something like:
>
> let topix = "300000,310010,420011,650934,280000"
> let top_loop = 0
>
> while (top_loop < length(topic))
> if (topix[top_loop, top_loop + 6] < 290000) then
> return 1
> end if
> end while
> return 0
Converting my prior suggestion into a stored procedure...
This will let you do something like
execute function tst_string(100,"400,800,-1,50000");
--------------------------------------------------------------------------------------------
create function tst_string(maxnum int, str lvarchar) returns intdefine tnum int;
define len int;
define sign int;
define sub int;
define tchar char(1);
let len = length(trim(str));
let sub = 1;
while sub < len
let tnum = 0;
let sign = 1;
let tchar = substring(str from sub for 1);
if tchar = '-' then
let sign = -1;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end if;
while ((sub < len) and (tchar != ','))
if (tchar != ',') then
let tnum = (tnum * 10) || tchar;
end if;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end while;
let sub = sub + 1;
if (tnum * sign) < maxnum then
return 1;
end if;
end while;
return 0;
end function;
On Jan 26, 12:01 pm, monkeys paw <mon...@joemoney.net> wrote:
> I need to parse a comma separated list of strings
> in 4gl. If there is a number less than 290000 in the
> list i need to return a true value, otherwise false.
> I have something like:
>
> let topix = "300000,310010,420011,650934,280000"
> let top_loop = 0
>
> while (top_loop < length(topic))
> if (topix[top_loop, top_loop + 6] < 290000) then
> return 1
> end if
> end while
> return 0
Opps - minor correction. the || should have been +
drop function tst_string(int, lvarchar);
create function tst_string(maxnum int, str lvarchar) returns intdefine tnum int;
define len int;
define sign int;
define sub int;
define tchar char(1);
let len = length(trim(str));
let sub = 1;
while sub < len
let tnum = 0;
let sign = 1;
let tchar = substring(str from sub for 1);
if tchar = '-' then
let sign = -1;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end if;
while ((sub < len) and (tchar != ','))
if (tchar != ',') then
let tnum = (tnum * 10) + tchar;
end if;
let sub = sub + 1;
let tchar = substring(str from sub for 1);
end while;
let sub = sub + 1;
if (tnum * sign) < maxnum then
return 1;
end if;
end while;
return 0;
end function;