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

How to compare substring in two tables fields

Former Member
0 Likes
883

Hi ABAP expert,

When I want to select database two tables, we just want to compare two table substring. For Example, both fields have yyyymmdd. But I have interested yyyymm. In the Oracle database and SQL server database, I can easily to use substr to achieve those goals. How in the ABAP program to archive those goals.

Thanks in advance,

Cliff Fan

Hi ABAP expert,

When I want to select database two tables, we just want to compare two table substring. For Example, both fields have yyyymmdd. But I have interested yyyymm. In the Oracle database and SQL server database, I can easily to use substr to achieve those goals. How in the ABAP program to archive those goals.

Thanks in advance,

Cliff Fan

3 REPLIES 3
Read only

Former Member
0 Likes
804

Hi you can access substrings in ABAP the following way:

 
data: s type string value 'yyyymmdd'. 

write: / s(6). "yyyymm 
write: / s+4(4). "mmdd 

so the number after '+' determines the position in the string and the number in parenthesis () determines the length of the substring.

Now you can just loop over both of your tables and perform the necessary comparison in the nested loop.

Read only

Former Member
0 Likes
803

Hi Daniel,

Thanks for your input. I really like to use SQL statement to solve this problem. I understand that we can use internal table to get results. May be I will need to use EXE SQL to get my results.

Cliff

Read only

0 Likes
803

Hi Cliff

if you wan't/need to use SQL for your comparison, then you have to use native SQL since Open SQL does not offer this possibility. Keep in mind that you loose the database independcy though.

For what reason do you wan't to use SQL rather then ABAP logic?