Question
I am trying to read a file with the CSV Connector, but there is a possibility that there are files with a different number of columns from the expected number of it.
When I checked the behavior, even if the number of items differs between the connector setting and the actual file, the script reads only the set number of items in the connector and completes successfully.
Is it possible to develop the process that returns error in such case, when the number of items differs between the setting and the actual file?
Answer
The number of items can be counted by combining Conditional Loop operation and mapper's After Specified Character logic.
Then, by comparing the number of items counted with the settings in the CSV Connector, it is possible to return an error if the file has a different number of items than expected.
Assumptions
Create a script variable of type string and assign a single line of read data to counted, by Fixed Length File Read Process for example, to the variable.
Settings
- Set Conditional Loop operation
Set Conditional Loop operation under the condition that the value of the script input variable is not equal to empty string. - Set After Specified Character logic
Place the After Specified Character logic in Mapper and map it so that the string after the delimiter of the data in the script variable is extracted and reassigned to the variable.
The number of items is stored in a Conditional Loop operation's component variable [count] by repeating the string extraction process in step 2 in the Conditional Loop which is set in step 1 until the script variable value becomes empty.
Then, in Conditional Branch operation, execute Raise Exception operation to return an error if the component variable [count] differs from the number of items set in the CSV connector.
Another Method
In the Read Variable-Length File operation, an error is generated when a file that cannot be read by the set structure definition is read.
Consider using the Read Variable-Length File operation if using the variable length connector is acceptable.
- Conditional Loop
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/flow_conditional_loop.htm - After Specified Character
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Mapper/SubstringAfter.htm - Conditional Branch
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/flow_conditional_branch.htm - Raise Exception
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/proc_raise_exception.htm - Read Variable-Length File
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/variablelength_get_data.htm - Variable-Length Wizard
https://www.hulft.com/help/en-us/HULFTSquare/Content/Designer/Connector/variable_wizard.htm
Comments
0 comments
Article is closed for comments.