Page 1 of 1

getlabel by position

Posted: March 6th, 2018, 6:32 am
by AriSilva
Hi folks,
I´m using the getlabel function to retrieve the labels in the valueset of a variable.
The problem is that we have to know in advance which are the existing values in the valueset. For example, if the values are 1....9, I can execute a do loop retrieving them
do varying i = 1 until i > 9
x = getlabel(E17_MENOS_VS1,i);
enddo;

But suppose that the values are not in order, like 1,4,8,9,17,99?
Then I would have to retrieve them one by one.
What I´m suggesting is that we might have something like the dynamic setvalueset, for example, getvalueset, but instead of returning a single value for the function, it would return the values and the labels in the arrays. Like
getvalueset(DISTRICT_VS1,vsCodes,vsLabels);

Or a function to retrieve the codes and another function to retrieve the labels for an index in the valueset. For example:
getvaluesetcode(district_vs1,i);
getvaluesetlabel(district_vs1,i);
where i would be the ith entry in the valueset.

We might need also the size of the valueset, in order to execute that in a do loop, like
do varying i = 1 until i > lentgh(district_vs1)
x = getvaluesetcode(district_vs1,i);
y = getvaluesetlabel(district_vs1,i);
enddo;

I know it is a little bit farfetched, but why not?
Best
Ari

Re: getlabel by position

Posted: March 6th, 2018, 9:42 am
by Gregory Martin
There has been discussion about adding enhanced value set operations in a future release. For now, you can skip over unused values by checking if getlabel returns blank. This code would allow you to only process the values in your value set:
do ctr = minvalue(FIELD_NAME) while ctr <= maxvalue(FIELD_NAME)

    if getlabel(FIELD_NAME,ctr) <> "" then
        // process
    endif;

enddo;