>>>I have a xtab query myself. I'm trying to limit the number of fields in a report to 16 the 1st field always. and loop back every 15 of the rest. Also I would like to break the loops (a do while and a for loop), when there is no more data. Here's what I have so far:
>>>
>>>SELECT xtab
>>>GO TOP
>>>lnFieldTot = 2
>>>DO WHILE !EOF()
>>>FOR lnFCnt = 1 TO 15
>>>SELECT xtab
>>>lcFName = FIELD(lnFieldTot)
>>>lcFCnt = STR(lnFCnt)
>>>IF lnFCnt < 10
>>>lcATAFName = "ATA_Report.project"+RIGHT(lcFCnt,1)
>>>ELSE
>>>lcATAFName = "ATA_Report.project"+RIGHT(lcFCnt,2)
>>>ENDIF
>>>IF lnFCnt = 1
>>>SELECT ATA_Report
>>>GO BOTTOM
>>>APPEND BLANK
>>>REPLACE ATA_Report.ata WITH xtab.exp_1
>>>ENDIF
>>>IF !EMPTY(lcFName)
>>>lnATAFValue = EVAL('xtab.'+lcFName)
>>>lcATAFValue = STR(lnATAFValue)
>>>SELECT ATA_Report
>>>GO BOTTOM
>>>REPLACE &lcATAFName WITH TRIM(lcATAFValue)
&& WILL NOT DO REPLACE>>>ENDIF
>>>lnFieldTot = lnFieldTot + 1
>>>IF lnFCnt = 15
>>>lnFCnt = 0
>>>ENDIF
>>>IF lnFieldTot > FCOUNT()
>>>llEnd = .T.
>>>EXIT
>>>ENDIF
>>>ENDFOR
>>>SELECT xtab
>>>SKIP
>>>IF EOF()
>>>IF!llEnd
>>>GO TOP
>>>ELSE
>>>EXIT
>>>ENDIF
>>>ENDIF
>>>ENDDO
>>>
>>>TIA
>>Perry,
>>I'm not sure I understood correctly but could this be what you want :
select xtab
>>lnNeededCopies = ceiling((fcount()-1)/15)
>>for ix = 1 to lnNeededCopies
>> lcFields = field(1)
>> for kx=(ix-1)*15+1+iif(ix=1,1,0) to min(ix*15,fcount())
>> lcFields = lcFields + "," + field(kx)
>> endfor
>> select &lcFields from xtab ;
>> into table ("xtab"+padl(ix,3,"0"))
>> use in ("xtab"+padl(ix,3,"0"))
>> select xtab
>>endfor
Cetin
>
>
>I'm taking data from xtab and inserting it into the other table the whole trouble lies in this section:
>
>
>lnATAFValue = EVAL('xtab.'+lcFName)
>lcATAFValue = STR(lnATAFValue)
>SELECT ATA_Report
>GO BOTTOM
>REPLACE &lcATAFName WITH TRIM(lcATAFValue)
&& WILL NOT DO REPLACE>
>The program won;t execute the REPLACE command. I have another FOR loop that does the same with numeric fields and it works (identical syntax). I find it a little strange and frustrating to be honest.
OK Perry,
Reread (honestly just read) your code and now I think understood.
lcATAFName = "ATA_Report.project"+RIGHT(lcFCnt,1)
SELECT ATA_Report
GO BOTTOM
REPLACE (lcATAFName) WITH TRIM(lcATAFValue)
go bottom in "Ata_report"
replace (lcATAFName) with TRIM(lcATAFValue) in "Ata_report"
While this would cease your replace problem after tracing your code I think it's a time consuming method. Why not also check the code I sent before and just change columnnames then append - might be faster ? Here is what it does :
Takes original xtab and splits into xtab001..xtab010...xtab0nn. Each xtabnnn table now has field(1) -description- + next block of 15 fields from original xtab. ie: xtab001 would have field(1)...field(15) of xtab, and xtab002 would have field(1),field(16)..field(30) of xtab and so on. I didn't touch fieldnames at all because at the end I would like to preserve them. Your report then could have field expressions as (still preserve one report definition but called n times) :
eval(field((repnumber-1)*15+iif(repnumber=1,1,0)+1))
eval(field((repnumber-1)*15+iif(repnumber=1,1,0)+2))...
Cetin