× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



I have an SQL statement that fails in my RPG but not when ran
interactively.
     P FAXNEWAREA      B                   EXPORT
     D FAXNEWAREA      PI             3A
     D OldAreaCode                    3A   CONST
     D Exchange                       3A   CONST

     D* Local fields
     D retField        S              3A
     D CutDays         s             10i 0 inz(180)
     D* Based on information from Ken Shaw of Sprint, Chris Edwards
determined that we can safely
     D* change the area codes up to 6 months, (180 days), after the cutoff
to use new area codes
     D* becomes mandatory.  Exchanges should not be reused before then.  In
other words, when the
     D* exchange 347 split off from area code 219 into the new 260, we
figure that we can assume
     D* that the old 219 area code will not start reusing 347 for a new
city until after this
     D* time has passed.
     D ac              s              5a
     D ex              s              5a

      /free
       ac=apos + OldAreaCode + apos;
       ex=apos + Exchange + apos;
      /end-free

     C/EXEC SQL
     C+ SELECT enew into :retField
     C+ from exfile join acfile on eold=cold
     C+ where enew=cnew and days(curdate())-days(
     C+ date(cepmth concat '/' concat cepday concat '/' concat cepyr))
<:CutDays
     C+ and eold=:ac and eexc=:ex
     C/end-exec

      /free
       Select;
       When sqlcod<>0;
        retField=*blanks;
       Endsl;
       return retField;
      /end-free
     P FAXNEWAREA      E

When ran in debug the values of the fields are:
retField=*null
CutDays=180
ac='219'
ex='347'
sqlcod=000000100

>From the joblog:
Job 468872/ROB/ROBS2 started on 02/12/02 at 09:15:11 in subsystem QINTER
  in QSYS. Job entered system on 02/12/02 at 09:15:11.
Message queue ROB is allocated to another job.
/*      */
edtlibl
Library list changed.
CHGJOB LOG(4 00 *SECLVL) LOGCLPGM(*YES)
STRDBG PGM(ROB/TEST) MAXTRC(32000) UPDPROD(*YES)
call test
Query options retrieved file QAQQINI in library QUSRSYS.
Query options retrieved file QAQQINI in library QUSRSYS.
CONNECT to relational database GDISYS completed.
Current connection is to relational database GDISYS.
Query options retrieved file QAQQINI in library QUSRSYS.
**** Starting optimizer debug message for query .
All access paths were considered for file ACFILE.
All access paths were considered for file EXFILE.
File ACFILE processed in join position 1.
File EXFILE processed in join position 2.
ODP created.
Blocking used for query.
ODP not deleted.
Row not found for SELECT.
SQLCOD = 000000100.

This is in a service program called by another program
Service program was created
CRTSQLRPGI OBJ(ROUTINES/SRVPGM) SRCFILE(ROUTINES/QRPGLESRC) COMMIT(*NONE)
OBJTYPE(*MODULE) TGTRLS(V5R1M0) DBGVIEW(*SOURCE)
then
CRTSRVPGM  SRVPGM(ROUTINES/SRVPGM) TGTRLS(V5R1M0) BNDDIR(QC2LE)
           ACTGRP(SRVPGM) SRCFILE(ROUTINES/QSRVSRC)

But the following works interactively
SELECT enew
from exfile join acfile on eold=cold
where enew=cnew and days(curdate())-days(
date(cepmth concat '/' concat cepday concat '/' concat cepyr))<180
and eold='219' and eexc='347'

Rob Berendt
--
"They that can give up essential liberty to obtain a little temporary
safety deserve neither liberty nor safety."
Benjamin Franklin



As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.