AK,
This is a perfect example for the use of the McGuyver technique. Please see the following files:
AK master:
FILE=AK, SUFFIX=FIX
SEGNAME=SEG1, SEGTYPE=S0
FIELD=DEPT, ALIAS=DP, USAGE=I3, ACTUAL=A3, $
FIELD=CITIES, ALIAS=CTS, USAGE=A50, ACTUAL=A50, $
AK data:
001Chicago,Lisle,Naperville
002Detroit,Southfield,Kalamazoo
003New York,Albany
004Washington
005San Francisco,Los Angeles,San Diego,Beverly Hills
Now the McGuyver file (with heartfelt thanks to Noreen!). Master:
FILENAME=FSEQ,SUFFIX=FIX
SEGNAME=CHAR1,SEGTYPE=S0
FIELDNAME=BLANK,BLANK,A1,A1,$
SEGNAME=CHARS,SEGTYPE=S0,PARENT=CHAR1,OCCURS=VARIABLE
FIELDNAME=CHAR,CHARS,A1,A1,$
FIELDNAME=COUNTER,ORDER,I2,I4,$
And the McGuyver data file (!! Very important-the data must start with a blank !!):
FILEFORMCGUYVERFILEFORMCGUYVERFILEFORMCGUYVERFILEFORMCGUYVERFILEFORMCGUYVER
And finally the focexec to solve your problem, taking into account that one knows the maximum number of cities in the CITIES field:
-* File AK1.fex
-SET &ECHO=ALL;
-SET &MAXCITY=4;
-*
-* Location of data files (AK doesn't need the AK since the data comes from an SQL table)
FILEDEF AK DISK C:\ibi\apps\focalpoint\AK.ftm
FILEDEF FSEQ DISK C:\ibi\apps\focalpoint\fseq.dat
-RUN
-*
-* This Join allows the multiplication of AK records in order to extract subsequent cities
JOIN BLANK WITH DEPT IN AK
TO BLANK IN FSEQ AS M_
END
-*
-* BLANK for joining to McGuyver
-* one CITY is extracted from the string for every value of COUNTER
DEFINE FILE AK
BLANK/A1 WITH DEPT=' ';
CITY/A25=GETTOK(CITIES, 50, COUNTER, ',', 25, 'A25');
END
-*
-* Limit the number of occurence to &MAXCITY and to non-blank values of CITY
TABLE FILE AK
PRINT CITY
BY DEPT
IF COUNTER LE &MAXCITY
IF CITY NE ' '
END
See if it works.
Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF