home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / dataflex / for_all.pkg < prev    next >
Encoding:
Text File  |  1993-08-10  |  5.6 KB  |  208 lines

  1. //************************************************************************
  2. //
  3. // Copyright 1987-1992 Data Access Corporation, Miami FL, USA
  4. // All Rights reserved
  5. // DataFlex is a registered trademark of Data Access Corporation.
  6. //
  7. //
  8. //     $Source: /u3/source.30/product/pkg/RCS/for_all.pkg,v $
  9. //     $Revision: 1.1 $
  10. //     $State: Exp $
  11. //     $Author: james $
  12. //     $Date: 1992/09/08 14:43:05 $
  13. //     $Locker:  $
  14. //
  15. //     $Log: for_all.pkg,v $
  16. //Revision 1.1  1992/09/08  14:43:05  james
  17. //Initial revision
  18. //
  19. //Revision 1.4  92/05/14  16:49:32  SWM
  20. //Updated Copyright slug.
  21. //
  22. //Revision 1.3  92/03/09  19:02:09  james
  23. //Added #CHKSUB directive to insure source
  24. //only compiled with correct revision of 
  25. //compiler.
  26. //
  27. //Revision 1.2  92/02/18  20:04:39  steve-l
  28. //altered main command to permit use of file.field instead of index.#
  29. //
  30. //Revision 1.1  91/10/23  10:20:51  elsa
  31. //Initial revision
  32. //
  33. //************************************************************************/
  34.  
  35. //************************************************************************
  36. //     File Name: For_All.Pkg
  37. // Creation Date: January 1, 1991
  38. // Modified Date: May 23, 1991
  39. //     Author(s): Steven A. Lowe
  40. //
  41. // This module contains the command definitions for the FOR_ALL construct.
  42. //
  43. // FOR_ALL is used to select and process a set of records in a database file;
  44. // FOR_ALL constructs may be nested. FOR_ALL is intended to work in
  45. // conjunction with constraint-clauses.
  46. //
  47. // SYNTAX:
  48. //
  49. //  For_All <File> BY|DOWN <Index> {AS QUE|QUEUE} {DO}
  50. //    <Constraints...>
  51. //    {DO}
  52. //      <loop body>
  53. //  End_For_All
  54. //
  55. // This set of macros implements a constraint-oriented file enumeration
  56. // syntax.  For example, to list all Customers by name in reverse order:
  57. // 
  58. //   For_All Customer DOWN Customer.Customer_Name DO
  59. //     showln "Customer: " Customer.RecNum "  " Customer.Customer_Name
  60. //   End_For_All
  61. //
  62. // To list only Customers with a Balance greater than their credit limit:
  63. //
  64. //   For_All Customer BY Index.1
  65. //     CONSTRAIN Customer.Balance GT Customer.Credit_Limit
  66. //     DO
  67. //       showln "Customer: " Customer.RecNum "  " Customer.Customer_Name
  68. //   End_For_All
  69. //
  70. // Constraint clauses are:
  71. //
  72. //   CONSTRAIN <File> RELATES TO <File> ...
  73. //   CONSTRAIN <File> AS <Expression>
  74. //   CONSTRAIN <File.Field> AS <Expression>
  75. //   CONSTRAIN <File.Field> BETWEEN <lowBound> AND <highBound>
  76. //
  77. // For example, to list all customers with a bad status whose names start
  78. // with "A" and which have not made a payment in thirty days:
  79. //
  80. //    For_All Customer BY Index.2       //Index.2 = <Status>+<Name>
  81. //      CONSTRAIN Customer.Status EQ BAD
  82. //      CONSTRAIN Customer.Customer_Name GE "A"
  83. //      CONSTRAIN Customer.Customer_Name LT "B"
  84. //      CONSTRAIN Customer.Last_Pymt_Date LE (Today - 30)
  85. //      DO
  86. //        showln "Customer: " Customer.RecNum "  " Customer.Customer_Name
  87. //    End_For_All
  88. //
  89. //************************************************************************/
  90.  
  91. #CHKSUB 1 1 // Verify the UI subsystem.
  92.  
  93. #COMMAND For_All TR "BY""DOWN" R """DO""AS" """AS""QUE""QUEUE" """DO""QUE""QUEUE" .
  94.   #CHECK !1.RECNUM   //must be a file
  95.   #PUSH !u
  96.   #SET U$ !a
  97.   #IFCLASS !3 "F"
  98.     integer FldNdx!uForAll       //make integer to hold index for field
  99.     #SET Q$ !1.RECNUM
  100.     !A [] $82 |CI!q FILENUMBER
  101.     #SET Q$ %!3                  //get field number
  102.     !A [] $82 !3 FIELDNUMBER
  103.     !A [] $345 FILENUMBER FldNdx!uForAll //FIELD_DEF command to set index int
  104.   #ENDIF
  105.   goto EP#!uINVOKE   //start loop
  106.   #IFSAME !4 DO
  107.   #ELSE
  108.     #IFSAME !6 DO
  109.     #ELSE
  110.       MAKEDEF$ FAC!u.X
  111.     #ENDIF
  112.   #ENDIF
  113.   #IFSAME !4 AS
  114.     MAKEDEF$ FAQ!u.X
  115.   #ELSE
  116.     #IFSAME !5 AS
  117.       MAKEDEF$ FAQ!u.X
  118.     #ENDIF
  119.   #ENDIF
  120.   #IFDEF FAQ!u.X
  121.   #ELSE
  122. EP#!uNEXT:
  123.     Constraint_Set (|CI!u * -1)
  124.     #IFSAME !2 BY
  125.       #IFCLASS !3 "F"
  126.         Constrained_Find GT !1 by FldNdx!uForAll
  127.       #ELSE
  128.         Constrained_Find GT !1 by !3
  129.       #ENDIF
  130.     #ELSE
  131.       #IFCLASS !3 "F"
  132.         Constrained_Find LT !1 by FldNdx!uForAll
  133.       #ELSE
  134.         Constrained_Find LT !1 by !3
  135.       #ENDIF
  136.     #ENDIF
  137. return
  138.   #ENDIF
  139. EP#!uFIRST:
  140.   Constraint_Set (|CI!u * -1)
  141.   #IFSAME !2 BY
  142.     #IFCLASS !3 "F"
  143.       Constrained_Find FIRST !1 by FldNdx!uForAll
  144.     #ELSE
  145.       Constrained_Find FIRST !1 by !3
  146.     #ENDIF
  147.   #ELSE
  148.     #IFCLASS !3 "F"
  149.       Constrained_Find LAST !1 by FldNdx!uForAll
  150.     #ELSE
  151.       Constrained_Find LAST !1 by !3
  152.     #ENDIF
  153.   #ENDIF
  154. return
  155. EP#!uINVOKE:
  156.   Constraint_Set (|CI!u * -1) CLEAR
  157.   #IFDEF FAC!u.X
  158.     gosub EP#!uCONSTRAIN           //initialize constraint set
  159.   #ENDIF
  160.   gosub EP#!uFIRST
  161. EP#!uNVKL:
  162.   indicate CONTINUE TRUE
  163.   [FOUND CONTINUE] begin
  164.     gosub EP#!uPROCESS
  165.     #IFDEF  FAQ!u.X                //if AS QUEUE|QUE,
  166.       [CONTINUE] gosub EP#!uFIRST  //find next queue element
  167.     #ELSE                          //else
  168.       [CONTINUE] gosub EP#!uNEXT   //find next set element
  169.     #ENDIF
  170.     [CONTINUE] goto EP#!uNVKL      //loop
  171.   end
  172.   goto EFA!u                       //exit past loop body
  173.   #IFDEF FAC!u.X
  174. EP#!uCONSTRAIN:
  175.   #ELSE
  176. EP#!uPROCESS:
  177.   #ENDIF
  178. #ENDCOMMAND
  179.  
  180. //
  181. //DO
  182. //
  183. //This command starts the loop process body when constraints are used;
  184. //If no constraints are required, DO should be specified on the FOR_ALL
  185. //command line, and not on a line by itself
  186. //
  187. #COMMAND Do 
  188.   #IFDEF EP#!uCONSTRAIN
  189. return
  190.   #ENDIF
  191. EP#!uPROCESS:
  192.   #IF (!0>0)
  193.     !1 !2 !3 !4 !5 !6 !7 !8 !9
  194.   #ENDIF
  195. #ENDCOMMAND
  196.  
  197. //
  198. //END_FOR_ALL
  199. //
  200. //Ends a For_All loop 
  201. //
  202. #COMMAND End_For_All .
  203. return
  204. EFA!u:
  205.   #POP U$
  206. #ENDCOMMAND
  207.  
  208.