Hello:As the compiler proceeds through the code it creates the data items. In the first example it creates each item with the value specified and then creates the redefines as an alias to the existing items.
I'm thinking about how a table can be initialized statically in cobol. Obviously, one simple approach is to use REDEFINES. Here is how I might define the table {4, 9, 6, 3, 5, 1}:
01 barzilay.
05 pic 9 value is 4.
05 pic 9 value is 9.
05 pic 9 value is 6.
05 pic 9 value is 3.
05 pic 9 value is 5.
05 pic 9 value is 1.
01 dina redefines barzilay.
05 digit pic 9 occurs 6 times.
I was surprised that this won't work backwards, i.e., if I were to define
01 dina.
05 digit pic 9 occurs 6 times.
01 barzilay redefines dina.
05 pic 9 value is 4.
05 pic 9 value is 9.
05 pic 9 value is 6.
05 pic 9 value is 3.
05 pic 9 value is 5.
05 pic 9 value is 1.
then gnu cobol (3.0/linux) would have digit(1)...digit(6) initialized to zero. It would seem to me that if cobol were not to treat these two examples the same way, that the compiler should have prevented me from assigning initial values under the REDEFINE line.
Can someone please explain this behaviour?
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
On Monday, October 1, 2018 at 5:53:30 AM UTC+13, Mayer Goldberg wrote:"I will survive!" :-)
Hello:
I'm thinking about how a table can be initialized statically in cobol. Obviously, one simple approach is to use REDEFINES. Here is how I might define the table {4, 9, 6, 3, 5, 1}:
01 barzilay.
05 pic 9 value is 4.
05 pic 9 value is 9.
05 pic 9 value is 6.
05 pic 9 value is 3.
05 pic 9 value is 5.
05 pic 9 value is 1.
01 dina redefines barzilay.
05 digit pic 9 occurs 6 times.
I was surprised that this won't work backwards, i.e., if I were to define
01 dina.
05 digit pic 9 occurs 6 times.
01 barzilay redefines dina.
05 pic 9 value is 4.
05 pic 9 value is 9.
05 pic 9 value is 6.
05 pic 9 value is 3.
05 pic 9 value is 5.
05 pic 9 value is 1.
then gnu cobol (3.0/linux) would have digit(1)...digit(6) initialized to zero. It would seem to me that if cobol were not to treat these two examples the same way, that the compiler should have prevented me from assigning initial values under the REDEFINE line.
Can someone please explain this behaviour?
As the compiler proceeds through the code it creates the data items. In the first example it creates each item with the value specified and then creates the redefines as an alias to the existing items.
In the second example it would create the data items with default values and then find that it could create an alias to those items but can't do anything about the values because the items already have values.
Rather than force compiler writers to do things that are hugely complicated and aren't useful they just put it in the standard to not do that.
Tough. Get over it.
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do:
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
On Sunday, September 30, 2018 at 9:18:47 PM UTC+3, Richard wrote:No. "USAGE DISPLAY" items are stored as ASCII (or EBCDIC) characters.
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do:
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
Does this mean that display numeric is always represented internally in big-endian?
On Sunday, September 30, 2018 at 9:18:47 PM UTC+3, Richard wrote:
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do:
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
Does this mean that display numeric is always represented internally in big-endian?
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do:
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
In any event, here is how I'm planning to use this example:Keep in mind that there are a mere 450 or so shopping days until 2020,
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
On Sun, 30 Sep 2018 10:06:40 -0700 (PDT), Mayer Goldberg <mayer.goldberg@gmail.com> wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
Keep in mind that there are a mere 450 or so shopping days until 2020,
when you'll have to adjust the number of days in February.
Louis
On Sun, 30 Sep 2018 10:06:40 -0700 (PDT), Mayer Goldberg <mayer.goldberg@gmail.com> wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
Keep in mind that there are a mere 450 or so shopping days until 2020,
when you'll have to adjust the number of days in February.
Louis
On 1/10/2018 7:18 AM, Richard wrote:I don't see why redefine, which would give you a statically-initialized array, would be any less efficient than a substring computation at run-time, even under the best optimizations. The redefine solution is more general too, and would work with computational rather than Z's and 9's. Even if you wanted to work with fixed points or integers, it would be nicer to be able to define each number separately, possibly skipping any leading zeros... If you were to generalize the string approach, all numbers would have to be initialized using substrings of equal length. This would be annoying.
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do:
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
The way you have set it out is clear and most COBOL Programmers would be happy with it.
Richard's simplification should also be acceptable to most people.
Here's a way that some would baulk at, but which I would use:
01 initial-values PIC X(24) VALUE "31283130...".
(Nothing else... no further definitions.)
Then, use refmodding to access it...
February... initial-values(3:2)
April... initial-values(7:2)
a general case derived from month number...
initial-values((monthNum * 2) -1:2)
No need for REDEFINES or OCCURS... and almost certainly more efficient (depends on compiler optimization and platform...) but perhaps not as immediately obvious as the original description.
Pete.
--
I used to write COBOL; now I can do anything...
On 1/10/2018 7:18 AM, Richard wrote:I am not sure how you came to the conclusion that an expression with a multiply and subtraction followed by a substring could be "almost certainly more efficient" than a simple index. Anyway the result of the substring is not numeric so in addition it probably needs to be moved to a PIC 99 or such.
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do:
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
The way you have set it out is clear and most COBOL Programmers would be happy with it.
Richard's simplification should also be acceptable to most people.
Here's a way that some would baulk at, but which I would use:
01 initial-values PIC X(24) VALUE "31283130...".
(Nothing else... no further definitions.)
Then, use refmodding to access it...
February... initial-values(3:2)
April... initial-values(7:2)
a general case derived from month number...
initial-values((monthNum * 2) -1:2)
No need for REDEFINES or OCCURS... and almost certainly more efficient (depends on compiler optimization and platform...) but perhaps not as immediately obvious as the original description.
On Tuesday, October 2, 2018 at 4:48:23 AM UTC+3, pete dashwood wrote:
On 1/10/2018 7:18 AM, Richard wrote:
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:The way you have set it out is clear and most COBOL Programmers would be
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do: >>>
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
happy with it.
Richard's simplification should also be acceptable to most people.
Here's a way that some would baulk at, but which I would use:
01 initial-values PIC X(24) VALUE "31283130...".
(Nothing else... no further definitions.)
Then, use refmodding to access it...
February... initial-values(3:2)
April... initial-values(7:2)
a general case derived from month number...
initial-values((monthNum * 2) -1:2)
No need for REDEFINES or OCCURS... and almost certainly more efficient
(depends on compiler optimization and platform...) but perhaps not as
immediately obvious as the original description.
Pete.
--
I used to write COBOL; now I can do anything...
I don't see why redefine, which would give you a statically-initialized array, would be any less efficient than a substring computation at run-time, even under the best optimizations.
On Tuesday, October 2, 2018 at 2:48:23 PM UTC+13, pete dashwood wrote:
On 1/10/2018 7:18 AM, Richard wrote:
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote:The way you have set it out is clear and most COBOL Programmers would be
In any event, here is how I'm planning to use this example:
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do: >>>
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
happy with it.
Richard's simplification should also be acceptable to most people.
Here's a way that some would baulk at, but which I would use:
01 initial-values PIC X(24) VALUE "31283130...".
(Nothing else... no further definitions.)
Then, use refmodding to access it...
February... initial-values(3:2)
April... initial-values(7:2)
a general case derived from month number...
initial-values((monthNum * 2) -1:2)
No need for REDEFINES or OCCURS... and almost certainly more efficient
(depends on compiler optimization and platform...) but perhaps not as
immediately obvious as the original description.
I am not sure how you came to the conclusion that an expression with a multiply and subtraction followed by a substring could be "almost certainly more efficient" than a simple index.
On 2/10/2018 5:16 PM, Richard wrote:
On Tuesday, October 2, 2018 at 2:48:23 PM UTC+13, pete dashwood wrote:
On 1/10/2018 7:18 AM, Richard wrote:
On Monday, October 1, 2018 at 6:06:41 AM UTC+13, Mayer Goldberg wrote: >>>> In any event, here is how I'm planning to use this example:The way you have set it out is clear and most COBOL Programmers would be >> happy with it.
01 gregorian-months-and-their-days.
05 initial-values.
10 pic 99 value is 31.
10 pic 99 value is 28.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
10 pic 99 value is 30.
10 pic 99 value is 31.
05 table-definition redefines initial-values.
10 gmonth-max-days pic 99 occurs 12 times.
So I have gmonth-max-days(1) ... gmonth-max-days(12) with the maximum number of days per Gregorian month.
You can simplify this because those items are display numeric you can do: >>>
05 initial-values PIC X(24) VALUE "31283130...".
and then redefine this as PIC 99 OCCURS 12.
Richard's simplification should also be acceptable to most people.
Here's a way that some would baulk at, but which I would use:
01 initial-values PIC X(24) VALUE "31283130...".
(Nothing else... no further definitions.)
Then, use refmodding to access it...
February... initial-values(3:2)
April... initial-values(7:2)
a general case derived from month number...
initial-values((monthNum * 2) -1:2)
No need for REDEFINES or OCCURS... and almost certainly more efficient
(depends on compiler optimization and platform...) but perhaps not as
immediately obvious as the original description.
I am not sure how you came to the conclusion that an expression with a multiply and subtraction followed by a substring could be "almost certainly more efficient" than a simple index.
Because I was thinking of the fixed cases which are resolved at compile time. :-)
I agree that the general case might require more cycles... (You still
have to calculate your subscript for the general case though, so there wouldn't be that much in it...)
Anyway the result of the substring is not numeric so in addition it probably needs to be moved to a PIC 99 or such.
That's a very good point and I missed it...
Pete.
--
I used to write COBOL; now I can do anything...
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 1,030 |
Nodes: | 10 (0 / 10) |
Uptime: | 58:49:08 |
Calls: | 13,349 |
Calls today: | 1 |
Files: | 186,574 |
D/L today: |
729 files (186M bytes) |
Messages: | 3,358,503 |