Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Fields in a cursor
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00566548
Message ID:
00566696
Views:
12
>It can be even easier if it is possible to create the cursor to insert data to (which is cCursor4) with the same field names as in cCursor instead of c1, c2, etc.
>
>SELECT (cCursor)
>SCATTER MEMVAR
>INSERT INTO (cCursor4) FROM MEMVAR
>
>This technique may not apply (or apply partially) if you do the INSERTs from other sources too.
>
>>You don't have to prefix in the field list cCursor4 and you can scatter memvar memo in cCursor1, so you would use m.pp, m.fname, etc. Or you should use Larry's suggestion or another alternative would be evaluate(cCursor+".pp"), etc.
>>
>>>>>I keep getting syntax error when I save my code. I'm trying to reference fields in my cursor as below. Is it not possible to refer to fields in cursor as (cursor).field ?
>>>>>
>>>>>
>>>>>
>>>>INSERT INTO (cCursor4) ((cCursor4).c1, (cCursor4).c2, (cCursor4).c3, (cCursor4).c4, ;
>>>>	(cCursor4).c5, (cCursor4).c6, (cCursor4).c7, (cCursor4).c8, (cCursor4).c9, ;
>>>>	(cCursor4).c10) ;
>>>>	VALUES((cCursor).pp, (cCursor).fname, (cCursor).totpay, (cCursor).fica,  (cCursor).retire_amt, ;
>>>>	(cCursor).health_ins, (cCursor).retiree_med, (cCursor).unempins, (cCursor).wrkcompins, ;
>>>>	(cCursor).total_salary)
>>>>				
>>>>>
>>>>>
>>>>>
>>>>>Thanks
>>>>>Nick Patel
>>>>
>>>>I believe you have to use
>>>>
>>>>&cCursor4..
>>>>
>>>>You must use the double "." because the first . stops the macro substitution and the second will be used in the expression.
>>>>
>>>>HTH.
>>>
>>>
>>>I tried (&cCursor4)".".fname and it did allow me to save, but when I ran the program, it gave me a syntax error. I even tried (&cCursor4).fname and it still gave me an error. Apparently it sees the value in &cCursor4 just fine, it just doesn't understand fname.
>>>
>>>Thanks
>>>Nick Patel
The reason why I can't use same names is because I need to convert information from cCursor that contains numeric data to a cursor that can hold character data. I am trying to build a custom report which is going to require totals group totals also lines in the reports. Here is the code and thanks for your help:
		do case
			&&in same pay period
			case not split
				messagebox('not split',0,'warning')
				ldFindDate = ldLTEDate 	&&find all records by this date value 
				par = (ed-bd)+1 &&number of partial days being calculated for
				cCursor = SYS(2015) &&generate random name for cursor
				select pp, fname, totpay, fica, retire_amt, health_ins, retiree_med, ;
					unempins, wrkcompins, total_salary  ;
					from payroll_tbl into cursor (cCursor) where payroll_tbl.bdate = ldBDate ;
						order by fname
				report form rep_bydate preview
				use				
			
			&&pay period fall inbetween bdate and edate in the table -- split into 2 payperiods
			case split
				messagebox('split',0,'warning')
				cCursor = SYS(2015) &&generate random name for cursor will hold calc and info
				cCursor2 = sys(2015) &&random cursor 2 where edate in array is beginning
				cCursor3 = sys(2015) &&random cursor 3 where edate in array is ending 
				cCursor4 = sys(2015) &&random cursor 4 print cursor				
				
				create cursor (cCursor)( pp c(7), fname c(25), totpay n(8,2), fica n(8,2), retire_amt n(8,2), ;
				 health_ins n(8,2), retiree_med n(8,2), unempins n(8,2), wrkcompins n(8,2), ; 
				 total_salary n(10,2), ssn c(9))
				 
				 index on fname tag fname
				 ppdays1 = (LowValue - bd) + 1 &&number of days in first pay period
				 ppdays2 = (ed - HighValue) + 1 &&number of days in second pay period
				
				.init_total
				
				&&find pay periods involved
				select distinct pp from payroll_tbl where edate between (Lowvalue) and a__gen2(gpos2+1,1) ;
					into array a__gen10
					a_cells = _tally
					
*!*					select pp, fname, totpay, fica, retire_amt, health_ins, retiree_med, ;
*!*						unempins, wrkcompins, total_salary, ssn ;
*!*						from payroll_tbl into cursor (cCursor2) where payroll_tbl.pp between a__gen10(1,1) and ;
*!*							a__gen10(a_cells,1) order by fname


				select pp, fname, (totpay)/ppdays1 as totpay, (fica)/ppdays1 as fica, (retire_amt)/ppdays1 as retire_amt, ;
					(health_ins)/ppdays1 as health_ins, (retiree_med)/ppdays1 as retiree_med, (unempins)/ppdays1 as unempins, ;
					(wrkcompins)/ppdays1 as wrkcompins, (total_salary)/ppdays1 as total_salary, ssn ;
					from payroll_tbl into cursor (cCursor2) where payroll_tbl.pp = a__gen10(1,1) order by fname

				select pp, fname, (totpay)/ppdays2 as totpay, (fica)/ppdays2 as fica, (retire_amt)/ppdays2 as retire_amt, ;
					(health_ins)/ppdays2 as health_ins, (retiree_med)/ppdays2 as retiree_med, (unempins)/ppdays2 as unempins, ;
					(wrkcompins)/ppdays2 as wrkcompins, (total_salary)/ppdays2 as total_salary, ssn ;
					from payroll_tbl into cursor (cCursor3) where payroll_tbl.pp = a__gen10(a_cells,1) order by fname

				&&create print cursor
				create cursor (cCursor4)(c1 c(7), c2 c(25), c3 c(8), c4 c(8), c5 c(8), ;
					 c6 c(8), c7 c(8), c8 c(8), c9 c(8), c10 c(10))

				select (cCursor)
				append from dbf((cCursor2))				
				append from dbf((cCursor3))
				set order to fname
				
				browse
				first_sw = .t.				
				scan 
					if first_sw = .t.
						first_sw = .f.
						hldname = &cCursor..fname &&hold new person name and do total break and then move to print cursor
						insert into (cCursor4) (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) ;
 						values(&cCursor..pp, &cCursor..fname, STR(&cCursor..totpay), STR(&cCursor..fica), ;
 									 STR(&cCursor..retire_amt), STR(&cCursor..health_ins), STR(&cCursor..retiree_med), ;
 									 STR(&cCursor..unempins), STR(&cCursor..wrkcompins), STR(&cCursor..total_salary))
					else
						if (&cCursor).fname == hldname &&move information into print cursor
							insert into (cCursor4) (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) ;
	 						values(&cCursor..pp, &cCursor..fname, STR(&cCursor..totpay), STR(&cCursor..fica), ;
	 									 STR(&cCursor..retire_amt), STR(&cCursor..health_ins), STR(&cCursor..retiree_med), ;
	 									 STR(&cCursor..unempins), STR(&cCursor..wrkcompins), STR(&cCursor..total_salary))
						else
							hldname = (&cCursor).fname &&hold new person name and do total break and then move to print cursor
							insert into (cCursor4) (c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) ;
	 						values(&cCursor..pp, &cCursor..fname, STR(&cCursor..totpay), STR(&cCursor..fica), ;
	 									 STR(&cCursor..retire_amt), STR(&cCursor..health_ins), STR(&cCursor..retiree_med), ;
	 									 STR(&cCursor..unempins), STR(&cCursor..wrkcompins), STR(&cCursor..total_salary))
							
							
							
							.init_total
						endif &&fname == hldname
					endif &&first_sw				
				
				
				
				endscan
				
				select (cCursor4)
				browse
 
				use	

&&do some report






		endcase 
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform