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: 

Conversion in Join statement

gerrit_meyer4
Explorer
0 Kudos

Hi SAP experts,

I have a join statement with 2 different data types. The first one is char 10 with alpha conversion and the second one char 4 with alpha conversion as well. The join statement is like this:

inner join on tab1-char10 = tab2-char4

The data types are like this:

char 10: 0000000001

char 4: 0001

Do you have any advice how to convert these data in the join statement? The expected result is that join condition is met in the example above.

Thanks in advance!

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert

I guess you are talking about Open SQL.

The comparison between the columns of an ON condition is carried out at the database and the comparison rules are database specific. In that special case either there is a truncation on the right of the longer field or the shorter field is filled up with blanks (that should be the canonic behavior). Both would give non equal values for your above example.

If your release already allows it, a solution would be to use LPAD on the LHS to fill up the shorter field with 000 on the left, (up to now, no expressions are allowed on the RHS). Otherwise you might use Native SQL.

6 REPLIES 6

jcgood25
Active Contributor

It the field is always zero padded like shown in 'char 10', then simply concatenate '00000000' to your field, and right trim in your SQL language of choice to the appropriate # of characters. Alias the field and use it in your join expression.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

Goes into the right direction, but in Open SQL it would not work to alter the fields in the SELECT list because you can use the alias only behind ORDER BY and nowhere else. Maybe it works in Native SQL.

jcgood25
Active Contributor
0 Kudos

Hi Horst - thanks for setting me straight. After I posted my original answer I thought about the primary tag of ABAP Development, and realized that my answer was more along the lines of SQL or Oracle syntax, where I have some past experience with data items like this where not all fields are the same fixed length and the padding is inconsistent.

umayaraj
Participant
0 Kudos
shift data1 left deleting leading '0'.  " char 10
*
shift data2 left deleting leading '0'.  "char 4
*
...where data1 = data2.
  

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

This is not an answer to the question ...

horst_keller
Product and Topic Expert
Product and Topic Expert

I guess you are talking about Open SQL.

The comparison between the columns of an ON condition is carried out at the database and the comparison rules are database specific. In that special case either there is a truncation on the right of the longer field or the shorter field is filled up with blanks (that should be the canonic behavior). Both would give non equal values for your above example.

If your release already allows it, a solution would be to use LPAD on the LHS to fill up the shorter field with 000 on the left, (up to now, no expressions are allowed on the RHS). Otherwise you might use Native SQL.