Page 1 of 1

Packed Decimals with Dates

PostPosted: Sat Nov 01, 2014 9:13 am
by Susansuth
If I am using packed decimals to represent dates, is there a way to get a beginning zero to print to the screen?

So, let's say I have a date like this 02081940F in a packed decimal field of length 5.

I want to use ED to bring it to the screen so that I will get this: 02/08/1940.

I can get it to work if I have a date like this 22081940F -- 22/08/1940.

But the beginning zero will not print for the 02/08/1940. If I use F0 as a fill character, I can get the zero to print, but it also prints the extra zero that fills out the remainder of the packed decimal field.

Is there a way to get that zero to print without grabbing the extra 0 that fills out the remainder of the packed decimal field?

Or is that pretty much something that isn't going to happen?

Any help would be appreciated. :) Thank you so much!

Susan

Re: Packed Decimals with Dates

PostPosted: Sat Nov 01, 2014 11:01 am
by steve-myers
From time to time I've run into the same issue. There's no solid answer; this is one solution, though it's limited.
         ED    FIELD,DATA
         MVI   FIELD,C' '
         ...
DATA     DC    P'01021948'                                         
FIELD    DC    0C'0MM/DD/YYYY',C'0',X'2120',C'/',2X'20',C'/',4X'20'
My date is different than the date you proposed, though it presents the same problem. The way the fill character is specified for ED instruction formats is a bit clumsy - and this situation really clarifies it. One would wish for a better idea, but it's way too late now!

Just this morning I wrote code to format mm/dd/yyyy, though the date I started with was PL4'cyyddd' Getting month and day of month from that mess is moderately painful. I formatted mm, dd and yyyy as separate fields using UNPK rather than combine them into P'mmddyyyy'

I've been using the method to define complex ED instruction formats like in my little example and I think it works pretty well. It's better than memorizing character codes, like the / in the format. Oddly enough I had been thinking X'61' for the /, and that turned out to be correct. X'F021206120206120202020' - the "standard" method - is pretty hard to digest, and very easy to screw up.

Re: Packed Decimals with Dates

PostPosted: Sat Nov 01, 2014 9:27 pm
by Susansuth
This is PERFECT. This helped me a lot. Just what I needed.

THank you so very much. You made my day! :)

Susan

Re: Packed Decimals with Dates

PostPosted: Mon Nov 03, 2014 9:39 am
by steve-myers
A couple of other “tricks” with ED and EDMK.

Append conditional text
         MVC   OUTPUT,EDMASK
         ED    OUTPUT,=P'-12345'
         ...
OUTPUT   DC    C' NNN.NN CR'
EDMASK   DC    0C' NNN.NN CR',C' ',X'202120',C'.',C'2020',C' CR'

The output will be 123.45 CR

Insert floating text
         MVC   OUTPUT,EDMASK
         LA    1,OUTPUT+4
         EDMK  OUTPUT,VALUE
         CP    VALUE,=P'0'
         BNM   PLUS
         BCTR  1,0
         MVI   0(1),C'-'
PLUS     BCTR  1,0
         MVI   0(1),C'$'
*                0----+--
OUTPUT   DC    C'  NNN.NN'
EDMASK   DC    0C'  NNN.NN',C' ',X'202120',C'.',X'2020'
VALUE    DC    P'-12345'

The output will be $-123.45. The tricky part is figuring out how to set register 1 before the EDMK so that something like P'00045' will format as $0.45. Using a ruler like I did helps.

An important rule with ED and EDMK is to have an odd number of digit select characters in the format. If you run into a situation where the report specifies an even number of digits, format the output in a separate area, and move the last even number of digits to the final report.

Re: Packed Decimals with Dates

PostPosted: Thu Nov 06, 2014 9:16 am
by Susansuth
This is great to know! Thanks for the extra information!! I appreciate the help!

Susan

Re: Packed Decimals with Dates

PostPosted: Tue Jan 12, 2016 6:41 pm
by Aliraza521
It appears you have to specify some parameter though I'm not 100% sure how to do this.????

Re: Packed Decimals with Dates

PostPosted: Tue Jan 12, 2016 7:39 pm
by Akatsukami
Please do not append a query to a thread that has been dormant for over a year.

Re: Packed Decimals with Dates

PostPosted: Tue Jan 12, 2016 11:24 pm
by steve-myers
Aliraza521 wrote:It appears you have to specify some parameter though I'm not 100% sure how to do this.????
There are three "parameters" with the ED instruction.
  • The address of the edit "pattern."
  • The length of the edit "pattern."
  • The address of the data area to be edited by the instruction.
Or do you mean something else?

To return to the topic starter's query, another solution might be -
         ED    PATTERN,=P'01021948'
         MVC   OUTPUT,PATTERN+1
         ...
PATTERN  DC    0C'0MM/DD/YYYY'
         DC    C'0',X'2120',C'/',X'2020',C'/',X'20202020'
OUTPUT   DC    C'MM/DD/YYYY'
Here the real output is separated from the pattern, though there is a real MVC to copy the edited data to the real output area. Writers of training material often seemed wired into the idea the edit pattern is part of the actual output image, but that is not always a real requirement.

I generally agree with Akatsukami that dormant threads should not be reopened, though I'm not the guilty party here. At least Aliraza521 attempted to stay on topic, which is often not the case when a dormant thread is restarted.