IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Need help in building a logic


IBM Mainframe Forums -> All Other Mainframe Topics
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Benchwarmer

New User


Joined: 16 Jul 2016
Posts: 22
Location: desk

PostPosted: Wed Feb 22, 2017 2:49 am
Reply with quote

I am working on a logic which is to assign a unique ID for records matched using a date and flag (Y/N).

It has following rules to assign a unique number

1. If date match
2. If Year in the date match with either month or day along with flag
3. If month and day match with difference in year is 1 along with flag

Initially we assigned unique numbers for a set of records. Now any population comes after need to be matched against the existing population to determine the unique ID.

But am unable to determine how to handle certain situations

e.g., Record from set1 with date 01/17/2017 and flag 'N' is assigned a unique value 008

New population comes in with date and flag as.
Code:
01/01/2017 Y
01/17/2017 Y


Based on the sequence and matching logic record 1 is not matching with any previous record and assigned a unique value 009, when record 2 is processed it matched with two unique value 008 & 009.

Ideally both the records should have to match with 008.

Any pointers would be helpful.

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

Global Moderator


Joined: 06 Jun 2008
Posts: 8569
Location: Dubuque, Iowa, USA

PostPosted: Wed Feb 22, 2017 3:05 am
Reply with quote

Quote:
Based on the sequence and matching logic record 1 is not matching with any previous record and assigned a unique value 009, when record 2 is processed it matched with two unique value 008 & 009.
According to your 3 rules, yes record 2 matches both -- so why do you think it should only match record 8?

Since you did not post any of the logic you are using, how can we help you? Are the rules prioritized?
Back to top
View user's profile Send private message
Benchwarmer

New User


Joined: 16 Jul 2016
Posts: 22
Location: desk

PostPosted: Wed Feb 22, 2017 3:41 am
Reply with quote

Quote:
According to your 3 rules, yes record 2 matches both -- so why do you think it should only match record 8?

The ultimate goal of establishing this logic is to assign unique ID based on specified rules and it becomes failure in this case.
Quote:

Since you did not post any of the logic you are using, how can we help you? Are the rules prioritized?

Apologies for that, Record ID is unique to each record.
Code:
WS-DATE = '2017-01-01'
WS-FLAG = 'Y'

SELECT UNIQUE_ID
  FROM RECORD_TABLE
 INNER
  JOIN UNIQUE_ID_TABLE B
    ON A.RECORD_ID = B.RECORD_ID
 WHERE (A.DATE     = WS-DATE --> Rule 1
    OR (YEAR(DATE) = YEAR(WS-DATE)  AND (MONTH(DATE) = MONTH(WS-DATE)  OR  DAY(DATE) = DAY(WS-DATE)) AND  A.FLAG = WS-FLAG) --> Rule 2
    OR (YEAR(DATE) BETWEEN YEAR(WS-DATE) - 1 AND YEAR(WS-DATE) + 1  AND (MONTH(DATE) = MONTH(WS-DATE)  AND  DAY(DATE) = DAY(WS-DATE)) AND  A.FLAG = WS-FLAG)) --> Rule 3


Even if I prioritize the rules, it is not going to help since the record 1 from previous post does not match for unique number '008' until the record 2 is going to be processed first. I considered using some sort sequence and I don't think it is going to help either.

If you need more info, please let me know.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7310
Location: Inside the Matrix

PostPosted: Wed Feb 22, 2017 4:22 am
Reply with quote

Make the conditions mutually exclusive, you can only get (at most) a match on one condition.

Code:
( condition 1 )
or ( ( condition 2 ) and ( not condition 1 ) )
or ( ( condition 3 ) and ( ( not condition 2 )  and ( not condition 1 ) ) )
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2632
Location: NYC,USA

PostPosted: Thu Feb 23, 2017 1:44 am
Reply with quote

Quote:
Ideally both the records should have to match with 008

Why will 01/01/2017 be a match as it has 'Y' flag instead of 'N' to get matched?
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> All Other Mainframe Topics

 


Similar Topics
Topic Forum Replies
No new posts Building a sort key DFSORT/ICETOOL 3
No new posts Sync logic between VSAM files and DB2... COBOL Programming 9
No new posts Restart logic by using cursor name in... DB2 1
This topic is locked: you cannot edit posts or make replies. Compare two files logic in COBOL COBOL Programming 4
No new posts use daylight logic in REXX CLIST & REXX 1
Search our Forums:

Back to Top