Babu Nagarajan
19th July 2016, 14:13
Hi Friends,
We are using Inter company transactions to make purchase and sales transactions between sister companies.
My parent company is 10 where I create an AR batch and sister company is 20 where I create an AP batch.
I have written a AFS script to do the process
I dont have problem in creating AP batch and transactions.
While creating the AP Batch I use switch.to.company(Child.company) before inserting the Data in the session tfgld1101m000. Subsequently I do the stpapi.handle.subproc() to insert the transaction data in tfacp1110s000. Then I do an stpapi.end.session() and then I do the switch.to.company(Parent.company).
Till here everything is fine. Now when my next AP batch is to be created in company 55 (another child company), again the AR batch and transaction is properly created in company 10 but when I do switch.to.company(child.company), the new AP batch is still getting created in company 20. On the back end the session tfgld1101m000 is not coming out of the previous process.
Is there anyone who came across the same kind of situation. I need to be able to switch companies using stpapi. I am attaching the sample code.
It will be really helpful if I can find a help.
Thanks
Babu
switch.to.company(sister.company)
stpapi.put.field("tfgld1101m000","tedt.f",str$(invoice.date))
stpapi.put.field("tfgld1101m000","tfgld101.year",str$(year.f))
stpapi.put.field("tfgld1101m000","bref.f",str$("Markup"))
stpapi.put.field("tfgld1101m000","fprd.f",str$(prno.f))
retval = stpapi.change.view("tfgld1101m000",errm)
stpapi.put.field("tfgld1101m000","tfgld101.ttyp",str$(tfgld503.ttyp))
retval = stpapi.insert("tfgld1101m000",true,errm)
stpapi.get.field("tfgld1101m000","tfgld101.btno",btno)
retval = stpapi.mark("tfgld1101m000",errm)
stpapi.handle.subproc("tfgld1101m000","tfacp1110s000","add")
stpapi.continue.process("tfgld1101m000",errm)
| tfgld501.famt = 1000
stpapi.put.field("tfacp1110s000","tfacp200.suno",str$(tfgld503.suno))
stpapi.put.field("tfacp1110s000","tfacp200.docd",str$(invoice.date))
stpapi.put.field("tfacp1110s000","screen.amnt",str$(tfgld501.famt))
isup = str$(tfgld501.tran)&"/"&str$(tfgld501.idoc)
stpapi.put.field("tfacp1110s000","tfacp200.isup",str$(isup))
stpapi.put.field("tfacp1110s000","tfacp200.refr",str$("Markup"))
stpapi.handle.subproc("tfacp1110s000","tfacp1120s000","add")
retval = stpapi.insert("tfacp1110s000",true,errm)
stpapi.save("tfacr4100m000",errm)
enter.purchase.invoice.transaction()
stpapi.get.field("tfacp1110s000","tfacp200.ttyp",ap_ttyp)
stpapi.get.field("tfacp1110s000","tfacp200.ninv",ap_ninv)
stpapi.end.session("tfacp1110s000")
stpapi.end.session("tfacp1101m000")
endselect
}
function enter.purchase.invoice.transaction()
{
select tfgld501.*
from tfgld501
where tfgld501._compnr = :ncmp
and tfgld501._index1 = {:tfgld500.cuno}
and tfgld501.tran = :ttyp
and tfgld501.idoc = :ninv2
selectdo
stpapi.put.field("tfacp1120s000","tfgld102.leac",str$(tfgld503.muas))
stpapi.put.field("tfacp1120s000","tfgld102.dim1",str$(tfgld501.dimx))
stpapi.put.field("tfacp1120s000","amount",str$(tfgld501.famt))
retval = stpapi.insert("tfacp1120s000",true,errm)
endselect
stpapi.end.session("tfacp1120s000")
switch.to.company(parent.company)
}
We are using Inter company transactions to make purchase and sales transactions between sister companies.
My parent company is 10 where I create an AR batch and sister company is 20 where I create an AP batch.
I have written a AFS script to do the process
I dont have problem in creating AP batch and transactions.
While creating the AP Batch I use switch.to.company(Child.company) before inserting the Data in the session tfgld1101m000. Subsequently I do the stpapi.handle.subproc() to insert the transaction data in tfacp1110s000. Then I do an stpapi.end.session() and then I do the switch.to.company(Parent.company).
Till here everything is fine. Now when my next AP batch is to be created in company 55 (another child company), again the AR batch and transaction is properly created in company 10 but when I do switch.to.company(child.company), the new AP batch is still getting created in company 20. On the back end the session tfgld1101m000 is not coming out of the previous process.
Is there anyone who came across the same kind of situation. I need to be able to switch companies using stpapi. I am attaching the sample code.
It will be really helpful if I can find a help.
Thanks
Babu
switch.to.company(sister.company)
stpapi.put.field("tfgld1101m000","tedt.f",str$(invoice.date))
stpapi.put.field("tfgld1101m000","tfgld101.year",str$(year.f))
stpapi.put.field("tfgld1101m000","bref.f",str$("Markup"))
stpapi.put.field("tfgld1101m000","fprd.f",str$(prno.f))
retval = stpapi.change.view("tfgld1101m000",errm)
stpapi.put.field("tfgld1101m000","tfgld101.ttyp",str$(tfgld503.ttyp))
retval = stpapi.insert("tfgld1101m000",true,errm)
stpapi.get.field("tfgld1101m000","tfgld101.btno",btno)
retval = stpapi.mark("tfgld1101m000",errm)
stpapi.handle.subproc("tfgld1101m000","tfacp1110s000","add")
stpapi.continue.process("tfgld1101m000",errm)
| tfgld501.famt = 1000
stpapi.put.field("tfacp1110s000","tfacp200.suno",str$(tfgld503.suno))
stpapi.put.field("tfacp1110s000","tfacp200.docd",str$(invoice.date))
stpapi.put.field("tfacp1110s000","screen.amnt",str$(tfgld501.famt))
isup = str$(tfgld501.tran)&"/"&str$(tfgld501.idoc)
stpapi.put.field("tfacp1110s000","tfacp200.isup",str$(isup))
stpapi.put.field("tfacp1110s000","tfacp200.refr",str$("Markup"))
stpapi.handle.subproc("tfacp1110s000","tfacp1120s000","add")
retval = stpapi.insert("tfacp1110s000",true,errm)
stpapi.save("tfacr4100m000",errm)
enter.purchase.invoice.transaction()
stpapi.get.field("tfacp1110s000","tfacp200.ttyp",ap_ttyp)
stpapi.get.field("tfacp1110s000","tfacp200.ninv",ap_ninv)
stpapi.end.session("tfacp1110s000")
stpapi.end.session("tfacp1101m000")
endselect
}
function enter.purchase.invoice.transaction()
{
select tfgld501.*
from tfgld501
where tfgld501._compnr = :ncmp
and tfgld501._index1 = {:tfgld500.cuno}
and tfgld501.tran = :ttyp
and tfgld501.idoc = :ninv2
selectdo
stpapi.put.field("tfacp1120s000","tfgld102.leac",str$(tfgld503.muas))
stpapi.put.field("tfacp1120s000","tfgld102.dim1",str$(tfgld501.dimx))
stpapi.put.field("tfacp1120s000","amount",str$(tfgld501.famt))
retval = stpapi.insert("tfacp1120s000",true,errm)
endselect
stpapi.end.session("tfacp1120s000")
switch.to.company(parent.company)
}