Joined: 15 Mar 2005 Posts: 17 Location: Toronto, Canada
Hi,
I need to sort first part of a Binary field , 8 in length, which stores date stamp in julian date format + time + 4 byte userid. I need only the date part to be sorted without the time part. Is it possible. if so please explain.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Siva,
You can use DFSORT's byte.bit notation to sort part of a binary field (e.g SORT FIELDS=(11,1.2,BI,A) for the first 10 bits starting at position 11). But in order to tell you the exact SORT statement to use, I need to know what position your binary field starts in and what your binary field looks like.
What part of the binary field do you need to sort (e.g. first 10 bits)?
Please show an example of what the binary field looks like in hex and identify where the date stamp is.
Joined: 15 Mar 2005 Posts: 17 Location: Toronto, Canada
Hi Frank,
Thanks for your quick reply. Here are the details you asked me to expalin the solution in a better way.
The binary filed in question starts in the record at position 11 for a length of 8 bytes. the field contains 0YYDDDHHMISSUSER. YYDDD is the julian date, HHMISS is the time and USER is the four digit userID. The data is right justified hence padded with zero on left.
Example: This is the data of this field in one record '0043662300000000' and its hex form is '000027B5EBE1AF00'. Please help explain how can I acheive sort only on the julian date part of this field.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
I don't know what you mean by "its hex form is '000027B5EBE1AF00'". It looks like the hex form is '0043662300000000' - that would correspond to an 8-byte value in '0YYDDDHHMISSUSER' form. Assuming that's true and the yy values represent 20yy years (not 19yy and 20yy years), you could use the following DFSORT job to sort by just the Julian date (YYDDD) in the field:
11.3 says the starting position is the second nibble in byte 11. 2.4 says the length is 20 bits (2 bytes and 1 nibble). 1 nibble = 1 hex = 4 bits.
Actually, since the first nibble is always 0, you can just treat the date as a 3-byte value (X'0YYDDD') in positions 11-13 and use the following SORT statement:
Code:
SORT FIELDS=(11,3,BI,A)
If the yy values represent 19yy and 20yy years, let me know.
If you want to see what the first few values look like in hex, you can use this DFSORT job:
Joined: 15 Mar 2005 Posts: 17 Location: Toronto, Canada
Hi Frank,
After your earlier reply, I read the 'bytes.bits' notation explanations in DFSORT Programming Guide and applied (11,3,BI,A) and it worked.
Sorry, I jumbled the data formats in my earlier mail.
The date stamp in this case has Julian date (consisting of no century). Including the padded zero, this date occupies 3 bytes (4 bits or half byte for each character) since this date part has 6 characters (0YYDDD). So SORT starting at 11 (starting position of the field) for 3 bytes of this Binary field should sort only the date portion of the date stamp.
Thanks for your help, which saved me from handling this aspect in a COBOL program.