Gods Of COBOL
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
Not a COBOL programmer, but here goes nothing: Comp-5 is a "native" binary format. Equivalent of "comp" type. pic 9(4) comp-5 is a two-byte unsigned binary 0 - 65535. Roughly in 'C, you are looking at: union { unsigned char buffer[2816] ; struct { unsigned short k01[37] ; unsigned short k02[1369]; } a ; } mem_area_one ; The layout of the two-bytes is platform specific ("native"), so if the COBOL is running on a PC platform, the two-bytes are stored in memory reversed (value of 12 decimal is stored as 0x0c00 in byte order).
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
As previously pointed out, MEMORY-AREA-ONE is a string of 2816 characters [PIC X(...) is the method by which character data is reserved/declared, and space assigned for it]. The REDEFINES... is a common COBOL method for permitting memory/data to be accessed in multiple ways. The C/C++ equivalent would be a "struct" definition with a "union" component -- you can access the memory using either elements of the struct, or elements of the union. Most "COMP-xx" data definitions are implementor-defined, so you will need the specific COBOL documentation for the machine upon which this code was implemented. IBM was a big user of COMP-xx declarations, and had several flavours of them, so you could have true floating-point, or packed-decimal data in a COBOL program by using their COMP-xx datatypes. Without the specific documentation, it is impossible to say exactly how the redefined data mask would lay out over the original character space. These kinds of implementor-defined situations always made conversions from one mainframe machine architecture to another somewhat interesting. The INDEXED BY clauses instruct the compiler to reserve specific indexes for iterating through the array created by the OCCURS clause. The assignment of an index usually translated (at the machine hardware level) into the use of a reserved index register. This was done for performance, rather than using a memory-based byte/word for storage of the array index value. As such, you don't need to be too worried about the INDEXED BY clause, as it's more a compiler instruction than anything else. Hope this helps. Norm Powroz Former member, CODASYL COBOL Committee (the people who designed the language) Former Member, ISO COBOL Experts Group Former Member, CSA COBOL Working Group ...and I'm not retired yet ;)
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
COBOL pre-allocates memory for everything in the code at runtime. All variables used are created in the WORKING STORAGE section. Nothing is dynamically created or destroyed in a garbage collection sweep. PIC X is a byte of memory, so PIC X(2816) is a block of memory taking 2816 bytes. By default, "PIC" will use the translation base of the machine, e.g. EBCDIC on a mainframe or ASCII on most anything else. "COMP" data types are a way to pack numeric values into a smaller number of bytes, much like INT and FLOAT. PIC 9 is a numeric data type. PIC 9(4) uses 4 bytes of memory to contain the number. PIC 9(4) COMP-5 in particular is a 32-bit signed float. "OCCURS" is used to create an array. "INDEXED BY" also creates the index to the array at the same time. "REDEFINES" means "uses the same memory space as". Putting it all together: 01 MEMORY-AREA-ONE is simply a block of memory using 2816 bytes. Inside that block of memory, there are two float arrays, one called K01-1 with 37 elements, and the other called K02-1 with 1369 element. To reference a given element in an array, you first assign a value to the index, then you can get what you need from the array. e.g. "MOVE 1 TO KO1-1-X." followed by "ADD K01-1 (KO1-1-X) TO TOTAL." I don't know why you use a REDEFINES for a bunch of floats, unless you needed to dump all of them to an output file for some reason, then it's only 1 line of code, rather than writing the loop logic. (I'm a 2nd-gen coder. The old man taught me this stuff when I was 14. His lab classes when he was in school were "paper-tape in, oscilloscope out" and they programmed in binary. He used to quote "Assembler was a godsend." I'm attending the VS 2010 launch in 15 minutes.) Good luck.
-
This is nothing more than a string (alphanumeric) 2816 characters
Chris Losinger wrote:
01 MEMORY-AREA-ONE PIC X(2816).
that second section
Chris Losinger wrote:
01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
Pic 9(04) COMP-5 is a 4 byte numeric stored in machine independent format Essentially, those two lines redefine the space originally defined by MEMORY-AREA-ONE into two blocks of unsigned 16-bit integers. I cannot recall what the INDEXED allows you to do anymore ... Not sure any of that helps you ... [edit] You might also considering hitting up the COBOL User Groups[^] for help with this, and/or other COBOL related issues you might have. Just a thought.
:..::. Douglas H. Troy ::..
Bad Astronomy |VCF|wxWidgets|WTLmodified on Friday, April 9, 2010 5:51 PM
Dougs' replay was the closest thing to correct so far. 01 MEMORY-AREA-ONE PIC X(2816). This just defines a 2816 byte vaariable and the PIC X means it's alphanumeric 01 REDEFINES MEMORY-AREA-ONE This says your going to redefine that chunk of data into a different structure/layout 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. These 2 lines make an array of 37 four digit numbers (0000-9999) and gives you a subscript named K01-1-X to reference entries 1-37 remember COBOL subscripts start at 1 not zero. This K01-1 array actually exists in the first 74 bytes of MEMORY-AREA-ONE The COMP-5 or any COMP in COBOL basicall says to save space by representing the numbers in memory (like they should) in a binary format. COBOL will basically use a string for numbers is you don't use COMP (1 byte for each digit) 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5. This is basically the same except it uses bytes 75-2812 of MEMORY-AREA-ONE to define and array of 1369 four digit numbers and gives you subscript K02-1-X to reference it. I'd say the original author didn't quite understand COBOL either as you dont need to define extra space in the MEMORY-AREA-ONE for the subscripts. if it was 01 MEMORY-AREA-ONE PIC X(2812) it would have worked the same.
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
This does not appear like a valid definition. Since "9(04) COMP-5" represents a 2-byte integer number and (37 + 1369) * 2 = 2812 and not 2816, you are certainly missing some further variable definitions or the COBOL program itself does not compile (or, if it does, it is not a very well made program). "INDEXED BY" just means that the tables defined by names K01-1 and K02-1 can be searched for values using built-in SEARCH function(s).
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
MEMORY-AREA-ONE is defining an alph-numeric space of 2816 bytes aligned to a work boundary The redefines is overlaying the mapping ( similar to a C union ) with two arrays of compresses numeric ( check your compiler doc regarding how these are represented internally ). The punch line is that 9(04) COMP-5 takes two bytes. My math may be off, but it looks like the original space has four extra bytes
-
MEMORY-AREA-ONE is defining an alph-numeric space of 2816 bytes aligned to a work boundary The redefines is overlaying the mapping ( similar to a C union ) with two arrays of compresses numeric ( check your compiler doc regarding how these are represented internally ). The punch line is that 9(04) COMP-5 takes two bytes. My math may be off, but it looks like the original space has four extra bytes
asherw0202 wrote:
My math may be off, but it looks like the original space has four extra byte
that's what it looked like to me, too. and that's really the primary reason i asked the question - why define an overlay/alias that doesn't fit the original memory ? is that intentional but sloppy, or is there some tricky COBOL thing that explains it?
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
I took a programming class years ago. Fortran & Cobol were all the rage for undergrds. The languages of the future... Something about formatted/organized/parsing clicked. From:http://www.cse.ohio-state.edu/~sgomori/314/langref.html#occurs[^] Occurs Occurs is used to define a table. It is followed by the number of elements in the table. COBOL does not support dynamic tables - the size must be specified. 01 WS-TABLE. 05 WS-ELEMENT OCCURS 100 TIMES PIC 9(5). Defines a table with 100 elements Index Subscripts and indexes are the two tools used to reference individual elements of a table. ... An index is created automatically by the system if it is directed to do so and only has limited availability to the programmer. Sounds like Memory area one is to be treated as tabular data and accessible by a column/row indexing scheme. Maybe.
-Bob
-
anybody here know COBOL ? what does this do?
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
i thought i understood what redefine and occurs meant, but i can't figure out what this declaration does. (funny answers are welcome!)
INDEXED BY means that K01-1 is an array that uses K01-1-X as the array subscript. Information on the PIC 9(04) COMP-5 found at http://www-01.ibm.com/software/awdtools/cobol/os390/about/ : Data items declared with the new USAGE COMP-5 data type are represented in storage as binary data and can contain values of magnitude up to the capacity of the native binary representation (2, 4, or 8 bytes). With USAGE COMP-5, data values are no longer limited to the value implied by the number of 9s in the picture for the item. These enhancements help your COBOL applications to exploit the open, network-computing environment, making COBOL a more powerful application development tool. From what I remember of COBOL, K0x numbers were normally used as database keys. This particular piece of code probably has around it a SCHEMA SECTION that defines the database that this memory area becomes the KeyIDs for. K01 and K02 are most likely lookup tables for some information found elsewhere in the code. Where did you find the vacuum tube that held this?
-
INDEXED BY means that K01-1 is an array that uses K01-1-X as the array subscript. Information on the PIC 9(04) COMP-5 found at http://www-01.ibm.com/software/awdtools/cobol/os390/about/ : Data items declared with the new USAGE COMP-5 data type are represented in storage as binary data and can contain values of magnitude up to the capacity of the native binary representation (2, 4, or 8 bytes). With USAGE COMP-5, data values are no longer limited to the value implied by the number of 9s in the picture for the item. These enhancements help your COBOL applications to exploit the open, network-computing environment, making COBOL a more powerful application development tool. From what I remember of COBOL, K0x numbers were normally used as database keys. This particular piece of code probably has around it a SCHEMA SECTION that defines the database that this memory area becomes the KeyIDs for. K01 and K02 are most likely lookup tables for some information found elsewhere in the code. Where did you find the vacuum tube that held this?
USAmab wrote:
Where did you find the vacuum tube that held this?
the US govt...
-
USAmab wrote:
Where did you find the vacuum tube that held this?
the US govt...
Funny, that's who I work for. Which DIVISION and SECTION is this piece of code in?
-
Funny, that's who I work for. Which DIVISION and SECTION is this piece of code in?
am i allowed to say ? :) it's a NCOA thing, for the USPS.
-
am i allowed to say ? :) it's a NCOA thing, for the USPS.
I work for a contractor. The DIVISION and SECTION that the code is in would be helpful, as the code would have a different function depending on where it is located. If in the SCHEMA SECTION, this is most likely a set of Key lookup tables. If in the LINKAGE SECTION, this could be a subroutine pass from another programming language. If this is in the WORKING-STORAGE SECTION, it's possible that the original programmer was trying to write a piece of code in Assembler and have it called as a binary routine. If this is the case, there will be a LOADING paragraph in the PROCEDURE DIVISION.
-
I work for a contractor. The DIVISION and SECTION that the code is in would be helpful, as the code would have a different function depending on where it is located. If in the SCHEMA SECTION, this is most likely a set of Key lookup tables. If in the LINKAGE SECTION, this could be a subroutine pass from another programming language. If this is in the WORKING-STORAGE SECTION, it's possible that the original programmer was trying to write a piece of code in Assembler and have it called as a binary routine. If this is the case, there will be a LOADING paragraph in the PROCEDURE DIVISION.
ah... that section/division (still learning the COBOL lingo). it's in the data division, working-storage section. it's a temp in-memory table. the full def'n is actually:
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 MEM-ONE-CHUNK OCCURS 11 TIMES INDEXED BY MEM-ONE-X PIC X(256). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
it looks like that MEM_ONE_CHUNK thing only used to initialize the entire buffer.
MOVE LOW-VALUES TO MEM-ONE-CHUNK(1) PERFORM VARYING MEM-ONE-X FROM 2 BY 1 UNTIL(MEM-ONE-X > 11) MOVE MEM-ONE-CHUNK(1) TO MEM-ONE-CHUNK(MEM-ONE-X) END-PERFORM
that's the only place that particular redefine is used. seems like an odd way to do things.
-
ah... that section/division (still learning the COBOL lingo). it's in the data division, working-storage section. it's a temp in-memory table. the full def'n is actually:
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 MEM-ONE-CHUNK OCCURS 11 TIMES INDEXED BY MEM-ONE-X PIC X(256). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
it looks like that MEM_ONE_CHUNK thing only used to initialize the entire buffer.
MOVE LOW-VALUES TO MEM-ONE-CHUNK(1) PERFORM VARYING MEM-ONE-X FROM 2 BY 1 UNTIL(MEM-ONE-X > 11) MOVE MEM-ONE-CHUNK(1) TO MEM-ONE-CHUNK(MEM-ONE-X) END-PERFORM
that's the only place that particular redefine is used. seems like an odd way to do things.
What is the definition line in the WORKING-STORAGE SECTION for "LOW-VALUES"? It's probably an "01" or "77" line. If it's a "77" line, it will not have anything underneath it that subdivides it like the "01" lines do. Because of the ">" in the PERFORM statement, you are using a "newer" version of COBOL (the older - COBOL 68, 74 standards forced the relationals to be written out "IS GREATER THAN"). Not that that's helpful at this point, but you may be able to find the "newer" COBOL manual(s). Are there any COMMENTS in the IDENTIFICATION DIVISION that tell you what this program is supposed to do? I also wonder, does this program have a LINKAGE SECTION in it? If so, this code could be called from another program.
-
ah... that section/division (still learning the COBOL lingo). it's in the data division, working-storage section. it's a temp in-memory table. the full def'n is actually:
01 MEMORY-AREA-ONE PIC X(2816). 01 REDEFINES MEMORY-AREA-ONE. 05 MEM-ONE-CHUNK OCCURS 11 TIMES INDEXED BY MEM-ONE-X PIC X(256). 01 REDEFINES MEMORY-AREA-ONE. 05 K01-1 OCCURS 37 TIMES INDEXED BY K01-1-X PIC 9(04) COMP-5. 05 K02-1 OCCURS 1369 TIMES INDEXED BY K02-1-X PIC 9(04) COMP-5.
it looks like that MEM_ONE_CHUNK thing only used to initialize the entire buffer.
MOVE LOW-VALUES TO MEM-ONE-CHUNK(1) PERFORM VARYING MEM-ONE-X FROM 2 BY 1 UNTIL(MEM-ONE-X > 11) MOVE MEM-ONE-CHUNK(1) TO MEM-ONE-CHUNK(MEM-ONE-X) END-PERFORM
that's the only place that particular redefine is used. seems like an odd way to do things.
Chris, check your "image processing toolkit" support email address. I've sent you an email for offline help.
-
Hi Chris, you are aware there are a couple of .NET COBOL compilers around? you might be lucky and have a look at the IL your source generates; and reflector might be willing to show you equivalent C# or VB.NET code. And maybe you don't need to translate it after all, just run it... :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
Fujitsu Cobol.NET has been very very good to me! Was my bridge from the mainframe world to the .NET world. Converted a legacy MicroFocus COBOL financial system to a .NET system. While Fujitsu may be a pig, it enabled us to re-use complicated COBOL business logic and increase our delivery time. Can't say I miss coding in COBOL but, .... in another 15 years who knows what the market will be paying folks with COBOL knowledge :cool:
-
What is the definition line in the WORKING-STORAGE SECTION for "LOW-VALUES"? It's probably an "01" or "77" line. If it's a "77" line, it will not have anything underneath it that subdivides it like the "01" lines do. Because of the ">" in the PERFORM statement, you are using a "newer" version of COBOL (the older - COBOL 68, 74 standards forced the relationals to be written out "IS GREATER THAN"). Not that that's helpful at this point, but you may be able to find the "newer" COBOL manual(s). Are there any COMMENTS in the IDENTIFICATION DIVISION that tell you what this program is supposed to do? I also wonder, does this program have a LINKAGE SECTION in it? If so, this code could be called from another program.
LOW-VALUES is not a literal or a variable, but a "figurative constant". Commonly used to initialise variables, or areas of storage, or for comparisons like IF MY-VARIABLE > SPACES THEN ... LOW-VALUES means binary zeros, the lowest thing possible in the collating sequence. HIGH-VALUES means binary ones, the highest value in the collating sequence. SPACES was the only other figurative constant that I remember. The practice of initialising one chunk of memory with a figurative constant, then using a loop to copy that chunk, was a performance optimisation, minimising the size of the object code and the run time taken. If I remember right, moving a figurative constant like "spaces" or "low-values" to up to 256 bytes took only one machine instruction, but if the target area was longer than 256 then the compiler generated a loop to set one byte at a time. So initialising 256 bytes, then looping to copy the 256 byte chunk, was faster for only a couple of bytes extra memory cost. This program, or at least this part of it, has been written with care by a skilled programmer putting in extra effort to produce a smaller faster runtime, instead of doing it the easiest way. So don't mock. Once upon a time, when dinosaurs roamed the earth, in my first year of programming I was tasked to make a suite of invoicing and sales ledger programs smaller, so that they would fit in whatever was going to be left over from the massive 64K of memory in our mighty 360/30 mainframe, after the new version of the IBM DOS/360 operating system was installed. We only had about 20 spare free with the previous version of DOS. No such thing as multi-programming or virtual memory, and the price of the next hardware upgrade had about five zeros on the end. I spent weeks rewriting little routines different ways and looking at the memory map of the generated code, changing all the literals like " " and " " or "XX" and "XXX" to multiple redefinitions of the same constants, thus saving the vital couple of hundred bytes.
-
Douglas Troy wrote:
Pic 9(04) COMP-5 is a 4 byte numeric stored in machine independent format
Machine-dependent format if I'm not mistaken. COMP-4 is machine independent.
-Sean ---- Fire Nuts
Correct The Comp-5 was i believe setup to handle the big-endian, little-endian problem. And COBOL is still better then many of the more advanced languages for many activities. Especially those that do batch processing. Admitably not good for interaction "GUI" processes. COBOL and FORTRAN did not survive this long and still constiture over 50% of operational systems by not being GOOD at what they do. New colorable clothes are not neccesarily better then older ones. Primitive people are always attracted to pretty baubles. Anyone want to exchange the latest and greatest hardware for some pretty beads i have.
-
LOW-VALUES is not a literal or a variable, but a "figurative constant". Commonly used to initialise variables, or areas of storage, or for comparisons like IF MY-VARIABLE > SPACES THEN ... LOW-VALUES means binary zeros, the lowest thing possible in the collating sequence. HIGH-VALUES means binary ones, the highest value in the collating sequence. SPACES was the only other figurative constant that I remember. The practice of initialising one chunk of memory with a figurative constant, then using a loop to copy that chunk, was a performance optimisation, minimising the size of the object code and the run time taken. If I remember right, moving a figurative constant like "spaces" or "low-values" to up to 256 bytes took only one machine instruction, but if the target area was longer than 256 then the compiler generated a loop to set one byte at a time. So initialising 256 bytes, then looping to copy the 256 byte chunk, was faster for only a couple of bytes extra memory cost. This program, or at least this part of it, has been written with care by a skilled programmer putting in extra effort to produce a smaller faster runtime, instead of doing it the easiest way. So don't mock. Once upon a time, when dinosaurs roamed the earth, in my first year of programming I was tasked to make a suite of invoicing and sales ledger programs smaller, so that they would fit in whatever was going to be left over from the massive 64K of memory in our mighty 360/30 mainframe, after the new version of the IBM DOS/360 operating system was installed. We only had about 20 spare free with the previous version of DOS. No such thing as multi-programming or virtual memory, and the price of the next hardware upgrade had about five zeros on the end. I spent weeks rewriting little routines different ways and looking at the memory map of the generated code, changing all the literals like " " and " " or "XX" and "XXX" to multiple redefinitions of the same constants, thus saving the vital couple of hundred bytes.
Chris, I think LockH is correct here in the description of producing a smaller faster runtime. That was because of the expense associated with the actual machine run-time allocation. That said, I think what this is doing is ensuring that the memory area used by K01 and K02 does not contain any incorrect or "ghost" information in the memory that could cause untraceable error messages within the program. You'll have to track down the actual use of the K01 and K02 and determine what those were used for. Something else to consider: COBOL was written for batch processing. It was only in the later years that the computer time became inexpensive enough to begin interactive processing. That said, this is most likely a "run this once a month, once a week, once a quarter" type program. That may help you in the detective work for the actual use of the program and/or the actual use of the environment that is being created here.