Ok, third reply to myself :)
>>>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:
>>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.
>
>Nick,
>
>Here is another algorithm.
<snip>
Would not work, as I realized at the way home. I was so concentrated on this problem, that got out on the wrong stop :(
This is the corrected algorithm:
select code from LookCode into array aCodes
lnLen=_tally
use yourtable
lnSize=0
for i=1 to lnLen
lnPos=atc(aCodes[i,1],col7)
if lnPos>0
lnSize=lnSize+1
dimension laPosCodes[lnSize,2]
laPosCodes[lnSize,1]=aCodes[i,1]
laPosCodes[lnSize,2]= lnPos
endif
next
=asort(laPosCodes,1,2)
lnCol=0
for i=1 to lnSize
lnCol=lnCol1+1
store evaluate('col'+transform(lnCol)) to &laPosCodes[i,1]
next
If it's not broken, fix it until it is.
My Blog