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 » Question about implementation decision

Post new topic  Reply to topic
 Question about implementation decision « View previous topic :: View next topic » 
Author Message
lfrestrepog
PostPosted: Thu Apr 16, 2015 2:43 pm    Post subject: Question about implementation decision Reply with quote

Novice

Joined: 08 Jul 2014
Posts: 22

Hello everyone.

Here's the scenario: I wanted to check the existence of a field in a message and came up with two ideas, they both work and the result is pretty much the same, but I'd like to receive comments on which would be preferable and why.

1. The obvious option:
Code:
DECLARE aux REFERENCE TO InputRoot.XMLNSC.doc.field;
IF LASTMOVE(aux) THEN
    -- Do stuff...
END IF;


2. A little more creative:
Create a procedure...
Code:

CREATE PROCEDURE alt_exists(IN field REFERENCE) RETURNS BOOLEAN
BEGIN
   RETURN LASTMOVE(field);
END;


Then in the module...
Code:
IF alt_exists(InputRoot.XMLNSC.doc.field) THEN
   -- Do stuff...
END IF;


The only benefit I find in the second option is that it prevents the use of an unnecessary reference, so it got me thinking if that should be considered an advantage or if actually the procedure call would be more expensive than the reference.

Any comments would be much appreciated.

Thanks!

--
Luis Fernando Restrepo
Back to top
View user's profile Send private message
shashivarungupta
PostPosted: Thu Apr 16, 2015 3:17 pm    Post subject: Reply with quote

Grand Master

Joined: 24 Feb 2009
Posts: 1343
Location: Floating in space on a round rock.

lfrestrepog wrote:
.. I wanted to check the existence of a field in a message..


I am not sure if you have got a chance to look at FIELDTYPE function (at InfoCentre)

IF FIELDTYPE(InputRoot.XMLNS.Message1.Name)
IS NULL THEN
// Name field does not exist, take error
action....
... more ESQL ...
ELSE
// Name field does exist, continue....
... more ESQL ...
END IF

I've used it in one of my applications, where 'reference to' input message (element) was used and that declared reference variable was used in the FIELDTYPE function, which worked effectively.

The first scenario where you've used reference to some field of InputRoot, should be effective than the scenario 2. (AFAIK).
{Sometimes it also matters that how deep and how far you are navigating into the message tree. If the element is deep then it would take more time/efforts to find it, than the element which is up on the tree and not that deep.}

Hope this will serve your purpose.

_________________
*Life will beat you down, you need to decide to fight back or leave it.
Back to top
View user's profile Send private message Send e-mail
kimbert
PostPosted: Fri Apr 17, 2015 3:46 am    Post subject: Reply with quote

Jedi Council

Joined: 29 Jul 2003
Posts: 5542
Location: Southampton

Any reason why nobody is recommending this?
Code:

IF EXISTS (InputRoot.XMLNSC.Message1.Name[])
    -- do stuff that depends on the field
ELSE
    -- field does not exist
    ... more ESQL ...
END IF


Two things to highlight here:
- don't forget to add the [] on the end of the path reference
- I never post examples that use XMLNS. XMLNSC should be used in all new message flows.
_________________
Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too.
Back to top
View user's profile Send private message
shashivarungupta
PostPosted: Sun Apr 19, 2015 5:51 pm    Post subject: Reply with quote

Grand Master

Joined: 24 Feb 2009
Posts: 1343
Location: Floating in space on a round rock.

kimbert wrote:

- I never post examples that use XMLNS. XMLNSC should be used in all new message flows.



and thanks for your notice on this. ( it was my bad while taking a quick reference from info center and its sample old example.. It should by XMLNSC. ).
_________________
*Life will beat you down, you need to decide to fight back or leave it.
Back to top
View user's profile Send private message Send e-mail
lfrestrepog
PostPosted: Mon Apr 27, 2015 10:49 am    Post subject: Reply with quote

Novice

Joined: 08 Jul 2014
Posts: 22

Thank you for your replies.

Another follow up question, considering the different options available to check whether or not a field is present in the message (and assuming I create references to prevent unnecessary path navigation, and so on); is there any reason to prefer one way over the rest?

I'm asking because, for practical purposes they all seem to work the same (am I missing something?).

The two options I proposed in the first post where chosen arbitrarily (I usually try to avoid any comparison with "null", hence the lastmove preference).

About the "EXISTS" option, suggested by kimbert, I notice it does prevent the use of unnecessary references, should that be the preferred way to check fields?

Just to be clear, we are not facing any problems regarding this topic at the moment, but we are trying to standardise our code conventions...

Thanks again... any further comments would be much appreciated.
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 » Question about implementation decision
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.