|
|
Newbie-ish question about PICTURE IS
The last time I did anything of note with COBOL was in the mid 1980s.
It's been a long long time and I've forgotten more than I ever knew.
That said, can someone explain to me why the REDEFINES in the code
below doesn't hide the leading zeroes, but the MOVE to display-counter
does.
Kind regards,
Bruce.
identification division.
program-id. ztest.
author. Bruce Axtens.
data division.
working-storage section.
01 counters.
05 counter1 picture is 99.
88 is-zero value 0.
05 counter-display redefines counter1 picture is ZZ.
01 display-counter picture is ZZ.
procedure division.
100-main section.
perform with test after varying counter1 from 10 by -1 until is-zero
display counter1 " " with no advancing
display counter-display " " with no advancing
move counter1 to display-counter
display display-counter
end-perform.
stop run.
end-program.
C:\OpenCobol>ztest
10 10 10
09 09 9
08 08 8
07 07 7
06 06 6
05 05 5
04 04 4
03 03 3
02 02 2
01 01 1
00 00
|
|
0
|
|
|
|
Reply
|
Bruce.Axtens (142)
|
10/12/2010 3:15:26 AM |
|
On Oct 11, 10:15=A0pm, axtens <bruce.axt...@gmail.com> wrote:
> The last time I did anything of note with COBOL was in the mid 1980s.
> It's been a long long time and I've forgotten more than I ever knew.
>
> That said, can someone explain to me why the REDEFINES in the code
> below doesn't hide the leading zeroes, but the MOVE to display-counter
> does.
>
> Kind regards,
> Bruce.
>
> identification division.
> program-id. ztest.
> author. Bruce Axtens.
> data division.
> working-storage section.
> 01 =A0 =A0 =A0counters.
> =A0 =A0 =A0 =A0 05 =A0 =A0 =A0counter1 =A0 =A0 =A0 =A0picture is 99.
> =A0 =A0 =A0 =A0 88 =A0 =A0 =A0is-zero value 0.
> =A0 =A0 =A0 =A0 05 =A0 =A0 =A0counter-display redefines counter1 picture =
is ZZ.
> 01 =A0 =A0 =A0display-counter picture is ZZ.
>
> procedure division.
> 100-main section.
> =A0 =A0 =A0 =A0 perform with test after varying counter1 from 10 by -1 un=
til is-zero
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 display counter1 " " with no advancing
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 display counter-display " " with no advan=
cing
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 move counter1 to display-counter
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 display display-counter
> =A0 =A0 =A0 =A0 end-perform.
> =A0 =A0 =A0 =A0 stop run.
> =A0 =A0 =A0 =A0 end-program.
>
> C:\OpenCobol>ztest
> 10 10 10
> 09 09 =A09
> 08 08 =A08
> 07 07 =A07
> 06 06 =A06
> 05 05 =A05
> 04 04 =A04
> 03 03 =A03
> 02 02 =A02
> 01 01 =A01
> 00 00
Somewhat simplified, the formatting happens when you move data to the
field. So when you move a new value to counter1, it's formatted as
pic 99 at that time. The pic ZZ field is only read, and that happens
largely like a character field, so the ZZ in counter-display never has
an opportunity to do anything.
|
|
0
|
|
|
|
Reply
|
robertwessel2 (1339)
|
10/12/2010 3:53:07 AM
|
|
<robertwessel2@yahoo.com> wrote in message
news:4baa074d-e699-4c3f-8670-b39903c1cf96@z28g2000yqh.googlegroups.com...
On Oct 11, 10:15 pm, axtens <bruce.axt...@gmail.com> wrote:
> The last time I did anything of note with COBOL was in the mid 1980s.
> It's been a long long time and I've forgotten more than I ever knew.
>
> That said, can someone explain to me why the REDEFINES in the code
> below doesn't hide the leading zeroes, but the MOVE to display-counter
> does.
>
> Kind regards,
> Bruce.
>
> identification division.
> program-id. ztest.
> author. Bruce Axtens.
> data division.
> working-storage section.
> 01 counters.
> 05 counter1 picture is 99.
> 88 is-zero value 0.
> 05 counter-display redefines counter1 picture is ZZ.
> 01 display-counter picture is ZZ.
>
> procedure division.
> 100-main section.
> perform with test after varying counter1 from 10 by -1 until is-zero
> display counter1 " " with no advancing
> display counter-display " " with no advancing
> move counter1 to display-counter
> display display-counter
> end-perform.
> stop run.
> end-program.
>
> C:\OpenCobol>ztest
> 10 10 10
> 09 09 9
> 08 08 8
> 07 07 7
> 06 06 6
> 05 05 5
> 04 04 4
> 03 03 3
> 02 02 2
> 01 01 1
> 00 00
..> Somewhat simplified, the formatting happens when you move data to the
> field. So when you move a new value to counter1, it's formatted as
> pic 99 at that time. The pic ZZ field is only read, and that happens
> largely like a character field, so the ZZ in counter-display never has
> an opportunity to do anything.
Another way to think about this is to remember that a REDEFINES *never*
changes the data in a field. It is just another way of looking at the data
that is there. (As well as determining how that data is received and sent)
|
|
0
|
|
|
|
Reply
|
wmklein1 (150)
|
10/12/2010 10:51:51 AM
|
|
|
2 Replies
36 Views
(page loaded in 0.052 seconds)
|
|
|
|
|
|
|
|
|