home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR36 / C7101.ZIP / REPORT.TPX < prev    next >
Text File  |  1994-01-12  |  14KB  |  277 lines

  1. #!┌───────────────────────────┤Template Segment├───────────┬─────────────────┐
  2. #!│                               Report.TPX               │Version: 3007.000│
  3. #!├───────────────────────────────┤Contents├───────────────┴─────────────────┤
  4. #!│Structure             Type       Description                              │
  5. #!│────────────────────  ─────────  ─────────────────────────────────────────│
  6. #!│Report                PROCEDURE  Print a report from a file               │
  7. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  8. #!│Version   Comments                                                        │
  9. #!│────────  ────────────────────────────────────────────────────────────────│
  10. #!│3007.000  Release of CDD3 version 3007 templates                          │
  11. #!└──────────────────────────────────────────────────────────────────────────┘
  12. #!
  13. #PROCEDURE(Report,'Print a Report'),REPORT,SCREEN
  14. #!
  15. #!┌──────────────────────────┤Procedure Template├──────────┬─────────────────┐
  16. #!│                                 Report                 │Version: 3007.000│
  17. #!├──────────────────────────────┤Description├─────────────┴─────────────────┤
  18. #!│This procedure template is designed to print most reports an application  │
  19. #!│may require.  Secondary file relationships (1:MANY) are handled by the    │
  20. #!│%RptGetRelatedRecords #GROUP code, which recurses through as many levels  │
  21. #!│of 1:MANY relationships as are defined in the File Schematic, starting    │
  22. #!│with the Primary file, going down the chain of Secondary files beginning  │
  23. #!│with the first Child file of the Primary.  Any other Child files of the   │
  24. #!│Primary file begin a second 1:MANY file chain -- this is not supported.   │
  25. #!│                                                                          │
  26. #!│The MANY:1 (lookup) relationships go multiple levels below the first file │
  27. #!│related to, for every 1:MANY (Parent-Child) relationship at each level.   │
  28. #!│A lookup file may generate a second related lookup.                       │
  29. #!│                                                                          │
  30. #!│This File Schematic is directly supported:                                │
  31. #!│   Primary                                                                │
  32. #!│    └──Secondary (Lookup MANY:1 from Primary)                            │
  33. #!│    │  └──Secondary (Lookup File from Lookup File)                       │
  34. #!│    └──Secondary (Lookup MANY:1 from Primary)                            │
  35. #!│    └─Secondary (Child File of Primary)                                 │
  36. #!│       └──Secondary (Lookup MANY:1 from Secondary Child)                 │
  37. #!│       └──Secondary (Lookup MANY:1 from Secondary Child)                 │
  38. #!│       │  └──Secondary (Lookup File from Lookup File)                    │
  39. #!│       └─Secondary (Child File of Secondary Child)                      │
  40. #!│          └──Secondary (Lookup MANY:1 from Secondary Child)              │
  41. #!│                                                                          │
  42. #!│This File Schematic is NOT directly supported:                            │
  43. #!│   Primary                                                                │
  44. #!│    └──Secondary (Lookup File from Primary)                              │
  45. #!│    │  └─Secondary (Child of Lookup File) -- NO Children of Lookups     │
  46. #!│    └─Secondary (Child File of Primary)                                 │
  47. #!│    │  └──Secondary (Lookup File from Secondary Child)                   │
  48. #!│    └─Secondary (Another Child File of Primary) -- NO 2nd Child chains  │
  49. #!│                                                                          │
  50. #!│Formula Classes supported are:                                            │
  51. #!│  The prefix of a Parent or Child file with :FILTER appended (Pre:FILTER).│
  52. #!│    Creates a record filter to skip records in which the filter           │
  53. #!│    expression does not evaluate as true, just after the file's record    │
  54. #!│    is read.                                                              │
  55. #!│  The name of a Parent or Child file (not a Lookup file).                 │
  56. #!│    Calculates the formula after each read from the file -- this is       │
  57. #!│    immediately after any Pre:FILTER is evaluated.                        │
  58. #!│  No class --                                                             │
  59. #!│    Calculates the formula every time a record is read from any file.     │
  60. #!│                                                                          │
  61. #!│Multi-Up labels are supported -- they must be in the Body Detail band.    │
  62. #!│Multiple Group Breaks are supported on every (Primary or Child Secondary  │
  63. #!│file not on Lookups.                                                      │
  64. #!├───────────────────────────────┤Comments├─────────────────────────────────┤
  65. #!│Version   Comments                                                        │
  66. #!│────────  ────────────────────────────────────────────────────────────────│
  67. #!│3007.000  Release of CDD3 version 3007 templates                          │
  68. #!└──────────────────────────────────────────────────────────────────────────┘
  69. #!
  70. #PROTOTYPE('')
  71. #DISPLAY(' ')
  72. #PROMPT('Enable ESC Key Abort',CHECK),%EscapeAbort
  73. #PROMPT('Show Report Progress',CHECK),%ProgressScreen
  74. #PROMPT('CLEAR Record &First',CHECK),%ClearRecord
  75. #PROMPT('Primary File &Access',OPTION),%AccessMethod
  76. #PROMPT('Keyed Order',RADIO)
  77. #PROMPT('Record Order',RADIO)
  78. #PROMPT('Range &Limit Field',COMPONENT),%KeyComponent
  79. #PROMPT('Range &Value Field',FIELD),%ScopeValue
  80. #PROMPT('Red&irect Procedure',PROCEDURE),%RedirectProc
  81. #PROMPT('View Procedure',PROCEDURE),%ViewProc
  82. #INSERT(%RptSetFlags)
  83. #INSERT(%ReportErrorCheck)
  84. #INSERT(%StandardHeader)
  85. #IF(%RedirectProc AND %ViewProc)
  86.   #MAP('TEMPFILE.INC')
  87. #ENDIF
  88.  
  89. %Procedure       PROCEDURE
  90.  
  91. #INSERT(%FileControl)
  92. %LocalData
  93.  
  94. #INSERT(%ReportDataDeclares)                    #!Internal data declarations
  95.   #IF(%ProgressScreen)
  96.  
  97. %ScreenStructure
  98.   #ENDIF
  99.  
  100. %ReportStructure
  101.  
  102. #EMBED('Data Section')
  103.  
  104.   CODE
  105.   #EMBED('Setup Procedure')
  106.   #INSERT(%RptRedirectGroup)                    #!Printer Redirection handling
  107.   #INSERT(%FileControl)
  108.   OPEN(%Report)                                 #<!Prepare to print report
  109.   #EMBED('After Report OPEN before Title page')
  110.   #SET(%CodePosition,'SETUP')                   #!Class = SETUP report
  111.   #INSERT(%ReportFormulas)                      #!Generate formulas
  112.   #IF(%ReportTitle)                             #!Print Title Page
  113.   PRINT(%ReportPre:%ReportTitle)                #<!Print Title Page
  114.     #IF(%ProgressScreen)
  115.   DISPLAY                                       #<!Display report progress
  116.     #ENDIF
  117.   #ENDIF
  118.   #IF(%ClearRecord)
  119.     #FIX(%File,%Primary)
  120.   CLEAR(%FilePre:Record)                       #<!Clear record buffer
  121.   #ENDIF
  122.   #IF(%AccessMethod = 'Record Order')           #!Determine primary file order
  123.   SET(%Primary)                                #<!Top of file, record order
  124.   #ELSIF(%SelectorAccess)
  125.     #FIX(%File,%Primary)
  126.     #FIX(%Key,%PrimaryKey)
  127.     #IF(%KeyIndex = 'INDEX')
  128.       #IF(%SharedFiles)
  129.   LOCK(%Primary,1)                             #<!Exclusive access for build
  130.   IF DiskError('Cannot Lock %Primary') THEN RETURN. #<!Check for lock error
  131.       #ENDIF
  132.   BUILD(%PrimaryKey)                           #<!Build the index first
  133.       #IF(%SharedFiles)
  134.   UNLOCK(%Primary)                             #<!Unlock locked file
  135.       #ENDIF
  136.     #ENDIF
  137.   %KeyComponent = %ScopeValue
  138.   #EMBED('Before Initial SET()')
  139.   SET(%PrimaryKey,%PrimaryKey)                 #<!Beginning of selected records
  140.   #ELSE
  141.     #FIX(%File,%Primary)
  142.     #FIX(%Key,%PrimaryKey)
  143.     #IF(%KeyIndex = 'INDEX')
  144.       #IF(%SharedFiles)
  145.   LOCK(%Primary,1)                             #<!Exclusive access for build
  146.   IF DiskError('Cannot Lock %Primary ') THEN RETURN. #<!Check for lock error
  147.       #ENDIF
  148.   BUILD(%PrimaryKey)                           #<!Built the index first
  149.       #IF(%SharedFiles)
  150.   UNLOCK(%Primary)                             #<!Unlock locked file
  151.       #ENDIF
  152.     #ENDIF
  153.   #EMBED('Before Initial SET()')
  154.   SET(%PrimaryKey)                             #<!Top of file, keyed order
  155.   #ENDIF
  156.   #IF(%ProgressScreen)
  157.   OPEN(%Screen)
  158.   #ENDIF
  159.   #FIX(%File,%Primary)
  160.   %FilePre::PRINTED = 0                        #<!Set records printed flag
  161.   #EMBED('Before primary LOOP after SET')
  162.   LOOP                                         #<!Primary file process loop
  163.     #EMBED('Top of primary LOOP')
  164.     NEXT(%Primary)                             #<!Get each %Primary record
  165.     IF ERRORCODE() THEN ErrEndFileFlag# = 1 ELSE ErrEndFileFlag# = 0. #<!Flag EOF
  166.     #EMBED('In primary LOOP immediately after NEXT')
  167.   #IF(%ReportSaveExist)
  168.     #SET(%SaveFile,%Primary)                    #!Check for footer save fields
  169.     #INSERT(%SaveFooterFields)
  170.   #ENDIF
  171.   #IF(INSTRING(%Primary,%BreakFilesQueue,1,1))  #!Check for group breaks
  172.     #SET(%CurrentFile,%Primary)
  173.     #INSERT(%GroupBreakNumber)
  174.     #FIX(%File,%Primary)
  175.     #SET(%CodePosition,(%FilePre&':FILTER'))
  176.     #INSERT(%RptRecordFilter)                   #!Generate record filter
  177.     #EMBED('In primary LOOP after Record Filter before Lookups')
  178.     #SET(%GetLookupFrom,%Primary)
  179.     #INSERT(%RptGetLookupRecords)               #!Get all Lookup records
  180.     #SET(%CodePosition,%Primary)                #!Class = primary file
  181.     #INSERT(%ReportFormulas)                    #!Generate formulas
  182.     #INSERT(%PrimaryGroupBreak)
  183.   #ELSE                                         #!No group break on this file
  184.     #IF(%SelectorAccess)                        #!If record selector
  185.     IF %KeyComponent <> %ScopeValue |          #<!Past selected records?
  186.        OR ErrEndFileFlag#                      #<!End of file? Terminate report
  187.       BREAK
  188.     END
  189.       #FIX(%File,%Primary)
  190.       #SET(%CodePosition,(%FilePre&':FILTER'))
  191.     #INSERT(%RptRecordFilter)                   #!Generate record filter
  192.     #EMBED('In primary LOOP after Record Filter before Lookups')
  193.       #SET(%GetLookupFrom,%Primary)
  194.     #INSERT(%RptGetLookupRecords)               #!Get all Lookup records
  195.       #SET(%CodePosition,%Primary)              #!Class = primary file
  196.     #INSERT(%ReportFormulas)                    #!Generate formulas
  197.     #ELSE                                       #!No record selector
  198.     IF ErrEndFileFlag# THEN BREAK.             #<!End of file? Terminate report
  199.       #FIX(%File,%Primary)
  200.       #SET(%CodePosition,(%FilePre&':FILTER'))
  201.     #INSERT(%RptRecordFilter)                   #!Generate record filter
  202.     #EMBED('In primary LOOP after Record Filter before Lookups')
  203.       #SET(%GetLookupFrom,%Primary)
  204.     #INSERT(%RptGetLookupRecords)               #!Get all Lookup records
  205.       #SET(%CodePosition,%Primary)              #!Class = primary file
  206.     #INSERT(%ReportFormulas)                    #!Generate formulas
  207.     #ENDIF
  208.   #ENDIF
  209.     #EMBED('In primary LOOP after Lookups')
  210.   #IF(%SecondaryExist)                          #!If there are secondary files
  211.     #SET(%Parent,%Primary)
  212.     #INSERT(%RptGetRelatedRecords)
  213.   #ENDIF
  214.   #IF(%DetailPrinted <> 'PRINTED')              #!If detail print not generated
  215.     #INSERT(%PrintDetail)
  216.     #INSERT(%RptAbortKey)                       #!Insert ESC key abort loop
  217.   #ENDIF
  218.   END                                          #<!End %Primary file loop
  219.   #IF(%DetailPrinted <> 'PRINTED')              #!If detail print not generated
  220.     #IF(%ReportLabel)
  221.   #INSERT(%PrintDanglingLabels)
  222.     #ENDIF
  223.   #ENDIF
  224.   #EMBED('After primary LOOP before grand totals & final page')
  225.   #IF(%ReportGrand)                             #!Print grand totals
  226.   PRINT(%ReportPre:%ReportGrand)               #<!Print grand totals
  227.     #IF(%ProgressScreen)
  228.   DISPLAY                                      #<!Display report progress
  229.     #ENDIF
  230.   #ENDIF
  231.   #IF(%ReportFinal)                             #!Print final page
  232.   PRINT(%ReportPre:%ReportFinal)               #<!Print final page
  233.     #IF(%ProgressScreen)
  234.   DISPLAY                                      #<!Display report progress
  235.     #ENDIF
  236.   #ENDIF
  237.   CLOSE(%Report)                               #<!Close report
  238.   #SET(%ResetTotalType,'NONE')                  #!Reset report totals
  239.   #INSERT(%ResetTotals)
  240.   #IF(%ProgressScreen)
  241.   CLOSE(%Screen)                               #<!Close report progress screen
  242.   #ENDIF
  243.   #IF(%ViewProc)
  244.   %ViewProc                                    #<!Call View Procedure
  245.     #IF(%RedirectProc)
  246.   IF TempFile                                    #<!Check for temporary file
  247.     IF RemoveFile(TempFile)                      #<! and delete it
  248.       #INSERT(%DelTempFileErrMsg)
  249.     END
  250.   END
  251.     #ENDIF
  252.   #ENDIF
  253.   DO ProcedureReturn
  254. !─────────────────────────────────────────────────────────────────────────────
  255. ProcedureReturn ROUTINE
  256.   #EMBED('Before Closing Files')
  257.   #INSERT(%FileControl)
  258.   DO EndOfProcedureEmbed
  259.   RETURN
  260. !─────────────────────────────────────────────────────────────────────────────
  261. EndOfProcedureEmbed ROUTINE
  262. #EMBED('End of Procedure')
  263. #EMBED('Custom Routines')
  264.  
  265.   #IF(%ReportGroupExist)
  266. #INSERT(%BreakFooterRoutines)                   #!Print Group Break footers
  267. #INSERT(%BreakHeaderRoutines)                   #!Print Group Break headers
  268.   #ENDIF
  269. #INSERT(%RptTotalRoutines)                      #!Total tallys and resets
  270.   #IF(%ReportSaveExist)
  271.     #SET(%TempQueue,%SaveFilesQueue)
  272. #INSERT(%SaveFooterRoutine)                     #!Footer save field saves
  273. #INSERT(%PrintFooterRoutine)                    #!Footer save field saves
  274. #INSERT(%RestoreFooterRoutine)                  #!Footer save field saves
  275.   #ENDIF
  276. #CHAIN('Print.tpx')
  277.