Use the Dup Key in Subfiles
September 2, 2009 Hey, Ted
I hope you don’t mind another question about the “old” stuff. How do I program for the Dup key in a data entry subfile? –David This is a good technique to know, David, and it’s not hard to do. Let’s start with a simple subfile of 10 records per page. There are three input fields: a date; a customer number; and an amount. Here’s the DDS: A DSPSIZ(24 80 *DS3) A INDARA A R SFL SFL A SDATE 6S 0I 8 6DUP(31) A SCUST 8A I 8 16DUP(32) A SAMOUNT 7Y 3I 8 30DUP(33) A R CTL SFLCTL(SFL) A SFLSIZ(12) A SFLPAG(12) A CF03(03) A 22 SFLDSP A 21 SFLDSPCTL A N21N22 SFLINZ A 7 6' Date Customer Amount' A DSPATR(UL) Notice the DUP keyword on each of the entry fields. DUP tells which indicator to turn on when the DUP key is pressed. And here’s what the subfile looks like: Date Customer Amount 010203 AAA 44______ ******* BBB 45______ ******* ******** ******** ******* CCC 55______ 010204 ******** 66______ The asterisks show where the dup key was used. In your program, which I’ll illustrate with RPG, you’ll need three save fields for the three duplicable fields. In my program, I cleverly begin the names of these save fields with the word Save. Here’s the idea: When you retrieve a record from the subfile, test the dup key indicators. If a dup key indicator is on, copy the save field to the entry field. If a dup key indicator is off, copy the entry field to the save field. Here’s my code that illustrates the process: Fqad2561d cf e workstn sfile(sfl:rrn) F indds(DspfInd) D rrn s 4s 0 D DspfInd ds D ExitRequested 1n overlay(DspfInd: 3) D WriteCtl 1n overlay(DspfInd: 21) D WriteSfl 1n overlay(DspfInd: 22) D DupDate 1n overlay(DspfInd: 31) D DupCust 1n overlay(DspfInd: 32) D DupAmount 1n overlay(DspfInd: 33) D SaveDate s like(SDate) D SaveCust s like(SCust) D SaveAmount s like(SAmount) /free *inlr = *on; dow '1'; // clear the subfile WriteCtl = *off; WriteSfl = *off; write ctl; // present the subfile WriteCtl = *on; WriteSfl = *on; exfmt ctl; if ExitRequested; leave; endif; for rrn = 1 to 10; chain rrn sfl; if DupDate; SDate = SaveDate; else; SaveDate = SDate; endif; if DupCust; SCust = SaveCust; else; SaveCust = SCust; endif; if DupAmount; SAmount = SaveAmount; else; SaveAmount = SAmount; endif; // do something here with the data // from the subfile record endfor; enddo; return; /end-free Maybe other readers will write in with more dup-key ideas. –Ted
|