Author |
Message
|
dogorsy |
Posted: Wed Aug 07, 2013 7:05 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
j.f.sorge wrote: |
Why not use the following code (it should work although I did not use WMBT to create it)
Code: |
DECLARE refSource REFERENCE TO refInSWEIOBody.choiceElement[1];
WHILE LASTMOVE(refSource) DO
--FOR source as refInSWEIOBody.choiceElement[] DO
DECLARE refChild REFERENCE TO refSource.<; --will point to FIRSTCHILD
--SET iSWEIOCount = iSWEIOCount + 1;
DECLARE chChild CHARACTER FIELDNAME(refChild);
--CASE FIELDNAME(source.*)
CASE chChild
WHEN 'structure14332' THEN
--IF refInSWEIOBody.choiceElement[iSWEIOCount].structure14332.structureBody14332.messageStream.KTHANLimithoehe.length = 'DDD' THEN
IF refChild.structureBody14332.messageStream.KTHANLimithoehe.length = 'DDD' THEN
SET chKTHANLimithoehe = '0';
ELSE
--SET chKTHANLimithoehe = refInSWEIOBody.choiceElement[iSWEIOCount].structure14332.structureBody14332.messageStream.KTHANLimithoehe.value;
SET chKTHANLimithoehe = refChild.structureBody14332.messageStream.KTHANLimithoehe.value;
END IF;
WHEN 'structure17836' THEN
--IF refInSWEIOBody.choiceElement[iSWEIOCount].structure17836.structureBody17836.messageStream.WEITAFunktionstyp.length <> 'DDD' THEN
IF refChild.structureBody17836.messageStream.WEITAFunktionstyp.length <> 'DDD' THEN
--SET chWEITAFunktionstyp = refInSWEIOBody.choiceElement[iSWEIOCount].structure17836.structureBody17836.messageStream.WEITAFunktionstyp.value;
SET chWEITAFunktionstyp = refChild.structureBody17836.messageStream.WEITAFunktionstyp.value;
ELSE
SET chWEITAFunktionstyp = 'ORD';
END IF;
--SET chWEITANummer = refInSWEIOBody.choiceElement[iSWEIOCount].structure17836.structureBody17836.messageStream.WEITANummer.value;
SET chWEITANummer = refChild.structureBody17836.messageStream.WEITANummer.value;
WHEN 'structure12856' THEN
--SET chIDENTInstrument_Ident = refInSWEIOBody.choiceElement[iSWEIOCount].structure12856.structureBody12856.messageStream.IDENTInstrument_Ident.value;
SET chIDENTInstrument_Ident = refChild.structureBody12856.messageStream.IDENTInstrument_Ident.value;
END CASE;
MOVE refSource NEXTSIBLING REPEAT NAME;
--END FOR;
END WHILE; |
|
it is not different to using a FOR loop, and has the disadvantage that you need to declare the reference and then do the move and check LASTMOVE. The FOR loop does it automatically for you |
|
Back to top |
|
 |
j.f.sorge |
Posted: Wed Aug 07, 2013 7:11 am Post subject: |
|
|
Master
Joined: 27 Feb 2008 Posts: 218
|
dogorsy wrote: |
...
it is not different to using a FOR loop, and has the disadvantage that you need to declare the reference and then do the move and check LASTMOVE. The FOR loop does it automatically for you |
Sure. It was just an idea because FOR did not seem to work correctly...  _________________ IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
ottfried11 |
Posted: Wed Aug 07, 2013 7:13 am Post subject: |
|
|
Apprentice
Joined: 28 Jun 2013 Posts: 29
|
here's the trace
Code: |
CREATE LASTCHILD OF OutputRoot.XMLNSC.Test NAME 'MyField' VALUE FIELDNAME(source.*);
(0x01000000:Folder):XMLNSC = ( ['xmlnsc' : 0x7fd0689aaaf0]
(0x01000000:Folder):Test = (
(0x03000000:PCDataField):MyField = 'structure14332' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure11013' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure16426' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure15244' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure14852' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure15386' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure12856' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure13280' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure16806' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17006' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17186' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17188' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17232' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17650' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17758' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17840' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17966' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17836' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17986' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure18044' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure18202' (CHARACTER)
(0x03000000:PCDataField):MyField = 'structure17862' (CHARACTER)
)
|
Looking at the trace, the code should have worked. I'll have to look at it again. |
|
Back to top |
|
 |
dogorsy |
Posted: Wed Aug 07, 2013 7:14 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
j.f.sorge wrote: |
It was just an idea because FOR did not seem to work correctly...  |
Probably due to a coding error. I always use FOR in preference to WHILE loops and it works perfectly ok ( when I get the code right though ! ). |
|
Back to top |
|
 |
j.f.sorge |
Posted: Wed Aug 07, 2013 7:23 am Post subject: |
|
|
Master
Joined: 27 Feb 2008 Posts: 218
|
dogorsy wrote: |
j.f.sorge wrote: |
It was just an idea because FOR did not seem to work correctly...  |
Probably due to a coding error. I always use FOR in preference to WHILE loops and it works perfectly ok ( when I get the code right though ! ). |
It seems to be better, as you may not forget to code the
Code: |
MOVE refSource NEXTSIBLING REPEAT NAME; |
which will result in an endless loop.
If you compare both ways via user-trace you may see if they seem to have the same internal behaviour. _________________ IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
dogorsy |
Posted: Wed Aug 07, 2013 7:35 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
j.f.sorge wrote: |
dogorsy wrote: |
j.f.sorge wrote: |
It was just an idea because FOR did not seem to work correctly...  |
Probably due to a coding error. I always use FOR in preference to WHILE loops and it works perfectly ok ( when I get the code right though ! ). |
It seems to be better, as you may not forget to code the
Code: |
MOVE refSource NEXTSIBLING REPEAT NAME; |
which will result in an endless loop.
If you compare both ways via user-trace you may see if they seem to have the same internal behaviour. |
I will leave the comparison as an exercise for you, as I already know it is better. |
|
Back to top |
|
 |
ottfried11 |
Posted: Wed Aug 07, 2013 7:39 am Post subject: |
|
|
Apprentice
Joined: 28 Jun 2013 Posts: 29
|
I don't know what I did wrong the last time. This works fine:
Code: |
FOR source as refInSWEIOBody.choiceElement[] DO
CASE FIELDNAME(source.*)
WHEN 'structure14332' THEN
IF source.structure14332.structureBody14332.messageStream.KTHANLimithoehe.length = 'DDD' THEN
SET chKTHANLimithoehe = '0';
ELSE
SET chKTHANLimithoehe = source.structure14332.structureBody14332.messageStream.KTHANLimithoehe.value;
END IF;
WHEN 'structure17836' THEN
IF source.structure17836.structureBody17836.messageStream.WEITAFunktionstyp.length <> 'DDD' THEN
SET chWEITAFunktionstyp = source.structure17836.structureBody17836.messageStream.WEITAFunktionstyp.value;
ELSE
SET chWEITAFunktionstyp = 'ORD';
END IF;
SET chWEITANummer = source.structure17836.structureBody17836.messageStream.WEITANummer.value;
WHEN 'structure12856' THEN
SET chIDENTInstrument_Ident = source.structure12856.structureBody12856.messageStream.IDENTInstrument_Ident.value;
END CASE;
END FOR;
|
Thanks a lot. Great help |
|
Back to top |
|
 |
dogorsy |
Posted: Wed Aug 07, 2013 7:51 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
ottfried11 wrote: |
I don't know what I did wrong the last time. This works fine:
Code: |
FOR source as refInSWEIOBody.choiceElement[] DO
CASE FIELDNAME(source.*)
WHEN 'structure14332' THEN
IF source.structure14332.structureBody14332.messageStream.KTHANLimithoehe.length = 'DDD' THEN
SET chKTHANLimithoehe = '0';
ELSE
SET chKTHANLimithoehe = source.structure14332.structureBody14332.messageStream.KTHANLimithoehe.value;
END IF;
WHEN 'structure17836' THEN
IF source.structure17836.structureBody17836.messageStream.WEITAFunktionstyp.length <> 'DDD' THEN
SET chWEITAFunktionstyp = source.structure17836.structureBody17836.messageStream.WEITAFunktionstyp.value;
ELSE
SET chWEITAFunktionstyp = 'ORD';
END IF;
SET chWEITANummer = source.structure17836.structureBody17836.messageStream.WEITANummer.value;
WHEN 'structure12856' THEN
SET chIDENTInstrument_Ident = source.structure12856.structureBody12856.messageStream.IDENTInstrument_Ident.value;
END CASE;
END FOR;
|
Thanks a lot. Great help |
Good. Now you can improve on that:
Code: |
FOR source as refInSWEIOBody.choiceElement[] DO
CASE FIELDNAME(source.*)
DECLARE cursor REFERENCE TO source.*.*.messageStream;
WHEN 'structure14332' THEN
IF cursor.KTHANLimithoehe.length = 'DDD' THEN
SET chKTHANLimithoehe = '0';
ELSE
SET chKTHANLimithoehe = cursor.KTHANLimithoehe.value;
END IF;
WHEN 'structure17836' THEN
IF cursor.WEITAFunktionstyp.length <> 'DDD' THEN
SET chWEITAFunktionstyp = cursor.WEITAFunktionstyp.value;
ELSE
SET chWEITAFunktionstyp = 'ORD';
END IF;
SET chWEITANummer = cursor.WEITANummer.value;
WHEN 'structure12856' THEN
SET chIDENTInstrument_Ident = cursor.IDENTInstrument_Ident.value;
END CASE;
END FOR;
|
|
|
Back to top |
|
 |
j.f.sorge |
Posted: Wed Aug 07, 2013 8:03 am Post subject: |
|
|
Master
Joined: 27 Feb 2008 Posts: 218
|
dogorsy wrote: |
...
Good. Now you can improve on that:
Code: |
FOR source as refInSWEIOBody.choiceElement[] DO
CASE FIELDNAME(source.*)
DECLARE cursor REFERENCE TO source.*.*.messageStream;
WHEN 'structure14332' THEN
IF cursor.KTHANLimithoehe.length = 'DDD' THEN
SET chKTHANLimithoehe = '0';
ELSE
SET chKTHANLimithoehe = cursor.KTHANLimithoehe.value;
END IF;
WHEN 'structure17836' THEN
IF cursor.WEITAFunktionstyp.length <> 'DDD' THEN
SET chWEITAFunktionstyp = cursor.WEITAFunktionstyp.value;
ELSE
SET chWEITAFunktionstyp = 'ORD';
END IF;
SET chWEITANummer = cursor.WEITANummer.value;
WHEN 'structure12856' THEN
SET chIDENTInstrument_Ident = cursor.IDENTInstrument_Ident.value;
END CASE;
END FOR;
|
|
Looks very cool because it uses short paths to get the values. But don't you have to DECLARE cursor before the CASE, do you?! _________________ IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
dogorsy |
Posted: Wed Aug 07, 2013 8:06 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
j.f.sorge wrote: |
But don't you have to DECLARE cursor before the CASE, do you?! |
Yes !... well spotted.
Now, if we compare that with the original code or the while loop, then you'll understand why I prefer to use FOR and REFERENCEs ( although it always takes me a few goes to get it right ! ) |
|
Back to top |
|
 |
j.f.sorge |
Posted: Wed Aug 07, 2013 8:16 am Post subject: |
|
|
Master
Joined: 27 Feb 2008 Posts: 218
|
dogorsy wrote: |
j.f.sorge wrote: |
But don't you have to DECLARE cursor before the CASE, do you?! |
Yes !... well spotted.
Now, if we compare that with the original code or the while loop, then you'll understand why I prefer to use FOR and REFERENCEs ( although it always takes me a few goes to get it right ! ) |
I think I'll have to think about replacing WHILE LASTMOVE by FOR. It is shorter and seems to be easier to use. But first I'll trace both in order to compare what WMB is doing internally to see whether both are doing the same. _________________ IBM Certified Solution Designer - WebSphere MQ V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.0
IBM Certified Solution Developer - WebSphere Message Broker V6.1
IBM Certified Solution Developer - WebSphere Message Broker V7.0 |
|
Back to top |
|
 |
dogorsy |
Posted: Wed Aug 07, 2013 8:28 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
j.f.sorge wrote: |
I think I'll have to think about replacing WHILE LASTMOVE by FOR. It is shorter and seems to be easier to use. But first I'll trace both in order to compare what WMB is doing internally to see whether both are doing the same. |
Cool. I tend to combine it with CREATE LASTCHILD OF ... VALUE source.something; That way never get inadvertently into a tight loop because you forgot to increment the counter or do a MOVE |
|
Back to top |
|
 |
ottfried11 |
Posted: Mon Aug 12, 2013 6:11 am Post subject: |
|
|
Apprentice
Joined: 28 Jun 2013 Posts: 29
|
Code: |
DECLARE cursor REFERENCE TO source.*.*.messageStream
|
the REFERENCE with two asterisks does not work. The cursor point to the same node as source. |
|
Back to top |
|
 |
dogorsy |
Posted: Mon Aug 12, 2013 6:45 am Post subject: |
|
|
Knight
Joined: 13 Mar 2013 Posts: 553 Location: Home Office
|
ottfried11 wrote: |
Code: |
DECLARE cursor REFERENCE TO source.*.*.messageStream
|
the REFERENCE with two asterisks does not work. The cursor point to the same node as source. |
Looking at previous posts, I can see that you have said before things don't work
Quote: |
This does not work.
|
I have just run a quick test, and it does work, so I think now it is up to you to debug your code. Do not expect people in this forum to debug it for you. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Aug 12, 2013 6:52 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
It wouldn't work if there wasn't an element named messageStream at the indicated location.
It wouldn't work if there wasn't an element as the first child of the source reference.
It wouldn't work if the messageStream element had a namespace.
The behavior you're seeing means that the reference couldn't be moved to the named location.
Nobody can tell you why the reference couldn't be moved to the named location for your specific message. |
|
Back to top |
|
 |
|