raikar_raviraj
13th March 2008, 04:47
Hi,

I am trying to achieve negative outbound functionality via AFS.
When i try to enter negative issue quantity in ticst0101m000 - Enter Material Issue for Production Order it suppresses it to zero hence i am not able to do Maintain Outbound for the same. I checked the AFS log, i see no discrepancy in the log.

here is the AFS code ive written.

function enter.material.issue()
{
msg1 = ""
ret.mesg1 = ""

select ticst001.*
from ticst001
where ticst001._index1 = {:lhnst103.pdno}
order by ticst001._index1 desc
as set with 1 rows
selectdo
run.order = lhnst103.pdno
stpapi.put.field("ticst0101m000","ticst001.pdno",str$(run.order))
rc = stpapi.change.view("ticst0101m000",msg1)
if isspace(msg1) then
run.pono = ticst001.pono + 10
run.item = lhnst103.item
run.qty = -1 * (lhnst103.quan + v_quan)
issu.qty = str$(run.qty)
stpapi.put.field("ticst0101m000","ticst001.pono",str$(run.pono))
stpapi.put.field("ticst0101m000","ticst001.sitm",str$(run.item))
stpapi.put.field("ticst0101m000","ticst001.cwar",str$(lhnst103.cwar))
stpapi.put.field("ticst0101m000","issu.quan",str$(run.qty))
stpapi.put.field("ticst0101m000","ticst001.bfls",str$(tcyesno.no))
stpapi.insert("ticst0101m000",true,msg1)
if isspace(msg1) then
stpapi.end.session("ticst0101m000")
update.issue.qty()
message("Production Order %d and Item %s Inserted on ticst0101m000",run.order,run.item)
else
message(""&msg1)
dsc1 = msg1
stpapi.recover("ticst0101m000",ret.mesg1)
stpapi.end.session("ticst0101m000")
endif
else
stpapi.end.session("ticst0101m000")
message("Production Order could not be inserted on ticst0101m000")
endif
selectempty
select max(ticst001.pono):maxpono
from ticst001 where ticst001.pdno = :lhnst103.pdno
selectdo
endselect
run.order = lhnst103.pdno
stpapi.put.field("ticst0101m000","ticst001.pdno",str$(run.order))
rc = stpapi.change.view("ticst0101m000",msg1)
if isspace(msg1) then
run.pono = maxpono + 10
run.item = lhnst103.item
run.qty = -1 * (lhnst103.quan + v_quan)
stpapi.put.field("ticst0101m000","ticst001.pono",str$(run.pono))
stpapi.put.field("ticst0101m000","ticst001.sitm",str$(run.item))
stpapi.put.field("ticst0101m000","ticst001.cwar",str$(lhnst103.cwar))
stpapi.put.field("ticst0101m000","issu.quan",str$(run.qty))
stpapi.put.field("ticst0101m000","ticst001.bfls",str$(tcyesno.no))
stpapi.insert("ticst0101m000",true,msg1)
if isspace(msg1) then
update.issue.qty()
stpapi.end.session("ticst0101m000")
message("Production Order %d and Item %s Inserted on ticst0101m000",run.order,run.item)
else
message(""&msg1)
dsc1 = msg1
stpapi.recover("ticst0101m000",ret.mesg1)
stpapi.end.session("ticst0101m000")
endif
else
stpapi.end.session("ticst0101m000")
message("Production Order could not be inserted on ticst0101m000")
endif
endselect
}

Is negative value possible through AFS???

mark_h
13th March 2008, 13:34
It should be, but I am not sure I have AFS code that does that. We use negative quantities when yielding parts from a teardown. When I get a chance later today I will try your code.

mark_h
13th March 2008, 15:21
stpapi.put.field("ticst0101m000","ticst001.pdno","341410")
rc = stpapi.change.view("ticst0101m000",err)
if isspace(err) then
stpapi.put.field("ticst0101m000","ticst001.pono","35")
stpapi.put.field("ticst0101m000","ticst001.sitm","6302998+R")
stpapi.put.field("ticst0101m000","ticst001.cwar","1LP")
stpapi.put.field("ticst0101m000","issu.quan","-20")
stpapi.put.field("ticst0101m000","ticst001.bfls",str$(tcyesno.no))
stpapi.insert("ticst0101m000",true,err)
endif

The above worked for me. So it is either your objects(libraries, etc.) or your code. Are you getting any errors at all? Just make sure the position number does not exist before the insert.

Also if the selectempty code is getting run - I would remove the below piece of code since you already know the production order number does not exist in ticst001 from the main select. Just set run.pono to 10.

select max(ticst001.pono):maxpono
from ticst001
where ticst001.pdno = :lhnst103.pdno
selectdo
endselect