cat > script.ff <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
	program cr3
	integer error
EXEC SQL INCLUDE SQLCA;
EXEC SQL BEGIN DECLARE SECTION ;
        character *25 name,date *20,amount *8
        character *25 name1,date1 *20,amnt1 *8
EXEC SQL END DECLARE SECTION ;
EXEC SQL INIT;
EXEC SQL DATABASE IS "DATABASE";
EXEC SQL DECLARE c CURSOR FOR SELECT DISTINCT FROM loans  
FOR UPDATE OF name;
EXEC SQL OPEN c;
	if(SQLRET.NE.0) then
	error=1
	goto 10
	endif
	print *,'open c ok'
50	continue 
	EXEC SQL FETCH c name,date,amount INTO :name,:date,:amount;
	if(SQLRET.EQ.0) then
	write (*,101) name,date,amount
 101    format (' ', A25, A20, A8)
	goto 60
	endif
	if(SQLRET.EQ.100) goto 60
	if(SQLRET.EQ.1) then
	print *,' lock busy'
	EXEC SQL FETCH_AGAIN c name,date,amount INTO :name1,:date1,:amnt1;
		 if(SQLRET.EQ.0) then
			 print *,name1, date1,amnt1
			else 
				EXEC SQL EXIT ;
			stop
		endif
	goto 60
	endif
	error=4
	goto 10
60	if(SQLRET.EQ.0) goto 50
	EXEC SQL INSERT INTO loans SET name,date,amount VALUES "RHODNIUS",
		:date,:amount;
	if(SQLRET.NE.0) then
	error=5
	goto 10
	endif
	print *,'insert ok'
	EXEC SQL CLOSE c;
	print *,'close c ok'
	EXEC SQL EXIT ;
	stop
10	print *,'error number ',error
	print *,'SQLRET number ',SQLRET
	EXEC SQL EXIT ;
	stop
	end
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 script.ff
cat > stdout <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
open c ok
Jones                    7 February  1981    $33.95  
Jones                    3 April     1981    $25.00  
Jones                    12 August    1981   $300.00 
Kilroy                   16 February  1981   $250.00 
Mosca                    2 February  1981    $150.00 
Mosca                    4 May       1981    $200.00 
Peterson                 6 June      1981    $50.00  
Wladislaw                27 February  1981   $55.00  
Wladislaw                12 May       1981   $25.00  
Wladislaw                25 June      1981   $75.00  
insert ok
close c ok
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 stdout
cat > tag <<'+-+-+-+-+-END-OF-FILE-+-+-+-+-+'
Cursor manipulation (3)
+-+-+-+-+-END-OF-FILE-+-+-+-+-+
chmod 644 tag
