Expr-InOps.xml 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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="IN_Operator">
  5. <title>IN Operator<indexterm>
  6. <primary>IN</primary>
  7. </indexterm><indexterm>
  8. <primary>IN Operator</primary>
  9. </indexterm></title>
  10. <para><emphasis>value </emphasis><emphasis role="bold">IN
  11. </emphasis><emphasis>value_set</emphasis></para>
  12. <informaltable colsep="1" frame="all" rowsep="1">
  13. <tgroup cols="2">
  14. <colspec align="left" colwidth="122.40pt" />
  15. <colspec />
  16. <tbody>
  17. <row>
  18. <entry><emphasis>value</emphasis></entry>
  19. <entry>The value to find in the <emphasis>value_set</emphasis>. This
  20. is usually a single value, but if the <emphasis>value_set</emphasis>
  21. is a DICTIONARY with a multiple-component key, this may also be a
  22. ROW.</entry>
  23. </row>
  24. <row>
  25. <entry><emphasis>value_set</emphasis></entry>
  26. <entry>A set of values. This may be a set expression, the SET
  27. function, or a DICTIONARY.</entry>
  28. </row>
  29. </tbody>
  30. </tgroup>
  31. </informaltable>
  32. <para>The <emphasis role="bold">IN</emphasis> operator is shorthand for a
  33. collection of OR conditions. It is an operator that will search a set to
  34. find an inclusion, resulting in a Boolean return. Using IN is much more
  35. efficient than the equivalent OR expression.</para>
  36. <para>Example:</para>
  37. <programlisting>ABCset := ['A', 'B', 'C'];
  38. IsABCStatus := Person.Status IN ABCset;
  39. //This code is directly equivalent to:
  40. // IsABCStatus := Person.Status = 'A' OR
  41. // Person.Status = 'B' OR
  42. // Person.Status = 'C';
  43. IsABC(STRING1 char) := char IN ABCset;
  44. Trades_ABCstat := Trades(IsABC(rate));
  45. // Trades_ABCstat is a record set definition of all those
  46. // trades with a trade status of A, B, or C
  47. //SET function examples
  48. r := {STRING1 Letter};
  49. SomeFile := DATASET([{'A'},{'B'},{'C'},{'D'},{'E'},
  50. {'F'},{'G'},{'H'},{'I'},{'J'}],r);
  51. x := SET(SomeFile(Letter &gt; 'C'),Letter);
  52. y := 'A' IN x; //results in FALSE
  53. z := 'D' IN x; //results in TRUE
  54. //DICTIONARY examples:
  55. rec := {STRING color,UNSIGNED1 code};
  56. ColorCodes := DATASET([{'Black' ,0 },
  57. {'Brown' ,1 },
  58. {'Red' ,2 },
  59. {'White' ,3 }], rec);
  60. CodeColorDCT := DICTIONARY(ColorCodes,{Code =&gt; Color});
  61. OUTPUT(6 IN CodeColorDCT); //true
  62. ColorCodesDCT := DICTIONARY(ColorCodes,{Color,Code});
  63. OUTPUT(ROW({'Red',2},rec) IN ColorCodesDCT);
  64. </programlisting>
  65. <para>See Also: <link linkend="Basic_Attribute_Types">Basic Definition
  66. Types</link>, <link linkend="Basic_Attribute_Types">Definition Types</link>
  67. (<link linkend="Set_Attributes">Set Definitions</link>), <link
  68. linkend="Logical_Operators">Logical Operators</link>, <link
  69. linkend="PARSE_Pattern_Value_Types">PATTERN</link>, <link
  70. linkend="DICTIONARY">DICTIONARY</link>, <link linkend="ROW">ROW</link>,
  71. <link linkend="SET">SET</link>, <link linkend="Recordset_Filtering">Sets and
  72. Filters</link>, <link linkend="SET_OF">SET OF</link>, <link
  73. linkend="Set_Operators">Set Operators</link></para>
  74. </sect1>