• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Another Reason to Use P-Fields

    January 26, 2005 Hey, Ted

    Within a subfile, I am using an indicator to highlight a field if the value of that field is invalid. Is there a way, when I read a subfile record, to analyze the attributes of the field to see if the indicator was switched on or off when the subfile record was written? My problem is that the display attribute is losing its original setting.

    –Alan

    I don’t know of a way to determine the original setting. I have included hidden one-byte fields in a subfile to store the settings of indicators so I could reset the indicators before updating the subfile record. You have put your finger on a good reason to use p-fields instead of indicators to control display file attributes.

    Here’s a display file, SFL223D, which uses indicator 71 to display a negative balance amount in reverse image.

     A                                      DSPSIZ(24 80 *DS3)
     A          R SFL01                     SFL
     A            LINENBR01      3  0O  9  2EDTCDE(4)
     A            NAME01        20   O    +2
     A            BALANCE01      9  2O    +2EDTCDE(J)
     A  71                                  DSPATR(RI)
     A          R CTL01                     SFLCTL(SFL01)
     A                                      CA03(03)
     A                                      SFLDSP
     A                                      SFLDSPCTL
     A                                      SFLSIZ(11)
     A                                      SFLPAG(10)
    

    Here’s a short program, SFL223R, which loads some records into the subfile and updates one of them. The first time the subfile is displayed, Don’s and Lou’s records show a balance in reverse image. When Don’s name is changed to Bubba, the reverse image attribute disappears.

     H dftactgrp(*no) actgrp(*caller)
     H option(*srcstmt: *nodebugio)
    
     Fsfl223d   cf   e             workstn
     F                                     sfile(sfl01:rrn)
    
     D rrn             s              3  0
    
     D Load            pr
     D  Name                         20    value
     D  Balance                       9p 2 value
     D  RecNbr                        3p 0
    
     D ChangeName      pr
     D  RecNbr                        3p 0 value
     D  NewName                      20    value
    
      /free
          Load('Bob': 200: RRN);
          Load('Don': -35: RRN);
          Load('Jim': 25.95: RRN);
          Load('Lew': 180: RRN);
          Load('Lou': -99999: RRN);
          Load('Sue': 500: RRN);
          Load('Tom': 1750: RRN);
          exfmt ctl01;
          ChangeName(2: 'Bubba');
          exfmt ctl01;
          *inlr = *on;
      /end-free
    
     P Load            b
     D                 pi
     D  Name                         20    value
     D  Balance                       9p 2 value
     D  RecNbr                        3p 0
      /free
        RecNbr += 1;
        LineNbr01 = RecNbr;
        Name01 = Name;
        Balance01 = Balance;
        *in71 = (Balance01 < *zero);
        write sfl01;
      /end-free
     P                 e
    
     P ChangeName      b
     D                 pi
     D  RecNbr                        3p 0 value
     D  NewName                      20    value
      /free
        chain RecNbr sfl01;
        if %found();
           Name01 = NewName;
           update sfl01;
        endif;
      /end-free
     P                 e
    

    Here’s the same display file, but the setting of the balance field is now controlled by p-field BALATTR01, which is written to the subfile record. The display attributes of the balance field are no longer dependent on the setting of an indicator.

     A                                      DSPSIZ(24 80 *DS3)
     A          R SFL01                     SFL
     A            LINENBR01      3  0O  9  2EDTCDE(4)
     A            NAME01        20   O    +2
     A            BALANCE01      9  2O    +2EDTCDE(J)
     A                                      DSPATR(&BALATTR01)
     A            BALATTR01      1A  P
     A          R CTL01                     SFLCTL(SFL01)
     A                                      CA03(03)
     A                                      SFLDSP
     A                                      SFLDSPCTL
     A                                      SFLSIZ(11)
     A                                      SFLPAG(10)
    

    Here’s the revised RPG code. When Don’s name is changed to Bubba, the balance of -35 continues to be displayed in reverse image.

     H dftactgrp(*no) actgrp(*caller)
     H option(*srcstmt: *nodebugio)
    
     Fsfl224d   cf   e             workstn
     F                                     sfile(sfl01:rrn)
    
     D rrn             s              3  0
     D Normal          c                   x'20'
     D Reverse         c                   x'21'
    
     D Load            pr
     D  Name                         20    value
     D  Balance                       9p 2 value
     D  RecNbr                        3p 0
     D ChangeName      pr
     D  RecNbr                        3p 0 value
     D  NewName                      20    value
    
      /free
          Load('Bob': 200: RRN);
          Load('Don': -35: RRN);
          Load('Jim': 25.95: RRN);
          Load('Lew': 180: RRN);
          Load('Lou': -99999: RRN);
          Load('Sue': 500: RRN);
          Load('Tom': 1750: RRN);
          exfmt ctl01;
          ChangeName(2: 'Bubba');
          exfmt ctl01;
          *inlr = *on;
      /end-free
    
     P Load            b
     D                 pi
     D  Name                         20    value
     D  Balance                       9p 2 value
     D  RecNbr                        3p 0
      /free
        RecNbr += 1;
        LineNbr01 = RecNbr;
        Name01 = Name;
        Balance01 = Balance;
        if (Balance01 >= *zero);
           BalAttr01 = Normal;
        else;
           BalAttr01 = Reverse;
        endif;
        write sfl01;
      /end-free
     P                 e
    
     P ChangeName      b
     D                 pi
     D  RecNbr                        3p 0 value
     D  NewName                      20    value
      /free
        chain RecNbr sfl01;
        if %found();
           Name01 = NewName;
           update sfl01;
        endif;
      /end-free
     P                 e
    


    To learn more about p-fields, see the article “Anatomy of a P-Field.”

    –Ted

    Click here to contact Ted Holt by e-mail.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Brooks Launches ExcelliPrint for IPDS Conversion SkyView Addresses Compliance with New OS/400 Security Service

    Leave a Reply Cancel reply

Volume 5, Number 4 -- January 26, 2005
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
Patrick Townsend & Associates
Guild Companies

Table of Contents

  • An Introduction to WDSc Table Views
  • Another Reason to Use P-Fields
  • The Save-Restore Commands

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