READC & SFLNXTCHG
Last Post 20 Feb 2007 07:12 AM by rajrajan. 5 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
rajrajan
New Member
New Member
Posts:22

--
19 Feb 2007 12:43 PM
Hi All, Please give me explanation on READC and SFLNXTCHG and the difference with good examples. Please write a small logic of the program for the following to illustrate. Writing RPG 4 program using READC only. Writing RPG 4 program using READC and SFLNXTCHG. Thanks in advance Raj
Bryan Leaman
Veteran Member
Veteran Member
Posts:1745
Avatar

--
19 Feb 2007 01:21 PM Accepted Answer
Here's the basic logic I follow...

 /free
    // If there is data in the subfile...
    if records_in_sfl > 1;   // or, if SFLDSP was turned on
    readc mysfl;
    dow not %eof(mydspf);

        // One of the fields in this subfile record was keyed into, so deal with it...
        Sfl_Error = *off

        // Perform actions, edit-check data keyed, etc. Turn on Sfl_Error if
        // there were any errors.
        exsr ProcessSflRcd;  

        // if there were any errors, turn on SFLNXTCHG so the record will be
        // read again next time.
        if Sfl_Error;
           SFLNXTCHG_ind = *on;
        else;
           SFLNXTCHG_ind = *off; 
        endif;

        // Update the record with 
        update mysfl;

        readc mysfl;
    enddo;
 /end-free
--Bryan
rajrajan
New Member
New Member
Posts:22

--
19 Feb 2007 01:33 PM Accepted Answer
Here's the basic logic I follow...

 /free
    // If there is data in the subfile...
    if records_in_sfl > 1;   // or, if SFLDSP was turned on
    readc mysfl;
    dow not %eof(mydspf);

        // One of the fields in this subfile record was keyed into, so deal with it...
        Sfl_Error = *off

        // Perform actions, edit-check data keyed, etc. Turn on Sfl_Error if
        // there were any errors.
        exsr ProcessSflRcd;  

        // if there were any errors, turn on SFLNXTCHG so the record will be
        // read again next time.
        if Sfl_Error;
           SFLNXTCHG_ind = *on;
        else;
           SFLNXTCHG_ind = *off; 
        endif;

        // Update the record with 
        update mysfl;

        readc mysfl;
    enddo;
 /end-free
--Bryan
Hi Bryan, Please explain me the use of SFLNXTCHG. Being a fresher, im not able to understand ur code also. Please help me in this. Wat will be the problem if i use readc only for update operation in subfile..? Thanks & Regards Raj Rajan
Bryan Leaman
Veteran Member
Veteran Member
Posts:1745
Avatar

--
19 Feb 2007 01:49 PM Accepted Answer
READC will cause your program to ONLY read subfile records that have been keyed into, whether the value has changed or not. So, for example, if you have a list of records with an input-capable "action/option/selection" field, then performing a READC will only return records that have had actions/options/selection keyed into them. However, if an action/option/selection has been blanked or field-exited out, that record is still "changed" and will be read with READC. One of the "gotchas" with READC is that if, for example, you have "2=Edit, 4=Delete" actions available to the users and they key a "3". If you just issue an error message and do nothing else, READC won't read that subfile record again until it is changed by the user. You could design your program to work with it this way, but usually you want to force any "error" entries to be read the next time the user presses "Enter" or a function key. That is the function of SFLNXTCHG. You turn on the indicator associated with SFLNXTCHG and update the subfile. Then the next time you enter your "readc, dow" loop you will get any newly-changed records along with any records that had the SFLNXTCHG indicator on when you updated them. I have seen people *always* turn on SFLNXTCHG for every record so they always process the whole subfile, but in my opinion, if you always want to see every record, you should just code a for loop from 1 to the number of records in your subfile and just chain to the subfile records. --Bryan
Bas Van Zetten
Basic Member
Basic Member
Posts:77

--
19 Feb 2007 01:52 PM Accepted Answer
You can program properly functioning subfiles without sflnxtchg, only using readc or even chain on recordnumber. When you set this flag -on sf recordlevel- you basically force the record to be read on the next readc. For example if you use a 1 page subfile in which you handle the (saving and restoring of) options after scrolling you could set nxtchg flag on so the restored option (from an array for example) is read during the next readc loop.
rajrajan
New Member
New Member
Posts:22

--
20 Feb 2007 07:12 AM Accepted Answer
READC will cause your program to ONLY read subfile records that have been keyed into, whether the value has changed or not. So, for example, if you have a list of records with an input-capable "action/option/selection" field, then performing a READC will only return records that have had actions/options/selection keyed into them. However, if an action/option/selection has been blanked or field-exited out, that record is still "changed" and will be read with READC. One of the "gotchas" with READC is that if, for example, you have "2=Edit, 4=Delete" actions available to the users and they key a "3". If you just issue an error message and do nothing else, READC won't read that subfile record again until it is changed by the user. You could design your program to work with it this way, but usually you want to force any "error" entries to be read the next time the user presses "Enter" or a function key. That is the function of SFLNXTCHG. You turn on the indicator associated with SFLNXTCHG and update the subfile. Then the next time you enter your "readc, dow" loop you will get any newly-changed records along with any records that had the SFLNXTCHG indicator on when you updated them. I have seen people *always* turn on SFLNXTCHG for every record so they always process the whole subfile, but in my opinion, if you always want to see every record, you should just code a for loop from 1 to the number of records in your subfile and just chain to the subfile records. --Bryan
Bryan, Thanks for this. I have understood it better now. When i started coding using this keywords i'll get more. Regards Raj.
You are not authorized to post a reply.

Acceptable Use Policy