I know it's a bear to follow someone elses script when it's more than several lines long, but, I using A5's Commit/Rollback in the below listed script to post an invoice register to vendor files and to the General ledger. The outer while loop posts to vendors (Vendbal.dbf) and the inner while loop is posting the GL (GLbal.dbf). I've removed additional code which moves records to appropriate history files and sets milestones, etc. for readability. I'm using Commit/Rollback to insure integrity amoung the tables.
In testing the routine, I locked a vendor record using the A5V5 beta, switched back to A5V4 (build 243), and ran the post. All was well, and either all records posted or none. In the second test, I locked a GL account in the same fashion and again ran the posting routine.
The error handler triggered and warned that the table was in use (I suspect this warning is being generated by the fetch method being employed on a table in change mode). On releasing the msg box by pressing the "OK" button, I get a second expected message that a portion of the file is in use (namely the record I knowingly have locked). I then switch to A5V5 beta and release the record, switch back to A5V4 and again press the "OK" button to complete the posting operation. At this point the script executes to completion.
But on checking the tables, I find that the lock record never posts.
Because of the sequence of error messages, and the failed posting, it seems that the "Resume 0" statement is returning the script to the line immediately *AFTER* the offending line instead of the offending line.
Any help...thoughts...suggestions, appreciated.
option nobreak
a = table.open("apinvset.set")
b = table.get("apinvdtl")
c = table.open("vendbal")
d = table.open("ApTrans")
e = table.open("Glbal")
f = table.open("sy02")
c.index_primary_put("Vendprd")
e.index_primary_put("Acctprd")
f.index_primary_put("PDDate")
a.fetch_first()
while .not. a.fetch_eof()
f.fetch_find(a.postprd)
vndkey = a.vendid + a.postprd
if exist(vndkey,"Vendbal","Vendprd") then
c.fetch_find(vndkey)
c.change_begin()
commit_flag = .t.
on error goto ERROR
c.amount = c.amount + a.invamt
else
c.enter_begin()
commit_flag = .t.
on error goto ERROR
c.fiscalyr = substr(a.postprd,3,4)
c.vendno = a.vendid
c.postprd = a.postprd
c.begprd = f.beg_date
c.endprd = f.end_date
c.amount = a.invamt
end if
b.fetch_first()
while .not. b.fetch_eof()
vglkey = remspecial(b.glno) + a.postprd
if exist(vglkey,"Glbal","Acctprd") then
e.fetch_find(vglkey)
e.change_begin()
e.amount = e.amount + b.amt
e.change_end(commit_flag)
else
e.enter_begin()
e.fiscalyr = substr(a.postprd,3,4)
e.acctno = remspecial(b.glno)
e.postprd = a.postprd
e.begprd = f.beg_date
e.endprd = f.end_date
e.amount = b.amt
e.enter_end(commit_flag)
end if
b.fetch_next()
end while
if c.mode_get() = 2 then
c.enter_end(commit_flag)
elseif c.mode_get() = 1 then
c.change_end(commit_flag)
end if
a.fetch_next()
end while
a.close()
c.close()
d.close()
e.close()
f.close()
end
ERROR:
commit_flag = .f.
err = error_code_get()
msg = error_text_get(err)
ui_msg_box("Error",msg)
resume 0
Thanks,
-Balto Cpa
In testing the routine, I locked a vendor record using the A5V5 beta, switched back to A5V4 (build 243), and ran the post. All was well, and either all records posted or none. In the second test, I locked a GL account in the same fashion and again ran the posting routine.
The error handler triggered and warned that the table was in use (I suspect this warning is being generated by the fetch method being employed on a table in change mode). On releasing the msg box by pressing the "OK" button, I get a second expected message that a portion of the file is in use (namely the record I knowingly have locked). I then switch to A5V5 beta and release the record, switch back to A5V4 and again press the "OK" button to complete the posting operation. At this point the script executes to completion.
But on checking the tables, I find that the lock record never posts.
Because of the sequence of error messages, and the failed posting, it seems that the "Resume 0" statement is returning the script to the line immediately *AFTER* the offending line instead of the offending line.
Any help...thoughts...suggestions, appreciated.
option nobreak
a = table.open("apinvset.set")
b = table.get("apinvdtl")
c = table.open("vendbal")
d = table.open("ApTrans")
e = table.open("Glbal")
f = table.open("sy02")
c.index_primary_put("Vendprd")
e.index_primary_put("Acctprd")
f.index_primary_put("PDDate")
a.fetch_first()
while .not. a.fetch_eof()
f.fetch_find(a.postprd)
vndkey = a.vendid + a.postprd
if exist(vndkey,"Vendbal","Vendprd") then
c.fetch_find(vndkey)
c.change_begin()
commit_flag = .t.
on error goto ERROR
c.amount = c.amount + a.invamt
else
c.enter_begin()
commit_flag = .t.
on error goto ERROR
c.fiscalyr = substr(a.postprd,3,4)
c.vendno = a.vendid
c.postprd = a.postprd
c.begprd = f.beg_date
c.endprd = f.end_date
c.amount = a.invamt
end if
b.fetch_first()
while .not. b.fetch_eof()
vglkey = remspecial(b.glno) + a.postprd
if exist(vglkey,"Glbal","Acctprd") then
e.fetch_find(vglkey)
e.change_begin()
e.amount = e.amount + b.amt
e.change_end(commit_flag)
else
e.enter_begin()
e.fiscalyr = substr(a.postprd,3,4)
e.acctno = remspecial(b.glno)
e.postprd = a.postprd
e.begprd = f.beg_date
e.endprd = f.end_date
e.amount = b.amt
e.enter_end(commit_flag)
end if
b.fetch_next()
end while
if c.mode_get() = 2 then
c.enter_end(commit_flag)
elseif c.mode_get() = 1 then
c.change_end(commit_flag)
end if
a.fetch_next()
end while
a.close()
c.close()
d.close()
e.close()
f.close()
end
ERROR:
commit_flag = .f.
err = error_code_get()
msg = error_text_get(err)
ui_msg_box("Error",msg)
resume 0
Thanks,
-Balto Cpa
Comment