Application Development and Automation 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: 
Read only

Checking data type compatibility

Former Member
1,491

Hi,

Is there a method to check if two data types are compatible with each other? I need to perform this check without any value at hand. With a value it works if I create data references and assign them to field symbols. How do I make the same more generic with just the data type and length given.

Any help would be greatly appreciated. Thanks.

regards,

nithya

8 REPLIES 8
Read only

Former Member
0 Likes
1,082

Pushing this thread up since I have not yet found a solution to this.

Any help folks?

Regards,

Nithya

Read only

Former Member
0 Likes
1,082

Please check the below info from the documenation:

"WA" and "STR" are not mutually convertible in Unicode systems, since you are trying to convert a structure to a field or vice versa. You can only convert these objects in the following cases:

If the structure is completely character-type, the single field can have any type.

Otherwise, the field must have the data type C and the structure must begin with a character-type field that is at least as long as the single field.

Comparison of Structure Layout and the field layout:

==> C(29) g(4)

C(23)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

P(7)

C(27)

P(7)

P(7)

C(16)

P(7)

P(7)

P(7)

P(7)

C(26)

P(7)

P(7)

C(3)

F(8)

C(5)

C(2)

P(5)

Kind Regards

Eswar

Read only

Former Member
0 Likes
1,082

Reffering the documentation...

"WA" and "STR" are not mutually convertible in Unicode systems, since you are trying to convert a structure to a field or vice versa. You can only convert these objects in the following cases:

If the structure is completely character-type, the single field can have any type.

Otherwise, the field must have the data type C and the structure must begin with a character-type field that is at least as long as the single field.

Read only

Former Member
0 Likes
1,082

Hi,

Can you give me the link to the documentation please?

I am not looking to compare a structure and a field, but just two fields that can be of any type. For example, can a date field be converted to type int ?

If two data types are given at runtime, is there a way to check if they can be mapped to each other?

Regards,

Nithya

Read only

0 Likes
1,082

I have extracted the below info from a document that i have with me. Do provide your mail-id if you need the document. I dont mind sharing...:)

Please check this for more understanding...

<b>Type Checks and Type Compatibility</b>

For historical reasons, the types of field symbols and parameters in subroutines or function modules can be defined with the STRUCTURE addition.

If the types of field symbols are defined with FIELD-SYMBOLS <f> STRUCTURE s DEFAULT wa and they are later assigned a data object wa with ASSIGN wa TO <f> ... , in a NUP both statements are checked to see if wa is at least as long as s and wa satisfies the alignment requirements of s at runtime.

16

If parameter types in function modules or subroutines are defined with FORM form1 USING/CHANGING arg STRUCTURE s ... or FORM form2 TABLES itab_a STRUCTURE s ... and the parameters are passed actual parameters with PERFORM form1 USING/CHANGING wa or PERFORM form2 USING/CHANGING itab_b, the NUP also only checks if wa or the line type of itab_b is at least as long as s and wa or the line type of itab_b satisfies the alignment requirements of s. The same is true for function module parameters whose types are defined with STRUCTURE.

The following extra rules are checked in a UP after defining the type with STRUCTURE when assigning data objects, that is for the DEFAULT addition in the FIELD-SYMBOLS statement, for ASSIGN, and when passing actual parameters.

1. If wa or the line type of itab_b is a flat or deep structure, the length of s must be the same for the Unicode fragment views of wa or of itab_b and s.

2. If wa is a single field, only the character-types C, N, D or T are allowed and the structure s must be purely character-type.

Checking both these rules requires additional runtime. It is therefore recommended that, if possible, you type the parameters using TYPE, since the test for actual compatibility is much faster.

If the type of an argument in a function module was defined with ... LIKE struc, where struc is a flat structure, the NUP only checks if the argument is a flat structure with the same length when the parameters are passed. In the UP, it also checks that the fragment views of the current and formal parameters are the same. For performance reasons, it is again recommended that you use TYPE to assign types.

Furthermore, two structures of which one or both contain Includes, are only compatible if the alignment gaps caused by the Include are the same on all platforms. In the following example, struc1 and struc2 are not compatible because a further alignment gap occurs in the US before the INCLUDE:

BEGIN OF struc1, BEGIN OF struc2, BEGIN OF struc3,

a(1) TYPE X, a(1) TYPE X. b(1) TYPE X,

b(1) TYPE X, INCUDE struc3. c(1) TYPE C,

c(1) TYPE C, END OF struc2. END OF struc3.

END OF struc1.

Since the type compatibility can differ in a UP and an NUP, the type compatibility rules of the calling program are valid in an NUS for checking the parameters. This means that if an NUP calls a UP, the type compatibility is defined as in the NUP. Conversely, the Unicode check is activated if a UP calls an NUP.

Kind Regards

Eswar

Read only

Former Member
0 Likes
1,082

Hi Eswar,

You can mail me at nithya.s@sap.com

Thanks,

Nithya

Read only

0 Likes
1,082

Have sent you the document, do confirm upon receiving the same...

Regards

Eswar

Read only

Former Member
0 Likes
1,082

Hi Eswar,

I got the doc, thanks a bunch!

Unable to mail you back since my mailbox is full!

Regards,

Nithya