2023 Aug 28 1:22 PM
Hi experts,
I am working on a tool for developers.
I have a CONV #( ... ) to convert dynamic data object at runtime (type unknown at compile time), which may be not convertible -> it fails with a short dump (e.g. OBJECTS_TABLES_NOT_COMPATIBLE for internal table).
It's normal.
ABAP Keyword Documentation - Assignment and Conversion Rules
Now I want to make my own ABAP code to check the "convertibility" to raise a catchable exception (with good validation message), in order to avoid the short dump.
Usually I do the code myself but I'm lazy today.
Does anyone have a code to do that? Or something close to it? Or any standard code?
NB: I will do a quick temporary solution with RFC 'NONE' and SYSTEM_FAILURE to handle the short dump, but I'm interested by your input. EDIT December 2023: still interested because the RFC solution works only with data objects which can be serialized + I guess that the performance is "low" due to RFC + producing short dumps in the system for just doing a check really "kills" me.
Thanks!
Sandra
2023 Dec 26 1:36 PM
As szebenyi_balint said, the code in CL_ABAP_UNIT_ASSERT=>ASSERT_EQUALS checks if variables can be compared, but doesn't check for assignment (convertibility).
I have started the below code to check convertibility. Pull requests are welcome to fix bugs and add missing features.
sandraros/abap-convertible: To check whether a data object is convertible to another (github.com)
2023 Aug 28 1:55 PM
2023 Aug 28 2:50 PM
A nice check whether two data fields can be compared can be found in CL_ABAP_UNIT_ASSERT=>ASSERT_EQUALS.
Best regards, Holm
2023 Aug 28 3:26 PM
2023 Aug 28 4:28 PM
2023 Nov 17 2:48 PM
Unfortunately this is wrong.
If I supply say 'ABC' in a string and ask if it can be compared to a NUMC, then it would not bind to the failure returning variable.
Which in turn could cause a CONVT_NO_NUMBER runtime exception if this string was part of a string range as low and one would like to check if 'ABC' is in ( sign = 'I' option = 'EQ' low = '123' ).
2023 Nov 17 3:58 PM
szebenyi_balint Thanks for the feedback. Could you share your code please, so that I can check on my system, please?
2023 Nov 17 6:27 PM
szebenyi_balint I confirm that the method analysis_Svc=>fail_If_Not_Comparable doesn't work as I expect, not limited to what you say, it needs to be adapted (I don't know how much). I will create and publish a code to test whether two data objects are convertible.
Probably it's because the method analysis_Svc=>fail_If_Not_Comparable deals with the comparison rules, which are different from the conversion rules.
2023 Dec 26 1:38 PM
szebenyi_balint I added an answer with link to GitHub code which performs a few convertibility checks.
2023 Dec 26 1:36 PM
As szebenyi_balint said, the code in CL_ABAP_UNIT_ASSERT=>ASSERT_EQUALS checks if variables can be compared, but doesn't check for assignment (convertibility).
I have started the below code to check convertibility. Pull requests are welcome to fix bugs and add missing features.
sandraros/abap-convertible: To check whether a data object is convertible to another (github.com)