Author |
Message
|
aks |
Posted: Sun Apr 04, 2004 7:16 pm Post subject: Is this possible with SELECT? |
|
|
Voyager
Joined: 19 Jul 2002 Posts: 84
|
Hi,
I have some XML:
<Policy>
<Risks>
<Fire>
<GroupID>1</GroupID>
</Fire>
<Fire>
<GroupID>2</GroupID>
</Fire>
<Burglary>
<GroupID>1</GroupID>
</Burglary>
<Burglary>
<GroupID>2</GroupID>
</Burglary>
</Risks>
</Policy>
I want to select a Fire element with a specific Group ID that I know.
I was doing it by declaring a reference to Policy.Risks.Fire[1] and then using a while loop and LASTMOVE to go through all the Fire elements (there can be a lot) by testing the GroupID element, but I wanted to do this with a SELECT statement like this:
DECLARE policyRef REFERENCE TO InputBody.Policy;
DECLARE riskRef REFERENCE TO policyRef; -- temporary assignment
SET riskRef = SELECT "Fire" FROM policyRef.Risks AS r WHERE r.GroupID = '1';
But I am getting a syntax error when I try to deploy:
Syntax error: expected ';' but found 'Fire'. I've tried other variations like SELECT r FROM policyRef.Risks.Fire[] AS r where r.GroupID = '1';
but no luck. Can SELECT be used like this? What would be the correct syntax?
Thanks
Alan |
|
Back to top |
|
 |
Missam |
Posted: Sun Apr 04, 2004 8:04 pm Post subject: |
|
|
Chevalier
Joined: 16 Oct 2003 Posts: 424
|
Code: |
DECLARE policyRef REFERENCE TO InputBody.Policy;
DECLARE riskRef REFERENCE TO policyRef; -- temporary assignment
SET riskRef = SELECT "Fire" FROM policyRef.Risks AS r WHERE r.GroupID = '1';
|
Can u tell us what exactly you are trying to do.In the Above code your provided, riskRef is nothing but a reference to InputBody.
You can not assign any thing to the input message tree.
All the thing you can do is construct an output tree based on input tree.
you code sholud be some thing like this
SET OutputRoot.... = InputBody....; |
|
Back to top |
|
 |
aks |
Posted: Sun Apr 04, 2004 8:23 pm Post subject: |
|
|
Voyager
Joined: 19 Jul 2002 Posts: 84
|
Sorry - I put my own syntax errors in the example!
What I am trying to do is to replace a while loop with a select.
The code used to look like this:
DECLARE policyRef REFERENCE TO InputBody.Policy;
DECLARE riskRef REFERENCE TO policyRef.Risks.Fire[];
WHILE LASTMOVE(riskRef) DO
IF (riskRef.GroupID = '1') THEN
-- lots of SET statements mapping output fields to riskRef fields
END IF;
MOVE riskRef NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
I know that one cannot assign something to an input tree, so I wrote this incorrectly, but I would like to get the correct riskRef using a SELECT without needing to loop through all the Fire elements checking the GroupID element. I've used SELECTs to get scalar values before, but each "Fire" contains child elements, which seems to be my problem.
Thanks
Alan |
|
Back to top |
|
 |
scaryjase |
Posted: Mon Apr 05, 2004 2:33 am Post subject: |
|
|
Novice
Joined: 17 Jul 2003 Posts: 22
|
You certainly can use a WHERE clause on a SELECT to refer to those elements you desire, but i'm not entirely clear what you want to do with it. You talk about the problem being with the Fire element having children - assuming you want the children, then SELECT them... _________________ scary |
|
Back to top |
|
 |
fjcarretero |
Posted: Mon Apr 05, 2004 2:53 am Post subject: |
|
|
Voyager
Joined: 13 Oct 2003 Posts: 88
|
Hi,
Try something like this:
Code: |
DECLARE policyRef REFERENCE TO InputBody.Policy;
DECLARE riskRef REFERENCE TO policyRef; -- temporary assignment
SET riskRef = SELECT r."Fire" FROM policyRef.Risks AS r WHERE r.Fire.GroupID = '1';
|
Cheers
Felipe |
|
Back to top |
|
 |
aks |
Posted: Mon Apr 05, 2004 3:09 am Post subject: |
|
|
Voyager
Joined: 19 Jul 2002 Posts: 84
|
There are a number of child elements under Fire, and I need to apply some business rules to these fields so that they map to the correct COBOL copybook fields, so just selecting them is not an option.
Also, I tried the code above but it gave a syntax error on deployment:
Syntax error : expected ';' but found 'r'.
I must be missing somtheing simple
Any further help would be appreciated
Thanks
Alan |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Apr 05, 2004 3:10 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
The syntax error is caused by the fact that the Select statement is not enclosed in parentheses.
Code: |
set OutputRoot.XYZ[] = (Select ...); |
_________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
|