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

Problem with select query when it returns a NULL value

Former Member
0 Likes
1,682

Hi all,

I have a d/b table called QMEL and i picked VBELN from that table. Now if the VBELN value in that table is NULL i have to wtite an if condition.

Can i say it like this

IF VBELN = ' '.

write: enter into the if condition.

ELSE.

write: enter into the else condition.

ENDIF.

or should is say some thing else? my objective is ..i should execute some statments if VBELN has no value and i should execute some othet statements if VBELN has a value.

Kindly help..as even though i put above condition..it deosnot work

Regards,

Jessica Sam

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,301

hi,

u can write like this



IF itab-VBELN = ' '.

write: enter into the if condition.

ELSE.

write: enter into the else condition.

ENDIF.

or 

IF itab-VBELN is INITIAL.

write: enter into the if condition.

ELSE.

write: enter into the else condition.

ENDIF.




11 REPLIES 11
Read only

former_member194669
Active Contributor
0 Likes
1,301

Yes you can validate as you mentioned or


if qmel-vbeln is initial.   " I think qmel is your internal table 
   " do something
else.
   " do something
endif.

Read only

anuj_srivastava
Active Participant
0 Likes
1,301

Hi jessica ,

The logic which u gave will work fine.

The only modification u need to do is write the the if condition with the table name followed by the field into which ur are storing the value for VBELN.

lets say u r stroing value for vbeln into field vbeln of internal table itab.

If itab-vbeln = ' '.

do something.

Else.

do something.

Endif.

If u r storing the value into a variable then u need to give the variable name only

If z_vbeln = ' '.

do something

else.

do something.

Endif.

Regards,

Anuj

Edited by: ANUJ SRIVASTAVA on Apr 7, 2009 10:57 PM

Edited by: ANUJ SRIVASTAVA on Apr 7, 2009 11:06 PM

Read only

former_member156446
Active Contributor
0 Likes
1,301
IF VBELN = space.

write: enter into the if condition.

ELSE.

write: enter into the else condition.

ENDIF.
Read only

Former Member
0 Likes
1,301

You have to use Internal table name followed by field.

I.e ITAB-FIELD.

The same is applicable always when you are working on the records of the internal table.

Read only

0 Likes
1,301

hi

check this

if u r using selection optins use this code

IF NOT s_material[] IS INITIAL.

SELECT material

FROM marc

INTO l_material

WHERE material IN s_material.

ENDSELECT.

IF sy-subrc NE 0 AND l_material IS INITIAL.

MESSAGE e302 WITH space.

ENDIF.

ENDIF.

if u r using parameter then

IF NOT P_material IS INITIAL.

SELECT material

FROM marc

INTO l_material

WHERE material EQ P_material.

ENDSELECT.

IF sy-subrc NE 0 AND l_material IS INITIAL.

MESSAGE e302 WITH space.

ENDIF.

ENDIF.

~linganna

Edited by: katigiri linganna on Apr 8, 2009 5:58 AM

Read only

Former Member
0 Likes
1,301

Hi Jessica,

After your Select Query when it fills some internal table suppose

itab, then you can use statement :



If not itab is initial.               "that is your intenral table contains some value
                                         " and is not empty
Then your logic.

endif.

Hope it helps

Regards

Mansi

Read only

Former Member
0 Likes
1,302

hi,

u can write like this



IF itab-VBELN = ' '.

write: enter into the if condition.

ELSE.

write: enter into the else condition.

ENDIF.

or 

IF itab-VBELN is INITIAL.

write: enter into the if condition.

ELSE.

write: enter into the else condition.

ENDIF.




Read only

0 Likes
1,301

Hi all,

I am putting this condition in an iterative loop.

So should I be clearing the qmel-vbeln field each time before entering into the loop?

because it is not working as exptected.so i am wondring what else could be wrong.

Regards,

Jessica Sam

Read only

0 Likes
1,301

if you are using a work area it should not be a problem, if you are using the old Header line concept you might have to clear the header line.

Read only

0 Likes
1,301

Hi Jay,

Say, my_wa-vbeln = 000123456

So, do u mean that, If I use explicit work area(my_wa), then, there is no need to CLEAR (my_wa-vbeln) in every iteration? Is it automatically CLEARs the value(say, 000123456) in every iteration?as layed-off, these days, i dont hv SAP access to check my self.

Hi Jessica,

Just info: I guess, you can not write logic solely depending on VBELN(space/value) value of the VQMEL/QMEL table...I mean, u hv to add some more conditions too it(ur IF condition).......ask ur functional guy.

thanq

Edited by: SAP ABAPer on Apr 8, 2009 11:20 PM

Read only

0 Likes
1,301

Thanks every body....soleved