Re: 4gl return value problem
Posted in 2004
daisy wrote:
>
>"June C. Hunt" <june_c_hunt@hotmail.com> wrote in message
>news:<2sd8c.52394$Fh4.329@twister.nyroc.rr.com>...
> > daisy wrote:
> > > I had a question occurred when my 4gl main program calling a
> > > function. There seems to be something wrong with the return value
> > >
> > > Statements in my main program :
> > >
> > > ud_fun()
> > > ...........
> > > let p=1
> > > while p
> > > if del_fun() then exit while end if
> > > let p=0
> > > end while
> > > if p then
> > > rollback work
> > > prompt "error... " for char answer
> > > end if
> > > ............
> > > end function
> > >
> > >
> > > del_fun()
> > > ........
> > > if m_ac31('2',n.acm02,n.acm00,n.acm01,
> > > o[i].acn02 thru o[i].acn15) then
> > > display "m_ac31 error ",o[i].acn02 at 21,1
> > > sleep 5
> > > return 1
> > > end if
> > > ..................
> > > end function
> > >
> > > statements in my function
> > >
> > > m_ac31()
> > > ...............
> > > if status or sqlca.sqlerrd[3]<1 then
> > > display "Upd ac31 err-",status
> > > sleep 5
> > > return 1
> > > end if
> > > ......
> > >
> > >
> > > My problem is that I 'sometimes ' found that the m_ac31
> > > function was performed successfully (because there is no error message
> > > displayed )
> > > but the results comed out wrong ; which means there were error
> > > during the function was called but my main program did not catch the
> > > return value .Could any one tell me where the problem is ?
> > >
> > > My Informix was old SE. I do not know what is the problem in my
> > > program.
> >
> > Since you don't specify what you mean when you say the results are
>wrong,
> > I'm just guessing at where to start. Was data changed that shouldn't
>have
> > been? Was data skipped? Were one or more unexpected records changed?
>Were
> > one or more expected records missed while others were selected? Simply
> > saying the results are "wrong" leaves a whole lot of possibilities.
> >
> > Without knowing exactly what "wrong" means, my first suggestion would be
>to
> > change the error checking in m_ac31. I would check SQLCA.SQLCODE rather
> > than STATUS - or check both. The STATUS variable will indicate errors
>from
> > both the form and from SQL statements whereas SQLCA.SQLCODE indicates
>errors
> > (or success) of just the SQL statements. Since you only show the error
> > checking, we can't be sure what comes before it in your code; I'd be
>more
> > comfortable checking the SQLCA record. I would also be inclined to
>evaluate
> > SQLCA.SQLERRD[3] against a known value. For example, I would find out
>how
> > many records I expect to process, and would compare SQLCA.SQLERRD[3]
>against
> > that value rather than zero. Is it possible that the problem isn't
>that no
> > records were processed but rather more records than you were expecting
>were
> > processed? With these changes, at least you'd be sure you were checking
>the
> > results of the last SQL statement and that you were processing as many
> > records as you were expecting. Note that this doesn't necessarily mean
>the
> > correct records were processed, but at least the actual number of
>records
> > can be determined.
>
>
>Sorry that I did not describe my question clearly.
>The statemenst in m_ac31 were as follows
> update ac31 set acp05=acp05-damt,
> acp06=acp06-camt,
> acp07=acp07-amt,
> acp08=acp08-amt,
> acp09=acp09-ramt
> where acp00=x.acn00 and acp01=x.acn04 and>acp02=ym
> and acp03=dno and acp04=x.acn05
> if status or sqlca.sqlerrd[3]<1 then
> let damt=damt*-1
> let camt=camt*-1
> let amt=amt*-1
> let ramt=ramt*-1
> insert into ac31 values>
>(x.acn00,x.acn04,ym,dno,x.acn05,damt,camt,
> amt,amt,ramt)
> if status or sqlca.sqlerrd[3]<1 then
> display "Upd ac31 err-",status
> sleep 5
> return 1
> end if
> end if
>
> What bothered me was that sometimes I found that the record to be
>updated were actually exist, but after the program were completed and
>check the result
>I found that the record were not updated at all and the return value
>did not pass to the calling procedure (in my situation that's function
>del_fun()).
>
> Once I manually cleard the wrong result and I run the program again,
>but it
>comed out right . I don't know if it's problem of file lock , or is
>there any
>mistakes in my program.
>
> Please give me some advice .
> Thanks again
No obvious mistakes in the program - what we can see of it, anyway. Is it
possible that the UPDATE was rolled back as a part of a larger group of
transactions in the ud_fun function? I'm also a little curious about the
purpose of the WHILE loop around that function call, but for the moment will
assume that you are showing just a portion of that code. What else is going
on between the BEGIN WORK/COMMIT WORK in that function?
If it were a locking issue, I'd exect it to be caught with the
SQLCA.SQLERRD[3]<1 check (assuming that a single record is being identified
by the WHERE clause and that multiple records aren't being updated). Even
so, I prefer to lock the record myself before attempting an update - just to
be sure that I've got it.
So - without seeing the rest of the code, my best guess is that the
transaction was rolled back. What else is going on in ud_fun?
--
June Hunt
_________________________________________________________________
All the action. All the drama. Get NCAA hoops coverage at MSN Sports by
ESPN. http://msn.espn.go.com/index.html?partnersite=espn
sending to informix-list