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

itab selection

Former Member
0 Likes
1,168

hi,

i have some records in gt_bseg.

i want only those records whose shkzg value = 'H'.

so coded like this.

loop at gt_bseg into wa_bseg .

read table gt_bseg into wa_bseg with key shkzg = 'H' .

if sy-subrc = 0.

move : wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

endif.

endloop.

loop at gth_bseg into wah_bseg.

write:/2(5) wah_bseg-BUKRS,8(10) wah_bseg-BELNR,20(8) wah_bseg-GJAHR,

30(3) wah_bseg-BSCHL,34(2) wah_bseg-SHKZG,37(2) wah_bseg-MwSKZ,40(9)

wah_bseg-WRBTR.

endloop.

but i am not getting the values . can any one help me?

Thanks

Santosini

1 ACCEPTED SOLUTION
Read only

former_member210123
Active Participant
0 Likes
1,136

instead try this.

DELETE TABLE internal_tab WITH TABLE KEY field ne 'H'.

12 REPLIES 12
Read only

Former Member
0 Likes
1,136

Hi,

loop at gt_bseg into wa_bseg where shkzg = 'H' .

move-corresponding wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

endloop.

Reward if helpful.

Regards,

Kumar

Read only

Former Member
0 Likes
1,136

Hi,

loop at gt_bseg .

read table gt_bseg into wa_bseg with key shkzg = 'H' .

if sy-subrc = 0.

move : wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

endif.

endloop.

loop at wah_bseg.

write:/2(5) wah_bseg-BUKRS,8(10) wah_bseg-BELNR,20(8) wah_bseg-GJAHR,

30(3) wah_bseg-BSCHL,34(2) wah_bseg-SHKZG,37(2) wah_bseg-MwSKZ,40(9)

wah_bseg-WRBTR.

endloop.

Now it works...

Read only

former_member210123
Active Participant
0 Likes
1,137

instead try this.

DELETE TABLE internal_tab WITH TABLE KEY field ne 'H'.

Read only

0 Likes
1,136

This would delete the pother entries and u can loop at the same internal table and have ur write commands asusal.This is simple way of doing it.

Read only

Former Member
0 Likes
1,136

Use sort statement before loop.

sort gt_bseg by shkzg.

loop at gt_bseg into wa_bseg .

read table gt_bseg into wa_bseg with key shkzg = 'H' .

if sy-subrc = 0.

move : wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

endif.

endloop.

Read only

Former Member
0 Likes
1,136

use like that

loop at gt_bseg into wa_bseg .

read table gt_bseg into wa_bseg with key shkzg = 'H' .

if sy-subrc = 0.

move corresonding wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

endif.

endloop.

Clear:wah_bseg. "need to clear the work area before loop.

loop at gth_bseg into wah_bseg.

write:/2(5) wah_bseg-BUKRS,8(10) wah_bseg-BELNR,20(8) wah_bseg-GJAHR,

30(3) wah_bseg-BSCHL,34(2) wah_bseg-SHKZG,37(2) wah_bseg-MwSKZ,40(9)

wah_bseg-WRBTR.

endloop.

Check the above code i think it will work for u...

Thanks

vipin

Read only

Former Member
0 Likes
1,136

Hi,

Put a break point and check what are the values coming in the internal table for SHKZG. There is a possibility that a conversion routine is being used.

Check in the database table is there any conversion routine used. If yes then you have to use some conversion FM.

Reward if helpful.

Regards

Sourabh Verma

Read only

Former Member
0 Likes
1,136

Hi,

Check this code.


*loop at gt_bseg into wa_bseg . "comment this line.
read table gt_bseg into wa_bseg with key shkzg = 'H' .

if sy-subrc = 0.
move : wa_bseg to wah_bseg.
append wah_bseg to gth_bseg.
endif.

*endloop."comment this line.

Check it now and let me know,

if you still not gettin values then give the structure of the fields which you have mentioned.

Reward if helpful.

Regards.

Read only

Former Member
0 Likes
1,136

hi,

i tried all whatever you suggested but not getting the data.

there are 4 records in the gt_bseg itab.

but its not going inside the loop.

its not reading the data.

thanks

Santosini

Read only

0 Likes
1,136

Hi,

Have you given the loop inside the

START OF SELECTION.

event ??

Reward if helpful.

Regards.

Read only

0 Likes
1,136

loop at gt_bseg into wa_bseg .

if wa_bseg-shkzg = 'H' . *<-- write this instead of read *

*read table gt_bseg into wa_bseg with key shkzg = 'H' .

move : wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

endif.

endloop.

Read only

Former Member
0 Likes
1,136

Hi,

You do like this.

loop at gt_bseg into wa_bseg .

if wa_bseg-shkzg = 'H' .

move : wa_bseg to wah_bseg.

append wah_bseg to gth_bseg.

else.

continue.

endif.

endloop.

loop at gth_bseg into wah_bseg.

write:/2(5) wah_bseg-BUKRS,8(10) wah_bseg-BELNR,20(8) wah_bseg-GJAHR,

30(3) wah_bseg-BSCHL,34(2) wah_bseg-SHKZG,37(2) wah_bseg-MwSKZ,40(9)

wah_bseg-WRBTR.

endloop.

Reward.