Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Field sizes in ACU COBOL 1

Status
Not open for further replies.

MuadDubby

Programmer
Sep 23, 1999
236
0
0
CA
I am trying to dynamically find out the size of a field (a 01 level with all its sublevels for e.g.). In other words, I'm running my program, and during execution I need to know how big a certain field is. I know I could hard code it, but I want to prepare for eventual changes to the field size, and not have the programmers go to every instance in the code where the size is used. <br><br>I'm basically looking for the ACU equivalent of the C function sizeof() ...
 
What about:<br><br>MOVE LENGTH OF SOMETHING TO LENGTH-OF-SOMETHING.<br><br>Length has a picture of S9(9) COMP.<br><br>I am not sure if this is a standard COBOL feature, but I use it for a long time in several environments.
 
Length of is an extension in some COBOL variants.<br><br>You can use, however:<br><br>Compute field-length = function length (01-Level).
 
Thanx to both of you for the info. Is &quot;FUNCTION LENGTH&quot; an extension just like &quot;LENGTH OF&quot;? I'm dealing with ACU Cobol here, and I found it to be pretty limited as far as extensions are concerned.
 
Thank you, but it didn't work. I tried both approaches, btw.<br><br>I guess ACU isn't very interested in supporting anything besdies the ANSI standard.<br><br>If anyone has any suggestions, I'd really appreciate it.<br><br>Thank you.
 
In the AcuCobol GT manuals (Version 4.3.0) I found the following : <br><br>SET result-item TO SIZE OF data-item <br><br>The number of standard character positions occupied by data-item is stored in result-item. <br><br>Please try if it works.<br><br>
 
dixi -<br><br>You're a genious. It worked like a charm! I guess I have to take my rebuke on ACU back now ...
 
I would like to know if there is any chance to start a Cobol application from another programming language? Not by using C and AcuCobol API.

Thank you
 
Yes, you can start an AcuCOBOL program from another application, assuming the application can run an executable program (.exe) and can pass the necessary parameters so that you can do the equivalent of:

wrun32.exe program-name

In VB, I think you'd call ShellExecute. You can check the newsgroups/web for examples. Other languages generally support similar interfaces.

Good luck!
 
One way to figure out the length is to redefine the entire area with a field like
----------------------------------------------
01 storage-area.
05 storage-area-all pic x(999).
05 storage-area-fields redefines storage-area all.
10 field-1 pic x(30).
10 field-2 pic 9999.99 comp-3.
-----------------------------------------------

If you get the storage area correctly it will compile with no error and no warnings. If the redefined area is not the right size, you will either get a warning or an error, depending if it is too large or too small.

You may be able to use the map compile option and make the compiler tell you what the size of a group element is.

You could try using an inspect with tallying counting all positions in the field, and just display or print the result.

None of these suggestions are Acucobol specific. If you do not like my post feel free to point out your opinion or my errors.
 
Nice idea, but this only tells me the size of the field at compile time, not runtime. I want to keep it so that all the programmer has to do (if necessary) is enlarge the field he is working on and nothing else. The rest of the program will adapt to the new size during runtime.

In any case, Dixi posted a great method up above. But thanx none the less!
 
Just to clarify.

FUNCTION LENGTH is in the current COBOL standard.

AcuCOBOL Supports it in v5 and later. If you have your target runtime set to v4.x you will still get errors trying to use it with v5, but I use the intrinsic functions with v5 all the time.

Your code will be transportable to other compilers as well this way.
 
Here is a way that doesn't use the new-fangled B-) functions.
Code:
01 LENGTH-OF-GROUP  PIC 999 VALUE 0.
01 LENGTH-OF-FIELD  PIC 999 VALUE 0.
01 GROUP-ITEM.
    05 FIELD1   PIC S999.
    05 FIELD2   PIC S9(5) PACKED-DECIMAL.
    05 FIELD3   PIC S9(3).
    05 FIELD4   PIC S9.
...
INSPECT GROUP-ITEM TALLYING LENGTH-OF-GROUP FOR CHARACTERS.
LENGTH-OF-GROUP contains the desired length. Don't forget to move zero to LENGTH-OF-GROUP if you want to reuse this throughout your code (TALLYING does not initialize the tallying data-item).

You can use reference modification to get the number of character positions in a numeric:
Code:
INSPECT FIELD2 (1:) TALLYING LENGTH-OF-FIELD FOR CHARACTERS.
 
Hmmm ... not too sure about that one. Won't the reported size of your 01 level be a little off because of memory alignment on PACKED DECIMAL or COMP items? Although it makes theoretical sense, this method seems a little dangerous to me.
 
Not dangerous at all. FUNCTION LENGTH on a group item includes the length of all implied FILLER (due to alignment); so will this.

Not just theory, as I used this technique long before intrinsic functions made their debut in COBOL, and for exactly the same reason stated in your Aug 21 post.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top