pralash
21st November 2017, 06:52
Hi,

I'm new for LN Programming... I'm using the break statement in order to exit the control from the body of selectdo and endselect. But I'm not able to get the break of the loop... Is it correct for using break with in the selectdo and endselect or some other else?

My Sample script is as follows....

function read.counter.table()
{
change = tcyesno.no
process.end = tcyesno.no


select tctls903.logg
from tctls903
where tctls903._index1 inrange {:logg.f} and {:logg.t}
selectdo

if logg.t.change=logg.t or logg.f.change=logg.t then
break
endif

if change=tcyesno.no then
act.date = sprintf$("%u(%04Y-%02m-%02d)",tctls903.logg)
logg.first=tctls903.logg
else
logg.first=logg.f.change
act.date = sprintf$("%u(%04Y-%02m-%02d)",logg.first)
endif


select tctls903.logg as temp
from tctls903
where tctls903._index1 inrange {:logg.first} and {:logg.t}
selectdo
act.date2 = sprintf$("%u(%04Y-%02m-%02d)",temp)
if act.date <> act.date2 then
logg.f.change = temp |kkkk
break
else
change=tcyesno.yes
logg.t.change=0
logg.t.change = temp
endif
endselect


counter = 0

select distinct tctls903.user
from tctls903
where tctls903._index1 inrange {:logg.first} and {:logg.t.change}
selectdo
counter = counter+1

endselect

rprt_send()
endselect

|message("%s",sprintf$("%u(%04Y-%02m-%02d)",logg.t.change))
}

Please let me know if there is some another methods are available to exit the control the body of the loop instead of the "Break" statement...?

Regards,
Pralash

bhushanchanda
21st November 2017, 08:09
Hi Pralash,

Remember, the "break" will only break the current loop and not all the select loops.

Here's an explanation of your code -

function read.counter.table()
{
change = tcyesno.no
process.end = tcyesno.no


select tctls903.logg |#First Select Loop
from tctls903
where tctls903._index1 inrange {:logg.f} and {:logg.t}
selectdo

if logg.t.change=logg.t or logg.f.change=logg.t then
break |# Will break the first select loop
endif

if change=tcyesno.no then
act.date = sprintf$("%u(%04Y-%02m-%02d)",tctls903.logg)
logg.first=tctls903.logg
else
logg.first=logg.f.change
act.date = sprintf$("%u(%04Y-%02m-%02d)",logg.first)
endif


select tctls903.logg as temp |# Second select loop
from tctls903
where tctls903._index1 inrange {:logg.first} and {:logg.t}
selectdo
act.date2 = sprintf$("%u(%04Y-%02m-%02d)",temp)
if act.date <> act.date2 then
logg.f.change = temp |kkkk
break |# Will break the second select loop and will go to third select loop and will also remain in first select loop
else
change=tcyesno.yes
logg.t.change=0
logg.t.change = temp
endif
endselect


counter = 0

select distinct tctls903.user |# Third select loop
from tctls903
where tctls903._index1 inrange {:logg.first} and {:logg.t.change}
selectdo
counter = counter+1

endselect

rprt_send()
endselect

|message("%s",sprintf$("%u(%04Y-%02m-%02d)",logg.t.change))
}

If you want the code to break the select loop 2 and get out of the select loop 1 as well, you can do this -

function read.counter.table()
{
domain tcbool break.all
change = tcyesno.no
process.end = tcyesno.no


select tctls903.logg
from tctls903
where tctls903._index1 inrange {:logg.f} and {:logg.t}
selectdo

if logg.t.change=logg.t or logg.f.change=logg.t then
break
endif

if change=tcyesno.no then
act.date = sprintf$("%u(%04Y-%02m-%02d)",tctls903.logg)
logg.first=tctls903.logg
else
logg.first=logg.f.change
act.date = sprintf$("%u(%04Y-%02m-%02d)",logg.first)
endif


break.all = false
select tctls903.logg as temp
from tctls903
where tctls903._index1 inrange {:logg.first} and {:logg.t}
selectdo
act.date2 = sprintf$("%u(%04Y-%02m-%02d)",temp)
if act.date <> act.date2 then
logg.f.change = temp |kkkk
break.all = true
break
else
change=tcyesno.yes
logg.t.change=0
logg.t.change = temp
endif
endselect


if break.all then
break |# Break from the select loop 1
endif

counter = 0

select distinct tctls903.user
from tctls903
where tctls903._index1 inrange {:logg.first} and {:logg.t.change}
selectdo
counter = counter+1

endselect

rprt_send()
endselect

|message("%s",sprintf$("%u(%04Y-%02m-%02d)",logg.t.change))
}

pralash
21st November 2017, 14:43
Hi bhushanchanda,
Thanks so much for your information...
I fixed the issue in my script...
Regards,
Pralash