|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Test for Occurances in COBOL |
« View previous topic :: View next topic » |
Author |
Message
|
EricCox |
Posted: Wed Sep 19, 2012 7:02 am Post subject: Test for Occurances in COBOL |
|
|
Master
Joined: 08 Apr 2011 Posts: 292
|
To all,
I know how to test for the CARDINALITY of instances of a COBOL structure.
However, it looks like the service I'm working on sends back 75 instances with only one or several potentially filled in.
How do I test the CARDINALITY or existence of instances based on the population of a single FIELD in the COBOL response structure?
I would like to count the instances based on something like this:
InputBody.RESPONSE_MESSAGE.INSTANCES[].FIELD1 <> ' ';
Is there an elegant way to do this without looping and adding to a variable when the condition is met?
Thanks |
|
Back to top |
|
 |
wbi_telecom |
Posted: Wed Sep 19, 2012 7:32 am Post subject: |
|
|
 Disciple
Joined: 15 Feb 2006 Posts: 188 Location: Harrisburg, PA
|
We use OCCURS DEPENDING ON in our copybooks which sends back a variable length COMMAREA based on number of occurences. It sends the number of occurences in one of the fields in the fixed length section of the copybook. So we do not have to send back the entire COMMAREA containing 75 instances when only one of them is populated.
In ESQL, you can access the field to find out the number of occurences so no need for using CARDINALITY or a loop.
The COBOL importer in broker understands OCCURS DEPENDING ON clause so your message set also parses the message without any issues.
Cheers, |
|
Back to top |
|
 |
kimbert |
Posted: Wed Sep 19, 2012 7:57 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
wbi_telecom is correct - that is the usual way to handle variable-length arrays in COBOL. If possible, obtain the copybook and import it, and everything will be done for you by the COBOL importer. If the copybook is not available then it's not hard to adjust the message definition yourself. Of course, that approach only works if there is a COUNT field somewhere in the input data.
Quote: |
Is there an elegant way to do this without looping and adding to a variable when the condition is met? |
If you cannot change the message set then you can use ESQL's SELECT function to create a ROW and then using CARDINALITY on the row.
But before you choose that solution, you may want to ask yourself why you need to know the number of non-empty occurrences. If it's only to control some later loop in your ESQL then you should use a REFERENCE variable instead. |
|
Back to top |
|
 |
NealM |
Posted: Wed Sep 19, 2012 8:08 am Post subject: |
|
|
 Master
Joined: 22 Feb 2011 Posts: 230 Location: NC or Utah (depends)
|
wbi_telecom is pointing out the standard way of dealing with this. Even in a fixed length Host response, there usually is a counter field that tells you how many of those 75 arrayed structures actually contain pertinent data. Look for it.
If it doesn't have a counter field, you need to know what the Host is padding the "empty" part of the structure with. Hopefully not X'00' s as that will mess you up (if they are, raise a flag and force them to send a valid char like X'40' back). And then do your loop processing, stopping at the first occurance of that padding in a field in your array that would never have that value if it contains data.
(Note: I just saw kimbert's response. What I am suggesting above is for handling a fixed length response.) |
|
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
|
|
|
|