Author |
Message
|
LH33 |
Posted: Wed Sep 10, 2003 6:17 am Post subject: setting a Repeating element value |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
HI! I have a message flow that has an indexed element <WorkCodeUDF>. If index 89 of the element exists, I have to transform it and put the new value in the output tag of the element with an index of 89. In the input XML, not all of the indices are present and when I try to set index 89 to the new value, I get a BIP 2436.
Here is my input XML:
<SyncJob revision="1.0.0" environment="Test">
<ApplicationArea>
<Sender>
<Component>ROMS</Component>
<Confirmation>Never</Confirmation>
<AuthorizationId>RICK</AuthorizationId>
</Sender>
<CreationDateTime>2003-07-31T12:29:41</CreationDateTime>
<BODId>02A92226D2264F1A9949F512C812B364</BODId>
</ApplicationArea>
<DataArea>
<Sync confirm="Never">
<SyncCriteria>
<SyncExpression action="Change">Job</SyncExpression>
</SyncCriteria>
</Sync>
<Job>
<JobNumber>EOM-20030715-0002</JobNumber>
<Filters>
<Filter index="1">OMSUNKNOWN</Filter>
</Filters>
<Status>
<StatusCode>CC</StatusCode>
</Status>
<TimeLine>
<CreationDateTime>2003-07-31T12:29:41</CreationDateTime>
</TimeLine>
<UDFS>
<UDF index="2">SERVICEREL</UDF>
</UDFS>
<WorkCodeUDFS>
<WorkCodeUDF index="77">Y</WorkCodeUDF>
<WorkCodeUDF index="78">2003-07-16T12:30:45</WorkCodeUDF>
<WorkCodeUDF index="80">Y</WorkCodeUDF>
<WorkCodeUDF index="81">Squirrel</WorkCodeUDF>
<WorkCodeUDF index="82">2</WorkCodeUDF>
<WorkCodeUDF index="89">ANIMAL</WorkCodeUDF> </WorkCodeUDFS>
</Job>
</DataArea>
</SyncJob>
Here is my code:
DECLARE CAUSES CHAR;
SET CAUSES = THE ( SELECT ITEM R FROM
InputRoot.XML.SyncJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[] as R where
R.(XML.Attribute)index = '89');
IF (CAUSES IS NOT NULL) THEN
DECLARE NEWCAUSE CHAR;
SET NEWCAUSE =
CASE CAUSES
WHEN 'ANIMAL' THEN 'Animal'
WHEN 'CONDCONTAC' THEN 'Conductor Contact'
WHEN 'CONTAM/COR' THEN 'Contamination/Corrosion'
END;
DECLARE searchRef REFERENCE TO OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[1];
DECLARE fieldFound BOOLEAN;
SET fieldFound = 'FALSE';
WHILE ((LASTMOVE(searchRef) = TRUE) AND (fieldFound = FALSE)) DO
IF searchRef.index = '89' THEN
SET searchRef = NEWCAUSE;
SET fieldFound = TRUE;
ELSE
MOVE searchRef NEXTSIBLING;
END IF;
END WHILE;
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[89] = searchRef;
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[89].(XML.Attribute)index=89;
END IF;
Can someone suggest how I can do this? Thanks, Lisa |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 6:32 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
This is very similar to the original problem you had when you were trying to reference an Input field array index that did not exist. In this you changed to referencing it via a dynamic reference that looked for the correct child with the name 'Index'. You are falling over a same issue when attempting :
Code: |
OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[89] = ......
|
There is no 89th occurence of WorkCodeUDF and it actually a child called index that you want to set with the value 89.
At this point if you are forming the OutputRoot message body as you go along then you should just be able to do then you could continue to use SET statements such as :
Code: |
DECLARE lastOccurence INT;
SET lastOccurence = CARDINALITY(OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[]);
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence + 1] = searchRef;
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence].(XML.Attribute)index=89;
|
Or you could try the index LAST+1 but Im not sure if that will work ... have never tried it.
However if you are creating lots of repeating fields in an output message, then I would not use explicit SET Statements. I would create the output tree with REFERENCE variables as well. This is far better performing than individual SET statements. _________________ Regards
Craig |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 6:33 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
Oops ... the last line in the example above should have been :
Code: |
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence+1].(XML.Attribute)index=89;
|
Sorry about that. _________________ Regards
Craig |
|
Back to top |
|
 |
LH33 |
Posted: Wed Sep 10, 2003 6:53 am Post subject: |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
Craig,
When I try the following, I get a BIP 2335. Did I code something wrong?
Thanks!! Lisa
DECLARE searchRef REFERENCE TO OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[1];
DECLARE fieldFound BOOLEAN;
SET fieldFound = 'FALSE';
WHILE ((LASTMOVE(searchRef) = TRUE) AND (fieldFound = FALSE)) DO
IF searchRef.index = '89' THEN
SET searchRef = NEWCAUSE;
SET fieldFound = TRUE;
ELSE
MOVE searchRef NEXTSIBLING;
END IF;
END WHILE;
DECLARE lastOccurence INT;
SET lastOccurence = CARDINALITY(OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[]);
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence + 1] = searchRef;
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence + 1].(XML.Attribute)index=89;
END IF; |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 7:09 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
The problem will be with the line "SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence + 1] = searchRef". The BIP2335 indicates you have a recursive copy routine. I did not notice that searchRef was pointing to the output tree and contains what you are creating, and so this makes it a recursive copy. Since your searchRef will be pointing at the WorkCodeUDF instance that has a child called Index with a value of 89, then searchref will already be at where you want to be in the OutputRoot message tree. Therefore Im not sure why you need these to SET statements at the end. You should be able to use searchref to create the output fields you require. What do you want to see in your output? Your set statements seem to be trying to create an Index with a value of 89, but according to your searchRef manipulation ... you are already looking for one in the OutputRoot tree. Are you trying to cope with the situation where you did not find one?? _________________ Regards
Craig |
|
Back to top |
|
 |
LH33 |
Posted: Wed Sep 10, 2003 7:15 am Post subject: |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
Craig,
Sorry if I confused you I am checking if <WorkCodeUDF index = 89 > is present first:
DECLARE CAUSES CHAR;
SET CAUSES = THE ( SELECT ITEM R FROM
InputRoot.XML.SyncJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[] as R where
R.(XML.Attribute)index = '89');
If CAUSES IS NOT NULL then I want to take the value, transform as follows and set the OutputRoot index = 89 to the new value:
IF (CAUSES IS NOT NULL) THEN
DECLARE NEWCAUSE CHAR;
SET NEWCAUSE =
CASE CAUSES
WHEN 'ANIMAL' THEN 'Animal'
WHEN 'CONDCONTAC' THEN 'Conductor Contact'
WHEN 'CONTAM/COR' THEN 'Contamination/Corrosion' END;
SET OutputRoot.XML.SyncJob.DataArea.newcause = NEWCAUSE;
DECLARE searchRef REFERENCE TO OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[1];
DECLARE fieldFound BOOLEAN;
SET fieldFound = 'FALSE';
WHILE ((LASTMOVE(searchRef) = TRUE) AND (fieldFound = FALSE)) DO
IF searchRef.index = '89' THEN
SET searchRef = NEWCAUSE;
SET fieldFound = TRUE;
ELSE
MOVE searchRef NEXTSIBLING;
END IF;
END WHILE;
DECLARE lastOccurence INT;
SET lastOccurence = CARDINALITY(OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[]);
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence + 1] = searchRef;
SET OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[lastOccurence + 1].(XML.Attribute)index=89;
END IF;
Thanks a lot for your help! |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 7:27 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
Ok ... so since all this is in the same IF block, then if you dont find any occurences of Index=89 then you do not want to do anything. You have set you searchRef to OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[1]; This would imply that you have done a SET OutputRoot = InputRoot in your compute node else these records wouldnt be in the OutputRoot tree to search. So if they are already in the OutputRoot tree, and you locate the record with index = 89, then you do SET searchRef = NEWCAUSE; . This makes the change that you want to. This record already has index = 89, else we would not find it in the first place. So you dont need the extra two SET statements since these records should already be there.
What am I missing with this scenario??  _________________ Regards
Craig |
|
Back to top |
|
 |
LH33 |
Posted: Wed Sep 10, 2003 7:42 am Post subject: |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
It's not you that's missing something, it's me You have the scenario correct - I must still be doing something wrong.
I just ran this code:
IF (CAUSES IS NOT NULL) THEN
DECLARE NEWCAUSE CHAR;
SET NEWCAUSE =
CASE CAUSES
WHEN 'ANIMAL' THEN 'Animal'
WHEN 'CONDCONTAC' THEN 'Conductor Contact'
WHEN 'CONTAM/COR' THEN 'Contamination/Corrosion'END;
DECLARE searchRef REFERENCE TO OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[1];
DECLARE fieldFound BOOLEAN;
SET fieldFound = 'FALSE';
WHILE ((LASTMOVE(searchRef) = TRUE) AND (fieldFound = FALSE)) DO
IF searchRef.index = '89' THEN
SET searchRef = NEWCAUSE;
SET fieldFound = TRUE;
ELSE
MOVE searchRef NEXTSIBLING;
END IF;
END WHILE;
Her is my output XML:
<SyncJob revision="1.0.0" environment="Test">
<ApplicationArea>
<Sender>
<Component>ROMS</Component>
<Confirmation>Never</Confirmation>
<AuthorizationId>RICK</AuthorizationId>
</Sender>
<CreationDateTime>2003-07-31T12:29:41</CreationDateTime>
<BODId>02A92226D2264F1A9949F512C812B364</BODId>
</ApplicationArea>
<DataArea>
<Sync confirm="Never">
<SyncCriteria>
<SyncExpression action="Change">Job</SyncExpression>
</SyncCriteria>
</Sync>
<Job>
<JobNumber>EOM-20030715-0002</JobNumber>
<Filters>
<Filter index="1"></Filter>
</Filters>
<Status>
<StatusCode>CC</StatusCode>
</Status>
<TimeLine>
<CreationDateTime>2003-07-31T12:29:41</CreationDateTime>
</TimeLine>
<UDFS>
<UDF index="2">MAINTENANC</UDF>
</UDFS>
<WorkCodeUDFS>
<WorkCodeUDF index="77">Y</WorkCodeUDF>
<WorkCodeUDF index="78">2003-07-16T12:30:45</WorkCodeUDF>
<WorkCodeUDF index="80">Y</WorkCodeUDF>
<WorkCodeUDF index="81">Squirrel</WorkCodeUDF>
<WorkCodeUDF index="82">2</WorkCodeUDF>
<WorkCodeUDF index="89">ANIMAL</WorkCodeUDF>
</WorkCodeUDFS>
</Job>
</DataArea>
</SyncJob>
What I want is for <WorkCodeUDF index="89">ANIMAL</WorkCodeUDF> to look like the transformatin in the CASE statement - Like this:
<WorkCodeUDF index="89">Animal</WorkCodeUDF>
Thanks for your help!! |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 7:51 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
OK .... now I understand. So we believe this code should work, but from your output it is not making the changes. Can we take a user level (debug) trace of the message flow and see what paths you are executing. You have a few IF conditions that check for IS NOT NULL and we need to make sure it is executing this block of code. Then when it does execute it, we need to see what it is searching.
Would it be possible for you to do this? If you could collect it, I could take a look at it if you emailed it to me or something. Thanks. _________________ Regards
Craig |
|
Back to top |
|
 |
LH33 |
Posted: Wed Sep 10, 2003 7:53 am Post subject: |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
Craig,
Sure, I will put trace nodes in before and after the Compute node as well as set some additional output tags to show what is being set to what and I will post them here or e-mail them to you. Which do you prefer?
Thanks!! Lisa |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 8:01 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
If the problem lies with your ESQL, then adding trace nodes will not help in this situation. A user debug trace will show every line of ESQL that is executed and what conditons were met etc. The new V5 has a nice ESQL Debugger which lets you step through the code!
If you go onto your broker machine and do the following :
1) mqsichangetrace <brokerName> -u -e <execGp> -f <flow> -l debug -r
2) Put message through the flow that generates the unchanged output message.
3) mqsireadlog <brokerName> -u -e <execGp> -f -o usertrace.xml
4) mqsiformatlog -i usertrace.xml -o usertrace.log
Then turn tracing off with
5) mqsichangetrace <brokerName> -u -e <execGp> -f <flow> -l none -r
where :
<brokerName> = name of the broker
<execGp> = Execution group name
<flow> = name of the flow.
Then the usertrace.log will contain the information as to what was executed for this flow from a user point of view. If you then send me a private message with your email address, I can respond and you can send me the trace. From there it shouldnt take long to see what is happening, and correct it.
Thanks. _________________ Regards
Craig |
|
Back to top |
|
 |
LH33 |
Posted: Wed Sep 10, 2003 8:20 am Post subject: |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
Craig,
Unfortuneately, I do not have access to the box where the broker lives. That is controlled by another area in my company. I only have access to Control Center to do application development.
I did run the code again and put some extra output tags in that show that the transformation from ANIMAL to Animal is happening and the CAUSES field is not null, however, it also shows that it is not finding searchRef.index = '89' for some reason. Any help will be greatly appreciated!!
SET OutputRoot.XML.SyncJob.DataArea.newcause = NEWCAUSE;
DECLARE searchRef REFERENCE TO OutputRoot.XML.CreateJob.DataArea.Job.WorkCodeUDFS.WorkCodeUDF[1];
DECLARE fieldFound BOOLEAN;
SET fieldFound = 'FALSE';
WHILE ((LASTMOVE(searchRef) = TRUE) AND (fieldFound = FALSE)) DO
IF searchRef.index = '89' THEN
SET searchRef = NEWCAUSE;
SET OutputRoot.XML.SyncJob.DataArea.searchref = searchRef;
SET fieldFound = TRUE;
ELSE
MOVE searchRef NEXTSIBLING;
END IF;
END WHILE;
Here is the output XML with the extra tags bolded:
<SyncJob revision="1.0.0" environment="Test">
<ApplicationArea>
<Sender>
<Component>ROMS</Component>
<Confirmation>Never</Confirmation>
<AuthorizationId>RICK</AuthorizationId>
</Sender>
<CreationDateTime>2003-07-31T12:29:41</CreationDateTime>
<BODId>02A92226D2264F1A9949F512C812B364</BODId>
</ApplicationArea>
<DataArea>
<Sync confirm="Never">
<SyncCriteria>
<SyncExpression action="Change">Job</SyncExpression>
</SyncCriteria>
</Sync>
<Job>
<JobNumber>EOM-20030715-0002</JobNumber>
<Filters>
<Filter index="1"></Filter>
</Filters>
<Status>
<StatusCode>CC</StatusCode>
</Status>
<TimeLine>
<CreationDateTime>2003-07-31T12:29:41</CreationDateTime>
</TimeLine>
<UDFS>
<UDF index="2">MAINTENANC</UDF>
</UDFS>
<WorkCodeUDFS>
<WorkCodeUDF index="77">Y</WorkCodeUDF>
<WorkCodeUDF index="78">2003-07-16T12:30:45</WorkCodeUDF>
<WorkCodeUDF index="80">Y</WorkCodeUDF>
<WorkCodeUDF index="81">Squirrel</WorkCodeUDF>
<WorkCodeUDF index="82">2</WorkCodeUDF>
<WorkCodeUDF index="89">ANIMAL</WorkCodeUDF>
</WorkCodeUDFS>
</Job>
<causes>ANIMAL</causes>
<newcause>Animal</newcause>
</DataArea>
</SyncJob> |
|
Back to top |
|
 |
Craig B |
Posted: Wed Sep 10, 2003 8:28 am Post subject: |
|
|
Partisan
Joined: 18 Jun 2003 Posts: 316 Location: UK
|
Hi,
Ok. Is it possible for you to send me an export of your flow, and input message, and then I can look at it from here, and debug it in anyway necessary? It would be quicker to do it that way. _________________ Regards
Craig |
|
Back to top |
|
 |
LH33 |
Posted: Wed Sep 10, 2003 8:29 am Post subject: |
|
|
Master
Joined: 21 Nov 2002 Posts: 200
|
Craig,
Sure!! Can you tell me how to send a private message?
Thanks!! Lisa |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Sep 10, 2003 8:31 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
LH33 wrote: |
Craig,
Sure!! Can you tell me how to send a private message?
Thanks!! Lisa |
Click on the button at the bottom of any of his messages labeled "PM". |
|
Back to top |
|
 |
|