× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Peter,

The CL language is not well suited for this sort of thing, since it doesn't have arrays. I think it's important to remember that what you are writing is source code -- under the covers, the data is not really accessed by a variable name. That's just done in source code to make it easier for the programmer. In reality, data is located in your computer's storage, and accessed by a storage address. So calculating a variable name at runtime in an expression doesn't make a lot of sense -- there is no variable name at run time.

What you can do, however, is force all of the data to be in a contiguous space in member, and access it by calculating the memory position. This could either be done with pointers, or perhaps it's simpler to use substrings.

For example, you could do this:



DCL VAR(&MEMBER) TYPE(*CHAR) LEN(10)
DCL VAR(&ALLMBR) TYPE(*CHAR) LEN(600)
DCLF FILE(YOUR-DSPF)

SNDRCVF

Now that you've got the &MEMBER01, &MEMBER02, etc variables filled in and given to your program, you can do something like this (this is where it starts to get awkward)

CHGVAR VAR(&ALLMBR) +
VALUE(&MEMBER01 *CAT &MEMBER02 *CAT &MEMBER03 +
*CAT &MEMBER04 *CAT &MEMBER05 *CAT &MEMBER06 +
*CAT &MEMBER07 *CAT &MEMBER08 *CAT &MEMBER09 +
*CAT &MEMBER10 *CAT &MEMBER11 *CAT &MEMBER12 +
*CAT &MEMBER13 *CAT &MEMBER14 *CAT &MEMBER15 +
*CAT &MEMBER16 *CAT &MEMBER17 *CAT &MEMBER18 +
*CAT &MEMBER19 *CAT &MEMBER20 *CAT &MEMBER21 +
*CAT &MEMBER22 *CAT &MEMBER23 *CAT &MEMBER24 +
*CAT &MEMBER25 *CAT &MEMBER26 *CAT &MEMBER27 +
*CAT &MEMBER28 *CAT &MEMBER29 *CAT &MEMBER30 +
*CAT &MEMBER31 *CAT &MEMBER32 *CAT &MEMBER33 +
*CAT &MEMBER34 *CAT &MEMBER35 *CAT &MEMBER36 +
*CAT &MEMBER37 *CAT &MEMBER38 *CAT &MEMBER39 +
*CAT &MEMBER40 *CAT &MEMBER41 *CAT &MEMBER42 +
*CAT &MEMBER43 *CAT &MEMBER44 *CAT &MEMBER45 +
*CAT &MEMBER46 *CAT &MEMBER47 *CAT &MEMBER48 +
*CAT &MEMBER49 *CAT &MEMBER50 *CAT &MEMBER51 +
*CAT &MEMBER52 *CAT &MEMBER53 *CAT &MEMBER54 +
*CAT &MEMBER55 *CAT &MEMBER56 *CAT &MEMBER57 +
*CAT &MEMBER58 *CAT &MEMBER59 *CAT &MEMBER60 )

This is necessary because there's no guarantee that the display file will put these fields in consecutive memory. Concatenating them all into a single string will, however, guarantee that the data is consecutive.

Now that you have all your members in a single LEN(600) variable you can loop through them like this:

CHGVAR VAR(&MEMBER_FLG) VALUE('0')
DOFOR VAR(&POS) FROM(1) TO(591) BY(10)
CHGVAR VAR(&MEMBER) VALUE(%SST(&ALLMBR &POS 10))
IF (&MEMBER *NE ' ') DO
CHGVAR VAR(&MEMBER_FLG) VALUE('1')
ENDDO
ENDDO

This is untested, so I might've made a syntax mistake.. but it should be very close to being right.

Hopefully you get the idea.


On 1/4/2013 8:32 AM, Vidal, Peter wrote:
GM list!

I have seen this issue explained before but I do not know how to describe it better than giving you an example about it.

I have 60 fields on a single screen. All of the fields start with the prefix "MEMBER" and they have a numeric suffix between 01 and 60. I want to use a DOFOR to check all of them and turn on a flag whenever I find one of these fields with some content in it. I would like to do something like this:

DCL VAR(&COUNTER) TYPE(*INT) LEN(2)
DCL VAR(&CNTR) TYPE(*CHAR) LEN(2)
DCL VAR(&MEMBER) TYPE(*CHAR) STG(*AUTO) LEN(10)
DCL VAR(&MEMBER_FLG) TYPE(*LGL) STG(*AUTO) LEN(1)
.
.
.

CHGVAR VAR(&MEMBER_FLG) VALUE('0')
DOFOR VAR(&COUNTER) FROM(1) TO(60) BY(1)
CHGVAR VAR(&CNTR) VALUE(&COUNTER)
CHGVAR VAR(&MEMBER) VALUE('MEMBER' || &CNTR)
IF COND(&MEMBER *NE ' ') THEN(DO)
CHGVAR VAR(&MEMBER_FLG) VALUE('1')
ENDDO
ENDDO

Obviously this will not work, but is the idea of what I am trying to accomplish. Same thing if I have 60 indicators (from 01 to 60) on this display and I would like to turn them all off without doing:
CHGVAR VAR(&IN01) VALUE('0')
CHGVAR VAR(&IN02) VALUE('0')
CHGVAR VAR(&IN03) VALUE('0')
Etc., etc., etc. ...

Thank you for your advices in advance!
Peter Vidal

________________________________
This communication is intended only for the use of the individual or entity named as the addressee. It may contain information which is privileged and/or confidential under applicable law. If you are not the intended recipient or such recipient's employee or agent, you are hereby notified that any dissemination, copy or disclosure of this communication is strictly prohibited. If you have received this communication in error, please immediately notify CareCentrix Compliance Hot Line at (877) 848-8229 and notify the sender by electronic mail. Please expunge this communication without making any copies. Thank you for your cooperation.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.