I am trying to populate a subfile with data read from a master file in a particular order. The user can switch order by pressing the appropriate Function Key. The problem is the data populates the subfile based on the first statement processed all the time. I have cleared the array before launching the SQL statement, but it still populates the same way. The SQLRPGLE code is below and any feedback is appreciated.
// Sort records by CAR#
//
If (IndDs.F5_Scar);
//
// Sort records by CAR Status
//
If (IndDs.F6_Sstat);
//
// Sort records by Reason
//
If (IndDs.F7_Sreason);
// Sort records by CAR#
//
If (IndDs.F5_Scar);
IndDs.Car_HIRI = *on;
IndDs.Stat_HIRI = *off;
IndDs.Reas_HIRI = *off;
exec sql DECLARE C0 CURSOR FOR
SELECT cmcar#, cmstat, substr(cmnconf,1,50) FROM carmst
ORDER BY cmcar#
FOR READ ONLY ;
exec sql OPEN C0;
exec sql FETCH C0 FOR :Elements ROWS INTO Data ;
exec sql GET DIAGNOSTICS :LastRecord = ROW_COUNT ;
exec sql CLOSE C0 ;
endif;IndDs.Stat_HIRI = *off;
IndDs.Reas_HIRI = *off;
exec sql DECLARE C0 CURSOR FOR
SELECT cmcar#, cmstat, substr(cmnconf,1,50) FROM carmst
ORDER BY cmcar#
FOR READ ONLY ;
exec sql OPEN C0;
exec sql FETCH C0 FOR :Elements ROWS INTO Data ;
exec sql GET DIAGNOSTICS :LastRecord = ROW_COUNT ;
exec sql CLOSE C0 ;
//
// Sort records by CAR Status
//
If (IndDs.F6_Sstat);
IndDs.Car_HIRI = *off;
IndDs.Stat_HIRI = *on;
IndDs.Reas_HIRI = *off;
exec sql DECLARE C1 CURSOR FOR
SELECT cmcar#, cmstat, substr(cmnconf,1,50) FROM carmst
ORDER BY cmstat
FOR READ ONLY ;
exec sql OPEN C1;
exec sql FETCH C1 FOR :Elements ROWS INTO Data ;
exec sql GET DIAGNOSTICS :LastRecord = ROW_COUNT ;
exec sql CLOSE C1 ;
endif;IndDs.Stat_HIRI = *on;
IndDs.Reas_HIRI = *off;
exec sql DECLARE C1 CURSOR FOR
SELECT cmcar#, cmstat, substr(cmnconf,1,50) FROM carmst
ORDER BY cmstat
FOR READ ONLY ;
exec sql OPEN C1;
exec sql FETCH C1 FOR :Elements ROWS INTO Data ;
exec sql GET DIAGNOSTICS :LastRecord = ROW_COUNT ;
exec sql CLOSE C1 ;
//
// Sort records by Reason
//
If (IndDs.F7_Sreason);
IndDs.Car_HIRI = *off;
IndDs.Stat_HIRI = *off;
IndDs.Reas_HIRI = *on;
exec sql DECLARE C2 CURSOR FOR
SELECT cmcar#, cmstat, substr(cmnconf,1,50) FROM carmst
ORDER BY cmnconf
FOR READ ONLY ;
exec sql OPEN C2;
exec sql FETCH C2 FOR :Elements ROWS INTO Data ;
exec sql GET DIAGNOSTICS :LastRecord = ROW_COUNT ;
exec sql CLOSE C2 ;
endif;
IndDs.Stat_HIRI = *off;
IndDs.Reas_HIRI = *on;
exec sql DECLARE C2 CURSOR FOR
SELECT cmcar#, cmstat, substr(cmnconf,1,50) FROM carmst
ORDER BY cmnconf
FOR READ ONLY ;
exec sql OPEN C2;
exec sql FETCH C2 FOR :Elements ROWS INTO Data ;
exec sql GET DIAGNOSTICS :LastRecord = ROW_COUNT ;
exec sql CLOSE C2 ;
endif;
Comment