Hi
The best method I can think of is also a bit complex ...
Code:
working-storage section.
01 var-length pic 9(05).
linkage section.
01 my-var pic x(100).
1. Call your compiler's function for allocating memory and give it the number of bytes you need to allocate.
2. Set the address of my-var to the address returned by the function.
Personally, I use ACU Cobol, so I would use this:
Code:
procedure division.
main-paragraph.
move 50 to var-length
call "M$ALLOC" using var-length, address of my-var
move all "*" to my-var(1:var-length)
display my-var(1:var-length)
call "M$FREE" using my-var
The DISPLAY command will display 50 stars. It's imrpotant to note that you MUST free the memory when you're doing with it (although the runtime would probably do it for when it shuts down, but still ...).
Also, the size of my_var must have an upper limit defined inthe linkage section (in this case 100) even though you may never reach that size. Just because you're defining it as x(100), though, doesn't mean it takes 100 bytes. It'll only take what you specified in the call to M$ALLOC.
Last but not least - make sure you never do anything in the unallocated area of my_var (i.e. my_var(51

). The results could be a little unpredictable as this is unassigned memory.
Hope that helps
![[smile] [smile] [smile]](/data/assets/smilies/smile.gif)
.DaviD.