Basics-FieldandAttribute.xml 6.1 KB

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