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

select statement

Former Member
0 Likes
756

why the below logic does not get executed.

//if val has value 0 then it says no records exists for the input items.

Data: VAL type I.

SELECT count(*) INTO VAL FROM SKB1

WHERE BUKRS = P_BUKRS1 //company code

AND SAKNR = P_RACCT. // GL account no

//want to check whether records exists for given input GL account no

and BUKRS(ie,ccode).

IF VAL EQ 0.

MESSAGE E003 with 'not exists'

ENDIF.

ambichan.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
731

Hello Ambichan,

In case you are using a parameters for the G/L Account Number,

SELECT SINGLE * FROM SKB1
 WHERE BUKRS = P_BUKRS
   AND SAKNR = P_RACCT.

IF SY-SUBRC NE 0.
* ISSUE AN ERROR MESSAGE  
ENDIF.  

I have a hunch that in this case, the value of P_BUKRS AND/OR P_RACCT is

getting cleared. Please check that through debugging.

======================================================================

In case you are using a select-options for a G/L Accont Number,

SELECT SINGLE * FROM SKB1
 WHERE BUKRS =  P_BUKRS
   AND SAKNR IN S_HKONT1.

IF SY-SUBRC NE 0.
* ISSUE AN ERROR MESSAGE  
ENDIF.  

Get back if you still have something to be understood.

Regards,

Anand Mandalika.

6 REPLIES 6
Read only

Former Member
0 Likes
731

Instead of

if val eq 0.
endif.

try

if sy-subrc <> 0.
*** My message
endif.

Regards,

Subramanian V.

Read only

Former Member
0 Likes
731

Hi,

Just executed your program and it seems to work fine. What exactly is the error that you find in your program?

Regards

Read only

Former Member
0 Likes
731

hey

i tried with sy-subrc also

it gives always value "4" even though input value matches table value or not matches.

even i tried sy-dbcnt.this value is always 0.

if i put in loop like this it works.

LOOP AT S_HKONT1.

SELECT * FROM SKB1 INTO CORRESPONDING FIELDS OF W_SKB1

WHERE SAKNR = S_HKONT1-LOW

AND BUKRS = P_BUKRS1.

ENDSELECT.

IF W_SKB1-SAKNR = ''.

MESSAGE: E999 WITH 'E-02: 'error'.

ENDIF.

ENDLOOP.

dont we have any other alternative way?

ambichan.

Read only

0 Likes
731

Hi,

I am not sure whether you are using proper approach or testing properly. Since all the approaches mentioned , except for your last code(which I haven't checked yet) , are working.


data: val type i.

select count(*) into val from z123 where matnr = '1234'.
if sy-subrc <> 0.
  write 'zero values'.
else.
  write 'values present'.
endif.

If you need to check whether an entry is present or not, you should use '<b>select single </b>' and not count ().

Press F1 on Select and help given for Count(*) is good.

Regards,

Subramanian V.

Read only

Former Member
0 Likes
731

ambi,

try checking if your P_BUKRS1 and P_RACCT is typed against SKB1-BUKRS and SKB1-SAKNR, as in:

parameters: p_bukrs1 like skb1-bukrs,
            p_racct  like skb1-saknr.

you may be having a type mismatch for the comparison.

and it might be better for you to check for SY-SUBRC rather than counting the number of contents.

and if you don't need the count, a SELECT SINGLE ought to do fine.

ryan.

Read only

Former Member
0 Likes
732

Hello Ambichan,

In case you are using a parameters for the G/L Account Number,

SELECT SINGLE * FROM SKB1
 WHERE BUKRS = P_BUKRS
   AND SAKNR = P_RACCT.

IF SY-SUBRC NE 0.
* ISSUE AN ERROR MESSAGE  
ENDIF.  

I have a hunch that in this case, the value of P_BUKRS AND/OR P_RACCT is

getting cleared. Please check that through debugging.

======================================================================

In case you are using a select-options for a G/L Accont Number,

SELECT SINGLE * FROM SKB1
 WHERE BUKRS =  P_BUKRS
   AND SAKNR IN S_HKONT1.

IF SY-SUBRC NE 0.
* ISSUE AN ERROR MESSAGE  
ENDIF.  

Get back if you still have something to be understood.

Regards,

Anand Mandalika.