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

Difference between direct select and abap select

benoit-schmid
Contributor
0 Likes
721

Hello,

If I run the following select, I find 4837

---

SQL> select count(*) from (select * from zengsal minus select * from

zengsal2);

  COUNT(*)

----------

      4837

---

If I run the following abap code, I find 4

---

EXEC SQL.

  select count(*) into :count_sal from (select * from zengsal minus

select * from zengsal2)

ENDEXEC.

count_sal_s = count_sal.

---

Would you know why count_sal_s is not equal to 4837?

Thanks in advance for your answer.

1 ACCEPTED SOLUTION
Read only

ThomasZloch
Active Contributor
0 Likes
685

How is count_sal and count_sal_s declared, maybe the result is truncated, please paste the relevant code.


Thomas

5 REPLIES 5
Read only

ThomasZloch
Active Contributor
0 Likes
686

How is count_sal and count_sal_s declared, maybe the result is truncated, please paste the relevant code.


Thomas

Read only

0 Likes
685

Hello,

They are declared as integer.

I paste the code.

---

* Data Declarations

DATA: lt_mailsubject     TYPE sodocchgi1.

DATA: lt_mailrecipients  TYPE STANDARD TABLE OF somlrec90 WITH HEADER LINE.

DATA: lt_mailtxt         TYPE STANDARD TABLE OF soli      WITH HEADER LINE.

DATA: count_sal, count_det type I.

DATA: count_sal_s, count_det_s TYPE STRING.

DATA: mail_string type string.

* Find the number of differences for zeng_det

EXEC SQL.

  select count(*) into :count_det from (select * from zengdet minus select * from zengdet2)

ENDEXEC.

count_det_s = count_det.

* Find the number of differences for zeng_sal

EXEC SQL.

  select count(*) into :count_sal from (select * from zengsal minus select * from zengsal2)

ENDEXEC.

count_sal_s = count_sal.

---

Thanks in advance for your answers.

Read only

0 Likes
685

Hi Benoit,

I'm suspicious that the abap query appears to return 4 which is the first integer in 4837, so like Thomas I suspect the value may be getting truncated. Try declaring your integer variables TYPE sydbcnt, which has a data type of INT4. Data element sydbcnt is the data element behind sy-dbcnt which is assigned during a select statement.

Cheers,

Amy

Read only

HermannGahm
Product and Topic Expert
Product and Topic Expert
0 Likes
685

Hi,

DATA: count_sal_s

this is a char length 1!

so

count_sal_s = 4837

will be

just 4 (first character of your integer...)

Kind regards,

Hermann

Read only

0 Likes
685

.

DATA: count_sal, count_det type I.

DATA: count_sal_s, count_det_s TYPE STRING.

count_sal_s = count_sal.


Here you have delare count_sal and count_sal_s without any types , so it will be defaulted to char1 . that is the reason your values are truncated.