11 Using CURSOR and FETCH into multiple host DS

**FREE
ctl-opt option(*nodebugio:*srcstmt);

dcl-ds FILEAx extname('FILEA') qualified end-ds;
dcl-ds FILEBx   extname('FILEB  ') qualified end-ds;

dcl-ds FILEAds extname('FILEA') end-ds;
dcl-ds FILEBds   extname('FILEB'  );
       FIELDA_     extfld('FIELDA');
       FIELDB_    extfld('FIELDB');
end-ds;

dcl-c SqlEof const('02000');

exec sql declare c1 cursor for
         select a.*,b.*
         from pgctrans/FILEA a
         left outer join pgctrans/FILEB b
         on a.FIELDA=b.FIELDA and a.FIELDB=b.FIELDB
         where b.FIELDX>' '
         order by a.FIELDA, b.FIELDX;

exec sql open c1;
exec sql fetch c1 into :FILEAx, :FILEBx;

if sqlStt <> sqlEof;
   FILEAds = FILEAx;
   FILEBds = FILEBx  ;
endif;

exec sql close c1;
*inlr=*on;
return; 

Comments

Popular posts from this blog

07 Using CURSOR and FETCH into host DS

12 FETCH and sub-procedures