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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Algorithm to convert CCYYMM to number 1 - 18

Status
Not open for further replies.

RICHINMINN

Programmer
Dec 31, 2001
138
0
0
I'm working with a DB2 database which is designed to hold 18 months'-worth of data, in 18 separate partitions. Does anyone have an algorithm that I can use to calculate the current month's partition on the database? I can do it for numbers of partitions that are multiples of 12, but having 18 partitions complicates things.

Thanks!

Rich (in Minn.)
 
Something like (12 * CCYY + MM) modulus 18 ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
And modulus arithmetic in COBOL is done with
Code:
DIVIDE month-count BY 18 giving who-cares REMAINDER partition-number.

Don't forget to add 1 if your partition number is not zero-relative...

Tom Morrison
 
k5tm,
What I ended up using was:
DIVIDE ((CCYY * 12) + MM) BY 18
GIVING PARTN-QUOTIENT
REMAINDER PARTN-REMAINDER.
IF PARTN-REMAINDER = 0
MOVE 18 TO PARTN-REMAINDER.

This gives me a range of 1 to 18. If I simply added 1 to PARTN-REMAINDER in all cases, I would also have 1 to 18, but a given year (January - December) would have partitions 2 through 13, not 1 through 12.

Thanks for everyone's input.

Rich (in Minn.)
 
Actually
DIVIDE ((CCYY * 12) + MM) BY 18
GIVING PARTN-QUOTIENT
REMAINDER PARTN-REMAINDER
would never give a result of 18 in PARTN-REMAINDER, so adding 1 in all cases is perfectly safe.

However, the above code is not valid COBOL sytax, and would not even compile with most compilers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top