Baanboard.com

Baanboard.com (http://www.baanboard.com/baanboard/index.php)
-   AFS/DDC/OLE: Function servers (http://www.baanboard.com/baanboard/forumdisplay.php?f=59)
-   -   Planned Order Distribution AFS Issue (http://www.baanboard.com/baanboard/showthread.php?t=70296)

frenny 9th August 2017 14:31

Planned Order Distribution AFS Issue
 
Hello All,

I am Trying To create Planned Purchase Order for Manufacturing Item
But It is giving Error During Order Line Distribution

Code:
Quote:

|Get Defult Scenario
select cprpd400.plnc
from cprpd400
where cprpd400.plfd > :1
wherebind(1, utc.num())
selectdo
endselect

stpapi.put.field("cprrp1600m000", "cprrp100.plnc", cprpd400.plnc)
stpapi.put.field("cprrp1600m000", "cprrp100.type", str$(etol(tckoor.cp.pur)))
stpapi.put.field("cprrp1600m000", "cprrp100.item.segment.3", trim$(i.item))
stpapi.put.field("cprrp1600m000", "cprrp100.quan", str$(i.qnty))
if not isspace(i.cwar) then
stpapi.put.field("cprrp1600m000", "cprrp100.dwar", str$(i.cwar))
endif
ret = stpapi.insert("cprrp1600m000", true, error_message)
if ret = 1 then
stpapi.get.field("cprrp1600m000", "cprrp100.orno", get.orno)
stpapi.handle.subproc("cprrp1600m000","cprrp1105m000","add")
stpapi.put.field("cprrp1105m000", "cprrp001.cprj", i.cprj)
stpapi.put.field("cprrp1105m000", "cprrp001.cspa", i.cspa)
stpapi.put.field("cprrp1105m000", "cprrp001.cact", i.cact)
stpapi.put.field("cprrp1105m000", "cprrp105.oqan", str$(i.qnty))
stpapi.enum.answer("cprrp1105m000","cprrp150101",tcokca.ok)
ret = stpapi.insert("cprrp1105m000",true, error_message)
if ret = 1 then
stpapi.end.session("cprrp1105m000")
stpapi.end.session("cprrp1600m000")
return("")
endif
endif
stpapi.end.session("cprrp1105m000")
stpapi.end.session("cprrp1600m000")

return(error_message)
It is Giving Error:
Enter a value for Project Field.:\\n\\n Reason:Project is Mandatory

mark_h 9th August 2017 15:06

Not sure if this thread helps or not http://www.baanboard.com/baanboard/s...=cprrp1105m000

If this was 4c4 I would expect it to look the handle.subproc before the insert - assuming the insert kicks off the subsession. If it does not kick off the subsession then look at the attached thread where they use the form command to kick off the distribution session.

stpapi.handle.subproc("cprrp1600m000","cprrp1105m000","add")
ret = stpapi.insert("cprrp1600m000", true, error_message)

If you have source code you can always put it in debug and see what happens in api mode.

frenny 10th August 2017 06:37

Hi Mark,

I have tried all solution mention in thread but still it is not working.

mark_h 10th August 2017 18:27

This isn't one of the mmt sessions is it?

Can you confirm that when the subsession opens it is controlled by the parent session? Then once the sub-session is open can you do some gets and to make sure it is where you expect. By this I mean can you see that it zoomed to the right purchase order to add distribution to?

It is always possible that something in the initial zoom to the subsession is not setting everything it should. Without source code sometimes this can be very difficult to trouble shoot. In the mean time hopefully someone comes along and has a solution.

frenny 11th August 2017 06:03

Hi mark ,

I have tried all combination, with MMT cprrp1600m000, with Single Distribution session cprrp1105m00, with Header session cprrp1100m000.

But its still giving error.

mark_h 11th August 2017 22:45

I can't think of anything else to try - hopefully someone comes along with a solution.

bhushanchanda 13th August 2017 06:43

Hi,

Have you tried using DAL here?

frenny 14th August 2017 06:51

Hello Bhushan sir,

We can not use DAL in this case
because Pegging fields are from different table cprrp001 ,
and main table for session cprrp1105m000 is cprrp105, and according to standard functionality it will create one specification number based on project, element, activity during planned distribution entry and that number update in cprrp105.

Quote:

|Insert New Entry
dal.clear.messages(MSG.ALL)
num.messages = 0
ret = dal.new.object("cprrp105")
dal.set.field("cprrp105.plnc", cprpd400.plnc) |Value - "ACT"
dal.set.field("cprrp105.koor", tckoor.cp.pur )
dal.set.field("cprrp105.orno", get.orno) |Value - generated order number
dal.set.field("cprrp105.lpon", 1)
dal.set.field("cprrp001.cprj", i.cprj) |Diffrent Maintable field - Any project
dal.set.field("cprrp001.cspa", i.cspa)
dal.set.field("cprrp001.cact", i.cact)
dal.set.field("cprrp105.oqan", i.qnty)
ret = dal.save.object("cprrp105", db.skip.dupl)
num.messages = dal.count.messages(MSG.ALL)
if ret then
for j = 1 to num.messages
ret = dal.get.error.message(error_message)
endfor
abort.transaction()
else
error_message = ""
commit.transaction()
endif

In Above case , It will insert planned distribution but with Blank Project, element, activity

bhushanchanda 14th August 2017 09:40

The Specification and its Hash fields in cprrp001 should get defaulted when you call dal.new.object("cprrp001")

I do not see you calling dal.new.object("cprrp001")

Can you try that?

Unfortunately, I do not have Project Pegged based environment to try this. But, I verified calling dal.new.object("cprrp001") and it generated the spid field nicely.

You may give it a try.

frenny 14th August 2017 11:42

Thank you very much sir .. It is Working Fine with below code..
Quote:

|Insert New Entry
dal.clear.messages(MSG.ALL)
num.messages = 0

ret = dal.new.object("cprrp001")
dal.set.field("cprrp001.cprj", i.cprj)
dal.set.field("cprrp001.cspa", i.cspa)
dal.set.field("cprrp001.cact", i.cact)
dal.set.field("cprrp001.copr", tcpeg.cpor.manual)
ret = dal.save.object("cprrp001", db.skip.dupl)
commit.transaction()

select cprrp001.spid
from cprrp001
where cprrp001.cprj = :i.cprj
and cprrp001.cspa = :i.cspa
and cprrp001.cact = :i.cact
selectdo
endselect

ret = dal.new.object("cprrp105")

dal.set.field("cprrp105.plnc", cprpd400.plnc)
dal.set.field("cprrp105.koor", tckoor.cp.pur )
dal.set.field("cprrp105.orno", get.orno)
dal.set.field("cprrp105.lpon", 1)
dal.set.field("cprrp105.spid", cprrp001.spid)
dal.set.field("cprrp105.oqan", i.qnty)
ret = dal.save.object("cprrp105", db.skip.dupl)

num.messages = dal.count.messages(MSG.ALL)
if ret then
for j = 1 to num.messages
ret = dal.get.error.message(error_message)
endfor
abort.transaction()
else
error_message = ""
commit.transaction()
endif


bhushanchanda 14th August 2017 11:51

Glad it worked for you! And hence, always keep DAL as your first choice if you are just inserting/updating the tables. For processing and stuff, try to find out the underlying DLL's. If everything fails, go for AFS.

frenny 16th August 2017 11:52

Hello Sir,

Actually Dal is always my 1st option , but for this case, Peg distribution fields are from different table and that will create confusion ,bcoz there are 2 different table fields .

This is new Learning point for me that how to use DAL in this kind of case.

Thank u Bhushan sir and Mark sir for your response.


All times are GMT +2. The time now is 04:31.


vB.Sponsors
©2001-2017 - Baanboard.com - Baanforums.com