Basics-FieldandAttribute.xml 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE sect1 PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
  4. <sect1 id="Field_and_Attribute_Qualification">
  5. <title>Field and Definition Qualification</title>
  6. <sect2 id="Imported_Attributes">
  7. <title>Imported Definitions</title>
  8. <para>EXPORTed<indexterm>
  9. <primary>EXPORTed</primary>
  10. </indexterm> definitions<indexterm>
  11. <primary>EXPORTed Definitions</primary>
  12. </indexterm> defined within another module and IMPORTed<indexterm>
  13. <primary>IMPORTed</primary>
  14. </indexterm> (see the <link linkend="EXPORT">EXPORT</link> and <link linkend="IMPORT">IMPORT</link>
  15. keywords) are available for use in
  16. the definition that contains the IMPORT. Imported Definitions must be
  17. fully qualified by their Module name and Definition name, using dot
  18. syntax<indexterm>
  19. <primary>dot syntax</primary>
  20. </indexterm> (module.definition).</para>
  21. <programlisting>IMPORT abc; //make all exported definitions in the abc module available
  22. EXPORT Definition1 := 5; //make Definition1 available to other modules
  23. Definition2 := abc.Definition2 + Definition1; // object qualification needed for Definitions from abc module</programlisting>
  24. </sect2>
  25. <sect2 id="Fields_in_Datasets">
  26. <title>Fields in Datasets</title>
  27. <para>Each Dataset counts as a qualified scope and the fields within them
  28. are fully qualified by their Dataset (or record set) name and Field name,
  29. using dot syntax (dataset.field). Similarly, the result set of the
  30. TABLE<indexterm>
  31. <primary>TABLE</primary>
  32. </indexterm> built-in function (see the <emphasis
  33. role="bold">TABLE</emphasis> keyword) also acts as a qualified scope. The
  34. name of the record set to which a field belongs is the object name:</para>
  35. <programlisting>Young := YearOf(Person.per_dbrth) &lt; 1950;
  36. MySet := Person(Young);</programlisting>
  37. <para>When naming a Dataset as part of a definition, the fields of that
  38. Definition (or record set) come into scope. If Parameterized Definitions
  39. (functions) are nested, only the innermost scope is available. That is,
  40. all the fields of a Dataset (or derived record set) are in scope in the
  41. filter expression. This is also true for expressions parameters of any
  42. built-in function that names a Dataset or derived record set as a
  43. parameter.</para>
  44. <programlisting>MySet1 := Person(YearOf(dbrth) &lt; 1950);
  45. // MySet1 is the set of Person records who were born before 1950</programlisting>
  46. <para></para>
  47. <programlisting>MySet2 := Person(EXISTS(OpenTrades(AgeOf(trd_dla) &lt; AgeOf(Person.per_dbrth))));</programlisting>
  48. <para></para>
  49. <programlisting>// OpenTrades is a pre-defined record set.
  50. //All Trades fields are in scope in the OpenTrades record set filter
  51. //expression, but Person is required here to bring Person.per_dbrth
  52. // into scope
  53. //This example compares each trades' Date of Last Activity to the
  54. // related person’s Date Of Birth</programlisting>
  55. <para>Any field in a Record Set <emphasis role="underline">can</emphasis>
  56. be qualified with either the Dataset name the Record Set is based on, or
  57. any other Record Set name based on the same base dataset. For
  58. example:</para>
  59. <programlisting>memtrade.trd_drpt
  60. nondup_trades.trd_drpt
  61. trades.trd_drpt</programlisting>
  62. <para>all refer to the same field in the memtrade dataset.</para>
  63. <para>For consistency, you should typically use the base dataset name for
  64. qualification. You can also use the current Record Set's name in any
  65. context where the base dataset name would be confusing.</para>
  66. </sect2>
  67. <sect2 id="Scope_Resolution_Operator">
  68. <title>Scope Resolution Operator</title>
  69. <para>Identifiers are looked up in the following order:</para>
  70. <para>1. The currently active dataset, if any</para>
  71. <para>2. The current definition being defined, and any parameters it is
  72. based on</para>
  73. <para>3. Any definitions or parameters of any MODULE or FUNCTION structure
  74. that contains the current definition</para>
  75. <para>This might mean that the definition or parameter you want to access
  76. isn't picked because it is hidden as in a parameter or private definition
  77. name clashing with the name of a dataset field.</para>
  78. <para>It would be better to rename the parameter or private definition so
  79. the name clash cannot occur, but sometimes this is not possible.</para>
  80. <para>You may direct access to a different match by qualifying the field
  81. name with the scope resolution operator (the carat (^) character), using
  82. it once for each step in the order listed above that you need to
  83. skip.</para>
  84. <para>This example shows the qualification order necessary to reach a
  85. specific definition/parameter:</para>
  86. <para><programlisting>ds := DATASET([1], { INTEGER SomeValue });
  87. INTEGER SomeValue := 10; //local definition
  88. myModule(INTEGER SomeValue) := MODULE
  89. EXPORT anotherFunction(INTEGER SomeValue) := FUNCTION
  90. tbl := TABLE(ds,{SUM(GROUP, someValue), // 1 - DATASET field
  91. SUM(GROUP, ^.someValue), // 84 - FUNCTION parameter
  92. SUM(GROUP, ^^.someValue), // 42 - MODULE parameter
  93. SUM(GROUP, ^^^.someValue), // 10 - local definition
  94. 0});
  95. RETURN<indexterm>
  96. <primary>RETURN</primary>
  97. </indexterm> tbl;
  98. END;
  99. EXPORT result := anotherFunction(84);
  100. END;
  101. OUTPUT(myModule(42).result);</programlisting></para>
  102. <para>In this example there are four instances of the name
  103. "SomeValue":</para>
  104. <para>a field in a DATASET.</para>
  105. <para>a local definition</para>
  106. <para>a parameter to a MODULE structure</para>
  107. <para>a parameter to a FUNCTION structure</para>
  108. <para>The code in the TABLE function<indexterm>
  109. <primary>TABLE function</primary>
  110. </indexterm> shows how to reference each separate instance.</para>
  111. <para>While this syntax allows exceptions where you need it, creating
  112. another definition with a different name is the preferred solution.</para>
  113. </sect2>
  114. </sect1>