Problem solve Get help with specific problems with your technologies, process and projects.

Get the most out of flexible subfiles

Demonstrate a technique where a sub file appears to have multiple record format.

Demonstrate a technique where a sub file appears to have multiple record format.

Subfile of the third kind - "Flexible subfile"

Subfiles have been around for many years now. Almost any programmer uses them.

There are two familiar techniques to use subfiles:

- Field conditioning, thus allowing different record format. Con
- The subfile record can become quite complex due of the heavy use of indicators.
- Each page scrolling requires the program to go back to the database to fetch records. (Most application do not need that.)
- If you use option field (Work with screen design) you have to use extra code to remember the marked records. (Since you have to clear the subfile every time there is a need to scroll.)

- Easy to implement.
- Allow for forward page at the time scrolling (performance benefit).
- Marked records are retained.
- Field conditioning is a no no!
As you can see neither technique is perfect.
It seems that we need field conditioning on "SFLPAG *NE SFLSIZ"

 May I introduce you to "Flexible subfile"? 

Flexible subfile

In the subfile record I created a single SFLLIN field, which will be filled using the eval
operation, This field will be visible to the user.

Display file DEM01102

As you can see I code the data base fields as hidden fields,
those fields will be available for future READC operation.

     A                                      DSPSIZ(27 132 *DS4)
     A                                      CHGINPDFT(UL)
     A                                      MSGLOC(24)
     A                                      PRINT
     A          R S0R10                     SFL
     A            RECID         10A  H      TEXT('Record Id')
     A            ORDER     R        H      REFFLD(ORDHDR/ORDER *LIBL/QORDHDR)
     A            CUST      R        H      REFFLD(ORDHDR/CUST *LIBL/QORDHDR)
     A            ORDDAT    R        H      REFFLD(ORDHDR/ORDDAT *LIBL/QORDHDR)
     A            SHPVIA    R        H      REFFLD(ORDHDR/SHPVIA *LIBL/QORDHDR)
     A            ORDSTS    R        H      REFFLD(ORDHDR/ORDSTS *LIBL/QORDHDR)
     A            ORDAMT    R        H      REFFLD(ORDHDR/ORDAMT *LIBL/QORDHDR)
     A            TOTLIN    R        H      REFFLD(ORDHDR/TOTLIN *LIBL/QORDHDR)
     A            INVNUM    R        H      REFFLD(ORDHDR/INVNUM *LIBL/QORDHDR)
     A            QTYORD    R        H      REFFLD(ORDDTL/QTYORD *LIBL/QORDDTL)
     A            PARTNO    R        H      REFFLD(ORDDTL/PARTNO *LIBL/QORDDTL)
     A                                      L)
     A            UNITAMT   R        H      REFFLD(ORDDTL/UNITAMT *LIBL/QORDDTL)
     A            TOTAMT    R        H      REFFLD(ORDDTL/TOTAMT *LIBL/QORDDTL)
     A            USEOPT         1Y 0B  7  2DSPATR(CS)
     A                                      EDTCDE(Z)
      * The output fields
     A            SFLLIN       128A  O  7  4
     A          R S0C10                     SFLCTL(S0R10)
     A                                      SFLSIZ(0032)
     A                                      SFLPAG(0018)
     A  41                                  SFLDSP
     A  42                                  SFLDSPCTL
     A            C10DR          4S 0H      SFLRCDNBR(CURSOR)
     A            C10AR          4S 0H      TEXT('Active record')
     Program DEM01102
     - The Hex fields (x'21',X'29') are display attributes that 
        can be used (Yes ! we do color !!!).
     - Numeric fields are edited as part of the eval operation using
      %EDITC and %EDITW function.
     FDEM01102  cf   e             workstn sfile(s0r10:c10ar)
      * files qordhdr & qordhdr are usuly found at QGPL 
     fqordhdr   if   e           k disk
     fqordhdr   if   e           k disk
     Ddspatr01         s              1
     C     *entry        plist
     c                   parm                    order
     c     klist02       klist
     c                   kfld                    order
     C     klist02       chain     QORDHDR
     C                   eval      dspatr01 = x'21'
      * Compose the header string
      * Field RECID can be used later for record identification 
      * when using READC operation 
 B01 C                   if        %found
  01 C                   eval      RECID  = 'ORDHDR'
  01 c                   eval      sfllin =
  01 C                             'Customer number:' +
  01 C                              CUST + ' '  +
  01 C                              'Order number:' + %EDITC(ORDER:'Z') + ' ' +
  01 C                              'Dated:' + %EDITW(ORDDAT:'  /  /  ') + ' ' +
  01 c                              'Ship via:'+ dspatr01 + shpvia + x'20' +
  01 C                              'Total items in order:' + %EDITC(TOTLIN:'Z')
 E01 C                   ENDIF
     c                   eval      c10ar = c10ar + 1
     c                   write     s0r10
      * Create empty line 
     c                   eval      c10ar = c10ar + 1
      * Loop on the detail records
     C     klist02       setll     QORDDTL
 B01 C                   dou       %eof(QORDDTL)
  01  *
  01 C     klist02       reade     QORDDTL
  01  *
 B02 C                   if        %eof(QORDDTL)
  02 C                   leave
 E02 C                   EndIf
  01  * Compose the detail string
  01 C                   eval      RECID  = 'ORDDTL'
  01 c                   eval      sfllin =
  01 C                             '           '  + X'29' + 'Low' + X'20'+
  01 C                             'Part number:' + %EDITC(PARTNO:'Z') + ' ' +
  01 C                              PARTDESC +
  01 C                              'Order quantity:' + %EDITC(QTYORD:'L')
  01  *
  01 c                   eval      c10ar = c10ar + 1
  01 c                   write     s0r10
  01  *
 E01 C                   EndDo
      * Show the masterpiece
     C                   eval      *in41 = *on
     C                   eval      *in42 = *on
     C                   eval      c10dr = 1
     C                   exfmt     S0C10
     C                   eval      *inlr = *on
Command DEM01102 (Make calling program easier)    

             CMD        PROMPT('Order Display')
             PARM       KWD(ORDER) TYPE(*DEC) LEN(5 0) PROMPT('Order +
This was last published in July 2002

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.