Sandy Blondino
13th September 2007, 20:01
Hi everybody,
I have a question regarding AFS and Production Orders.
I created an AFS session that is supposed to check existing open orders for a particular item, then report operations complete on the order.
I am getting an error message - "Order not yet in production" from the AFS automation. I don't get the error message when I report operations complete manually using the tisfc0102m000 session.
Does anyone have any idea of what is going on?
Thanks for any help.
Sandy
mark_h
15th September 2007, 21:47
Post your code, we might see something. I can compare to our code on Monday.
baan.tools
17th September 2007, 11:37
Can you please post the code what you have written....
Sandy Blondino
17th September 2007, 19:54
Hi Guys,
Here is the code:
select tisfc010.*
from tisfc010
where tisfc010._index1 = {:tdlit419.pdno}
and tisfc010.tano = 118
selectdo
stpapi.put.field("tisfc0102m000", "tisfc001.pdno", str$(tdlit419.pdno))
stpapi.put.field("tisfc0102m000", "tisfc010.opno", str$(tisfc010.opno))
found = stpapi.find("tisfc0102m000")
if found = 1 then
stpapi.put.field("tisfc0102m000", "tisfc010.opno", str$(tisfc010.opno))
stpapi.put.field("tisfc0102m000", "tisfc010.qcmp", str$(tisfc010.qpln))
stpapi.put.field("tisfc0102m000", "tisfc010.comp", str$(tcyesno.yes))
stpapi.update("tisfc0102m000", 1, err.msg)
stpapi.enum.answer("tisfc0102m000", "tisfc01021", tcyesno.yes)
endif
if not isspace(err.msg) then
stpapi.recover("tisfc0102m000", err.msg)
endif
stpapi.end.session("tisfc0102m000")
endselect
mark_h
17th September 2007, 20:24
First thing I see is that the stpapi.enum.answer must be before the stpapi.update. Also why are you putting the operation again? If you find the correct order and operation you should not need to put it twice.
I forgot that we developed our own report operations complete. Also make sure you have the current session objects and stpapi libraries.
Sandy Blondino
17th September 2007, 21:58
Hello,
I made the change that you suggested...moved the update line after the enum.answer line.
I'm not getting any errors, but it's not updating either.
I'm not sure what's going on.
I can still report operations complete manually without any errors and it works perfectly.
Thanks for your suggestions.
Sandy
mark_h
18th September 2007, 03:17
First do you have to put operation complete as tcyesno.yes? I am curious because I thought when you did it manually all you had to do was put a qty complete and then do a save. Also what is continue mapped to? Have you tried stpapi.save versus update?
Do you own source? Then you can debug what is happening.
Thomasm
18th September 2007, 09:37
Sandy,
Haven't really looked at your code but below works for me in Baan IV. You should note that this function always reports the quantity of 1 completed. So if you need it to complete the whole operatoin independant of quantity you need to change it.
You will also notice that there are some specific error handling with pre-defined variables that you probably don't need.
Good luck,
/Thomas
function extern long reportOneOperationComplete( const domain tcpdno production.order,
const domain tcopno operation.number,
const domain tcyesno do.backflush, const domain tcyesno do.update.preceding,
const long end.sess, ref long err.id, ref string err.msg )
{
DLLUSAGE
Function to report 1 operation complete using session tisfc0102m000
NOTE that the quantity is always one (1) so if there are quantity 2 still to be completed a single call to this function will leave quantity 1 ramaining
args: - const domain tcpdno production.order: The production order to update
- const domain tcopno operation.number: The operation number to update
- const domain tcyesno do.backflush: How to answer the 'Backflush Immediately' question
- const domain tcyesno do.update.preceding: How to answer the 'Update Preceding ...' question
- const long end.sess: make this true if the session tdinv1101 should be closed after use
make this false if otherwise and make it the responsibility of the caller to close the session
NOTE: the session will NOT die when the calling session ends!! It will have to be KILLED -9
- ref long err.id: The error code (as defined by Besam) will be returned here (if any)
- ref string err.msg: Any error message will be returned here
Returns: true if success, false otherwise
ENDDLLUSAGE
| stp.api variables
long upd, save, recov, enum.answer
string update.msg( 150 )
string recover.msg( 150 )
string save.msg( 150 )
string end.msg( 150 )
string sess( 13 )
| session specific variables
string already.completed.str(15)
long already.completed
string planned.quantity.str(15)
long planned.quantity
string current.backflush.str( 15 )
long current.backflush
sess = "tisfc0102m000"
err.id = 0
err.msg = "" | reset
| find the operation for the production order
stpapi.put.field( sess, "tisfc010.pdno", str$( production.order ) )
stpapi.put.field( sess, "tisfc010.opno", str$( operation.number ) )
if ( stpapi.find( sess ) = 1 ) then | 1 means found, 2 means session OK but the record not found
| get number of planned and number of already completed and number to backflush
stpapi.get.field( sess, "tisfc010.qcmp", already.completed.str )
already.completed = lval( already.completed.str )
stpapi.get.field( sess, "tisfc010.qpln", planned.quantity.str )
planned.quantity = lval( planned.quantity.str )
stpapi.get.field( sess, "tisfc010.qtbf", current.backflush.str )
current.backflush = lval( current.backflush.str )
| Compare number of completed with number of planned and start input data
if planned.quantity > already.completed then | not all planned items are reported
| set 1 item completed
stpapi.put.field( sess, "tisfc010.qcmp", str$( already.completed + 1 ) ) | Completed
stpapi.put.field( sess, "tisfc010.qrjc", str$( 0 ) ) | Rejected
stpapi.put.field( sess, "tisfc010.qtbf", str$( current.backflush + 1 ) ) | Backflushing To Do
| set the operation completed or not
if( planned.quantity = already.completed + 1 )then |if all planned now are completed
stpapi.put.field( sess, "tisfc010.comp", str$( tcyesno.yes ) )
else
stpapi.put.field( sess, "tisfc010.comp", str$( tcyesno.no ) )
endif
|update, answer questions and save
upd = stpapi.update(sess, false, update.msg)
if upd then
| answer no to question 'Backflush hours/material immediately?'
enum.answer = stpapi.enum.answer( sess, "tisfc02023", do.backflush )
|answer the question 'Update all preceding operations?'
| This means that all preceding operations are reported comleted too.
enum.answer = stpapi.enum.answer( sess, "tisfc02021", do.update.preceding )
| Everything OK, now save
save = stpapi.save(sess, save.msg)
endif
| Manage errors in case of not updated or saved
if not upd or not save then
recov = stpapi.recover( sess, recover.msg)
if not upd then | update was the problem
err.id = ERR.COULD.NOT.UPDATE
err.msg = "Update.msg: " & update.msg & " Recov.msg: " & recover.msg
else | save was the problem
err.id = ERR.COULD.NOT.SAVE
err.msg = "Save.msg: " & save.msg & " Recov.msg: " & recover.msg
endif
| close the session in case of errors
stpapi.end.session( sess, end.msg )
if not isspace( end.msg ) then
err.msg = err.msg & " End.msg: " & end.msg
endif
| make sure to return failure
return( false )
endif
else
err.id = ERR.DATA.INCONSISTENT
err.msg = " Already reported all planned number of items"
| close the session in case of errors
stpapi.end.session( sess, end.msg )
if not isspace( end.msg ) then
err.msg = err.msg & " End.msg: " & end.msg
endif
return( false )
endif
else
err.id = ERR.RECORD.NOT.FOUND
err.msg = "Record not found"
| close the session in case of errors
stpapi.end.session( sess, end.msg )
if not isspace( end.msg ) then
err.msg = err.msg & " End.msg: " & end.msg
endif
return( false )
endif
| close the session only if the caller requires. Otherwise it is the callers reponsibility
| NOTE: the session will NOT die when the calling session ends!!
if ( end.sess ) then
stpapi.end.session( sess, end.msg )
if not isspace( end.msg ) then
err.id = ERR.COULD.NOT.END
err.msg = err.msg & " End.msg: " & end.msg
return( false )
endif
endif
| OK if we get here
return( true )
}
mark_h
18th September 2007, 13:42
Sandy,
Notice that the posted code does update with false followed by a save. Thanks for the code Thomas.
Sandy Blondino
18th September 2007, 14:19
Hello,
We don't own the source code, so I'm not sure what's going on in the background.
I'll try some of the changes you mentioned and see what happens.
I'll let you know.
Thanks for all your help.
Sandy