Focal Point
[CLOSED] In variable with comma seprated values

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

March 25, 2011, 09:09 AM
Deepu
[CLOSED] In variable with comma seprated values
Hi

can any one give solution for this how to do

Select Emp_ID from emp ;

TABLE FILE SQLOUT
PRINT EMP_ID
ON TABLE HOLD AS EMP_VAL FORMAT ALPHA
END

-RUN
-READ EMP_VAL &EMPID.A10

Values will be storing in this variable(&EMPID) like this (101 102 103 104 105)

But I need to store these values in variable(&EMPID) like this &EMPID = 101,102,103,104,105

and this varable(&EMPID) i need to use in SQL Query

How to do for loop in webfocus ,plz how to do this

This message has been edited. Last edited by: Kerry,


WebFOCUS 7.6
Windows, All Outputs
March 25, 2011, 09:51 AM
j.gross
Here's one way:

TABLE FILE CAR
PRINT 
 COMPUTE SEQ/I4=SEQ+1; NOPRINT
 COMPUTE COMMA/A1=IF SEQ EQ 1 THEN ' ' ELSE ','; 
 CAR
BY CAR NOPRINT
ON TABLE SET HOLDLIST PRINTONLY
ON TABLE HOLD AS CARLIST FORMAT ALPHA
END


and then
select...
where widget in (
-INCLUDE CARLIST
)
March 29, 2011, 05:28 AM
Deepu
-SET &ECHO = ALL;
TABLE FILE CAR
PRINT SEATS
ON TABLE SAVE AS HCOUNTRY
END
-*?FF HCOUNTRY
-*-EXIT
-RUN

-SET &COUNTER=&LINES - 1;
-READ HCOUNTRY &STRING1.A3 NOCLOSE
-SET &STRING = TRUNCATE(&STRING1.EVAL);
-REPEAT READLIST &COUNTER.EVAL TIMES

-READ HCOUNTRY &VALUE1.A3
-SET &VALUE= TRUNCATE(&VALUE1.EVAL);

-SET &STRING='&STRING.EVAL'||','||'&VALUE.EVAL';
-READLIST
-TYPE &STRING


WebFOCUS 7.6
Windows, All Outputs
March 29, 2011, 05:43 AM
FrankDutch
Deepu

once you have stored the values in a alhpa hold file you can also say


TABLE FILE EMP
PRINT ID
ON TABLE HOLD FORMAT ALPHA
END

TABLE FILE XXXX
PRINT whatever
WHERE KEYFIELD IN FILE HOLD
END


There is a limit on the size of the hold file, the limits depend on the fieldsize and the number of records.




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

March 29, 2011, 09:55 AM
jfr99
Here's another example using the CAR file.

-*
-** This creates a file of 5 EMP_ID's using the CAR file (holds as SQLOUT)
-*
DEFINE FILE CAR
CNTR/I5 WITH CAR = CNTR + 1;
EMP_ID/A3 = DECODE CNTR (1 '101' 2 '102' 3 '103' 4 '104' 5 '105');
END
-*
TABLE FILE CAR
PRINT EMP_ID
WHERE RECORDLIMIT EQ 5
ON TABLE HOLD AS SQLOUT FORMAT ALPHA
END
-*
-** This creates one record of all EMD_ID's seperated by commas (holds as EMP_VAL)
-** NOTE: works for up to 100 EMP_ID's(If you need more - change the EMP_LIT define statement)
-*
DEFINE FILE SQLOUT
EMP_LIT/A399 = IF EMP_LIT EQ ' '
THEN EMP_ID
ELSE SUBSTR(399, EMP_LIT, 1, 395, 395, 'A395') || (',' | EMP_ID);
END
-*
TABLE FILE SQLOUT
SUM EMP_LIT
ON TABLE HOLD AS EMP_VAL FORMAT ALPHA
END
-RUN
-*
-** This reads the EMP_VAL hold file(one record) into the EMPID variable
-*
-READ EMP_VAL &EMPID.A399
-*
-** This displays the EMPID variable
-*
-TYPE *****************************************************************
-TYPE EMPID --- &EMPID
-TYPE *****************************************************************
-EXIT

Hope this helps.

Jim


WebFocus 8.201M, Windows, App Studio
March 29, 2011, 09:58 AM
Tom Flynn
Just shows the flexibility and the many ways to climb the WF mountain! No limitations on this...

  
-SET &LOOP   = 0;
-SET &EMPID  = '101 102 103 104 105 106 107 108 109 110';
-SET &EMP_ID = '';
-*****************************************************
-BUILD_TEST
-*****************************************************
-SET &LOOP   = &LOOP + 1;
-SET &XEMPID = GETTOK(&EMPID, &EMPID.LENGTH, &LOOP, ' ', &EMPID.LENGTH, 'A&EMPID.LENGTH');
-IF &XEMPID EQ '' GOTO BUILD_DONE;
-SET &EMP_ID = IF &LOOP EQ 1 THEN &XEMPID ELSE &EMP_ID || ',' || &XEMPID;
-GOTO BUILD_TEST
-*****************************************************
-BUILD_DONE
-SET &WHERE_BUILD = 'WHERE EMPL_ID IN (' || &EMP_ID || ');';
-*****************************************************
-TYPE  &WHERE_BUILD
-EXIT



Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
March 29, 2011, 05:02 PM
Waz
Are the values in a single field ?


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!