Application Development 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: 

select for two conditions on a z table with optional field

Former Member
0 Kudos
119

Hi.

i have requirement like.

i have to select the data from ztable on the basis of 3 fields out of which one is optional.

need to check if the value comes from this select then read,if no values return,then sleect on the same table removing that 1 optional field,and then check if value is coming.

After getting the data,i have to update the data base table.

please suggest how to make select statements.

thanks inadv

1 ACCEPTED SOLUTION

Former Member
0 Kudos
64

Hi,

select *

from ztable

into tab1

where fld1 = ' '

and fld2 = ' '

and opt_fld3 = ' '.

if sy-subrc = 0.

read table itab into <work_area> where fld1 = ' ' and fld2 = ' '.

and opt_fld3 = ' '.

else.

select *

from ztable

into tab1

where fld1 = ' '

and fld2 = ' '

if sy-subrc = 0.

read table itab into <work_area> where fld1 = ' ' and fld2 = ' '.

if sy-subrc = 0.

modify ztable1 from tab1. "updating the reqd database table.

endif.

endif.

endif.

Regards,

Mdi.Deeba

4 REPLIES 4

Former Member
0 Kudos
64

Hi,

Select * from ztable into table itab1 where field1 = ' ' and field2 = ' ' and field3 = ' '.

if itab1 is initial.

Select * from ztable into table itab1 where field1 = ' ' and field2 = ' '.

else.

Read table itab1..

endif.

Thanks,

Nithya

0 Kudos
64

issue is solved.

but after getting the values,i have to replace the table values with this new one(becaouse i am getting the old value from exit)

how can i update it.

thanks

Former Member
0 Kudos
64

You may have to write two select statements first with the optional field in the where clause if it doesnt return value then run another query

Please see if you can get FM or BAPI to update database table

Former Member
0 Kudos
65

Hi,

select *

from ztable

into tab1

where fld1 = ' '

and fld2 = ' '

and opt_fld3 = ' '.

if sy-subrc = 0.

read table itab into <work_area> where fld1 = ' ' and fld2 = ' '.

and opt_fld3 = ' '.

else.

select *

from ztable

into tab1

where fld1 = ' '

and fld2 = ' '

if sy-subrc = 0.

read table itab into <work_area> where fld1 = ' ' and fld2 = ' '.

if sy-subrc = 0.

modify ztable1 from tab1. "updating the reqd database table.

endif.

endif.

endif.

Regards,

Mdi.Deeba