Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Forum Index
 
Register
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Relational operator compare date range with today

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Wed Feb 06, 2019 6:19 pm    Post subject: Relational operator compare date range with today
Reply with quote

Hi,
I want to compare whether today falls within a date range of DST1 & DST2 ?

If satisfy, then set 5 else set 6.

today = Date('Base')
DST1= 737127
DST2= 737365

if X(today >= DST1 & today <= DST2)
this is not working which I am trying
Thanks
Back to top
View user's profile Send private message

Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1054
Location: Dublin, Ireland / Edinburgh, Scotland

PostPosted: Wed Feb 06, 2019 6:30 pm    Post subject:
Reply with quote

Code:
if X(today >= DST1 & today <= DST2)


What is the X function?

Do you mean
Code:
if (today >= DST1 & today <= DST2)
??

Date('Base') is returning 737005 today which falls outside the range and you should then return 6.

Garry.
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Wed Feb 06, 2019 6:55 pm    Post subject: Reply to: Relational operator compare date range with today
Reply with quote

Yes, I mean to compare
if (today >= DST1 & today <= DST2)

I think to put the result into X, don't need X.

If it satisfies, then need to setup with some value else some other value.

Thanks
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Wed Feb 06, 2019 7:14 pm    Post subject: Reply to: Relational operator compare date range with today
Reply with quote

Yes, I tried with

if today >= DST1 & today <= DST2 then say "5"
if today < DST1 & today > DST then say "6"

but this case returns with "0" not 5 or 6.

Thanks
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1054
Location: Dublin, Ireland / Edinburgh, Scotland

PostPosted: Wed Feb 06, 2019 7:17 pm    Post subject:
Reply with quote

For your 2nd test you should use OR not AND - it can't be both < and > .

But why not
Code:
if today >= DST1 & today <= DST2 then say "5"
              else say "6"


Garry
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 726
Location: Pennsylvania

PostPosted: Wed Feb 06, 2019 7:46 pm    Post subject:
Reply with quote

It may just be me, but my brain freezes with multiple ors (>= <=) along with ands (&) included.

I find this much easier to understand.

Note: If this is you universal time offset / daylight savings time solution,
then it will require maintenance every year.

Code:
/* REXX */
TODAY = DATE('BASE')
DST1= 737127
DST2= 737365
SELECT
  WHEN TODAY < DST1 THEN OFFSET = 5
  WHEN TODAY > DST2 THEN OFFSET = 5
  OTHERWISE OFFSET = 6
END
SAY TODAY OFFSET
EXIT
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Wed Feb 06, 2019 7:49 pm    Post subject: Reply to: Relational operator compare date range with today
Reply with quote

yes, it's working fine now. Thanks

in this case it returns "6" which is true.
so how to pass this value to the main module based on the value return in this ?

Thanks
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8787
Location: Welsh Wales

PostPosted: Wed Feb 06, 2019 8:08 pm    Post subject:
Reply with quote

daveporcelan wrote:

Code:
/* REXX */
TODAY = DATE('BASE')
DST1= 737127
DST2= 737365
SELECT
  WHEN TODAY < DST1 THEN OFFSET = 5
  WHEN TODAY > DST2 THEN OFFSET = 5
  OTHERWISE OFFSET = 6
END
SAY TODAY OFFSET
EXIT

With the SELECT being used like that I can't see it working correctly. When you use SELECT it only drops down to the next SELECT option if none of the above have been satisfied.

So if TODAY is less than DST1 then there will be no further checking performed so TODAY could be less than both DST1 and DST2 yet still set the OFFSET to 5
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 726
Location: Pennsylvania

PostPosted: Wed Feb 06, 2019 8:26 pm    Post subject:
Reply with quote

I will respond to three things at once.

First, my logic was slightly flawed (only in the OFFSET value). Corrected exec is below.

Second, Expat sure it works. Take the exec below (corrected) and set TODAY value manually. The OTHERWISE is only hit when TODAY is in the range.

Third, Max, the EXIT statement returns the value of OFFSET back to the calling program.

Code:
/* REXX */
TODAY = DATE('BASE')
DST1= 737127
DST2= 737365
SELECT
  WHEN TODAY < DST1 THEN OFFSET = 6
  WHEN TODAY > DST2 THEN OFFSET = 6
  OTHERWISE OFFSET = 5
END
SAY TODAY OFFSET
EXIT (OFFSET)
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Wed Feb 06, 2019 11:06 pm    Post subject: Reply to: Relational operator compare date range with today
Reply with quote

Thanks a lot, it's working fine.
one more issue I am facing while calculating DST1:

year = 2019
DST1 = Date('Base', year'0301', 'Standard')
DayOfWeek = DST1//7
if DayOfWeek < 6 then
DST1 = DST1 + 13 - DayOfWeek

Here I don't want to hard code the year in the code, instead I want to pass the year automate, so that I should not change the code everytime for the next year.

2nd: while calculating the DST1: it is the 2nd sunday of march every year.
while calculating, if the 1st day of march is sunday for any year(i.e., 2020), then it is not calculating the 2nd sunday, instead it is giving 1st sunday only.

If you have any suggestion, please let me know.
Thanks
Back to top
View user's profile Send private message
daveporcelan

Active Member


Joined: 01 Dec 2006
Posts: 726
Location: Pennsylvania

PostPosted: Wed Feb 06, 2019 11:43 pm    Post subject:
Reply with quote

Try removing this line of code. Always do the calculation.

Code:
if DayOfWeek < 6 then
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Thu Feb 07, 2019 12:34 pm    Post subject: Reply to: Relational operator compare date range with today
Reply with quote

Thanks for the advice, i removed the condition, now it's working fine.

Right now I am passing year as hard coded as below, can it be possible to fetch the only current year from somewhere or any command which can be fetched only current YYYY ?

year = 2019
DST1 = Date('Base', year'0301', 'Standard')

Thanks
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8787
Location: Welsh Wales

PostPosted: Thu Feb 07, 2019 12:44 pm    Post subject:
Reply with quote

daveporcelan wrote:

Second, Expat sure it works. Take the exec below (corrected) and set TODAY value manually. The OTHERWISE is only hit when TODAY is in the range.

Yeah, must have been having a brain job yesterday, now after a better look

icon_redface.gif
Back to top
View user's profile Send private message
Willy Jensen

Active User


Joined: 01 Sep 2015
Posts: 323
Location: Denmark

PostPosted: Thu Feb 07, 2019 2:55 pm    Post subject:
Reply with quote

Quote:
fetch the only current year from somewhere

You are already using Date('S') so you must have noticed that the left 4 bytes is the current year? So "yyyy=Left(Date('s'),4)" will do the trick. Or "Parse value date('s') with yyyy +4 mm +2 dd" if you want the month- and date numbers too.
Back to top
View user's profile Send private message
maxsubrat

Active User


Joined: 27 Feb 2008
Posts: 106
Location: india

PostPosted: Thu Feb 07, 2019 4:51 pm    Post subject: Reply to: Relational operator compare date range with today
Reply with quote

Yes, thanks.. it's done.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts File compare, where file has header a... VINAY PALLELA SYNCSORT 8 Thu Nov 07, 2019 5:05 pm
No new posts Mainframe datasets without any last r... rajatbagga All Other Mainframe Topics 1 Tue Sep 24, 2019 8:47 am
This topic is locked: you cannot edit posts or make replies. Compare two files logic in COBOL Nishant Singhal COBOL Programming 4 Sun Aug 25, 2019 2:25 am
No new posts Select based on a range from a differ... sergeyken SYNCSORT 2 Fri Aug 16, 2019 12:37 am
This topic is locked: you cannot edit posts or make replies. Select based on a range from a differ... vamsimul SYNCSORT 13 Tue Aug 13, 2019 12:36 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us