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

if condition not working

Former Member
0 Likes
1,298

Hello Experts,

My if condition is not working is there some syntax i am missing.

SELECT a~aufnr
       a~auart
       a~objnr
       a~werks
       b~stat
       C~RSNUM
       D~KZEAR
       D~XLOEK INTO CORRESPONDING FIELDS OF TABLE itab
              FROM aufk AS A JOIN jest AS B
              ON   a~objnr EQ b~objnr
              INNER JOIN AFKO AS C ON C~AUFNR = A~AUFNR
              INNER JOIN RESB AS D ON D~RSNUM = C~RSNUM
              WHERE a~aufnr IN  s_aufnr AND
                    b~stat  IN  ('I0002','I0340').

from here i get my itab-kzear = X AND ITAB-XLOEK =X

if itab-kzear eq 'X' OR ITAB-XLOEK eq 'X'.

SELECT a~aufnr
       a~auart
       a~objnr
       a~werks
       b~stat
       C~RSNUM
       D~KZEAR
       D~XLOEK INTO CORRESPONDING FIELDS OF TABLE itab
              FROM aufk AS A JOIN jest AS B
              ON   a~objnr EQ b~objnr
              INNER JOIN AFKO AS C ON C~AUFNR = A~AUFNR
              INNER JOIN RESB AS D ON D~RSNUM = C~RSNUM
              WHERE a~aufnr IN  s_aufnr AND
                    b~stat  IN  ('I0002','I0340', 'I0045').
ENDIF.

Please let me kno what can be done.

Thanks and Regrds,

Nikhil.

Hello Experts,

My if condition is not working is there some syntax i am missing.

SELECT a~aufnr
       a~auart
       a~objnr
       a~werks
       b~stat
       C~RSNUM
       D~KZEAR
       D~XLOEK INTO CORRESPONDING FIELDS OF TABLE itab
              FROM aufk AS A JOIN jest AS B
              ON   a~objnr EQ b~objnr
              INNER JOIN AFKO AS C ON C~AUFNR = A~AUFNR
              INNER JOIN RESB AS D ON D~RSNUM = C~RSNUM
              WHERE a~aufnr IN  s_aufnr AND
                    b~stat  IN  ('I0002','I0340').

from here i get my itab-kzear = X AND ITAB-XLOEK =X

if itab-kzear eq 'X' OR ITAB-XLOEK eq 'X'.

SELECT a~aufnr
       a~auart
       a~objnr
       a~werks
       b~stat
       C~RSNUM
       D~KZEAR
       D~XLOEK INTO CORRESPONDING FIELDS OF TABLE itab
              FROM aufk AS A JOIN jest AS B
              ON   a~objnr EQ b~objnr
              INNER JOIN AFKO AS C ON C~AUFNR = A~AUFNR
              INNER JOIN RESB AS D ON D~RSNUM = C~RSNUM
              WHERE a~aufnr IN  s_aufnr AND
                    b~stat  IN  ('I0002','I0340', 'I0045').
ENDIF.

Please let me kno what can be done.

Thanks and Regrds,

Nikhil.

10 REPLIES 10
Read only

Former Member
0 Likes
1,242

Hi,

ITAB is an internal table. How can you use that directly in the IF statemetn.

You need to pass it to the work area and use it in the IF statement

Regards

Ansari

Read only

Former Member
0 Likes
1,242

HI,

You have put if condition on internal table your internal table should be with header line to work your code.

check internal table with header line.

other wise use work area. & put loop on internal table or use read table statment to populate work area.

Regards,

Rahul Wagh

Read only

faisalatsap
Active Contributor
0 Likes
1,242

Hi, Nikhil

Use the Logic Bellow hope will solve out your problem,

DATA: select_ok(2).
READ TABLE itab WITH KEY kzear = 'X'. " Add These Lines of Code Just After 1st Select
IF sy-subrc EQ 0.
  select_ok = 'OK'.
ENDIF.
READ TABLE itab WITH KEY xloek = 'X'.
IF sy-subrc EQ 0.
  select_ok = 'OK'.
ENDIF.
IF select_ok = 'OK'.

*  do your 2nd Select Here

ENDIF.

Please reply back if not solve.

Best Regards,

Faisal

Read only

Former Member
0 Likes
1,242

Hi,

Try this way,


SELECT a~aufnr
       a~auart
       a~objnr
       a~werks
       b~stat
       C~RSNUM
       D~KZEAR
       D~XLOEK INTO CORRESPONDING FIELDS OF TABLE itab
              FROM aufk AS A JOIN jest AS B
              ON   a~objnr EQ b~objnr
              INNER JOIN AFKO AS C ON C~AUFNR = A~AUFNR
              INNER JOIN RESB AS D ON D~RSNUM = C~RSNUM
              WHERE a~aufnr IN  s_aufnr AND
                    b~stat  IN  ('I0002','I0340').

loop at itab.
if itab-kzear = X AND ITAB-XLOEK =X.
SELECT single a~aufnr
       a~auart
       a~objnr
       a~werks
       b~stat
       C~RSNUM
       D~KZEAR
       D~XLOEK APPENDING TABLE itab
              FROM aufk AS A JOIN jest AS B
              ON   a~objnr EQ b~objnr
              INNER JOIN AFKO AS C ON C~AUFNR = A~AUFNR
              INNER JOIN RESB AS D ON D~RSNUM = C~RSNUM
              WHERE a~aufnr IN  s_aufnr AND
                    b~stat  IN  ('I0002','I0340', 'I0045').
endif.
endloop.

Regards,

Vikranth

Read only

0 Likes
1,242

hi Vikrant,

Its not working it does not accept appending table in joins

Thanks,

Nikhil.

Hi Fiasal,

Your statemnent is working will debugg it and let you know if my report wrks properly

Thanks,

Nikhil.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,242

Hello NIkhil,

Can you please explain what exactly are you trying to achieve through this coding (i mean the business requirement)?

May be this will help us in suggesting a better solution.

Awaiting your response.

BR,

Suhas

Read only

0 Likes
1,242

>

> Hi Fiasal,

>

> Your statemnent is working will debugg it and let you know if my report wrks properly

>

> Thanks,

>

> Nikhil.

If no than Please Explain Your Requirement for the 2nd Select

Regard,

Faisal

Read only

0 Likes
1,242

Hello Suhas,

My business requirement is that I have to book the number of PM orders checking it from RESB tABLE.

I get my order no from afko table field name aufnr than I need to take reservation no rsnum from resb and compare it.

Than checking from rsnum in resb I need to check the positions from table resb field name if RESB-KZEAR = u2018Xu2019 RESB-XLOEK =

X.

If these fields found are X than I need to set a status from Jest table

stat = I0045.

I am working on Pm Module.

Hope its clear now.

Thanks and Regrds,

Nikhil.

Read only

Former Member
0 Likes
1,242

hi nikhil,

add these two condition to your where condition of select statement.

Read only

Former Member
0 Likes
1,242

hi,

You have to use your 2nd select query inside the loop at itab.

loop at itab where kzear =X OR kloek = X.

SELECT single a~aufnr

a~auart

a~objnr

a~werks

b~stat

C~RSNUM

D~KZEAR

D~XLOEK APPENDING TABLE itab

FROM aufk AS A JOIN jest AS B

ON aobjnr EQ bobjnr

INNER JOIN AFKO AS C ON CAUFNR = AAUFNR

INNER JOIN RESB AS D ON DRSNUM = CRSNUM

WHERE a~aufnr IN s_aufnr AND

b~stat IN ('I0002','I0340', 'I0045').

endloop.

hope it will work.

regards,

Lokesh