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 query returning data when AND condition fails

Former Member
0 Likes
1,762

Hi All,

The below query should ideally not work when range table : s_blart_final is empty .But somehow its still working and fetching data.

How can I rectify this??

SELECT      rprctr

                rbukrs

                kunnr

                ryear

                poper

                budat

                racct

                docnr

                docln

                blart

                refdocnr

                ksl

                rtcur

                usnam

                matnr

                rassc

                vkbur

                spart

                werks

                msl

                hsl

                tsl

                fkart

                bwtar

                refdocln

                drcrk

     FROM        glpca

     UP TO       2501 ROWS

     INTO TABLE gt_glpca_2k

     FOR ALL ENTRIES IN gt_bukrs_hkont

     WHERE rbukrs EQ gt_bukrs_hkont-bukrs

     AND   racct  EQ gt_bukrs_hkont-hkont

     AND rhoart = gc_rhoart

     AND kokrs = gc_kokrs

     AND   ryear  IN s_ryear

     AND activ = gc_activ

     AND   poper  IN s_poper

     AND rldnr = gc_rldnr

     AND rrcty = gc_rrcty

     AND rvers = gc_rvers

     AND   blart  IN s_blart_final

     AND   werks  IN s_werks

     AND   matnr  IN s_matnr

     AND   vkbur  IN s_vkbur

     AND   kunnr  IN s_kunnr.

Regards,

Faiz

1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,715

Why it should not work a blank range is as good as this field is not considered for filtering out the selection.. you are expecting it to pick on values where document type is initial?

Nabheet

Why it should not work a blank range is as good as this field is not considered for filtering out the selection.. you are expecting it to pick on values where document type is initial?

Nabheet

10 REPLIES 10
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
1,716

Why it should not work a blank range is as good as this field is not considered for filtering out the selection.. you are expecting it to pick on values where document type is initial?

Nabheet

Read only

0 Likes
1,715

Hi nabheet,

my requirement is that if this range field :s-blart_final is empty, then the query should fail.

How do I achieve this???

Read only

0 Likes
1,715

Then simple put a check before the query if S_BLART[] is not initial

Read only

arivazhagan_sivasamy
Active Contributor
0 Likes
1,715

Hi Faiz,

If s_blart_final is empty, it will fetch all the values from table glpca corresponding to blart.


If s_blart_final is having any values, it will fetch the corresponding blart from table glpca.


Arivazhagan S

Read only

thangam_perumal
Contributor
0 Likes
1,715

Hi Rahman,

                yeah sivasamy correctly said if s_blart_final is empty it will select the all the possible values.

if had any value mean it will  select the condition with respect to s_blart_final values.



Regards,

Thangam.P

Read only

Former Member
0 Likes
1,715

Your are using s_blart_final as a range table, so this condition work as an optional check, if value exist in s_blart_final then it will check for the condition otherwise it will skip this condition.

If u want to make s_blart_final mandatory then you have to check it it initial or not before select query..

if s_blart_final[ ] is not initial.

<SELECT QUERY>

endif.

And you are also using FOR ALL ENTRIES so make sure that gt_bukrs_hkont is not empty.

Read only

former_member187748
Active Contributor
0 Likes
1,715

Hi Faizur,

just write before fetching data to check

IF s_blart_final is not initial.

SELECT ......

ENDIF.

You don't have to worried about it too much.

Read only

sachin_khedkar
Explorer
0 Likes
1,715

This message was moderated.

Read only

Former Member
0 Likes
1,715

Hi,

Before writing select query u check s_blart_final table is empty or not,

If s_blart_final[] is not initial then proceed other wise exit..

Regards

Abhay Manna.


Read only

NooruBohra
Active Participant
0 Likes
1,715

Hi Rahman,

If s_blart_final is empty then query will fetch the record from database, If you're requirement is that the query should not get executed when s_blart_final is initial then perform a check


IF s_blart_final[ ] is not initial.

     Select Query * . . .

ENDIF.

Regards,

Nooruddin