ben.kansas
24th November 2009, 00:08
Howdy all,

I am using AFS in a 3GL session to reset the scrap factor for a released production order to zero.

However, when the session runs the code executes perfectly, but there are no changes made to the database.

Any help would be appreciated.

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

table tticst001
table ttisfc001
table ttilit450

#pragma used dll ottstpapihand


|****************************** PROGRAM SECTION ***************************
|****************************** ZOOM FROM SECTION ***************************
|****************************** FORM SECTION ***************************
|****************************** CHOICE SECTION ***************************
|****************************** FIELD SECTION ***************************
|****************************** MAIN TABLE SECTION ***************************
|****************************** FUNCTION SECTION ***************************
function main()
{
domain tcdesc session
domain tcdesc error.msg
domain tcpdno prod.order
long return.val
long ret.val
long no.scrap.factor

return.val = 0
ret.val = 0
session = "tisfc0110m000"


SELECT tisfc001.pdno, tisfc001.osta, ticst001.*
FROM ticst001, tisfc001
WHERE tisfc001.pdno = ticst001.pdno
AND tisfc001.osta = tcosta.in.prod
AND ticst001.scpf > 0
SELECTDO
no.scrap.factor = 0
SELECT *
FROM tilit450
SELECTDO
if(ticst001.cwar = tilit450.cwar)then
no.scrap.factor = 1
endif
ENDSELECT
if(no.scrap.factor = 0)then
stpapi.put.field(session, "ticst001.pdno", str$(ticst001.pdno))
stpapi.put.field(session, "ticst001.pono", str$(ticst001.pono))
return.val = stpapi.find(session, error.msg)
if(return.val = 1) then
stpapi.put.field(session, "ticst001.scpf", "0")
endif
|ret.val = stpapi.update(session, 1, error.msg)
ret.val = stpapi.save(session, error.msg)
if(not ret.val) then
return.val = stpapi.recover(session, error.msg)
endif
stpapi.end.session(session)
endif
ENDSELECT



}

Thanks,
Ben

mark_h
24th November 2009, 16:32
Well this code (copied from yours) worked for me.

stpapi.put.field("tisfc0110m000", "ticst001.pdno", str$(343514))
stpapi.put.field("tisfc0110m000", "ticst001.pono", str$(10))
rc = stpapi.find("tisfc0110m000", err)
if(rc = 1) then
stpapi.put.field("tisfc0110m000", "ticst001.scpf", "0")
endif
rc = stpapi.update("tisfc0110m000", 1, err)

What happens if you do it manually? Any messages? Are you getting any messages? I know I can not modify any that were already issued or in outbound.

ben.kansas
25th November 2009, 03:45
Hi Mark,

Thanks for your help.

The session is set to run as a job once a minute throughout the day. Originally, I was puzzled why certain orders were not being cleared, but it turns out that they had outbound against them. After I discovered that I wasn't as worried about it.

Then I discovered that the session wouldn't reset the SF when it was being run as a job. However, if you just run the session manually then it would reset the SF.

I am currently trying to see if any specific permissions are needed to run tisfc0110m000.

I would certainly welcome any suggestions that you have at this point.

Ben

mark_h
25th November 2009, 16:10
Hi Mark,

Thanks for your help.

The session is set to run as a job once a minute throughout the day. Originally, I was puzzled why certain orders were not being cleared, but it turns out that they had outbound against them. After I discovered that I wasn't as worried about it.


So it worked as a job?


Then I discovered that the session wouldn't reset the SF when it was being run as a job. However, if you just run the session manually then it would reset the SF.

And now it doesn't? Did it ever work in batch? Did any updates get applied? Not sure I understand - so the session works when it is run manuall. What about if you run the job manually? What if you run the job using your ID(launching the cron as yourself)?

All I know is if it works manually for you then it should also work in batch - we use a different ID for that. All of our batch ID's are set up as superusers and we do not have an issue. I can not think of anything else a user might need access to besides tisfc0110m000.