|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
  |
|
Regarding Select function in ESQL |
View previous topic :: View next topic |
Author |
Message
|
anilmekala |
Posted: Thu Jun 11, 2015 4:08 am Post subject: Regarding Select function in ESQL |
|
|
Acolyte
Joined: 19 Oct 2012 Posts: 63
|
Hi All,
I hope everybody doing good.
I need some clarification regarding select function. I am receiving sample message from external system as below :
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<PLAN>
<PLANT_CODE>3981</PLANT_CODE>
<ORDER_ID>A-BC12345-00</ORDER_ID>
<PART_NUMBER>101-101-101-101</PART_NUMBER>
<QUANTITY_ORDERED>1</QUANTITY_ORDERED>
<PLAN_REVISION>2</PLAN_REVISION>
<OPERATIONS>
<OPERATION>
<OPER_NUNBER>0010</OPER_NUNBER>
<OPER_TITLE>TITLE1</OPER_TITLE>
<WORK_LOCATION>ABCDE</WORK_LOCATION>
</OPERATION>
<OPERATION>
<OPER_NUNBER>0020</OPER_NUNBER>
<OPER_TITLE>TITLE2</OPER_TITLE>
<WORK_LOCATION>FGHIJ</WORK_LOCATION>
<PARTS>
<PART_CONSUMED>
<PART_NUMBER>202-202-202</PART_NUMBER>
<QUANTITY_CONSUMED>1</QUANTITY_CONSUMED>
</PART_CONSUMED>
</PARTS>
<PARTS>
<PART_CONSUMED>
<PART_NUMBER>303-303-303</PART_NUMBER>
<QUANTITY_CONSUMED>2</QUANTITY_CONSUMED>
</PART_CONSUMED>
</PARTS>
</OPERATION>
<OPERATION>
<OPER_NUNBER>0030</OPER_NUNBER>
<OPER_TITLE>TITLE3</OPER_TITLE>
<WORK_LOCATION>KLMNO</WORK_LOCATION>
<PARTS>
<PART_CONSUMED>
<PART_NUMBER>404-404-404</PART_NUMBER>
<QUANTITY_CONSUMED>3</QUANTITY_CONSUMED>
</PART_CONSUMED>
</PARTS>
</OPERATION>
</OPERATIONS>
</PLAN> |
I am expected out put is :
101-101-101-101 MIRA-BC12345-00 2 0010ABCDETITLE1 0000.000 000000
101-101-101-101 MIRA-BC12345-00 2 0020FGHIJTITLE2 0000.000202-202-202 000001
101-101-101-101 MIRA-BC12345-00 2 0020FGHIJTITLE2 0000.000303-303-303 000002
101-101-101-101 MIRA-BC12345-00 2 0030KLMNOTITLE3 0000.000404-404-404 000003
I have created DFDL model to map the output .
in my ESQL i have written as below :
Code: |
SET OutputRoot.XMLNSC.I3880LEGACYSFC.BODY[] =
(SELECT P.PART_NUMBER AS PartNumber,
P.PLANT_CODE AS PlantCode,
P.ORDER_ID AS TravelerID,
P.PLAN_REVISION AS RevisionNumber,
O.OPER_NUNBER AS Operation,
O.WORK_LOCATION AS WorkCenter,
O.OPER_TITLE AS OperName ,
'0000.000' AS StandardHours,
PC.PART_NUMBER AS ComponentPartNumber,
PC.QUANTITY_CONSUMED AS ComponentQuantity,
SPACE(4) AS Filler
FROM InputRoot.XMLNSC.PLAN[] AS P,
InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION[] AS O ,
InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION.PARTS.PART_CONSUMED[] AS PC
); |
but i am not able to see the out put . if i remove PC.PART_NUMBER AS ComponentPartNumber, PC.QUANTITY_CONSUMED AS ComponentQuantity, and InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION.PARTS.PART_CONSUMED[] AS PC then it is working .
Please help me on to construct correct structure,
Thanks ,
Anil. |
|
Back to top |
|
 |
vishnurajnr |
Posted: Thu Jun 11, 2015 5:19 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
The code
Code: |
InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION.PARTS.PART_CONSUMED[] |
will select the first child named 'OPERATION' under OPERATIONS.
Here in your sample XML,
Quote: |
<OPERATIONS>
<OPERATION>
<OPER_NUNBER>0010</OPER_NUNBER>
<OPER_TITLE>TITLE1</OPER_TITLE>
<WORK_LOCATION>ABCDE</WORK_LOCATION>
</OPERATION> |
, this will (first child) return NULL since there is no element named PARTS and PART_CONSUMED.
So PC.PART_NUMBER AS ComponentPartNumber, PC.QUANTITY_CONSUMED AS ComponentQuantity are returning NULL values.
Please try specific element tree such as
Code: |
InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION[b][2][/b].PARTS.PART_CONSUMED[] |
for example. |
|
Back to top |
|
 |
anilmekala |
Posted: Thu Jun 11, 2015 5:28 am Post subject: |
|
|
Acolyte
Joined: 19 Oct 2012 Posts: 63
|
Hi,
Thanks for your reply .
when i tried to place below statement in my code its giving syntax error:
[InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION[2].PARTS.PART_CONSUMED[]]
I have to display null values , if PARTS, PART_CONSUMED are not present.
Please share the correct one.
Thanks,
[/code] |
|
Back to top |
|
 |
vishnurajnr |
Posted: Thu Jun 11, 2015 7:01 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
I have used the same Input XML,
Used the below ESQL snippet,
Code: |
SET OutputRoot.XMLNSC.I3880LEGACYSFC.BODY[] =
(SELECT P.PART_NUMBER AS PartNumber,
P.PLANT_CODE AS PlantCode,
P.ORDER_ID AS TravelerID,
P.PLAN_REVISION AS RevisionNumber,
O.OPER_NUNBER AS Operation,
O.WORK_LOCATION AS WorkCenter,
O.OPER_TITLE AS OperName ,
'0000.000' AS StandardHours,
PC.PART_NUMBER AS ComponentPartNumber,
PC.QUANTITY_CONSUMED AS ComponentQuantity,
SPACE(4) AS Filler
FROM InputRoot.XMLNSC.PLAN[] AS P,
InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION[] AS O ,
InputRoot.XMLNSC.PLAN.OPERATIONS.OPERATION[2].PARTS.PART_CONSUMED[] AS PC
); |
Got the Output as :
Code: |
<I3880LEGACYSFC>
<BODY>
<PartNumber>101-101-101-101</PartNumber>
<PlantCode>3981</PlantCode>
<TravelerID>A-BC12345-00</TravelerID>
<RevisionNumber>2</RevisionNumber>
<Operation>0010</Operation>
<WorkCenter>ABCDE</WorkCenter>
<OperName>TITLE1</OperName>
<StandardHours>0000.000</StandardHours>
<ComponentPartNumber>202-202-202</ComponentPartNumber>
<ComponentQuantity>1</ComponentQuantity>
<Filler> </Filler>
</BODY>
<BODY>
<PartNumber>101-101-101-101</PartNumber>
<PlantCode>3981</PlantCode>
<TravelerID>A-BC12345-00</TravelerID>
<RevisionNumber>2</RevisionNumber>
<Operation>0020</Operation>
<WorkCenter>FGHIJ</WorkCenter>
<OperName>TITLE2</OperName>
<StandardHours>0000.000</StandardHours>
<ComponentPartNumber>202-202-202</ComponentPartNumber>
<ComponentQuantity>1</ComponentQuantity>
<Filler> </Filler>
</BODY>
<BODY>
<PartNumber>101-101-101-101</PartNumber>
<PlantCode>3981</PlantCode>
<TravelerID>A-BC12345-00</TravelerID>
<RevisionNumber>2</RevisionNumber>
<Operation>0030</Operation>
<WorkCenter>KLMNO</WorkCenter>
<OperName>TITLE3</OperName>
<StandardHours>0000.000</StandardHours>
<ComponentPartNumber>202-202-202</ComponentPartNumber>
<ComponentQuantity>1</ComponentQuantity>
<Filler> </Filler>
</BODY>
</I3880LEGACYSFC> |
IIB 9.0.0.1.
Please share the exception you are getting and the WMB/IIB version you are using. _________________ -------
A man is great by deeds, not by birth...! |
|
Back to top |
|
 |
anilmekala |
Posted: Thu Jun 11, 2015 11:35 pm Post subject: |
|
|
Acolyte
Joined: 19 Oct 2012 Posts: 63
|
Hi ,
Thanks for your reply.
here am pasting my mapping document :[Source Field Source Structure Destination Field Width Notes
Code: |
PART_NUMBER PLAN Part Number Char(16) 1
PLANT_CODE PLAN Plant Code Char(3) 4
ORDER_ID PLAN Traveler ID Char(16) 1
PLAN_REVISION PLAN Revision Number Char(6) 1
OPER_NUNBER OPERATIONS Operation Char (4) 1
WORK_LOCATION OPERATIONS Work Center Char(5) 1
OPER_TITLE OPERATIONS Oper Name Char(20) 1
RUN_TIME OPERATIONS Standard Hours 9(4).9(3) 2
PART_NUMBER PART_CONSUMED Component Part Number Char(16) 1,6
QUANTIY_CONSUMED PART_CONSUMED Component Quantity 9(6) 3, 7
Filler Char(4) 5
] |
sample input :
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<PLAN>
<PLANT_CODE>3981</PLANT_CODE>
<ORDER_ID>A-BC12345-00</ORDER_ID>
<PART_NUMBER>101-101-101-101</PART_NUMBER>
<QUANTITY_ORDERED>1</QUANTITY_ORDERED>
<PLAN_REVISION>2</PLAN_REVISION>
<OPERATIONS>
<OPERATION>
<OPER_NUNBER>0010</OPER_NUNBER>
<OPER_TITLE>TITLE1</OPER_TITLE>
<WORK_LOCATION>ABCDE</WORK_LOCATION>
</OPERATION>
<OPERATION>
<OPER_NUNBER>0020</OPER_NUNBER>
<OPER_TITLE>TITLE2</OPER_TITLE>
<WORK_LOCATION>FGHIJ</WORK_LOCATION>
<PARTS>
<PART_CONSUMED>
<PART_NUMBER>202-202-202</PART_NUMBER>
<QUANTITY_CONSUMED>1</QUANTITY_CONSUMED>
</PART_CONSUMED>
</PARTS>
<PARTS>
<PART_CONSUMED>
<PART_NUMBER>303-303-303</PART_NUMBER>
<QUANTITY_CONSUMED>2</QUANTITY_CONSUMED>
</PART_CONSUMED>
</PARTS>
</OPERATION>
<OPERATION>
<OPER_NUNBER>0030</OPER_NUNBER>
<OPER_TITLE>TITLE3</OPER_TITLE>
<WORK_LOCATION>KLMNO</WORK_LOCATION>
<PARTS>
<PART_CONSUMED>
<PART_NUMBER>404-404-404</PART_NUMBER>
<QUANTITY_CONSUMED>3</QUANTITY_CONSUMED>
</PART_CONSUMED>
</PARTS>
</OPERATION>
</OPERATIONS>
</PLAN>
|
sample output : [101-101-101-101 MIRA-BC12345-00 2 0010ABCDETITLE1 0000.000 000000
101-101-101-101 MIRA-BC12345-00 2 0020FGHIJTITLE2 0000.000202-202-202 000001
101-101-101-101 MIRA-BC12345-00 2 0020FGHIJTITLE2 0000.000303-303-303 000002
101-101-101-101 MIRA-BC12345-00 2 0030KLMNOTITLE3 0000.000404-404-404 000003
]
I have created message flow with below nodes.
MQ Input Node --->compute Node ---> Mq out put.
I have created DFDL schema for out .
i have tried with references and lastmove function to construct out put
Code: |
DECLARE refToPlan REFERENCE TO InputRoot.XMLNSC.PLAN;
DECLARE refToOperations REFERENCE TO refToPlan.OPERATIONS.OPERATION;
DECLARE iPartsCunt INTEGER;
DECLARE iPartsConsumedCunt INTEGER;
DECLARE bodyIndex INTEGER 1;
WHILE LASTMOVE(refToOperations) DO
DECLARE refToParts REFERENCE TO refToOperations.PARTS;
SET iPartsCunt= CARDINALITY(refToOperations.PARTS[]);
IF iPartsCunt>=1 THEN
WHILE LASTMOVE(refToParts) DO
DECLARE refToPartConsumed REFERENCE TO refToParts.PART_CONSUMED;
SET iPartsConsumedCunt = CARDINALITY(refToParts.PART_CONSUMED[]);
IF iPartsConsumedCunt>=1 THEN
WHILE LASTMOVE(refToPartConsumed) DO
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PartNumber = refToPlan.PART_NUMBER;
IF (refToPlan.PLANT_CODE ='3910') THEN
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = 'MEX';
ELSEIF(refToPlan.PLANT_CODE ='3981') THEN
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = 'MIR';
ELSE
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = '???';
END IF;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].TravelerID = refToPlan.ORDER_ID;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].RevisionNumber = refToPlan.PLAN_REVISION;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].Operation = refToOperations.OPER_NUNBER;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].WorkCenter = refToOperations.WORK_LOCATION;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].OperName = refToOperations.OPER_TITLE;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].StandardHours = '0000.000';
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].ComponentPartNumber = refToPartConsumed.PARTS.PART_CONSUMED.PART_NUMBER;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].ComponentQuantity = refToPartConsumed.PARTS.PART_CONSUMED.QUANTIY_CONSUMED;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].Filler = SPACE(4);
--SET bodyIndex = bodyIndex +1;
MOVE refToPartConsumed NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
ELSE
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PartNumber = refToPlan.PART_NUMBER;
IF (refToPlan.PLANT_CODE ='3910') THEN
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = 'MEX';
ELSEIF(refToPlan.PLANT_CODE ='3981') THEN
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = 'MIR';
ELSE
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = '???';
END IF;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].TravelerID = refToPlan.ORDER_ID;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].RevisionNumber = refToPlan.PLAN_REVISION;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].Operation = refToOperations.OPER_NUNBER;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].WorkCenter = refToOperations.WORK_LOCATION;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].OperName = refToOperations.OPER_TITLE;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].StandardHours = '0000.000';
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].ComponentPartNumber = SPACE(16);
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].ComponentQuantity = '000000';
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].Filler = SPACE(4);
END IF;
SET bodyIndex = bodyIndex +1;
MOVE refToParts NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
ELSE
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PartNumber = refToPlan.PART_NUMBER;
IF (refToPlan.PLANT_CODE ='3910') THEN
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = 'MEX';
ELSEIF(refToPlan.PLANT_CODE ='3981') THEN
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = 'MIR';
ELSE
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].PlantCode = '???';
END IF;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].TravelerID = refToPlan.ORDER_ID;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].RevisionNumber = refToPlan.PLAN_REVISION;
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].Operation = SPACE(4);
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].WorkCenter = SPACE(5);
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].OperName = SPACE(20);
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].StandardHours = '0000.000';
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].ComponentPartNumber = SPACE(16);
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].ComponentQuantity = '000000';
SET OutputRoot.DFDL.I3880LEGACYSFC.body[bodyIndex].Filler = SPACE(4);
END IF;
SET bodyIndex = bodyIndex+1;
MOVE refToOperations NEXTSIBLING REPEAT TYPE NAME;
END WHILE;
END; |
with above code am getting index issue.
I plan to construct sample out put by using select function but no luck
here am pasting validation rules[
1) Right pad with spaces and truncate to the required length
2) Hard code the value to “0000.000”
3) Extract the whole number portion. Left pad with zeros. Example 12.3 becomes 000012
4) Use the following translation rules
a. “3910” converts to “MEX”
b. “3981” converts to “MIR”
c. All other values convert to “???”
5) Hard code to 4 spaces
6) Hardcode to 16 spaces when there is no Part_Consumed array
7) Hardcode to “000000” when there is no Part_Consumed array
]
Please help to to complete this task.
Regards,
Anil. |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Jun 12, 2015 4:40 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
If you convert all of those [] loops to use references, you won't get index errors. |
|
Back to top |
|
 |
vishnurajnr |
Posted: Sat Jun 13, 2015 6:46 am Post subject: |
|
|
 Centurion
Joined: 08 Aug 2011 Posts: 134 Location: Trivandrum
|
I think you might use some simple ESQL mapping since it is direct one-one mapping.
Use COALESCE function to map default values if not present (eg: PARTS and PART_CONSUMED).
Something like the below snippet may work:
Code: |
DECLARE inRef REFERENCE TO InputRoot.XMLNSC.PLAN;
DECLARE outRef REFERENCE TO OutputRoot.DFDL.I3880LEGACYSFC;
DECLARE I, J INT 1;
SET J = CARDINALITY(inRef.OPERATIONS.OPERATION[]);
WHILE I<=J DO
DECLARE refToOperations REFERENCE TO inRef.OPERATIONS.OPERATION[I];
SET outRef.Body[I].PartNumber = inRef.PART_NUMBER;
IF (inRef.PLANT_CODE ='3910') THEN
SET outRef.Body[I].PlantCode = 'MEX';
ELSEIF(inRef.PLANT_CODE ='3981') THEN
SET outRef.Body[I].PlantCode = 'MIR';
ELSE
SET outRef.Body[I].PlantCode = '???';
END IF;
SET outRef.body[I].TravelerID = inRef.ORDER_ID;
SET outRef.body[I].RevisionNumber = inRef.PLAN_REVISION;
SET outRef.body[I].Operation = refToOperations.OPER_NUNBER;
SET outRef.body[I].WorkCenter = refToOperations.WORK_LOCATION;
SET outRef.body[I].OperName = refToOperations.OPER_TITLE;
SET outRef.body[I].StandardHours = '0000.000';
SET outRef.body[I].ComponentPartNumber = COALESCE(refToOperations.PARTS.PART_CONSUMED.PART_NUMBER,SPACE(16));
SET outRef.body[I].ComponentQuantity = COALESCE(refToOperations.PARTS.PART_CONSUMED.QUANTITY_CONSUMED,'000000');
SET outRef.body[I].Filler = SPACE(4);
SET I = I+1;
END WHILE;
|
|
|
Back to top |
|
 |
mqjeff |
Posted: Mon Jun 15, 2015 4:51 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You should actually be able to include the COALESCE around the necessary parameters in the SELECT.. |
|
Back to top |
|
 |
|
|
  |
|
Page 1 of 1 |
|
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
|
|
|
|