Template for generating Column and Group equates for ABC browse

I took Rick’s template for Generating Column Equates and added Equates for LIST Groups. Everything Rick said applies to Groups also.

Instead of using hard-coded numeric constants for column numbers in code for manipulating your list control columns, it is better to use an equate for the column number. Hard-coded column numbers can become incorrect when new columns are added or columns deleted or reordered in the list format. Using the use equates means your code won’t need to be updated when the order of your list control columns change.

Groups are NOT numbered 1,2,3, instead their number is the first column in the Group. So my Group equates simply reference the column equates. Here’s a screen capture showing the Column equates, the Group Equates, then code using them to change Group Headers in the list.

The templates offer no %Symbols I could find return the FORMAT for a Group … Anyone ???

For each Column there is %ControlFieldFormat plus the entire format is EXTRACT(%ControlStatement, 'FORMAT', 1). Parsing a FORMAT is complicated but I realized I could look at the format just before the %ControlFieldFormat for the Group’s ‘[’ . I left in my parsing debug as comments.

Rick labeled his equates “:FieldNo:” which I changed to “:ColumnNo:” but you can check a box to get his labels. IMO the LIST has Columns and the FieldNo is for the Queue that works with WHO(Q,FieldNo). The Equate PROPLIST:MouseDownField is wrongly named because to the the Queue Field you must use that Column number in PROPLIST:FieldNo.

Template below code and it is attached: UP_BrowseHelper_TPL.zip (1.5 KB)

#TEMPLATE(UP_BrowseHelper,'Browse Helper - Upper Park Solutions'), FAMILY('ABC')
#! ***************************************************************************
#! ***************************************************************************
#! Template based on https://github.com/Rick-UpperPark/UpperParkFree/blob/master/Templates/UP_BrowseHelper.tpw
#! Modifications by Carl Barnes https://github.com/CarlTBarnes
#! Note Carl changed "FieldNo" to "ColumnNo" because Field is usually for Queue not LIST. 
#! Check Rick's Way box to revert to wrong names
#!
#EXTENSION(UP_BrowseColumnEquates2,'Generate Browse Column and Group Number equates'),PROCEDURE,MULTI,REQ(BrowseBox(ABC),AFTER)
  #DISPLAY('Template to generate equates for each column ')
  #DISPLAY('in a ABC browse list control.') 
  #DISPLAY('Equates named: Brw#:ColumnNo:FieldVariable') 
  #DISPLAY('') 
  #DISPLAY('Carl Barnes added GROUP Equates. ')   
  #DISPLAY('Equates named: Brw#:GroupNo:FieldVariable')   
  #DISPLAY('The Variable is the first in the Group')   
  #DISPLAY('')   
  #PROMPT('Use "FieldNo" instead of "ColumnNo" equates (Rick''s way)',CHECK),%UseRicksFieldNo,AT(2) 
  #PROMPT('LIST Groups [] generate "GroupNo" equates',CHECK),%GenGroupEquates,AT(2)
  #DISPLAY('')   
  #DISPLAY('These equates can be used instead of hard-coded ')
  #DISPLAY('numeric constants in code where you need the column number.') 
  #DISPLAY('The equate automatically generates the correct value')
  #DISPLAY('if the order of the columns change or new columns are added.') 
#AT(%DataSection)
#IF (%UseRicksFieldNo=%False)
  #EQUATE(%ColumnNoLabel,':ColumnNo')
#ELSE
  #EQUATE(%ColumnNoLabel,':FieldNo')
#ENDIF
! %ListControl Equates for PROPLIST column numbers - UP_BrowseColumnEquates template
#!  ITEMIZE(1),PRE(%ManagerName:FieldNo)  <-- Carl changed FieldNo to ColumnNo
  ITEMIZE(1),PRE(%ManagerName%ColumnNoLabel)
  #FIX(%Control,%ListControl)
  #FOR(%ControlField)
    #SET(%ValueConstruct,%ControlField)
    #INSERT(%CleanDimensions(ABC))
%[30]ValueConstruct EQUATE()
  #ENDFOR
  End
#! ============== Groups =================
#! Groups start with '['. 
#! In the LIST Format() find the Start of the Next List Field's Format in %ControlFieldFormat
#! If that's a Group there will be a '[' BEFORE the Control's Format
  #IF (%GenGroupEquates=%True)
    #DECLARE(%FormatLIST,STRING)
    #SET(%FormatLIST, EXTRACT(%ControlStatement, 'FORMAT', 1))
    #IF (INSTRING('[',%FormatLIST,1))
      #SET(%FormatLIST, SUB(%FormatLIST, 2, LEN(%FormatLIST)-2))  
      #DECLARE(%GroupConstruct,STRING)
      #DECLARE(%PosFieldFmt, LONG)  
         #!dbg: FormatLIST: %FormatLIST
      #SUSPEND
#?!Group Equates %ListControl{PROPLIST:Group + PROPLIST:xxxx, BRW#:GroupNo:Pre:Field}
      #FIX(%Control,%ListControl)
      #FOR(%ControlField)
        #SET(%PosFieldFmt, INSTRING(%ControlFieldFormat, %FormatLIST, 1, 1))
        #IF (INSTRING('[',SUB(%FormatLIST,1,%PosFieldFmt-1),1))
          #SET(%ValueConstruct,%ControlField)
          #INSERT(%CleanDimensions(ABC))
          #SET(%ValueConstruct,%ManagerName & %ColumnNoLabel &':'& %ControlField)
          #SET(%GroupConstruct,%ManagerName &':GroupNo:'& %ControlField)
%[30]GroupConstruct EQUATE(%ValueConstruct)    
            #!dbg: CtrlPos=%PosFieldFmt Fmt List=%(SUB(%FormatLIST,1,%PosFieldFmt+5))  Ctrl=%ControlFieldFormat
        #ENDIF 
        #! Cutoff the front the FormatLIST just found for Column's format
        #SET(%FormatLIST,SUB(%FormatLIST,%PosFieldFmt + LEN(%ControlFieldFormat),9999) )
            #!dbg: FormatNext=%FormatLIST
      #ENDFOR
      #RESUME
    #ENDIF  
  #ENDIF    
#ENDAT

image

Below is that same LIST with groups and the Format viewed in my Preview class. I call the Groups 1,2,3 but if you look at the Grp2 LISTPROP you see the number you use with PROPLIST:Group is 3

image

4 Likes