tracylee
9th August 2018, 11:10
Hi,

I have a problem on my customization session. I do a reloop function on my script but when second reloop same function then prompt the message "Function 'reloop": recursion not possible; refcount = 2". Is it cannot reloop same function? My code as below. Please advise. Thanks.


function calculation.bar()
{
domain tclgth abc,def
domain tcpono posi
abc = 1
def = 6100
posi = 10
test.reloop(abc, def, posi)
}

function test.reloop(domain tclgth countlongbar, domain tclgth longbarlength, domain tcpono position)
{
domain tclgth test.countlongbar, test.longbarlength
domain tcpono posi

test.countlongbar = countlongbar + 1
test.longbarlength = longbarlength +1
posi = position + 1

test.reloop(test.countlongbar, test.longbarlength, posi)
}

giggty
9th August 2018, 12:06
From here (http://www.baanboard.com/programmers_manual_baanerp_help_3gl_features_function_calls):
It is possible to use recursive function calls. This means that in a function block a call to the same function is used. However, this is currently implemented only for functions without local variables and arguments.
Never really needed recursion in LN but this is kinda shabby :o

tracylee
10th August 2018, 03:54
From here (http://www.baanboard.com/programmers_manual_baanerp_help_3gl_features_function_calls):

Never really needed recursion in LN but this is kinda shabby :o

Thanks for your information. Then have any coding can work around it? Thanks.

giggty
10th August 2018, 08:24
Well, if you absolutely need recursion then you ought to use global variables. But in your particular case as far as I can see all you do is infinitely increment 3 variables (without even returning them). This better be done using simple for- or while-loop :)

tracylee
10th August 2018, 08:43
Well, if you absolutely need recursion then you ought to use global variables. But in your particular case as far as I can see all you do is infinitely increment 3 variables (without even returning them). This better be done using simple for- or while-loop :)

Thanks for your reply. How to use global variables? Actually my code is more completed than the above code. Please advise.

giggty
10th August 2018, 08:55
Instead of passing abc, def, posi as test.reloop arguments you need to declare them as global variables, then you initialize them before the first test.reloop() call and inside it you just increment abc, def, posi (without declaring local ones!).

tracylee
10th August 2018, 09:13
Instead of passing abc, def, posi as test.reloop arguments you need to declare them as global variables, then you initialize them before the first test.reloop() call and inside it you just increment abc, def, posi (without declaring local ones!).

My actual passing abc, def, posi is not increment value. It will have different value, so i want pass it back to same function to continue loop and get other value. Please advise.

giggty
10th August 2018, 09:29
New different values will get passed to the new layer of recursion, because those are global variables.
Post your actual may be?

tracylee
10th August 2018, 09:46
New different values will get passed to the new layer of recursion, because those are global variables.
Post your actual may be?

Hi,

my code as below.

|******************************************************************************
|* tccus0124m100 0 VRC B61C a pmb
|* Update Short Bar List
|* IS
|* 2018-08-07
|******************************************************************************
|* Main table cprrp100 Planned Orders, Form Type 4
|******************************************************************************

|****************************** declaration section ***************************
declaration:
#include <bic_dam>

table tcprrp100 | Planned Orders
table ttccus024 | Short Bar List
table ttibom010 | BOM
table ttccus025 | Cut List Calculation

extern domain cpcom.plnc order.scenario
extern domain tckoor order.type
extern domain cpitem order.item
extern domain cpcom.quan order.qty
extern domain tclgth long.lgth, short.lgth
extern domain tcitem short.item, short.item.without.project
extern domain tcsect short.section
extern domain tiqbm2 short.qty, total.bom.qty

string temp.txt(250), instr(1)
long str.no, i, pos.1, ret


|****************************** program section ********************************
before.program:


|****************************** group section **********************************
group.1:
init.group:
get.screen.defaults()


|****************************** functions **************************************
Functions:

function extern upd.short.bar()
{
calculate.long.bar()
}

function calculate.long.bar()
{
domain tcpono position
long countg, countss, count.lgth, i2
countg = 1
countss = 0

while countg <> 0
countg = 0

select count(tccus024.lgth):count.lgth
from tccus024
where tccus024.tqty > 0
group by tccus024.sect
selectdo
endselect

for i2 = 0 to (count.lgth - 1)
countg = countg + 1
endfor

if (countg > 0) then

position = 0
countss = countss + 1

reloop(countss, long.lgth, position)
endif
endwhile
}


function reloop(long countlongbar, domain tclgth longbarlength, domain tcpono position)
{
domain tcsect ssection
domain tclgth mmbalance, newquty, iw

long slength, squty, allocatedqty
long longs, temp, balance


select tccus024.*
from tccus024
where tccus024.tqty > 0 and tccus024.lgth <= :longbarlength
order by tccus024.lgth desc as set with 1 rows
selectdo
endselect

ssection = tccus024.sect
slength = tccus024.lgth
squty = tccus024.tqty
allocatedqty = tccus024.oqty
position = position + 10

mmbalance = 0 | use to store long bar balance
longs = longbarlength | assign long bar balance to a new variable longs

iw = longs / slength | use long bar balance to divide then we will get how many qty can produce

temp = 0 | use to store the actual length of produce qty times short length

balance = 0 | use to store if the short lgth still have balance qty after produce

if (iw > squty) then
balance = 0 | set to zero
newquty = squty | set new qty = short lgth balance qty
temp = slength * round(newquty,0,0) | short lgth * new qty
mmbalance = longs - temp | current long bar balance - temp
iw = newquty | new short bar lgth able produce qty to new qty

else
balance = squty - round(iw,0,0) | new short lgth balance qty
temp = slength * round(iw,0,0) | total produce short lgth
mmbalance = longs - temp | update long bar balance = current long bar balance - temp
endif

|******* Update balance qty and temp total back to table **************
select tccus024.*
from tccus024 for update
where tccus024.sect = :ssection and tccus024.lgth = :slength
selectdo
ret = dal.change.object("tccus024")

dal.set.field("tccus024.sect", ssection)
dal.set.field("tccus024.lgth", str$(slength))
dal.set.field("tccus024.tqty", str$(balance))

ret = dal.save.object("tccus024")
commit.transaction()
endselect

|******* Insert Cut List Table **************
select tccus025.*
from tccus025 for update
where tccus025.sect = :ssection |and tccus025.slen = :slength
selectdo
ret = dal.change.object("tccus025")

dal.set.field("tccus025.sect", ssection)
dal.set.field("tccus025.slen", str$(slength))
dal.set.field("tccus025.csle", str$(round(iw,0,0)))
dal.set.field("tccus025.clle", str$(countlongbar))
dal.set.field("tccus025.lbal", str$(mmbalance))

ret = dal.save.object("tccus025")
commit.transaction()
selectempty
ret = dal.new.object("tccus025")

dal.set.field("tccus025.pono", position)
dal.set.field("tccus025.sect", ssection)
dal.set.field("tccus025.slen", str$(slength))
dal.set.field("tccus025.csle", str$(round(iw,0,0)))
dal.set.field("tccus025.clle", str$(countlongbar))
dal.set.field("tccus025.lbal", str$(mmbalance))

ret = dal.save.object("tccus025")
commit.transaction()
endselect

if (mmbalance = 0) then
stop()
else
reloop(countlongbar, mmbalance, position)
endif
}




Please advise.

giggty
10th August 2018, 10:26
Try something like this:

|******************************************************************************
|* tccus0124m100 0 VRC B61C a pmb
|* Update Short Bar List
|* IS
|* 2018-08-07
|******************************************************************************
|* Main table cprrp100 Planned Orders, Form Type 4
|******************************************************************************

|****************************** declaration section ***************************
declaration:
#include <bic_dam>

table tcprrp100 | Planned Orders
table ttccus024 | Short Bar List
table ttibom010 | BOM
table ttccus025 | Cut List Calculation

extern domain cpcom.plnc order.scenario
extern domain tckoor order.type
extern domain cpitem order.item
extern domain cpcom.quan order.qty
extern domain tclgth long.lgth, short.lgth
extern domain tcitem short.item, short.item.without.project
extern domain tcsect short.section
extern domain tiqbm2 short.qty, total.bom.qty

string temp.txt(250), instr(1)
long str.no, i, pos.1, ret

long countlongbar
domain tclgth longbarlength
domain tcpono position

domain tcsect ssection
domain tclgth mmbalance, newquty, iw

long slength, squty, allocatedqty
long longs, temp, balance


|****************************** program section ********************************
before.program:


|****************************** group section **********************************
group.1:
init.group:
get.screen.defaults()


|****************************** functions **************************************
Functions:

function extern upd.short.bar()
{
calculate.long.bar()
}

function calculate.long.bar()
{
domain tcpono position
long countg, countss, count.lgth, i2
countg = 1
countlongbar = 0
longbarlength = 0

while countg <> 0
countg = 0

select count(tccus024.lgth):count.lgth
from tccus024
where tccus024.tqty > 0
group by tccus024.sect
selectdo
endselect

for i2 = 0 to (count.lgth - 1)
countg = countg + 1
endfor

if (countg > 0) then

position = 0
countlongbar = countlongbar + 1

reloop()
endif
endwhile
}


function reloop()
{
select tccus024.*
from tccus024
where tccus024.tqty > 0 and tccus024.lgth <= :longbarlength
order by tccus024.lgth desc as set with 1 rows
selectdo
endselect

ssection = tccus024.sect
slength = tccus024.lgth
squty = tccus024.tqty
allocatedqty = tccus024.oqty
position = position + 10

mmbalance = 0 | use to store long bar balance
longs = longbarlength | assign long bar balance to a new variable longs

iw = longs / slength | use long bar balance to divide then we will get how many qty can produce

temp = 0 | use to store the actual length of produce qty times short length

balance = 0 | use to store if the short lgth still have balance qty after produce

if (iw > squty) then
balance = 0 | set to zero
newquty = squty | set new qty = short lgth balance qty
temp = slength * round(newquty,0,0) | short lgth * new qty
mmbalance = longs - temp | current long bar balance - temp
iw = newquty | new short bar lgth able produce qty to new qty

else
balance = squty - round(iw,0,0) | new short lgth balance qty
temp = slength * round(iw,0,0) | total produce short lgth
mmbalance = longs - temp | update long bar balance = current long bar balance - temp
endif

|******* Update balance qty and temp total back to table **************
select tccus024.*
from tccus024 for update
where tccus024.sect = :ssection and tccus024.lgth = :slength
selectdo
ret = dal.change.object("tccus024")

dal.set.field("tccus024.sect", ssection)
dal.set.field("tccus024.lgth", str$(slength))
dal.set.field("tccus024.tqty", str$(balance))

ret = dal.save.object("tccus024")
commit.transaction()
endselect

|******* Insert Cut List Table **************
select tccus025.*
from tccus025 for update
where tccus025.sect = :ssection |and tccus025.slen = :slength
selectdo
ret = dal.change.object("tccus025")

dal.set.field("tccus025.sect", ssection)
dal.set.field("tccus025.slen", str$(slength))
dal.set.field("tccus025.csle", str$(round(iw,0,0)))
dal.set.field("tccus025.clle", str$(countlongbar))
dal.set.field("tccus025.lbal", str$(mmbalance))

ret = dal.save.object("tccus025")
commit.transaction()
selectempty
ret = dal.new.object("tccus025")

dal.set.field("tccus025.pono", position)
dal.set.field("tccus025.sect", ssection)
dal.set.field("tccus025.slen", str$(slength))
dal.set.field("tccus025.csle", str$(round(iw,0,0)))
dal.set.field("tccus025.clle", str$(countlongbar))
dal.set.field("tccus025.lbal", str$(mmbalance))

ret = dal.save.object("tccus025")
commit.transaction()
endselect

if (mmbalance = 0) then
stop()
else
longbarlength = mmbalance
reloop()
endif
}

tracylee
10th August 2018, 11:08
Try something like this:

|******************************************************************************
|* tccus0124m100 0 VRC B61C a pmb
|* Update Short Bar List
|* IS
|* 2018-08-07
|******************************************************************************
|* Main table cprrp100 Planned Orders, Form Type 4
|******************************************************************************

|****************************** declaration section ***************************
declaration:
#include <bic_dam>

table tcprrp100 | Planned Orders
table ttccus024 | Short Bar List
table ttibom010 | BOM
table ttccus025 | Cut List Calculation

extern domain cpcom.plnc order.scenario
extern domain tckoor order.type
extern domain cpitem order.item
extern domain cpcom.quan order.qty
extern domain tclgth long.lgth, short.lgth
extern domain tcitem short.item, short.item.without.project
extern domain tcsect short.section
extern domain tiqbm2 short.qty, total.bom.qty

string temp.txt(250), instr(1)
long str.no, i, pos.1, ret

long countlongbar
domain tclgth longbarlength
domain tcpono position

domain tcsect ssection
domain tclgth mmbalance, newquty, iw

long slength, squty, allocatedqty
long longs, temp, balance


|****************************** program section ********************************
before.program:


|****************************** group section **********************************
group.1:
init.group:
get.screen.defaults()


|****************************** functions **************************************
Functions:

function extern upd.short.bar()
{
calculate.long.bar()
}

function calculate.long.bar()
{
domain tcpono position
long countg, countss, count.lgth, i2
countg = 1
countlongbar = 0
longbarlength = 0

while countg <> 0
countg = 0

select count(tccus024.lgth):count.lgth
from tccus024
where tccus024.tqty > 0
group by tccus024.sect
selectdo
endselect

for i2 = 0 to (count.lgth - 1)
countg = countg + 1
endfor

if (countg > 0) then

position = 0
countlongbar = countlongbar + 1

reloop()
endif
endwhile
}


function reloop()
{
select tccus024.*
from tccus024
where tccus024.tqty > 0 and tccus024.lgth <= :longbarlength
order by tccus024.lgth desc as set with 1 rows
selectdo
endselect

ssection = tccus024.sect
slength = tccus024.lgth
squty = tccus024.tqty
allocatedqty = tccus024.oqty
position = position + 10

mmbalance = 0 | use to store long bar balance
longs = longbarlength | assign long bar balance to a new variable longs

iw = longs / slength | use long bar balance to divide then we will get how many qty can produce

temp = 0 | use to store the actual length of produce qty times short length

balance = 0 | use to store if the short lgth still have balance qty after produce

if (iw > squty) then
balance = 0 | set to zero
newquty = squty | set new qty = short lgth balance qty
temp = slength * round(newquty,0,0) | short lgth * new qty
mmbalance = longs - temp | current long bar balance - temp
iw = newquty | new short bar lgth able produce qty to new qty

else
balance = squty - round(iw,0,0) | new short lgth balance qty
temp = slength * round(iw,0,0) | total produce short lgth
mmbalance = longs - temp | update long bar balance = current long bar balance - temp
endif

|******* Update balance qty and temp total back to table **************
select tccus024.*
from tccus024 for update
where tccus024.sect = :ssection and tccus024.lgth = :slength
selectdo
ret = dal.change.object("tccus024")

dal.set.field("tccus024.sect", ssection)
dal.set.field("tccus024.lgth", str$(slength))
dal.set.field("tccus024.tqty", str$(balance))

ret = dal.save.object("tccus024")
commit.transaction()
endselect

|******* Insert Cut List Table **************
select tccus025.*
from tccus025 for update
where tccus025.sect = :ssection |and tccus025.slen = :slength
selectdo
ret = dal.change.object("tccus025")

dal.set.field("tccus025.sect", ssection)
dal.set.field("tccus025.slen", str$(slength))
dal.set.field("tccus025.csle", str$(round(iw,0,0)))
dal.set.field("tccus025.clle", str$(countlongbar))
dal.set.field("tccus025.lbal", str$(mmbalance))

ret = dal.save.object("tccus025")
commit.transaction()
selectempty
ret = dal.new.object("tccus025")

dal.set.field("tccus025.pono", position)
dal.set.field("tccus025.sect", ssection)
dal.set.field("tccus025.slen", str$(slength))
dal.set.field("tccus025.csle", str$(round(iw,0,0)))
dal.set.field("tccus025.clle", str$(countlongbar))
dal.set.field("tccus025.lbal", str$(mmbalance))

ret = dal.save.object("tccus025")
commit.transaction()
endselect

if (mmbalance = 0) then
stop()
else
longbarlength = mmbalance
reloop()
endif
}



Hi,

Thanks a lot. Now it can reloop all. :)