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

need logic

Former Member
0 Likes
644

Hi all,,

I have a loop containing material number, bwkey , bwtar.

And for the combination of material number and bwkey, we could find two records for different bwtar.

one record whose bwtar would be empty and

other record whose bwtar will hold some value.

The issue is, now while looping into the loop, am using the read stmt with the combination of material number and bwkey.

And i want to pick first the record whose bwtar holds some value.and next if i dont find bwtar which holds value, then i need to look for bwtar which is empty..

Could you please help us with the logic:

loop at internal table.

read table with combination of matnr&bwkey

If material has a bwtar

then i need this record

else

then i need to take record whose bwtar is empty.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
621

Hi,

In READ statement you can not use the logical operators.

Better you take two internal tables one is to fill the records those having the BWTAR as blank and second one is to fill the records those are having some value for BWTAR field.

So that you can write READ statement for both of the internal tables as shown below.

loop at itab.

read table itab1 with key matnr = itab-matnr bwkey = itab-bwkey bwtar = ' '.

if sy-subrc ne 0.

read table itab2 with key matnr = itab-matnr bwkey = itab- bwkey.

endif.

endloop.

4 REPLIES 4
Read only

Former Member
0 Likes
621

Hi ,

U can loop and read twice.

loop at internal table.

read table with combination of matnr&bwkey & bwtar <> space.

if sy-subrc = 0.

use the record.

else.

read table with combination of matnr&bwkey & bwtar = space

if sy-subrc = 0

use the record.

endif.

endif.

Thanks,

Read only

Former Member
0 Likes
621

Hi naveena,

You do like this.

sort itab by matnr bwkey bwtar decending.

Loop at it_some.

read table itab with key matnr = it_some-matnr

bwkey = it_some-bwkey.

if sy-subrc = 0.

then do the process....

endif.

endloop.

You will get all the value entries.

Reward points.

Regards,

Madan.

Read only

vinod_vemuru2
Active Contributor
0 Likes
621

Hi Naveena,

Then u have to sort ur itab accordingly.

SORT itab ASCENDING BY matnr bwkey DESCENDING by bwtar.

LOOP at table.

READ with matnr and bwkey

if sy-subrc is initial.

do ur processing

else.

do ur second processing.

endif.

ENDLOOP.

thanks,

Vinod.

Read only

Former Member
0 Likes
622

Hi,

In READ statement you can not use the logical operators.

Better you take two internal tables one is to fill the records those having the BWTAR as blank and second one is to fill the records those are having some value for BWTAR field.

So that you can write READ statement for both of the internal tables as shown below.

loop at itab.

read table itab1 with key matnr = itab-matnr bwkey = itab-bwkey bwtar = ' '.

if sy-subrc ne 0.

read table itab2 with key matnr = itab-matnr bwkey = itab- bwkey.

endif.

endloop.