Query on packed decimals



JES, JES2, JCL utilities, IDCAMS, Compile & Run JCLs, PROCs etc...

Query on packed decimals

Postby Mann_B » Tue Apr 26, 2011 1:00 pm

Hi

I have julian and year in seperate fields..I need to copy that to a single field.
Julian-date is of PIC S9(03) comp-3 redefined to PICx(02).
Year is of PIC 9(04)..

and my o/p fileds is of length PIC s9(07) COMP-3 redefined to PIC x(04).

I have tried defining the 2 fields in a gropu var. and made move accordingly,


01  WS-TEMP-JDYEAR.                                       
   03  WS-TEMP-JULIAN-DATE               PIC X(02).       
   03  WS-TEMP-YEAR                      PIC S9(05) COMP-3.
   03  WS-TEMP-YEAR-C                    REDEFINES         
       WS-TEMP-YEAR                     PIC X(03).     


Now in the group field am getting as
WS-TEMP-JDYEAR

10001------------   10     0 0 1
1F21C               1F     2 1 C


here 110 is the JD and 2011 is the year,,, this field is of lenth x(05)...
But my o/p field is of length PIC X(04).
How can I define fields so that I can get
1001
121C
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: Query on packed decimals

Postby prino » Tue Apr 26, 2011 1:39 pm

This is a forum for beginners and students, not for people who cannot even read.

This is a forum for JCL. Packed Decimals and COBOL have nothing to do with JCL!
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

Re: Query on packed decimals

Postby Mann_B » Tue Apr 26, 2011 1:47 pm

Am sorry...I have posted many queries on JCl and this is my first COBOL post...so in a hurry I have posted in JCL itself..n Do u have any idea on the query ...
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: Query on packed decimals

Postby enrico-sorichetti » Tue Apr 26, 2011 2:15 pm

these issues should be discussed with Your application support!
what are the standards for date handling inside Your organization!

anyway
the answer the solution is just basic, very basic, mathematic, ( not even mathematic, just arithmetic )

given also that the standard format for julian dates is YYYYDDD
julian = year * 1000 + days

or if You want to stick to Your illogic
garbag = days * 10000 + years


and define the julian/garbag field as a comp capable of holding a 7 digit packed integer
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Query on packed decimals

Postby steve-myers » Tue Apr 26, 2011 11:43 pm

The "standard" "Julian" (which it isn't, but that's not for this forum!) date is a 6 digit packed decimal value in 4 bytes with the format 0cyydddF, where c is 0 for dates from January 1, 1900 through December 31, 1999, 1 for dates from January 1, 2000 through December 31, 2099, yy is 01 through 99, and ddd is the day of year from 001 to 365 or 366 in a leap year, and F is an alternate packed decimal sign.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Query on packed decimals

Postby BillyBoyo » Wed Apr 27, 2011 4:56 am

steve-myers wrote:The "standard" "Julian" (which it isn't, but that's not for this forum!) date is a 6 digit packed decimal value in 4 bytes with the format 0cyydddF, where c is 0 for dates from January 1, 1900 through December 31, 1999, 1 for dates from January 1, 2000 through December 31, 2099, yy is 01 through 99, and ddd is the day of year from 001 to 365 or 366 in a leap year, and F is an alternate packed decimal sign.


I suppose there must be some reason for that :-) So instead of x'19' it is x'00' and instead of x'20' it is x'01'? Was there some fear that 81 centuries (OK, 80-and-a-bit centuries) wouldn't be enough, so they decided on 10?

Anyway, off the topic.

01  W-JULIAN-DATE-CCYYDDD PIC 9(7). (deliberately with no sign)
01  FILLER REDEFINES W-JULIAN-DATE-CCYYDDD.
      05  W-JULIAN-DATE-CCYY PIC 9(4). (again, deliberate)
      05  W-JULIAN-DATE-DDD PIC 999. (again).


Moves to the 05. Then move to 01 to a comp-3 pic s9(7) (or pic 9(7) depending on what value you want in the sign, C or F).

If you want the day and year the wrong way round, just swap them in the definition above.

enrico's solutions will achieve the same results. The multiplies just being a means to "shift left" by 3 or 4 bytes respectively.

If you want the "standard", as above, first chop off the century (so PIC 99 for W-JULIAN-DATE-YY). Then move to a comp-3 of pic s9(5) (or 9(5), yaddady, yaddady...). Then, iterrogate the century. If 19, move an X'00', if 20, move an X'01' into field arranged as below.
01  W-JULIAN-DATE-XYYDDD COMP-3 PIC 9(7). (deliberately with no sign)
01  FILLER REDEFINES W-JULIAN-DATE-XYYDDD.
      05  W-JULIAN-DATE-X-IND PIC X.
      05  W-JULIAN-DATE-YYDDD COMP-3 PIC 9(5). (again, deliberate)
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Query on packed decimals

Postby steve-myers » Wed Apr 27, 2011 6:35 am

The original OS/360 "Julian" data format was 00yydddF. I can remember thinking about what they would do for the 2000s as early as 1982 or so. I'm not sure exactly when IBM changed the format to 0cyydddF, but it was around that time. While 19yydddF and 20yydddF would work, it would also break a lot of existing code, both in IBM land and customer land.
steve-myers
Global moderator
 
Posts: 2105
Joined: Thu Jun 03, 2010 6:21 pm
Has thanked: 4 times
Been thanked: 243 times

Re: Query on packed decimals

Postby Mann_B » Fri Apr 29, 2011 12:14 pm

Hi

garbag = days * 10000 + years

I have tried this,What enrico-sorichetti posted ...and it is working and I got the results as I required .
But wil it work every time throught...
I will try with what BillyBoyo has posted also..
Thank a lot for your response..
Mann_B
 
Posts: 79
Joined: Wed Mar 31, 2010 11:48 am
Has thanked: 0 time
Been thanked: 0 time

Re: Query on packed decimals

Postby enrico-sorichetti » Fri Apr 29, 2011 12:36 pm

But wil it work every time throught...


mathematics id pretty deterministic ...
if the input respects the proper numeric bounds
no reason why it should not
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

Re: Query on packed decimals

Postby BillyBoyo » Fri Apr 29, 2011 6:08 pm

Mann_B wrote:Hi

garbag = days * 10000 + years

I have tried this,What enrico-sorichetti posted ...and it is working and I got the results as I required .
But wil it work every time throught...
I will try with what BillyBoyo has posted also..
Thank a lot for your response..


I think you are missing something. enrico has give a solution which works in any language which supports multiplication. I have given you a Cobol-specific implementation of enrico's solution. You could do a COMPUTE in Cobol to implement it directly (I would comment the code to make it clear why you multiply part of a date by 10,000), but you can do it by defining the storage, an implementation you shouldn't need to comment for a Cobol programmer.

If you give it bad data, enrico's solution, and my implementation of it, will not work. If you give it good data, it will always work.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Next

Return to JCL

 


  • Related topics
    Replies
    Views
    Last post