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

condition problem

Former Member
0 Likes
1,029

Hi Friends,

Is any thing wrong with the statement, inv_date and invr_date is type date, trans and trans-high is NUMC and usname is char.

IF NOT ( ( zinv_reg-inv_date IS INITIAL

AND zinv_reg-invr_date IS INITIAL )

OR ( zinv_mov-trans IS INITIAL

AND trans-high IS INITIAL )

OR usname IS INITIAL ).

IF sy-subrc = 0.

SELECT trans lifnr xblnr usnam appdate status

FROM zinv_mov INTO TABLE lt_mov

WHERE ( appdate GE zinv_reg-inv_date

AND appdate LE zinv_reg-invr_date )

OR ( trans GE zinv_mov-trans

AND trans LE trans-high )

OR usnam EQ name.

Regards,

Line

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,005

Hi Turbin,

No need of checking subrc value in this case.

IF NOT ( zinv_reg-inv_date IS INITIAL AND zinv_reg-invr_date IS INITIAL )

OR ( zinv_mov-trans IS INITIAL AND trans-high IS INITIAL )

OR usname IS INITIAL .

SELECT trans lifnr xblnr usnam appdate status

FROM zinv_mov INTO TABLE lt_mov

WHERE ( appdate GE zinv_reg-inv_date

AND appdate LE zinv_reg-invr_date )

OR ( trans GE zinv_mov-trans

AND trans LE trans-high )

OR usnam EQ name.

Award points if this helpful.

Regards,

Ravi G

8 REPLIES 8
Read only

Former Member
0 Likes
1,006

Hi Turbin,

No need of checking subrc value in this case.

IF NOT ( zinv_reg-inv_date IS INITIAL AND zinv_reg-invr_date IS INITIAL )

OR ( zinv_mov-trans IS INITIAL AND trans-high IS INITIAL )

OR usname IS INITIAL .

SELECT trans lifnr xblnr usnam appdate status

FROM zinv_mov INTO TABLE lt_mov

WHERE ( appdate GE zinv_reg-inv_date

AND appdate LE zinv_reg-invr_date )

OR ( trans GE zinv_mov-trans

AND trans LE trans-high )

OR usnam EQ name.

Award points if this helpful.

Regards,

Ravi G

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
1,005

Hi,

Your IF condition checks

1) IF both zinv_reg-inv_date and zinv_reg-invr_date are not INITIAL. So if this condition is true ,that is if both these dates are not initial your other conditions(Checking of TRANS HIGH and USNAME) will never be checked since you are using OR and in the case of OR the second condition will be checked only of First condition is FALSE.

Is this what you want or something else just find out.

<b>also could not understand why you are using IF sy-subrc = 0.?</b> First IF itself is enough..

Regards,

Sesh

Read only

0 Likes
1,005

Hi Sesh,

Actually my condition is that if inv_date and invr_date is initial or trans and trans-high is initial or usnam is intial then the select querry should execute.

Regards,

Line

Read only

0 Likes
1,005

Hi,

Following if should be enough


IF  ( zinv_reg-inv_date IS INITIAL
AND zinv_reg-invr_date IS INITIAL ) " Check if these two or inittial
 OR ( zinv_mov-trans IS INITIAL " Else check if these two or initial, this will be checked only if first condition is false that is one of the dates are not initial.
AND trans-high IS INITIAL ) 
 OR usname IS INITIAL . " Else check if usname is initial

* execute select query here
ENDIF.

Read only

0 Likes
1,005

Hi,

But the select querry is picking all the records from the database it is not selecting based on the condition.

Regards,

Line

Read only

0 Likes
1,005

Hi,

As said I changed the code in the if condition but what is wrong with my select querry it is picking all the records from the data base.

Regards,

Line

Read only

0 Likes
1,005

Hi,

Try this query

SELECT trans lifnr xblnr usnam appdate status

FROM zinv_mov INTO TABLE lt_mov

WHERE appdate <b>between</b> zinv_reg-inv_date AND zinv_reg-invr_date OR trans <b>between</b> zinv_mov-trans and trans-high OR usnam EQ name.

Also in your if condition you are checking if they are INITIAL, you want to check if they are initial or NOT initial?

Regards,

Sesh

Read only

Former Member
0 Likes
1,005

IF (zinv_reg-INV_DATE IS INITIAL

AND zinv_reg-INVR_DATE IS INITIAL) OR

( zinv_mov-TRANS IS INITIAL AND

zinv_mov-TRANS_HIGH IS INITIAL) OR

USNAM IS INITIAL.