Hello,
In my stream I turn JSON into a STRING.
I have numbers declared as an object that can therefore have values like below:
Null
178.0
178.25
And sometimes and by mistake:
0.181 instead of 181.0
I would like to test that the format of this number has at most only 2 decimals.
What is the invoke to use for this ?
This is my current flow in the attached file.
is one possible regex you could use. A search of the web will reveal other possibilities that may be more suited to your specific need.
That said, are you sure you want/need to do this “in the middle?” If the module is simply passing this value on to some system, why not let that system detect/enforce the format instead of doing it in middleware?
If you’re going to “fix” the value, be careful. Should you round? Truncate? Round up, down, half-up, etc.? People will forget that the middleware is explicitly modifying the data and you’ll end up with production support tickets about the data being “corrupted.”
Thanks for your answer.
But I don’t want to change the data (neither round nor truncate) but just test if I have more than 2 decimals to not process this record and just move on to the next.
The people in the trade make seizure errors that I want to intercept.
Without putting a test I had an error in the IS : “Error Logged. See Error log for details. Error: [SAP.102.9000] JCo error: com.sap.conn.jco.ConversionException - Number 0.181 cannot be encoded as a BCD of length 11 with 2 decimal places at field PRIX_OBJECTIF”
and the stream stopped.
Thanks but how to test the value of the list [2] > 2.
In my example, I calculate the length of the value [2] and I test in BRANCH /zLength if the length:
= 1, it’s OK
= 2, it’s OK
$default It’s Ko
Is there a better way ?
Sorry, I’m a beginner on webMethods.
I have a mistake:
“Cannot define switch and use label conditions at ’ unlabeled BRANCH '”
I defined the BRANCH/zLenght with evaluate labels = True
and 2 sequences:
Label:% zLength%< = 2 (exit on Failure)
Label: $default
Where do i put% zLength%< = 2?
Thanks
So an exception is already being thrown – you do not need to test this yourself and throw a different exception. If you’re notifying someone of the error, use try/catch block to catch the ConversionException that is already being thrown. That way you’ll catch this and any other error that might happen.
“…optimized and best…” is debatable. Another way, as noted earlier:
BRANCH on zTargetPrice
/\d+(\.\d{1,2})?/: SEQUENCE (Ok)
$default: SEQUENCE (Ko)
The regular expression in the branch will match if zTargetPrice is 1 or more numbers, optionally folllowed by a decimal and 1 or 2 numbers. No need for steps to tokenize nor get a length.
The way you have it in your original post, the way Mahesh provided and this way will all work. I still question the need to do it at all but without the additional info about what you’re doing when the error occurs or is detected by your steps, it’s hard to know for sure.