Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ABAP code to check for dynamic data object convertibility to avoid short dump

Sandra_Rossi
Active Contributor
1,174

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

  1. If the data objects are neither compatible nor convertible, no assignment can take place. If the syntax check recognizes this state, a syntax error is raised, otherwise an exception is raised when the program is executed.

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

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
0 Kudos
986

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)

9 REPLIES 9

matt
Active Contributor
986

I use the RFC route.

holm
Participant
986

A nice check whether two data fields can be compared can be found in CL_ABAP_UNIT_ASSERT=>ASSERT_EQUALS.

Best regards, Holm

abo
Active Contributor
0 Kudos
986

Cool, this is already there in older systems!

Sandra_Rossi
Active Contributor
0 Kudos
986

Exactly what I need, thank you!

0 Kudos
986

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' ).

Sandra_Rossi
Active Contributor
0 Kudos
986

szebenyi_balint Thanks for the feedback. Could you share your code please, so that I can check on my system, please?

Sandra_Rossi
Active Contributor
986

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.

Sandra_Rossi
Active Contributor
0 Kudos
986

szebenyi_balint I added an answer with link to GitHub code which performs a few convertibility checks.

Sandra_Rossi
Active Contributor
0 Kudos
987

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)