× 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.



Hi Srinivas

Why are you storing the dates in their individual elements? It would be
much easier for your program to handle the dates if they were a) using a
date type field or b) stored as a single value.

However, whether you are using a single value or individual elements for
your key you have to think about the relationships between the elements of a
date. For example, a year (YY) is a sub-division of a century (CC). A
month is a sub-division of a year and a day is a sub-division of a month.

If you were to write a list of ordered dates (regardless of format) you
would subconsciously put the earlier years first and then the earlier months
of the year and then the days.

The key for your logical file, should therefore be:

C KEY KLIST
C KFLD FCC
C KFLD FYY
C KFLD FMM
C KFLD FDD
C KFLD TCC
C KFLD TYY
C KFLD TMM
C KFLD TDD

In your program you can probably get away with only using a key list of:

C KEY KLIST
C KFLD FCC
C KFLD FYY
C KFLD FMM
C KFLD FDD

When you read the file you can position to the first record using the key,
but you will need to test the record after you have read it to see if it is
within the date range.

This is where it gets a lot more complex by using individual fields for the
date elements because you need to test each individual element in relation
to the other elements.

For example if the range I am checking has the date elements in STRCC,
STRYY, STRMM, STRDD, ENDCC, ENDYY, ENDMM and ENDD then my testing would be
something along the lines of:

C If (FCC >= STRCC and FYY >= STRYY) and
C (TCC <= ENDCC and TYY >= STRYY) and
C If ((FCC = STRCC and TCC = STRCC) and
C (FYY = STRYY) and (FMM >= STRMM)) or
C ((FCC = STRCC and TCC = STRCC) and
C (FYY > STRYY)) or
C ((FCC <> STRCC)
C If ...

Which is overly complicated, and prone to errors. An easier method would be
to combine the date elements back together again into YYCCMMDD order:

C Eval StrDate = (StrCC * 1000000) +
C (StrYY * 10000) + (StrMM * 100) + StrDD

C Eval EndDate = (EndCC * 1000000) +
C (EndYY * 10000) + (EndMM * 100) + EndDD

C Eval FDate = (FCC * 1000000) + (FYY * 10000) +
C (FMM * 100) + FDD

C Eval TDate = (TCC * 1000000) + (TYY * 10000) +
C (TMM * 100) + TDD

Now, your testing can be a lot simpler by comparing date against date:

C If FDate >= StrDate and FDate <=EndDate
C ...
C EndIf

If both the FDATE and TDATE have to be in the range then the test becomes:

C If FDate >= StrDate and FDate <=EndDate and
C TDate >= StrDate and TDate <=EndDate
C ...
C EndIf

Both of which are a lot easier to read, understand and test. Even easier
would be to store the from and to dates on the file in CCYYMMDD format, or
better yet as a date type field then you don't need to do rebuild the dates
for testing with.

Best regards

Jonathan

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Srinivas Boggula
Sent: 12 September 2007 10:40
To: RPG programming on the AS400 / iSeries
Subject: Dates Problem


Hi every one,



How do I Select from Date To - To Date in RPGLE



Say suppose I have 20 records in a Physical File and I have 8 fields in
it.

Now I want to retrieve from Dates To - To Date.



I tried with the following way created a logical file of eight fields
all of them are keyed



In RPGLE program I have created KLIST ( KEY AND KEY1)



C KEY KLIST

C KFLD FDD

C KFLD FMM

C KFLD FCC

C KFLD FYY

C*

C KEY1 KLIST

C KFLD TDD

C KFLD TMM

C KFLD TCC

C KFLD TYY



With the help of KEY & Chain I can able to set pointer to from date and
read the record.

But how do I stop at To-Date.



0004.43 C KEY CHAIN DSPREC 90



Physical File Data :

FCC FYY FMM FDD TCC TYY TMM TDD NAME
000001 20 2 8 1 20 7 7 21 JOHN
000002 20 2 9 2 20 7 8 22 FAYAZ
000003 20 2 10 3 20 8 9 23 RAJASHEKAR
000004 20 2 11 4 20 7 9 24 SRINIVAS REDDY
000005 20 2 12 5 20 7 11 30 PRAVEEN
000006 20 7 11 30 20 8 12 31 SRINIVAS

****** ******** End of report ********


Please Can any one guide me on this issue.



Thanks in Advance



Regards,

Srinivas













I want to retrieve records from 10 to 15, I can able to set pointer and
read 10th

record using SETLL and READE but how do I Stop at 15th record.



Thanks in Advance



Regards,

Srinivas





























iGATE is ranked as 3rd best IT employer in India as per DQ-IDC Best
Employer Survey-2007
----------------------------------------------------------------DISCLAIM
ER---------------------------------------------------------
Information transmitted by this EMAIL is proprietary to iGATE Group of
Companies and is intended for use only by the individual
or entity to whom it is addressed and may contain information that is
privileged, confidential, or exempt from disclosure under
applicable law. If you are not the intended recipient of this EMAIL
immediately notify the sender at iGATE or mailadmin@xxxxxxxxx
and delete this EMAIL including any attachments

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

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.