>I have a table that contains 7 columns. The first 6 columns contain payroll deductions. The 7th column has information on types of deduction being held in the columns 1 thur 6. My problem is that I have to parse the information in 7th column. The order in which the names appear in 7th column determines which 1 thru 6 columns contain the deductions. For example:
>
>first record
>col1 = 68
>col2 = 35
>col3 = 45
>col4 = 0
>col5 = 0
>col6 = 0
>col7 = "HLTH01 CCAPE C INS" ---> need to be parse to hlth01, ccape, c ins
>
>so HLTH01 = 68, CCAPE = 35 and C INS = 45
>
>
>second record
>col1 = 50
>col2 = 60
>col3 = 70
>col4 = 80
>col5 = 0
>col6 = 0
>col7 = "HLTH01FLXD CCAPE UTWAY" ---> need to be parse to hlth01, flxd, ccape, utway
>
>so HLTH01 = 50, FLXD = 60, CCAPE = 70 and UTWAY = 80
>
>
>as you can see the names in col7 can run into each such as HLTH01 and FLXD. They can also contain spaces between name such as "C INS". How can I go about searching in the sting for a particular name and also determine what position those name are in reference to deduction columns 1 thur 6. I hope I haven't confused anyone. thanks
>
>Nick Patel
Hi Nick,
I think about one algorithm here, though I'm not sure, it's the best from optimization point of view (Ed Rauh definitely would suggest WSH algorithm :))
Ok, these are the steps:
1) Create two dimensional array of all possible codes, like:
dimension aCodes[100,2]
select code from LookCode into array aCodes
for i=1 to 100
store 0 to aCodes[i,2]
next
2)
use yourtable
scan
for i=1 to 100
aCodes[i,2]=atc(aCodes[i,1],col7)
next
endscan
=asort(aCodes,1,2)
3) Array is sorted now by second index
lnCol=0
for i=1 to 100
if aCodes[i,2]>0
lnCol=lnCol1+1
store evaluate('col'+lnCol) to &aCodes[i,1]
endif
next
I've just written this off the top of my head, so you should tweak this code a little. But you will get the idea.
Hope this helps.
If it's not broken, fix it until it is.
My Blog