marwest98
25th July 2008, 22:39
A user is getting a Fatal error message on Tfcap9202m000 - Create Auto Invoice I have not been able to figure out why.

I have attached a copy of the error message she is receiving. I have not been able to recreate it, the session does not create the invoices either.

Andreas
28th July 2008, 09:28
Hi,
as your profile says you 're on 5.0c. There is no standard Session tfacp9209m000 at least in my environment.
Is this a cutomized Session?

Andreas

marwest98
29th July 2008, 21:01
The issue is with one of the Baan standard sessions called by this script. they are tfgld1101m000 and tfacp1120s000. We think it is in one of the API calls.

Here is the script
|******************************************************************************
|* tfacp9202 0 VRC B50C c ptst
|* Create Auto Invoice
|* pcraven
|* 07-14-06 [12:00]
|******************************************************************************
|******************************************************************************
|* Main table tfgld100 Batch Status, Form Type 4
|******************************************************************************


|******************************************************************************
|* Script Type: 4
|******************************************************************************

|****************************** DECLARATION SECTION ***************************

declaration:

extern domain tfgld.btno btno.f
extern domain tfgld.btno btno.t
extern domain tfgld.long seqn.f
extern domain tfgld.long seqn.t
extern domain tcyesno post.based.invd
extern domain tfgld.date trans.entry.date
extern domain tcmcs.str40 batch.desc
extern domain tfgld.btno zoom.btno
extern domain tfgld.long zoom.seqn


extern domain tcmcs.str100 error.message
domain tfgld.year tax.year
domain tfgld.prod tax.period
domain tfgld.year fiscal.year
domain tfgld.prod fiscal.period
domain tfgld.year report.year
domain tfgld.prod report.period
domain tfgld.amnt temp.namt
domain tcbool first.time


domain tcncmp t.comp.num
domain tfgld.btno t.batch.num
domain tfgld.ttyp t.trans.type
domain tfgld.docn t.doc.num |, t.doc.num2
domain tfgld.lino t.line.num |, t.line.num2
domain tfgld.serl t.seq.num
domain tfgld.srno t.back.seq.num
domain tfgld.year t.fiscal.year
domain tfgld.prod t.fiscal.period
domain tfgld.year t.report.year
domain tfgld.prod t.report.period



string doc.num(10)
long ret, count, invoice.count, err.ret, series
string batch.num(10)
string line.num(6)
string seq.num(6)
string back.seq.num(6)
string fisc.year(4)
string tran.type(4)
string trans.type(4)
string ledger(6)
string comp.num(4)
string bank(3)

#include <bic_tt>
#pragma used dll ottstpapihand |Baan API handler

table ttfgld100 | Batch Status
table ttfgld006 | End Dates by Year
table ttfgld008 | Chart of Accounts
table ttfgld011 | Transaction Types
table ttfgld014 | Last used batch
table ttfgld102 | Transactions
table ttfcmg903 | Route, Vendor
table ttfacp900 | Auto Invoice parameters
table ttfacp901 | Auto Invoice details
table ttfgld005 | Periods
table ttccom100 | Business Partners
table ttccom122 | Invoice-From Business Partners
table ttccom124 | Pay-To Business Partners
table ttccom125 | Banks by Pay-to BP
table ttfacp200 | Open Items (Purchase Invoices and Payments

|****************************** form section **********************************

form.1:
init.form:
display.all()

|****************************** choice section ********************************

choice.user.0:
on.choice:
first.time = true
read.auto.invoice.parameters()
get.default.order.series()
read.records.from.tfacp901.table()

|****************************** field section *********************************

field.btno.f:
after.zoom:
btno.f = zoom.btno
seqn.f = zoom.seqn
after.input:
btno.t = btno.f

field.btno.t:
after.zoom:
btno.t = zoom.btno
seqn.t = zoom.seqn

|****************************** function section ******************************

functions:

function read.auto.invoice.parameters()
{
select tfacp900.*
from tfacp900
where tfacp900.sern = 1
selectdo
endselect
}

function read.records.from.tfacp901.table()
{
invoice.count = 0
count = 0

db.retry.point()

select tfacp901.*
from tfacp901 for update
where tfacp901._index1 inrange {:btno.f, :seqn.f} and {:btno.t, :seqn.t} and
tfacp901.aist = 1 and
tfacp901.namt < 0.0
selectdo
if not read.tfcmg903() then
tfacp901.aist = tfacp.aist.errn
tfacp901.emsg = "Routing code mapping not found!"
db.update(ttfacp901, db.retry)
else
if not valid.ledger() then
tfacp901.aist = tfacp.aist.errn
tfacp901.emsg = "Ledger mapping not found!"
db.update(ttfacp901, db.retry)
else
if not valid.business.partner() then
tfacp901.aist = tfacp.aist.errn
db.update(ttfacp901, db.retry)
else
maintain.invoices.tfgld1101m000()
commit.transaction()
endif
endif
endif
endselect

select tfacp901.*
from tfacp901 for update
where tfacp901._index1 inrange {:btno.f, :seqn.f} and {:btno.t, :seqn.t} and
tfacp901.aist = 1 and
tfacp901.namt > 0.0
selectdo
if not read.tfcmg903() then
tfacp901.aist = tfacp.aist.errn
tfacp901.emsg = "Routing code mapping not found!"
db.update(ttfacp901, db.retry)
else
if not valid.ledger() then
tfacp901.aist = tfacp.aist.errn
tfacp901.emsg = "Ledger mapping not found!"
db.update(ttfacp901, db.retry)
else
if not valid.business.partner() then
tfacp901.aist = tfacp.aist.errn
db.update(ttfacp901, db.retry)
else
maintain.invoices.tfgld1101m000()
commit.transaction()
endif
endif
endif
selectempty
endselect

stpapi.end.session( "tfacp1110s000" )
stpapi.end.session( "tfgld1101m000" )

message("%s invoices processed with batch %s", invoice.count,batch.num)

execute(end.program)
}

|******************************************************************************************************************|
function maintain.invoices.tfgld1101m000()
|******************************************************************************************************************|
{
if first.time then
create.tfgld1101.transaction()
endif
create.purchase.invoices()
create.purchase.invoice.lines()
}

|****************************************** TRANSACTIONS **********************************************************|
function create.tfgld1101.transaction()
{
first.time = false

stpapi.put.field( "tfgld1101m000", "tedt.f", str$(trans.entry.date) )

stpapi.put.field( "tfgld1101m000", "bref.f", batch.desc )

ret = stpapi.change.view("tfgld1101m000", error.message)

stpapi.put.field( "tfgld1101m000", "tfgld101.ttyp", tfacp900.pitt )

ret = stpapi.insert( "tfgld1101m000", 1, error.message)

stpapi.get.field( "tfgld1101m000", "tfgld101.year", fisc.year )
stpapi.get.field( "tfgld1101m000", "tfgld101.btno", batch.num )
stpapi.get.field( "tfgld1101m000", "tfgld101.ttyp", tran.type )

ret = stpapi.mark( "tfgld1101m000", error.message)

if ret = 1 then
stpapi.handle.subproc( "tfgld1101m000", "tfacp1110s000", "add" )
endif
stpapi.form.command( "tfgld1101m000", 5, "exec.cont.process", error.message )
}

|****************************************** PURCHASE INVOICES *****************************************************|
function create.purchase.invoices()
{
| stpapi.put.field( "tfacp1110s000", "tfacp200.ninv", "60" )
stpapi.put.field( "tfacp1110s000", "tfacp200.ninv", str$(series) )

stpapi.put.field( "tfacp1110s000", "tfacp200.docd", str$(tfacp901.invd) )

stpapi.put.field( "tfacp1110s000", "tfacp200.ifbp", tfcmg903.vcod )

if post.based.invd = tcyesno.yes then
get.tax.year.and.period()
stpapi.put.field( "tfacp1110s000", "tfacp200.vaty", str$(tax.year) ) | invoice tax year
stpapi.put.field( "tfacp1110s000", "tfacp200.vatp", str$(tax.period) ) | invoice tax period
endif

temp.namt = tfacp901.namt * -1
stpapi.put.field( "tfacp1110s000", "screen.amnt", str$(temp.namt) )
stpapi.put.field( "tfacp1110s000", "tfacp200.reas", "ACH" )

ret = stpapi.insert( "tfacp1110s000", 0, error.message)
ret = stpapi.save( "tfacp1110s000", error.message )

stpapi.get.field( "tfacp1110s000", "tfacp200.ninv", doc.num )

get.default.bank()

if post.based.invd = tcyesno.yes then
ret = stpapi.find( "tfacp1110s000" )
stpapi.put.field( "tfacp1110s000", "tfacp200.vatp", str$(tax.period) ) | tax period
stpapi.put.field( "tfacp1110s000", "tfacp200.bank", bank )
ret = stpapi.update( "tfacp1110s000", true, error.message )
ret = stpapi.save( "tfacp1110s000", error.message )
else
ret = stpapi.find( "tfacp1110s000" )
stpapi.put.field( "tfacp1110s000", "tfacp200.bank", bank )
ret = stpapi.update( "tfacp1110s000", true, error.message )
ret = stpapi.save( "tfacp1110s000", error.message )
endif

stpapi.handle.subproc( "tfacp1110s000", "tfacp1120s000", "add" )
stpapi.form.command( "tfacp1110s000", 5, "exec.cont.process", error.message )
}

|****************************************** PURCHASE INVOICE LINES ***********************************************|
function create.purchase.invoice.lines()
{
stpapi.put.field( "tfacp1120s000", "tfgld102.leac", tfcmg903.leac )


| if post.based.invd = tcyesno.yes then
| get.fiscal.year.and.period()
| stpapi.put.field( "tfacp1120s000", "tfgld102.fyer", str$(fiscal.year) ) | financial year
| stpapi.put.field( "tfacp1120s000", "tfgld102.fprd", str$(fiscal.period) ) | financial period
| get.report.year.and.period()
| stpapi.put.field( "tfacp1120s000", "tfgld102.ryer", str$(report.year) ) | report year
| stpapi.put.field( "tfacp1120s000", "tfgld102.rprd", str$(report.period) ) | report period
| endif


ret = stpapi.insert( "tfacp1120s000", 1, error.message )
ret = stpapi.save( "tfacp1120s000", error.message )

if post.based.invd = tcyesno.yes then
db.retry.point()
ret = stpapi.find( "tfacp1120s000" )
get.fiscal.year.and.period()
get.report.year.and.period()
stpapi.get.field( "tfacp1120s000", "tfgld102.tcom", comp.num ) | Company
stpapi.get.field( "tfacp1120s000", "tfgld102.leac", ledger ) | Ledger Account
stpapi.get.field( "tfacp1120s000", "tfgld102.btno", batch.num ) | Batch
stpapi.get.field( "tfacp1120s000", "tfgld102.ttyp", trans.type ) | Transaction Type
stpapi.get.field( "tfacp1120s000", "tfgld102.docn", doc.num ) | Document Number
stpapi.get.field( "tfacp1120s000", "tfgld102.lino", line.num ) | Line number
stpapi.get.field( "tfacp1120s000", "tfgld102.serl", seq.num ) | Sequence Number
stpapi.get.field( "tfacp1120s000", "tfgld102.srno", back.seq.num ) | Background sequence number



t.comp.num = val(comp.num)
t.batch.num = val(batch.num)
t.trans.type = trans.type
t.doc.num = val(doc.num)
t.line.num = val(line.num)
t.seq.num = val(seq.num)
t.back.seq.num = val(back.seq.num)
t.fiscal.year = fiscal.year
t.fiscal.period = fiscal.period
t.report.year = report.year
t.report.period = report.period

select tfgld102.*
from tfgld102 for update
where tfgld102._index1 = {:t.comp.num, :t.fiscal.year, :t.batch.num, :t.trans.type, :t.doc.num, :t.line.num, :t.seq.num, :t.back.seq.num}
selectdo
tfgld102.fprd = t.fiscal.period
tfgld102.back = tfgld.back.yes
tfgld102.rprd = t.report.period
tfgld102.ryer = t.report.year
db.update(ttfgld102, db.retry, err.ret)
count = count + 1

| commit.transaction()
endselect

| stpapi.put.field( "tfacp1120s000", "tfgld102.tcom", comp.num ) | Company
| stpapi.put.field( "tfacp1120s000", "tfgld102.fyer", str$(fiscal.year) ) | financial year
| stpapi.put.field( "tfacp1120s000", "tfgld102.btno", batch.num ) | Batch
| stpapi.put.field( "tfacp1120s000", "tfgld102.ttyp", trans.type ) | Transaction Type
| stpapi.put.field( "tfacp1120s000", "tfgld102.docn", doc.num ) | Document Number
| stpapi.put.field( "tfacp1120s000", "tfgld102.lino", line.num ) | Line number
| stpapi.put.field( "tfacp1120s000", "tfgld102.serl", seq.num ) | Sequence Number
| stpapi.put.field( "tfacp1120s000", "tfgld102.srno", back.seq.num ) | Background sequence number
| stpapi.put.field( "tfacp1120s000", "tfgld102.fprd", str$(fiscal.period) ) | financial period
| stpapi.put.field( "tfacp1120s000", "tfgld102.ryer", str$(report.year) ) | report year
| stpapi.put.field( "tfacp1120s000", "tfgld102.rprd", str$(report.period) ) | report period
| ret = stpapi.insert( "tfacp1120s000", 1, error.message )
| ret = stpapi.save( "tfacp1120s000", error.message )
endif

if error.message = "" then
tfacp901.aist = tfacp.aist.proc
if tfacp901.namt > 0.0 then
tfacp901.ttyp = tfacp900.pctt
else
tfacp901.ttyp = tfacp900.pitt
endif
tfacp901.docn = lval(doc.num)

db.update(ttfacp901, db.retry)

invoice.count = invoice.count + 1
count = count + 1
if count > 50 then
| commit.transaction()
count = 0
endif
endif

stpapi.end.session( "tfacp1120s000" )
}

function domain tcbool read.tfcmg903()
{
select tfcmg903.*
from tfcmg903
where tfcmg903._index1 = {:tfacp901.rnum}
selectdo
selectempty
return(false)
endselect
return(true)
}

function domain tcbool valid.ledger()
{
tfacp901.emsg = ""
select tfgld008.*
from tfgld008
where tfgld008._index1 = {:tfcmg903.leac}
selectdo
return(true)
selectempty
return(false)
endselect
return(false)
}

function domain tcbool valid.business.partner()
{
select tccom100.*
from tccom100
where tccom100._index1 = {:tfcmg903.vcod}
selectdo
selectempty
tfacp901.emsg = "Business Partner " & strip$(tfcmg903.vcod) & " not found!"
return(false)
endselect

select tccom122.*
from tccom122
where tccom122._index1 = {:tfcmg903.vcod}
selectdo
selectempty
tfacp901.emsg = "Invoice-From Business Partner " & strip$(tfcmg903.vcod) & " not found!"
return(false)
endselect

select tccom124.*
from tccom124
where tccom124._index1 = {:tfcmg903.vcod}
selectdo
selectempty
tfacp901.emsg = "Pay-To Business Partner " & strip$(tfcmg903.vcod) & " not found!"
return(false)
endselect
return(true)
}

function get.tax.year.and.period()
{
select tfgld005.*
from tfgld005
where tfgld005.ptyp = tfgld.ptyp.vat and
tfgld005.stdt <= :tfacp901.invd
order by tfgld005.stdt desc
as set with 1 rows
selectdo
tax.year = tfgld005.year
tax.period = tfgld005.prno
selectempty
tax.year = 0
tax.period = 0
endselect
}

function get.fiscal.year.and.period()
{
select tfgld005.*
from tfgld005
where tfgld005.ptyp = tfgld.ptyp.financial and
tfgld005.stdt <= :tfacp901.invd
order by tfgld005.stdt desc
as set with 1 rows
selectdo
fiscal.year = tfgld005.year
fiscal.period = tfgld005.prno
selectempty
fiscal.year = 0
fiscal.period = 0
endselect
}

function get.report.year.and.period()
{
select tfgld005.*
from tfgld005
where tfgld005.ptyp = tfgld.ptyp.reporting and
tfgld005.stdt <= :tfacp901.invd
order by tfgld005.stdt desc
as set with 1 rows
selectdo
report.year = tfgld005.year
report.period = tfgld005.prno
selectempty
report.year = 0
report.period = 0
endselect
}

function get.default.bank()
{
select tccom125.*
from tccom125
where tccom125._index1 = {:tfcmg903.vcod}
as set with 1 rows
selectdo
bank = tccom125.cban
endselect
}

function get.default.order.series()
{
select tfgld011.*
from tfgld011
where tfgld011.ttyp = :tfacp900.pitt
selectdo
series = tfgld011.dsrn
endselect
}

marwest98
30th July 2008, 02:45
We have determined that the problem is in a stpapi call. These are supposed to be somewhere under tools in Baan 5c. They work under Unix/Oracle, do they have to be changed for SQLServer2005/Windows2003?