Author |
Message
|
apsy |
Posted: Mon Aug 02, 2004 4:07 pm Post subject: ESQL Procedures |
|
|
 Novice
Joined: 10 Feb 2004 Posts: 24
|
I need to accomplish the following.
1. Create a re-usable procedure that will create a new output root and send it back
Requirements: I want to create a brand new XML message in a procedure, that is returned back to the caller.
So far, I have achieved the following piece of code and it works:
/********************/
DECLARE rOutRefXml REFERENCE TO OutputLocalEnvironment;
DECLARE rInRefXml REFERENCE TO InputLocalEnvironment;
MOVE rInRefXml TO InputRoot.XML;
--Build the XML Decleration
CREATE FIELD OutputRoot.XML.(XML.XmlDecl)XML;
SET OutputRoot.XML.(XML.XmlDecl).(XML.Version) = '1.0';
SET OutputRoot.XML.(XML.XmlDecl).(XML."Encoding") = 'UTF-8';
CREATE LASTCHILD of OutputRoot.XML AS rOutRefXml NAME 'CompanyNew';
--This procedure is created in a separate ESQL file:
--Call this procedure to build the output xml
CALL ProcAddFields(rInRefXml,rOutRefXml);
I get an output root that I then successfully send to an MQ output node.
/********************/
/**********/
Procedure that creates a brand new XMl mesage and returns back to caller
/********** Define procedure in new ESQl file ************/
BROKER SCHEMA LIB_Common
-- This procedure builds output xml from input xml and returns a xml tree
CREATE PROCEDURE ProcAddFields(IN rInRefXml REFERENCE,INOUT rOutRefXml REFERENCE)
BEGIN
SET rOutRefXml.Empid = '2374521';
SET rOutRefXml.LastName = 'Sam';
RETURN;
END;
/********End procedure *******?
3) I tried moving everyting within the procedure by passing in the output oot directly to my procedure and manipulating it., I got an o/p message forwarded to my queue, but the length was zero.
4) What I want to do is, move even the XML declaration (in bold above) into the procedure. That way , the caller does not have to do anything. Anytime he needs an o/p message of that structure, he just calls the procedure, which accomplishes everything. I want the caller to be oblivious to what is being returned back. All the caller should do is to forward the message to a queue.Is this possible?
The reason I want to do this is, the procedure is something that all my flows across message flow projects and within message flows will use it multiple times, and I want to avoid code redundancy.
Sample test i/p message
<?xml version = "1.0" encoding = "UTF-8"?>
<CrCard>
<company>Test</company>
<DeptNo>1001</DeptNo>
</CrCard>
Sample test o/p message
<?xml version="1.0" encoding="UTF-8"?>
<CompanyNew>
<Empid>2374521</Empid>
<LastName>Sam</LastName>
</CompanyNew> |
|
Back to top |
|
 |
CoolDude |
Posted: Mon Aug 02, 2004 5:45 pm Post subject: |
|
|
Apprentice
Joined: 17 Jan 2004 Posts: 39
|
Please check the Reference variable. you have declared the reference variable to an OutputLocalEnvironment. Is should be declared as reference to some Output Tree.
Code: |
DECLARE rOutRefXml REFERENCE TO OutputLocalEnvironment; |
Consider the below example.
Note : I am using the same Input message that you have specified.
CREATE FIELD OutputRoot.XML.Employee;
DECLARE rOutRefXml REFERENCE TO OutputRoot.XML.Employee;
DECLARE rInRefXml REFERENCE TO InputRoot.XML.CrCard;
Call cOuputXML(rInRefXml, rOutRefXml);
CREATE PROCEDURE cOuputXML(IN rInRefXml REFERENCE,INOUT rOutRefXml REFERENCE)
BEGIN
SET rOutRefXml.Empid = rInRefXml.DeptNo;
SET rOutRefXml.LastName = rInRefXml.company;
RETURN;
END;
This would create
<Employee>
<Empid>1001</Empid>
<LastName>Test</LastName>
</Employee>
Thanks _________________ Correct Me from Wrong . If i am correct Appreciate Me  |
|
Back to top |
|
 |
javaforvivek |
Posted: Tue Aug 03, 2004 1:45 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi,
You can also refer to messagebroker_esql.pdf for constructing and manipulating XML Messages. It is really helpful.
I have done such transforms as SWIFT Message to application specific accounting mesage (both in XML) using these manipulation technique.
I am not very sure, but you can always pass the reference variable to the common procedure and see what will happen.
But what CoolDude says is true. You have to declare the reference variable to refer to your Input/Output Roots rather than LocalEnvironments.
The useful technique is, retain the original XML Message in some temp folder as part of your outputroot tree, and delete it when you finish your transformation. _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
apsy |
Posted: Tue Aug 03, 2004 5:18 am Post subject: |
|
|
 Novice
Joined: 10 Feb 2004 Posts: 24
|
Basically, the XML message that I am constructing within a procedure is actualy used for logging purposes and is independent of the message data (xml, fixed length , etc,etc)coming in .
so my requirement is that I always construct an XML message . The challenge I am facing is that I want the entire Output root to be constructed and returned from within the procedure. I do not want to manipulte an incoming message. I am not able to do that compactly within my procedure, because my XMl declaration statements do not seem to work if I move them inside my procedure.  |
|
Back to top |
|
 |
mgk |
Posted: Tue Aug 03, 2004 5:59 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
Hi,
If you search this forum you should find a post from me decribing the difference between OutputRoot and a Reference to OutputRoot.
However as you are using version 5 of the brokers, you should know that the root Correlation Names (OutputRoot etc) are now effectively Implicitly Declared Module Level Variables. This means that you can use them in functions and procedures that are written at module (but not schema) scope without having to pass them in as a reference. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
apsy |
Posted: Tue Aug 03, 2004 10:34 am Post subject: |
|
|
 Novice
Joined: 10 Feb 2004 Posts: 24
|
Thanks a lot mgk !!!!. I found ur earlier post. Gave me exactly what I was looking for.
-Apsy |
|
Back to top |
|
 |
javaforvivek |
Posted: Wed Aug 04, 2004 12:09 am Post subject: |
|
|
 Master
Joined: 14 Jun 2002 Posts: 282 Location: Pune,India
|
Hi mgk,
Can you give the link to that post??
Thx in advance _________________ Vivek
------------------------------------------------------
...when you have eliminated the impossible, whatever remains, however improbable, must be the truth. |
|
Back to top |
|
 |
mgk |
Posted: Wed Aug 04, 2004 1:57 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
May I respectfully suggest that you do what the previous posted did and search the forum yourself. _________________ MGK
The postings I make on this site are my own and don't necessarily represent IBM's positions, strategies or opinions. |
|
Back to top |
|
 |
apsy |
Posted: Wed Aug 04, 2004 11:39 am Post subject: |
|
|
 Novice
Joined: 10 Feb 2004 Posts: 24
|
Vivek ,
Search for a post and by authored by "mgk"
and then lookfor the title
"Message Headers not getting copied to output" |
|
Back to top |
|
 |
|