View Full Version: Dynamic Variables In Cobol/4gl

LawsonTalk > Coding, Program Errors and Bugs > Dynamic Variables In Cobol/4gl


Title: Dynamic Variables In Cobol/4gl
Description: Is this possible?


mmrobinette - November 17, 2007 11:50 PM (GMT)
hey all

i'm looking for some coding advice. i've found myself in a position where using dynamic reference of variables would be greatly beneficial.

essentially what i'm trying do is be able to reference variables i named sequentially. here is an example of how i named them.

WS-FUND-1
WS-FUND-2
WS-FUND-3

what i'm wondering is if i could reference the numerical portion of this variable in a loop. essentially something like.

move variable-x to WS-FUND-(x).

is there a way to do this in cobol??

It would save me a lot of coding. Otherwise I'll be writing IF-THEN-ELSE statements for as many scenarios as i can expect.

does this make sense? is there a way?

mmrobinette - November 18, 2007 02:02 AM (GMT)
ALSO

I need to further clarify that I'm not looking to do an occurs clause for an array. To be very specific i'm looking to do some dynamic column heading assingments. That way I could name them sequentially and then reference them like an array OR like a derived field in a lawson table. If anyone can make sense of my madness please advice. THANKS.

MannieJ - November 19, 2007 04:33 PM (GMT)
Yes this is doable. We have a lot of 4GL programs that use dynamic variables for either output files (csv) or for reporting. As an example would be a benefit statement form. We have a lot of benefit types and we use dynamic variables for field headings etc during open enrollment. Your COBOL programmers should be able to do this easily.

mmrobinette - November 19, 2007 04:48 PM (GMT)
Actually I was wondering if you could give me an example. I am the cobol programmer but have never used dynamic variables. And they will be used for naming of column headings dynamicly based on user parameters.

Any help would be appreciated.

MannieJ - November 19, 2007 05:38 PM (GMT)
Basically in your .rpt file(report), you basically define all your field headings, title etc as all X's (this will be an unknown variable) in can be as any length up to 132 characters. You will also define the same in WS and further redefines the field into several fields that is required. There will also be a corresponding items (88) that will be defined so your PERFORM statements will be pointed to the correct items or variables.

I have to catch my plane so this should give you a hint of what should it look like.

Milo - November 19, 2007 06:01 PM (GMT)
You can use an array. COBOL does not do dynamic variable manipulation, because all variables are are stated up-front in the the Data Division. That's the reason it's so good for business programming.

With arrays and 88's you can effectively get the same result.

Also, although COBOL isn't good with string manipulation, Lawson provides the 500-series API's for working with strings. I've used some of those routines when working with employee names, in order to get names formatted into a "nice and readable" format. Check the API manual.



Hosted for free by InvisionFree