WebSphere Message Brokers
File: ak05770_
Writer: Bill Oppenheimer

Task topic

This build: July 31, 2007 21:32:29

Returning a scalar value in an XML message

Use a SELECT statement to return a scalar value by including both the THE and ITEM keywords, for example:

1 + THE(SELECT ITEM T.a FROM Body.Test.A[] AS T WHERE T.b = '123')

Use of the ITEM keyword

The following example shows the use of the ITEM keyword to select one item and create a single value.

SET OutputRoot.MQMD = InputRoot.MQMD;

SET OutputRoot.XML.Test.Result[] = 
   (SELECT ITEM T.UnitPrice FROM InputBody.Invoice.Purchases.Item[] AS T);

When the Invoice message is received as input, the ESQL shown generates the following output message:

<Test>
  <Result>27.95</Result>
  <Result>42.95</Result>
  <Result>59.99</Result>
</Test>

When the ITEM keyword is specified, the output message includes a list of scalar values. Compare this message to the one that is produced if the ITEM keyword is omitted, in which a list of fields (name-value pairs) is generated:

<Test>
  <Result>
    <UnitPrice>27.95</UnitPrice>
  </Result>
  <Result>
    <UnitPrice>42.95</UnitPrice>
  </Result>
  <Result>
    <UnitPrice>59.99</UnitPrice>
  </Result>
</Test>

Effects of the THE keyword

The THE keyword converts a list containing one item to the item itself.

The two previous examples both specified a list as the source of the SELECT in the FROM clause (the field reference has [] at the end to indicate an array), so typically the SELECT generates a list of results. Because of this you need to specify a list as the target of the assignment (thus the "Result[]" as the target of the assignment). However, you often know that the WHERE clause that you specify as part of the SELECT only returns TRUE for one item in the list. In this case use the THE keyword.

The following example shows the effect of using the THE keyword:

SET OutputRoot.MQMD = InputRoot.MQMD;

SET OutputRoot.XML.Test.Result =              
    THE (SELECT T.Publisher, T.Author FROM InputBody.Invoice.Purchases.Item[] 
         AS T WHERE T.UnitPrice = 42.95);

The THE keyword means that the target of the assignment becomes OutputRoot.XML.Test.Result (the "[]" is not permitted). Its use generates the following output message:

<Test>
  <Result>
    <Publisher>Morgan Kaufmann Publishers</Publisher>
    <Author>Don Chamberlin</Author>
  </Result>
</Test>

Selecting from a list of scalars

Consider the following sample input message:

<Test>
 <A>1</A>
 <A>2</A>
 <A>3</A>
 <A>4</A>
 <A>5</A>
</Test>

If you code the following ESQL statements to process this message:

SET OutputRoot.XML.Test.A[] = 
  (SELECT ITEM A from InputBody.Test.A[]  
   WHERE CAST(A AS INTEGER) BETWEEN 2 AND 4);

the following output message is generated:

      <A>2</A>
      <A>3</A>
      <A>4</A>
Notices | Trademarks | Downloads | Library | Support | Feedback

Copyright IBM Corporation 1999, 2007Copyright IBM Corporation 1999, 2007. All Rights Reserved.
This build: July 31, 2007 21:32:29

ak05770_ This topic's URL is: