fhg
Volume 9, Number 27 -- September 2, 2009

Use the Dup Key in Subfiles

Published: 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




                     Post this story to del.icio.us
               Post this story to Digg
    Post this story to Slashdot


Sponsored By
PRODATA COMPUTER SERVICES

Simplify your iT!

DBU - super easy to use. The leading data access tool on the market.

DBU RDB - does the work for you. Analyze data on all your servers.
MySQL, Microsoft SQL Server, Oracle, DB2 databases and others.

RDB Connect - programmatic access to remote data! Full SQL access to
remote databases from all System i high-level languages.

Download your free trials NOW.
Order today and SAVE $$$!
www.prodatacomputer.com
800.228.6318


Senior Technical Editor: Ted Holt
Technical Editor: Joe Hertvik
Contributing Technical Editors: Edwin Earley, Brian Kelly, Michael Sansoterra
Publisher and Advertising Director: Jenny Thomas
Advertising Sales Representative: Kim Reed
Contact the Editors: To contact anyone on the IT Jungle Team
Go to our contacts page and send us a message.

Sponsored Links

Maximum Availability:  Upgrade to *noMAX - save 20% on current fees
ARCAD Software:  Start 5250 emulation sessions from your RDi workspace - download freeware!
COMMON:  Celebrate our 50th anniversary at annual conference, May 2 - 6, 2010, in Orlando


 

IT Jungle Store Top Book Picks

Easy Steps to Internet Programming for AS/400, iSeries, and System i: List Price, $49.95
The iSeries Express Web Implementer's Guide: List Price, $49.95
The System i RPG & RPG IV Tutorial and Lab Exercises: List Price, $59.95
The System i Pocket RPG & RPG IV Guide: List Price, $69.95
The iSeries Pocket Database Guide: List Price, $59.00
The iSeries Pocket SQL Guide: List Price, $59.00
The iSeries Pocket Query Guide: List Price, $49.00
The iSeries Pocket WebFacing Primer: List Price, $39.00
Migrating to WebSphere Express for iSeries: List Price, $49.00
Getting Started With WebSphere Development Studio Client for iSeries: List Price, $89.00
Getting Started with WebSphere Express for iSeries: List Price, $49.00
Can the AS/400 Survive IBM?: List Price, $49.00
Chip Wars: List Price, $29.95


 
The Four Hundred
CIOs Say Power Systems Are the Most Reliable

A Closer Look at IBM's Q2 Server Sales

Has IBM Given Up on the i?

Mad Dog 21/21: Terms and Conditions

Jack Henry Lays Out $17 Million for Goldleaf After Good 4Q

Four Hundred Stuff
Managed File Transfer: A New Product Category That's Here to Stay

IBM to Formally Announce EGL Community Edition Today

Linoma Introduces MFT Software for External Exchanges

SEQUEL Updates i OS Time and Date Override Software

Cosyn Augments BPCS Accounting with AP Minder

Four Hundred Monitor
Four Hundred Monitor's
Full iSeries Events Calendar

System i PTF Guide
August 29, 2009: Volume 11, Number 35

August 22, 2009: Volume 11, Number 34

August 15, 2009: Volume 11, Number 33

August 8, 2009: Volume 11, Number 32

August 1, 2009: Volume 11, Number 31

July 25, 2009: Volume 11, Number 30

July 18, 2009: Volume 11, Number 29

TPM at The Register
VMware vSphere gets more gadgets

Semiconductor sales rise 5.3% in July

Sun sales plummet 30.6% in Q4

AMD plays it cool with low-volt Istanbuls

Xen packages build-your-own-cloud kit

OpSource floats VMware cloud

Intel boosts Q3 guidance

Novell profits even as sales slide

VMware goes into hyper-drive with vSphere 4.0

Cray nabs PathScale compilers from SiCortex

Tibco snaps up DataSynapse for $28m

Sun goes over Rainbow Falls

Amazon does virtual private clouds

Big chip for big boxes: IBM cracks open lid on Power7

THIS ISSUE SPONSORED BY:

ProData Computer Services
East Coast Computer
Manta Technologies


Printer Friendly Version


TABLE OF CONTENTS
Use the Dup Key in Subfiles

An Overview of User-Defined Types in DB2 for i

Admin Alert: The Road to Live CBU Fail Over, Part 1

Four Hundred Guru

BACK ISSUES




 
Subscription Information:
You can unsubscribe, change your email address, or sign up for any of IT Jungle's free e-newsletters through our Web site at http://www.itjungle.com/sub/subscribe.html.

Copyright © 1996-2009 Guild Companies, Inc. All Rights Reserved.
Guild Companies, Inc., 50 Park Terrace East, Suite 8F, New York, NY 10034

Privacy Statement