SIMPLE 4GL PROGRAM
Posted in 2000
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL
I have written a program as shown below. The problem is that after every two
rows it fails and has to be re run again to work as if
it needs to be re-initialised after having completed the first loop. Could
some assist me with how I can modify the program such that
it re - initialises after every loop.
database ptc0
DEFINE g_bkrecA RECORD LIKE bkrec.*
DEFINE g_bkrecB RECORD LIKE bkrec.*
MAIN
DECLARE bkrec_cur CURSOR FOR
SELECT * from bkrec
WHERE bkr_proof = 0
AND bkr_status = 'R'
AND bkr_linkref = ' '
AND bkr_multicurr = ' '
AND bkr_code <> 'CHQ'
AND bkr_batchref NOT MATCHES ' *'
{order by bkr_batchref}
FOREACH bkrec_cur INTO g_bkrecA.*
DISPLAY g_bkrecA.bkr_batchref,' voucher ',g_bkrecA.bkr_voucher,
'linkref',g_bkrecB.bkr_linkref AT 15,15
SELECT * INTO g_bkrecB.*
FROM bkrec , bkpaymnt
WHERE bkr_batchref = g_bkrecA.bkr_batchref
AND bkr_currvalue = g_bkrecA.bkr_currvalue
AND bkr_source = bkpm_source
AND bkr_code != "CHQ"
AND bkr_page = 0
AND bkr_proof = bkpm_proof
AND bkr_status = "U"
AND bkr_linkref = bkpm_linkref
IF STATUS = NOTFOUND THEN
ERROR "Corresponding record not found.", g_bkrecA.bkr_voucher
ELSE
UPDATE bkrec
SET bkr_status = 'R',
bkr_page = g_bkrecA.bkr_page
WHERE bkr_source = g_bkrecB.bkr_source
AND bkr_voucher = g_bkrecB.bkr_voucher
AND bkr_trantype = g_bkrecB.bkr_trantype
IF STATUS <> 0 THEN
ERROR "ERROR ", STATUS,
" Updating record voucher :", g_bkrecB.bkr_voucher
ELSE
DELETE FROM bkrec
WHERE bkr_source = g_bkrecA.bkr_source
AND bkr_voucher = g_bkrecA.bkr_voucher
AND bkr_trantype = g_bkrecA.bkr_trantype
END IF
END IF
END FOREACH
How does it fail? Error message?
Langton.Tigere@icl.com wrote:
>
>
> I have written a program as shown below. The problem is that after every two
> rows it fails and has to be re run again to work as if
> it needs to be re-initialised after having completed the first loop. Could
> some assist me with how I can modify the program such that
> it re - initialises after every loop.
>
> database ptc0
> DEFINE g_bkrecA RECORD LIKE bkrec.*
> DEFINE g_bkrecB RECORD LIKE bkrec.*
>
> MAIN
> DECLARE bkrec_cur CURSOR FOR
> SELECT * from bkrec
> WHERE bkr_proof = 0
> AND bkr_status = 'R'
> AND bkr_linkref = ' '
> AND bkr_multicurr = ' '
> AND bkr_code <> 'CHQ'
> AND bkr_batchref NOT MATCHES ' *'
> {order by bkr_batchref}>
> FOREACH bkrec_cur INTO g_bkrecA.*
> DISPLAY g_bkrecA.bkr_batchref,' voucher ',g_bkrecA.bkr_voucher,
> 'linkref',g_bkrecB.bkr_linkref AT 15,15
> SELECT * INTO g_bkrecB.*
> FROM bkrec , bkpaymnt
> WHERE bkr_batchref = g_bkrecA.bkr_batchref
> AND bkr_currvalue = g_bkrecA.bkr_currvalue
> AND bkr_source = bkpm_source
> AND bkr_code != "CHQ"
> AND bkr_page = 0
> AND bkr_proof = bkpm_proof
> AND bkr_status = "U"
> AND bkr_linkref = bkpm_linkref
> IF STATUS = NOTFOUND THEN
> ERROR "Corresponding record not found.", g_bkrecA.bkr_voucher
> ELSE
> UPDATE bkrec
> SET bkr_status = 'R',
> bkr_page = g_bkrecA.bkr_page
> WHERE bkr_source = g_bkrecB.bkr_source
> AND bkr_voucher = g_bkrecB.bkr_voucher
> AND bkr_trantype = g_bkrecB.bkr_trantype>
> IF STATUS <> 0 THEN
> ERROR "ERROR ", STATUS,
> " Updating record voucher :", g_bkrecB.bkr_voucher
> ELSE
> DELETE FROM bkrec
> WHERE bkr_source = g_bkrecA.bkr_source
> AND bkr_voucher = g_bkrecA.bkr_voucher
> AND bkr_trantype = g_bkrecA.bkr_trantype
> END IF
> END IF>
> END FOREACH
>
Langton.Tigere@icl.com wrote:
>
> I have written a program as shown below. The problem is that after every two
> rows it fails and has to be re run again to work as if
> it needs to be re-initialised after having completed the first loop. Could
> some assist me with how I can modify the program such that
> it re - initialises after every loop.
>
> ...
> SELECT * INTO g_bkrecB.*
> FROM bkrec , bkpaymnt
> WHERE bkr_batchref = g_bkrecA.bkr_batchref
> AND bkr_currvalue = g_bkrecA.bkr_currvalue
> AND bkr_source = bkpm_source
> AND bkr_code != "CHQ"
> AND bkr_page = 0
> AND bkr_proof = bkpm_proof
> AND bkr_status = "U"
> AND bkr_linkref = bkpm_linkref
It could fail here if the SELECT stmt returns more than 1 row. A lot can be
said for your use of "SELECT *" and "LIKE <table>.*", but snow here, in
Ottawa, is getting me down.
Rudy
Barry Lloyd wrote:
>
> How does it fail? Error message?
>
> Langton.Tigere@icl.com wrote:
> >
> >
> > I have written a program as shown below. The problem is that after every two
> > rows it fails and has to be re run again to work as if
> > it needs to be re-initialised after having completed the first loop. Could
> > some assist me with how I can modify the program such that
> > it re - initialises after every loop.
> >
> > database ptc0
> > DEFINE g_bkrecA RECORD LIKE bkrec.*
> > DEFINE g_bkrecB RECORD LIKE bkrec.*
> >
> > MAIN
> > DECLARE bkrec_cur CURSOR FOR
> > SELECT * from bkrec
> > WHERE bkr_proof = 0
> > AND bkr_status = 'R'
> > AND bkr_linkref = ' '
<snippage>
There are a few things that you can do to save error messages and
make them more informative. This should give you a clue - it
might be a select returning two rows, it might be locked record.
Start the errorlog to some file somewhere using CALL
startlog("/where/ever/file.err") then create a little function
like
FUNCTION lerreur()
CALL errorlog(sqlca.sqlcode)
EXIT PROGRAM(STATUS)
END FUNCTION
And use
WHENEVER ERROR CALL lerreur
at the top of your program. You might also consider explicitly
setting the isolation mode.
--
So Archimedes Plutonium is tied to a stake in the backyard, and
sleeping in his kennel. Kibo tiptoes up (carrying a dustbin lid)
and measures the length of the chain Arch is tied to, then marks
a radius on the ground...