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

sy-dbcnt for select * statement

Former Member
0 Likes
3,701

Sir,

           The statement is

                    

               loop at record.
                     select * from vfkp where fknum = record-FKNUM_001.
                     endselect.
                     if sy-subrc = 0.
                          
if sy-DBCNT = 1.
                                
Perform Operation_One.
                          
elseif sy-DBCNT = 2.
                              
Perform Operation_two.
                            
endif.
                     endif.
                endloop.

THERE WAS DATA IN THE TABLE VFKP AND THE SY-DBCNT IS DISPALYING AS '0'.

IS THERE ANOTHER WAY THAT I CAN PROCEED FURTHER.

Thanks & Regards.

Sir,

           The statement is

                    

               loop at record.
                     select * from vfkp where fknum = record-FKNUM_001.
                     endselect.
                     if sy-subrc = 0.
                          
if sy-DBCNT = 1.
                                
Perform Operation_One.
                          
elseif sy-DBCNT = 2.
                              
Perform Operation_two.
                            
endif.
                     endif.
                endloop.

THERE WAS DATA IN THE TABLE VFKP AND THE SY-DBCNT IS DISPALYING AS '0'.

IS THERE ANOTHER WAY THAT I CAN PROCEED FURTHER.

Thanks & Regards.

8 REPLIES 8
Read only

Former Member
0 Likes
2,148

Hi Satish-

You can do DESCRIBE TABLE vfkp LINES var_lines.

DATA: var_lines TYPE sy-dbcnt.


DESCRIBE TABLE vfkp LINES var_lines.
IF var_lines = 1.
  PERFORM Operation_One.
ELSEIF var_lines = 2.
  PERFORM Operation_two.
ENDIF.

Read only

Former Member
0 Likes
2,148

Hi,

You may want to try.

loop at record.


     select count(*) from vfkp where fknum = record-FKNUM_001.

    

     if sy-subrc = 0.
                          
if sy-DBCNT = 1.
                                
Perform Operation_One.
                          
elseif sy-DBCNT = 2.
                              
Perform Operation_two.
                            
endif.
     endif.




endloop.

Hope it helps!

Read only

Former Member
0 Likes
2,148

Hi Satish kumar

             in your case, sy-dbcnt hold value '0' always...sy-dbcnt triggers in another case, not this. you cant perform your code using sy-dbcnt. one thing, that you use select statement in loop....endloop. in real scenario we always avoid select statement between loop....endloop.

Thanks

Sabyasachi

Read only

Former Member
0 Likes
2,148

Hi Satish,

Sy-dbcnt will get filled only when the select operation is performed for chunk of data. It holds the number of entries fetched from DB.

In your case, instead of

select.. endselect..

Try to use,

data: it_vfkp type table of vfkp,

select * from vfkp into table it_vfkp.

This statement will fill the sy-dbcnt variable to number of entries fetched.

Hope this clarifies.

Regards,

Manjesh.

Read only

kumud
Active Contributor
0 Likes
2,148

Hello,

There could be many ways of doing it as already suggested in replies above. But I was curious to find out why sy-dbcnt is 0. The only possible reason for sy-dbcnt to be 0 could be, you have to use conversion routine before doing the check in where condition on field FKNUM. Thanks.

Regards,

Kumud

Read only

Former Member
0 Likes
2,148

Sir,

The data i am passing in the spread sheet consisting of 9 characters.

The field FKNUM length is 10 characters, if i am passing with additional

zero with the values  (ex :- 0128999890). then in sy-dbcnt the value was displaying.

Thanks & Regards.

Read only

Former Member
0 Likes
2,148

Requirement: Get value in Sy-dbcnt (Number of records fetched)

As your are saying it is working with padding Zero. Please use Padding Zero conversion exit function module before select query.

Thank you

Read only

Former Member
0 Likes
2,148

Ya the problem is because the select statement is failing to search as you have to have data in '0000111122' format only for character types. So use conversion exit alpha and modify the data in the internal table before using select statement.