Focal Point
[SOLVED] Distinct values in maintain stack

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3247068126

July 03, 2012, 12:54 AM
Shankar
[SOLVED] Distinct values in maintain stack
Hi All,
I have a DB table column. I want to fetch only distinct values of that column in stack and then populate a combox with those values. e.g, In CAR, We have COUNTRY column which has multiple instances of same values. I want to fetch only distinct values ENGLAND,JAPAN,ITALY and W GERMANY in a stack and then associate it with ComboBox so that in dropdown, only these values appears once. How can we achieve this? Please Suggest.

Thanks in advance.

This message has been edited. Last edited by: Kerry,
July 03, 2012, 03:27 AM
Alan B
The easiest approach is to EXEC a focexec to retrieve the values using a BY fld. It would generally be a rule of thumb that list boxes and combo boxes are populated like this.

Trying to do this based on the values in a stack is doable but much more complex.

For example, to get a unique list of midinitial from an EMPDATA stack called empStack into initStack Mid:
case popStack
Declare (i/i4;j/i4;);
j=2;
stack sort empStack by midinitial;
repeat empStack.foccount i = 1;
if i eq 1 begin 
  initStack(i).Mid = empStack(i).midinitial;
  goto endrepeat;
endbegin
if empStack(i).midinitial eq empStack(i-1).midinitial goto endrepeat;
initStack(j).Mid = empStack(i).midinitial;
j=j+1;
endrepeat i=i+1;
EndCase



Alan.
WF 7.705/8.007
July 03, 2012, 07:41 AM
Shankar
Thanks a lot Alan B.

Warm Regards,
Anil


WF 8.1.04,Windows 7,
DataBase: Oracle 11g,Output :Excel,PDF,HTML
April 09, 2013, 06:12 AM
Chirag
Hi,

Can somebody help me with easier approach of calling a focexec to get the distinct values in a dropdown on a maintain screen.

Regards,
Chirag
7.6.11
OS: Linux
April 09, 2013, 06:58 AM
Alan B
Chirag

This is basic Maintain code covered on the training courses. It is essential that you take these courses.

To call a focexec:
MAINTAIN

$$Declarations

Case Top
$$ Create a stack field to take the focexec output.
empStack.DEPARTMENT/a10;
$$ Call the focexec, simple approach
exec getDepartment into empStack;
Winform Show Form1; 
EndCase

END
and the focexec getDepartment:
TABLE FILE EMPLOYEE
BY DEPARTMENT
ON TABLE PCHOLD
END

Ensure that you have a stack field with field name and format matching the output of the focexec.


Alan.
WF 7.705/8.007
April 09, 2013, 07:48 AM
Maintain Wizard
I use this method when trying to get the distinct categories from the Movies file. Table has a DST operator that works great. In my Maintain I have:

EXEC GetCats INTO CATSTK


And GetCats is:
TABLE FILE MOVIES
PRINT DST.CATEGORY
ON TABLE PCHOLD
END
-RUN

Just remember to INFER CATSTK before the exec.

Mark
April 10, 2013, 05:37 AM
Chirag
Thanks Alan for the response. I had been away from maintain for couple of years. Again, had to deliver something. Thanks for your prompt response.

Regards,
Chirag