|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
Array Subscript Error |
« View previous topic :: View next topic » |
Author |
Message
|
madrox |
Posted: Tue Jul 12, 2016 2:21 pm Post subject: Array Subscript Error |
|
|
 Acolyte
Joined: 11 Mar 2015 Posts: 71
|
I am reading a file which has 100 records and then making a web service call. My file has a date value which is not in the date format mmddyyyy and the webservice is expecting mm/dd/yyyy
So I have to loop thru the 100 records and covert each date to the required format.
Code: |
DECLARE iLoop, iMax INT;
SET iLoop = 1;
SET iMax = Cardinality(InputRoot.DFDL.file.body[]);
WHILE iLoop <= iMax DO
SET OutputRoot.JSON.Data[iLoop].firstName = InputRoot.DFDL.file.body[iLoop].firstname;
SET OutputRoot.JSON.Data[iLoop].lastName = InputRoot.DFDL.file.body[iLoop].lastname;
SET cCdataTimestamp = InputRoot.DFDL.file.body[iLoop].dateofbirth;
SET cCdataTimestamp1 = SUBSTRING(cCdataTimestamp from 1 for 2);
SET cCdataTimestamp2 = SUBSTRING(cCdataTimestamp from 3 for 2);
SET cCdataTimestamp3 = SUBSTRING(cCdataTimestamp from 5 for 4);
SET tsDate = cCdataTimestamp1||'/'||cCdataTimestamp2||'/'||cCdataTimestamp3;
SET OutputRoot.JSON.Data[iLoop].Dob = tsDate;
SET iLoop = iLoop + 1;
PROPAGATE TO TERMINAL 'out';
END WHILE;
RETURN FALSE;
END;
|
The first record goes thru fine, but for the second record I get an Array Subscript Error
Quote: |
RecoverableException
File:CHARACTER:F:\build\S1000_slot1\S1000_P\src\DataFlowEngine\ImbRdl\ImbRdlStatementGroup.cpp
Line:INTEGER:792
Function:CHARACTER:SqlStatementGroup::execute
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2488
Text:CHARACTER:Error detected, rethrowing
Insert
Type:INTEGER:5
Text:CHARACTER:.getUpdate_Update_Salesforce.Main
Insert
Type:INTEGER:5
Text:CHARACTER:26.4
Insert
Type:INTEGER:5
Text:CHARACTER:SET OutputRoot.JSON.Data[iLoop].recordCheckResults = InputRoot.DFDL.file.body[iLoop].recordcheck;
RecoverableException
File:CHARACTER:F:\build\S1000_slot1\S1000_P\src\DataFlowEngine\ImbRdl\ImbRdlFieldRef.cpp
Line:INTEGER:2370
Function:CHARACTER:SqlFieldReference::navigateAbsoluteToParentOfFirst
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2498
Text:CHARACTER:Navigation error
Insert
Type:INTEGER:5
Text:CHARACTER:.getUpdate_Update_Salesforce.Main
Insert
Type:INTEGER:5
Text:CHARACTER:26.8
Insert
Type:INTEGER:2
Text:CHARACTER:3
RecoverableException
File:CHARACTER:F:\build\S1000_slot1\S1000_P\src\DataFlowEngine\ImbRdl\ImbRdlFieldRef.cpp
Line:INTEGER:1167
Function:CHARACTER:SqlPathElement::navigateCursorFirst
Type:CHARACTER:
Name:CHARACTER:
Label:CHARACTER:
Catalog:CHARACTER:BIPmsgs
Severity:INTEGER:3
Number:INTEGER:2436
Text:CHARACTER:Array subscript error
Insert
Type:INTEGER:2
Text:CHARACTER:2
|
Please let me know what I'm doing wrong |
|
Back to top |
|
 |
smdavies99 |
Posted: Tue Jul 12, 2016 9:56 pm Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
1) Use references so that you don't have to reparse every line from the root
2) Don't use array subscripts. Use reference pointers and things like FOR and MOVE instructions.
You are seeing the reason why array subscripts are not regarded as good practice.
3) cast the input date/time string into a TIMESTAMP variable. Then cast that into the desired format string using the CAST(xxx as char format 'yyyy/mm/dd' (or whatever format you want).
Give them a try and see what happens. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
timber |
Posted: Wed Jul 13, 2016 2:27 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
I agree. Your first instinct when looping should be a FOR loop. Only consider alternatives when a FOR loop starts to look clumsy for some reason. |
|
Back to top |
|
 |
mgk |
Posted: Wed Jul 13, 2016 4:22 am Post subject: |
|
|
 Padawan
Joined: 31 Jul 2003 Posts: 1642
|
I agree that using references or a FOR loop would be better. The reason this is failing is that the PROGAGATE statement inside the loop deletes the entire message by default after the propagation returns therefore, second time around, the first [1] item in the output does not exist and so the index to the second [2] item will fail. You can simply change "OutputRoot.JSON.Data[iLoop]." to be "OutputRoot.JSON.Data." to see the difference.
Kind regards, _________________ 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 |
|
 |
|
|
 |
|
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
|
|
|
|