ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Deferencing a fow from DB2

Post new topic  Reply to topic
 Deferencing a fow from DB2 « View previous topic :: View next topic » 
Author Message
Gideon
PostPosted: Tue Nov 08, 2011 11:41 am    Post subject: Deferencing a fow from DB2 Reply with quote

Chevalier

Joined: 18 Aug 2009
Posts: 403

After viewing the following doc:

I am trying to dereference a row derived from a SLECT statement of a DB2 table

I am trying to get the pid and price values in separate fields.

I wrote the following code:

Code:
   DECLARE cmd CHARACTER;
   DECLARE row1 ROW;

   SET cmd = 'select price, pid from db2inst1.catalog where pid = 1';
   --SET pid = PASSTHRU(cmd);
   SET row1.result[] = PASSTHRU(cmd);
   DECLARE ref1   REFERENCE TO row1.results[1];

   SET OutputLocalEnvironment.Variables.Ret3 = SQLCODE;
   SET OutputLocalEnvironment.Variables.Ret31 = row1.result[1];
   SET OutputLocalEnvironment.Variables.Ret32 = ref1;

From that I get the following in the Local Environment:


Code:
  (0x01000000:Name):Variables = (
    (0x03000000:NameValue):Ret3            = 0 (INTEGER)
    (0x01000000:Name     ):Ret31           = (
      (0x03000000:NameValue):PRICE = 1.00 (DECIMAL)
      (0x03000000:NameValue):PID   = 1 (INTEGER)
    )
    (0x01000000:Name     ):Ret32           = (
      (0x01000000:Name):result = (
        (0x03000000:NameValue):PRICE = 1.00 (DECIMAL)
        (0x03000000:NameValue):PID   = 1 (INTEGER)
      )
    )


I tried to dereference the reference as follows:

Code:
   SET OutputLocalEnvironment.Variables.Ret32 = ref1[1];


But this causes a syntax error

How do I write this so I can grab the '1' value from the "PID = 1 " data
Back to top
View user's profile Send private message Send e-mail
fjb_saper
PostPosted: Tue Nov 08, 2011 11:45 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

Don't know if it is a typo but you have

DECLARE ref1 REFERENCE TO row1.results[1];

and

SET OutputLocalEnvironment.Variables.Ret31 = row1.result[1];

One has an s at the end. The other does not...
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
Gideon
PostPosted: Tue Nov 08, 2011 12:11 pm    Post subject: Reply with quote

Chevalier

Joined: 18 Aug 2009
Posts: 403

I cleaned up my code:

Code:
   DECLARE cmd CHARACTER;
   DECLARE row1 ROW;

   SET cmd = 'select price, pid from db2inst1.catalog where pid = 1';
   --SET pid = PASSTHRU(cmd);
   SET row1.results[] = PASSTHRU(cmd);
   DECLARE ref1   REFERENCE TO row1.results[1];

   SET OutputLocalEnvironment.Variables.Ret3 = SQLCODE;
   SET OutputLocalEnvironment.Variables.Ret31 = row1.results[1];
   SET OutputLocalEnvironment.Variables.Ret32 = ref1;


And reran the program, and got the following:

Code:
  (0x01000000:Name):Variables = (
    (0x03000000:NameValue):Ret3            = 0 (INTEGER)
    (0x01000000:Name     ):Ret31           = (
      (0x03000000:NameValue):PRICE = 1.00 (DECIMAL)
      (0x03000000:NameValue):PID   = 1 (INTEGER)
    )
    (0x01000000:Name     ):Ret32           = (
      (0x03000000:NameValue):PRICE = 1.00 (DECIMAL)
      (0x03000000:NameValue):PID   = 1 (INTEGER)


I still do not know how to get the first section of the data, when I try to do the following:

Code:
   SET OutputLocalEnvironment.Variables.Ret32 = ref1[1];


I get a syntax error
Back to top
View user's profile Send private message Send e-mail
mqjeff
PostPosted: Tue Nov 08, 2011 12:23 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

So, typically, if you wanted the value of PID, you would
Code:
SET OutputLocalEnvironment.Variables.Ret32= ref1.PID;


If you wanted "the first child of ref1", you would
Code:
SET OutputLocalEnvironment.Variables.Ret32 = ref1.[1];

You could likewise
Code:
MOVE ref1 FIRSTCHILD;
or something similar...

Treat a Reference variable as if it were something like OutputRoot.
Back to top
View user's profile Send private message
vmcgloin
PostPosted: Tue Nov 08, 2011 12:34 pm    Post subject: Reply with quote

Knight

Joined: 04 Apr 2002
Posts: 560
Location: Scotland

mqjeff - does ref1.[1] work or should it be ref1.*[1]?

(just curious... I am no longer a mq/broker gal otherwise I'd check myself, but can't keep away)
Back to top
View user's profile Send private message
mqjeff
PostPosted: Tue Nov 08, 2011 12:52 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

vmcgloin wrote:
mqjeff - does ref1.[1] work or should it be ref1.*[1]?

(just curious... I am no longer a mq/broker gal otherwise I'd check myself, but can't keep away)


I think they both work but could do slightly different things.

but I haven't checked lately, so an exercise for the reader...
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Deferencing a fow from DB2
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.