>leftside topfields cellvalue >Z1 Dest1 1200 >Z1 Dest2 2000 >Z2 Dest1 3000 >Z1 Dest3 12000 >....and distinct count on topfields is suitable to generate an xtab (<=255) here is a simple xtab routine :
>* cOurtable is table name >*Leftside, topfields, cellvalue should be parametric or changed manually >*and correspond to above structure >lparameters cOurTable >select padr("AAAAAAA", fsize("TopFields",cOurTable)," ") as Field_name, ; > "C" as Field_type, ; > fsize("LeftSide",cOurTable) as field_len, ; > 0 as field_dec ; > from (cOurTable) ; > union ; > (select distinct chrtran(topfields," ","_") as Field_name, ; > "Y" as Field_type, ; > 8 as field_len, ; > 0 as field_dec ; > from (cOurTable) ; > where !empty(topfields) ) ; > into array aMyStruc >aMyStruc[1,1] = "Zones" && SQL would order it so "AAAAA" is top elem >select distinct LeftSide ; > from (cOurTable) ; > where !empty(leftside) ; > into array aMyZones >create cursor myXtab from array aMyStruc >for ix = 1 to alen(aMyZones,1) > scatter memvar blank > m.zones = aMyZones[ix] > select chrtran(TopFields," ","_"), CellValue ; > from (cOurTable) ; > where LeftSide == aMyZones[ix] ; > into array aCellValues > for jx = 1 to alen(aCellValues,1) > store aCellValues[jx,2] to ("m."+aCellValues[jx,1]) > endfor > insert into myXtab from memvar >endfor >browseCetin