# Need help in building a logic

Author Message
Benchwarmer

New User

Joined: 16 Jul 2016
Posts: 22
Location: desk

Posted: Wed Feb 22, 2017 2:49 am

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.

Thanks
Robert Sample

Global Moderator

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

Posted: Wed Feb 22, 2017 3:05 am

 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?
Benchwarmer

New User

Joined: 16 Jul 2016
Posts: 22
Location: desk

Posted: Wed Feb 22, 2017 3:41 am

 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.

Bill Woodger

Moderator Emeritus

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

Posted: Wed Feb 22, 2017 4:22 am

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 ) ) )
Rohit Umarjikar

Global Moderator

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

Posted: Thu Feb 23, 2017 1:44 am

 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?
 View Bookmarks All times are GMT + 6 Hours

 Topic Forum Replies Similar Topics Building a sort key DFSORT/ICETOOL 3 Sync logic between VSAM files and DB2... COBOL Programming 9 Restart logic by using cursor name in... DB2 1 Compare two files logic in COBOL COBOL Programming 4 use daylight logic in REXX CLIST & REXX 1
Search our Forums: