• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • 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



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

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Rocket Software

    Unlock the full potential of your data with Rocket Software. Our scalable solutions deliver AI-driven insights, seamless integration, and advanced compliance tools to transform your business. Discover how you can simplify data management, boost efficiency, and drive informed decisions.

    Learn more today.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    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

    IBM Delivers Optim Archiving and Test Software for JDE, But Goofs Up i OS Support The Feeds and Guessed Speeds of Power7

    Leave a Reply Cancel reply

Volume 9, Number 27 -- September 2, 2009
THIS ISSUE SPONSORED BY:

ProData Computer Services
East Coast Computer
Manta Technologies

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

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle