SpecStruc-Interface.xml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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="INTERFACE_Structure">
  5. <title>INTERFACE Structure<indexterm>
  6. <primary>INTERFACE Structure</primary>
  7. </indexterm></title>
  8. <para><emphasis>interfacename </emphasis><emphasis role="bold">[
  9. (</emphasis><emphasis> parameters </emphasis><emphasis role="bold">) ] :=
  10. INTERFACE<indexterm>
  11. <primary>INTERFACE</primary>
  12. </indexterm> [ (</emphasis><emphasis> inherit </emphasis><emphasis
  13. role="bold">) ]</emphasis><emphasis role="bold"> </emphasis></para>
  14. <para><emphasis>members;</emphasis></para>
  15. <para><emphasis role="bold">END;</emphasis></para>
  16. <informaltable colsep="1" frame="all" rowsep="1">
  17. <tgroup cols="2">
  18. <colspec align="left" colwidth="122.40pt" />
  19. <colspec />
  20. <tbody>
  21. <row>
  22. <entry><emphasis>interfacename</emphasis></entry>
  23. <entry>The ECL definition name of the interface.</entry>
  24. </row>
  25. <row>
  26. <entry><emphasis>parameters</emphasis></entry>
  27. <entry><para>Optional. The input parameters to the
  28. interface.</para></entry>
  29. </row>
  30. <row>
  31. <entry><emphasis>inherit</emphasis></entry>
  32. <entry>Optional. A comma-delimited list of INTERFACE structures
  33. whose <emphasis>members</emphasis> to inherit. This may not be a
  34. passed parameter. Multiple <emphasis>inherited</emphasis> interfaces
  35. may contain attributes with the same name if they are the same type
  36. and receive the same parameters, but if those
  37. <emphasis>inherited</emphasis> <emphasis>members</emphasis> have
  38. different values defined for them, the conflict must be resolved by
  39. overriding that <emphasis>member</emphasis> in the current
  40. instance.</entry>
  41. </row>
  42. <row>
  43. <entry><emphasis>members</emphasis></entry>
  44. <entry>Definitions, which may be EXPORTed or SHARED. These may be
  45. similar to fields defined in a RECORD structure where only the type
  46. and name are defined—the expression that defines the value may be
  47. left off (except in some cases where the expression itself defines
  48. the type of definition, like TRANSFORM structures). If no default
  49. value is defined for a <emphasis>member</emphasis>, any MODULE
  50. derived from the INTERFACE must define a value for that
  51. <emphasis>member</emphasis> before that MODULE can be used. These
  52. may not include other INTERFACE or abstract MODULE
  53. structures.</entry>
  54. </row>
  55. </tbody>
  56. </tgroup>
  57. </informaltable>
  58. <para>The <emphasis role="bold">INTERFACE </emphasis>structure defines a
  59. structured block of related <emphasis>members</emphasis> that may be passed
  60. as a single parameter to complex queries, instead of passing each attribute
  61. individually. It is similar to a MODULE structure with the VIRTUAL option,
  62. except errors are given for private (not SHARED or EXPORTed)
  63. <emphasis>member</emphasis> definitions.</para>
  64. <para>An INTERFACE is an abstract structure—a concrete instance must be
  65. defined before it can be used in a query. A MODULE structure that inherits
  66. the INTERFACE and defines the values for the <emphasis>members</emphasis>
  67. creates the concrete instance for use by the query.</para>
  68. <para>Example:</para>
  69. <programlisting>HeaderRec := RECORD
  70. UNSIGNED4 RecID;
  71. STRING20 company;
  72. STRING25 address;
  73. STRING25 city;
  74. STRING2 state;
  75. STRING5 zip;
  76. END;
  77. HeaderFile := DATASET([{1,'ABC Co','123 Main','Boca Raton','FL','33487'},
  78. {2,'XYZ Co','456 High','Jackson','MI','49202'},
  79. {3,'ABC Co','619 Eaton','Jackson','MI','49202'},
  80. {4,'XYZ Co','999 Yamato','Boca Raton','FL','33487'},
  81. {5,'Joes Eats','666 Slippery Lane','Nether','SC','12345'}
  82. ],HeaderRec);
  83. //define an interface
  84. IHeaderFileSearch := INTERFACE
  85. EXPORT STRING20 company_val;
  86. EXPORT STRING2 state_val;
  87. EXPORT STRING25 city_val := '';
  88. END;
  89. //define a function that uses that interface
  90. FetchAddress(IHeaderFileSearch opts) := FUNCTION
  91. //define passed values tests
  92. CompanyPassed := opts.company_val &lt;&gt; '';
  93. StatePassed := opts.state_val &lt;&gt; '';
  94. CityPassed := opts.city_val &lt;&gt; '';
  95. //define passed value filters
  96. NFilter := HeaderFile.Company = opts.company_val;
  97. SFilter := HeaderFile.State = opts.state_val;
  98. CFilter := HeaderFile.City = opts.city_val;
  99. //define the actual filter to use based on the passed values
  100. filter := MAP(CompanyPassed AND StatePassed AND CityPassed
  101. =&gt; NFilter AND SFilter AND CFilter,
  102. CompanyPassed AND StatePassed
  103. =&gt; NFilter AND SFilter ,
  104. CompanyPassed AND CityPassed
  105. =&gt; NFilter AND CFilter,
  106. StatePassed AND CityPassed
  107. =&gt; SFilter AND CFilter,
  108. CompanyPassed =&gt; NFilter ,
  109. StatePassed =&gt; SFilter ,
  110. CityPassed =&gt; CFilter,
  111. TRUE);
  112. RETURN HeaderFile(filter);
  113. END;
  114. //*****************************************************************
  115. //then you can use the interface
  116. InRec := {HeaderRec AND NOT [RecID,Address,Zip]};
  117. //this MODULE creates a concrete instance
  118. BatchHeaderSearch(InRec l) := MODULE(IHeaderFileSearch)
  119. EXPORT STRING120 company_val := l.company;
  120. EXPORT STRING2 state_val := l.state;
  121. EXPORT STRING25 city_val := l.city;
  122. END;
  123. //that can be used like this
  124. FetchAddress(BatchHeaderSearch(ROW({'ABC Co','',''},InRec)));
  125. //or we can define an input dataset
  126. InFile := DATASET([{'ABC Co','Boca Raton','FL'},
  127. {'XYZ Co','Jackson','MI'},
  128. {'ABC Co','',''},
  129. {'XYZ Co','',''},
  130. {'Joes Eats','',''}
  131. ],InRec);
  132. //and an output nested child structure
  133. HeaderRecs := RECORD
  134. UNSIGNED4 Pass;
  135. DATASET(HeaderRec) Headers;
  136. END;
  137. //and allow PROJECT to run the query once for each record in InFile
  138. HeaderRecs XF(InRec L, INTEGER C) := TRANSFORM
  139. SELF.Pass := C;
  140. SELF.Headers := FetchAddress(BatchHeaderSearch(L));
  141. END;
  142. batchHeaderLookup := PROJECT(InFile,XF(LEFT,COUNTER));
  143. batchHeaderLookup;</programlisting>
  144. <para>See Also: <link linkend="MODULE_Structure">MODULE Structure</link>,
  145. <link linkend="LIBRARY">LIBRARY</link></para>
  146. </sect1>