Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clarion code - How do I use set to for a match >= to a value? 2

Status
Not open for further replies.

rleiman

Programmer
May 3, 2006
258
US
Hi Everyone,

Please look at my code. The purpose of the code is to add sales amounts for items purchased on a particular date range. It works fine if the starting date is exactly found, but if the date is a day or so greater then the start date, the initial set will fail and not even look at the rest of the code.

Can you show me how to change this code so the initial set will find a row with a date = or > then the start date?

Thanks.

Emad

Code:
! Jewlery sales for week 1.
!--------------------------

LOC:TotalJewlerySalesWeek1 = 0
ITEPUR:PurchaseDate = LOC:Week1 - 6

Set (ITEPUR:KeyPurchaseDate, ITEPUR:KeyPurchaseDate)    !Set pointer to week 3.
Loop                                                    !Process all records
 Next (StoneItemsPurchased)                             ! read a record sequentially

 If ErrorCode () Or ITEPUR:PurchaseDate > LOC:Week1 |
 Then
    Break
 End

 LOC:TotalJewlerySalesWeek1 = LOC:TotalJewlerySalesWeek1 + ITEPUR:AmountPaid
END
 
Hi Emad,

Are you doing a CLEAR(ITEPUR:Record) before the assignment and SET() i.e.

CLEAR(ITEPUR:Record)
ITEPUR:purchaseDate = LOC:Week1 - 6
SET(ITEPUR:KeyPurchaseDate, ITEPUR:KeyPurchaseDate)
....

The CLEAR() is very important especially if the KEY in question has multiple columns in it. I personally think it is a good programming practice to clear the BUFFER before retrieving the data.

Regards
 
Hi ShankarJ,

No, I did not put it in.

I will do it.

Thanks for the help.

Truly,

Emad
 
Hi Emad,

Also,

Code:
LOC:TotalJewlerySalesWeek1 = LOC:TotalJewlerySalesWeek1 + ITEPUR:AmountPaid

can be represented as

Code:
LOC:TotalJewlerySalesWeek1 += ITEPUR:AmountPaid

Regards

 
Hi Emad and ShankarJ,

The reason why ShankarJ suggested CLEAR(ITEPUR:Record) was to make sure that ALL components of the key were set as desired. Even so, it's a bit more complicated than that. Normally you will want to CLEAR( x , -1) or CLEAR( x , 1) depending on if the component is ascending or descending.

Another problem you _might_ be experiencing is if the FILE StoneItemsPurchased is different from the prefix ITEPUR. This inability to tell without other information is one reason why I'm trying to move my code AWAY from using prefixes, and instead use dot notation.

I say this because you HAVE to use the file label on the NEXT, however on other code you can use EITHER the file label in a dot notation, or the prefix.

IOW, CLEAR(StoneItemsPurchased.Record) followed by a few other commands and then NEXT(StoneItemsPurchased) seems more obvious to me than CLEAR(ITEPUR:Record) followed later by NEXT(StoneItemsPurchased)

likewise
Set (ITEPUR:KeyPurchaseDate, ITEPUR:KeyPurchaseDate)
would become
Set (StoneItemsPurchased.KeyPurchaseDate, StoneItemsPurchased.KeyPurchaseDate)

HTH,
Mark Goldberg
 
Hi Mark,

I like the dot notation more because I use that kind of syntax in my Oracle pl/sql coding at work.

Thanks.

Truly,
Emad
 
Hi ShankarJ,

The += looks like a good space saver when writing the code.

Thanks.

Truly,
Emad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top