eric.dizon
10th February 2016, 21:58
Hello, I am trying to get back using AFS again. I have the following code below to insert a new record in the Adjustment Order MMT session. It works on inserting the header records but I am having issues in inserting the detail records. I cannot seem to get past the issues I have. The code as it stands works on inserting the header record but having a error "Reason: Lot Bxxxx not found for item. " - What table do I verify if the lot is there? I try entering the same values using the actual session and it saves them no error.
string main.sess(13)
string sync.sess(13)
main.sess = "whinh5120m100"
sync.sess = "whinh5121m000"
stpapi.clear(main.sess)
stpapi.put.field(main.sess, "whinh520.orno", "ADJ")
stpapi.put.field(main.sess, "whinh520.cwar", "300832")
stpapi.put.field(main.sess, "whinh520.adrn", "INV17")
stpapi.put.field(main.sess, "whinh520.emno", "")
stpapi.put.field(main.sess, "whinh520.adst", "10")
stpapi.put.field(main.sess, "whinh520.mnad", "1")
h.ret = stpapi.insert(main.sess,true,errmsg)
if h.ret then |Insert succeeds
stpapi.get.field(main.sess, "whinh520.orno", l.orno)
|Find the record created
First question : Should I be using the main.sess or the sync.sess ? I tried both but having different issues
stpapi.put.field(sync.sess, "whinh521.orno", l.orno )
ret = stpapi.find(sync.sess , errfindmsg)
if isspace(errfindmsg)
2nd Q: Which session do I sync main or sync session ?
3rd Q: I am inserting a detail record do I use "add/modify" ?
ret = stpapi.synchronize.dialog(sync.sess, "modify", errmsg)
if ret then |
stpapi.put.field(sync.sess, "whinh521.orno", l.orno)
stpapi.put.field(sync.sess, "whinh521.pono", "1")
stpapi.put.field(sync.sess, "whinh521.cwar", "300832")
|stpapi.put.field(sync.sess, "whinh521.item", " CSBP043-030AAAA")
stpapi.put.field(sync.sess, "whin521.item.segment.1", "" ) |value(1; 9)
stpapi.put.field(sync.sess, "whin521.item.segment.2", "CSBP043-030AAAA") | CSBP043-030AAAA
stpapi.put.field(sync.sess, "whinh521.clot", "B00000575-15-10-0016") | l.clot) |B00000575-15-10-0016
stpapi.put.field(sync.sess, "whinh521.stun", "m") | Handling Unit
stpapi.put.field(sync.sess, "whinh521.qadr", str$(l.rmmt)) | Inventory Adjusted
l.vari = v.qhnd - l.rmmt
stpapi.put.field(sync.sess, "whinh521.qrvr", str$(l.vari)) | Variance
stpapi.put.field(sync.sess, "whinh521.adrn", "INV17")
4th Q: Do I use stpapi.insert or stpapi.update ?
rval = stpapi.insert(sync.sess,true,errmsg) | "Get an error here: Lot number not found "
if rval then |If insert fails
ret = stpapi.save(sync.sess, saveerror)
endif
endif
endif
bhushanchanda
11th February 2016, 06:19
Hi,
You can use DAL instead of AFS over here as you are just inserting the data. Else, you can create the header with your AFS and insert the lines using DAL.
It's an MMT session, so there are chances of getting errors. Another solution is to go with Easy Entry Adjustment Order session.
sam291091
11th February 2016, 06:22
Hi,
Try following code for Line Insertion
stpapi.put.field(main.sess, "whinh520.orno", l.orno ) |"ADJ003147")
ret = stpapi.find(main.sess , errfindmsg)
stpapi.handle.subproc(main.sess ,sync.sess ,"add")
stpapi.put.field(sync.sess, "whinh521.orno", l.orno)
stpapi.put.field(sync.sess, "whinh521.pono", "1")
stpapi.put.field(sync.sess, "whinh521.cwar", "300832")
stpapi.put.field(sync.sess, "whin521.item.segment.1", "" ) |value(1; 9)
stpapi.put.field(sync.sess, "whin521.item.segment.2", "CSBP043-030AAAA") | CSBP043-030AAAA
stpapi.put.field(sync.sess, "whinh521.clot", l.clot) |B00000575-15-10-0016
stpapi.put.field(sync.sess, "whinh521.stun", "m") | Handling Unit
stpapi.put.field(sync.sess, "whinh521.qadr", str$(l.rmmt)) | Inventory Adjusted
l.vari = v.qhnd - l.rmmt
stpapi.put.field(sync.sess, "whinh521.qrvr", str$(l.vari)) | Variance
stpapi.put.field(sync.sess, "whinh521.adrn", "INV17")
rval = stpapi.insert(sync.sess,true,errmsg)
eric.dizon
11th February 2016, 16:11
Hi bhushanchanda,
I am trying to trigger this function from a MMT form command or menu while a record is selected.
You always directed me to use DAL to solve the issue for AFS in LN. I have a couple of questions on how to this and an example would be nice too.
1. How can I trigger the DAL function from my custom MMT session?
2. If I am inserting an adjustment order and the reason I am using AFS is there maybe validation and triggers that need to happen just using simple db.update commands. Will does trigger any DALs related to entering Adjustment orders ?
Regards,
Eric
mark_h
11th February 2016, 18:31
Please post only in one forum. This is the correct forum for AFS questions.
Thanks
eric.dizon
11th February 2016, 18:50
Hi sam291091,
I tried your code below to include handle ? I get same error command disabled.
If I try to add this after stpapi.handle using "add" - I still get command disabled.
ret = stpapi.synchronize.dialog(sync.sess, "add", errmsg)
else if I use modify I get Adjustment Order not found. Enter another order.
ret = stpapi.synchronize.dialog(sync.sess, "modify", errmsg)
stpapi.put.field(main.sess, "whinh520.orno", l.orno ) |"ADJ003147")
ret = stpapi.find(main.sess , errfindmsg)
stpapi.handle.subproc(main.sess ,sync.sess ,"add")
stpapi.put.field(sync.sess, "whinh521.orno", l.orno)
stpapi.put.field(sync.sess, "whinh521.pono", "1")
stpapi.put.field(sync.sess, "whinh521.cwar", "300832")
stpapi.put.field(sync.sess, "whin521.item.segment.1", "" ) |value(1; 9)
stpapi.put.field(sync.sess, "whin521.item.segment.2", "CSBP043-030AAAA") | CSBP043-030AAAA
stpapi.put.field(sync.sess, "whinh521.clot", l.clot) |B00000575-15-10-0016
stpapi.put.field(sync.sess, "whinh521.stun", "m") | Handling Unit
stpapi.put.field(sync.sess, "whinh521.qadr", str$(l.rmmt)) | Inventory Adjusted
l.vari = v.qhnd - l.rmmt
stpapi.put.field(sync.sess, "whinh521.qrvr", str$(l.vari)) | Variance
stpapi.put.field(sync.sess, "whinh521.adrn", "INV17")
rval = stpapi.insert(sync.sess,true,errmsg)
eric.dizon
11th February 2016, 19:58
Hi sam291091,
I tried your code below to include handle ? I get same error command disabled.
If I try to add this after stpapi.handle using "add" - I still get command disabled.
ret = stpapi.synchronize.dialog(sync.sess, "add", errmsg)
else if I use modify I get Adjustment Order not found. Enter another order.
ret = stpapi.synchronize.dialog(sync.sess, "modify", errmsg)
stpapi.put.field(main.sess, "whinh520.orno", l.orno ) |"ADJ003147")
ret = stpapi.find(main.sess , errfindmsg)
stpapi.handle.subproc(main.sess ,sync.sess ,"add")
stpapi.put.field(sync.sess, "whinh521.orno", l.orno)
stpapi.put.field(sync.sess, "whinh521.pono", "1")
stpapi.put.field(sync.sess, "whinh521.cwar", "300832")
stpapi.put.field(sync.sess, "whin521.item.segment.1", "" ) |value(1; 9)
stpapi.put.field(sync.sess, "whin521.item.segment.2", "CSBP043-030AAAA") | CSBP043-030AAAA
stpapi.put.field(sync.sess, "whinh521.clot", l.clot) |B00000575-15-10-0016
stpapi.put.field(sync.sess, "whinh521.stun", "m") | Handling Unit
stpapi.put.field(sync.sess, "whinh521.qadr", str$(l.rmmt)) | Inventory Adjusted
l.vari = v.qhnd - l.rmmt
stpapi.put.field(sync.sess, "whinh521.qrvr", str$(l.vari)) | Variance
stpapi.put.field(sync.sess, "whinh521.adrn", "INV17")
rval = stpapi.insert(sync.sess,true,errmsg)
shashig
12th February 2016, 09:12
function extern long afs.whinh5120m000.insert.lines(domain tcorno i.orno, domain tcitem i.item,
domain tccdis i.adrn, domain tcqst1 i.qvrr,
domain tcclot i.clot, ref string err.msg)
{
long ret, ret1
string line(5), err1
domain tcclot i.lot
long adj.pono
adj.pono = 0
err.msg = ""
stpapi.put.field("whinh5120m100","whinh520.orno", i.orno)
ret = stpapi.find("whinh5120m100", err.msg)
if ret = 1 then
stpapi.handle.subproc("whinh5120m100", "whinh5121m000", "add")
stpapi.put.field("whinh5121m000", "whinh521.orno", i.orno)
stpapi.put.field("whinh5121m000", "whinh521.item.segment.1", i.item(1;9))
stpapi.put.field("whinh5121m000", "whinh521.item.segment.2", i.item(10))
stpapi.put.field("whinh5121m000", "whinh521.adrn", i.adrn)
if is.item.lot.controlled(i.item) then
stpapi.put.field("whinh5121m000", "whinh521.clot", i.clot)
endif
stpapi.put.field("whinh5121m000", "whinh521.qvrr", str$(i.qvrr))
ret = stpapi.insert("whinh5121m000", TRUE, err.msg)
if ret then
stpapi.get.field("whinh5121m000", "whinh521.pono", line)
adj.pono = lval(strip$(line))
stpapi.end.session("whinh5121m000")
stpapi.end.session("whinh5120m100")
return(TRUE)
else
log.in.error.file(err.msg)
stpapi.recover("whinh5121m000", err.msg)
endif
stpapi.end.session("whinh5121m000")
else
log.in.error.file(err.msg)
endif
stpapi.end.session("whinh5120m100")
return(FALSE)
}
Regards,
Shashi
shashig
12th February 2016, 09:13
function extern long afs.whinh5120m000.insert.lines(domain tcorno i.orno, domain tcitem i.item,
domain tccdis i.adrn, domain tcqst1 i.qvrr,
domain tcclot i.clot, ref string err.msg)
{
long ret, ret1
string line(5), err1
domain tcclot i.lot
long adj.pono
adj.pono = 0
err.msg = ""
stpapi.put.field("whinh5120m100","whinh520.orno", i.orno)
ret = stpapi.find("whinh5120m100", err.msg)
if ret = 1 then
stpapi.handle.subproc("whinh5120m100", "whinh5121m000", "add")
stpapi.put.field("whinh5121m000", "whinh521.orno", i.orno)
stpapi.put.field("whinh5121m000", "whinh521.item.segment.1", i.item(1;9))
stpapi.put.field("whinh5121m000", "whinh521.item.segment.2", i.item(10))
stpapi.put.field("whinh5121m000", "whinh521.adrn", i.adrn)
if is.item.lot.controlled(i.item) then
stpapi.put.field("whinh5121m000", "whinh521.clot", i.clot)
endif
stpapi.put.field("whinh5121m000", "whinh521.qvrr", str$(i.qvrr))
ret = stpapi.insert("whinh5121m000", TRUE, err.msg)
if ret then
stpapi.get.field("whinh5121m000", "whinh521.pono", line)
adj.pono = lval(strip$(line))
stpapi.end.session("whinh5121m000")
stpapi.end.session("whinh5120m100")
return(TRUE)
else
log.in.error.file(err.msg)
stpapi.recover("whinh5121m000", err.msg)
endif
stpapi.end.session("whinh5121m000")
else
log.in.error.file(err.msg)
endif
stpapi.end.session("whinh5120m100")
return(FALSE)
}
Regards,
Shashi
bhushanchanda
12th February 2016, 09:23
Hi,
Here is a sample of creating Adjustment Order using DAL.
dal.new.object("whinh520")
dal.set.field("whinh520.orno","5")
dal.set.field("whinh520.cwar","003")
dal.set.field("whinh520.adrn","XYZ")
dal.set.field("whinh520.emno","10")
dal.set.field("whinh520.mnad",tcyesno.yes)
ret = dal.save.object("whinh520")
if ret = 0 then
dal.new.object("whinh521")
dal.set.field("whinh521.orno",whinh520.orno)
dal.set.field("whinh521.pono",10)
dal.set.field("whinh521.cwar","1003")
dal.set.field("whinh521.item"," 123456789 ")
dal.set.field("whinh521.loca","21")
dal.set.field("whinh521.clot","0000000001")
dal.set.field("whinh521.stun","NR")
dal.set.field("whinh521.qadr",23)
dal.set.field("whinh521.qrvr",23)
dal.set.field("whinh521.adrn","ATZZ")
ret = dal.save.object("whinh521")
if ret = 0 then
commit.transaction()
else
abort.transaction()
dal.get.error.message(err)
endif
else
abort.transaction()
dal.get.error.message(err)
endif
1. How can I trigger the DAL function from my custom MMT session?
- The DAL validations(if present) will automatically get triggered if you use dal.* functions.
2. If I am inserting an adjustment order and the reason I am using AFS is there maybe validation and triggers that need to happen just using simple db.update commands. Will does trigger any DALs related to entering Adjustment orders ?
- If you use db.* functions, the DAL won't be triggered. You need to use only dal.* functions in order to trigger the standard DAL.
For processing sessions i.e. where form commands are involved, you can go fo AFS and if in case you can find the DLL/DAL Business Method related to that, you can call that.
e.g. To process an adjustment order you can call -
whinh.dll5221.process.adjustment.orders( domain tcorno i.order.from, domain tcorno i.order.to, domain tccwar i.warehouse.from, domain tccwar i.warehouse.to, domain tcemno i.employee.from, domain tcemno i.employee.to, domain tcdate i.order.date.from, domain tcdate i.order.date.to, domain tcpono i.order.line.from, domain tcpono i.order.line.to, boolean i.report.open, boolean i.with.commit, boolean i.progress.indicator, ref long o.number.of.processed.lines )
Refer ttstpbaandoc for the input and output parameters to this DLL.
e.g.
ret = whinh.dll5221.process.adjustment.orders(
whinh521.orno,
whinh521.orno,
warehouse.from,
warehouse.to,
employee.from,
employee.to,
order.date.from,
order.date.to,
whinh521.pono,
whinh521.pono,
false,
true,
false,
dummy.number.of.lines.processed)
eric.dizon
12th February 2016, 15:42
Thank you all for your replies and help. I will try and will update which one worked.
eric.dizon
16th February 2016, 15:48
Thanks bhushan! Now I've learn something new with DAL that if dal.* command instead of db.* Validation gets triggered
Ajesh
27th February 2016, 15:36
Hi Eric
You are going to insert a fresh record in the detail session, isnt it? It has to be in "Add" Mode..
eric.dizon
31st October 2016, 16:14
Thank you for your Bhushan.