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: 

Loop statement in ABAP OO

Former Member
0 Kudos

Hi,

I am trying to change a BADI interface and since BADIs use ABAP OO, a simple loop statement fails to work.

I need to loop through an internal table and for each record in the internal table I need to read another db table which has a field in common with the internal table.

Ideally,

Loop at lt_selections

select logsys from /bic/mzcs_unit where /bic/zcs_unit = lt_selections-cs_unit

endloop.

But this piece of code fails to work in BADI because of OO concepts.

Can anyone help me out here?

THank you

1 ACCEPTED SOLUTION

alejandro_lpez
Contributor
0 Kudos

Hi,

Try using this code:

1. Create a work area to internal table lt_selections.

data: wa_selections like line of lt_selections.

2. Change the loop:

Loop at lt_selections into wa_wa_selections.

select logsys from /bic/mzcs_unit where /bic/zcs_unit = wa_selections-cs_unit

endloop.

or use FOR ALL ENTRIES statement:

select logsys from /bic/mzcs_unit

FOR ALL ENTRIES IN lt_selections

where /bic/zcs_unit = lt_selections-cs_unit.

Regards,

Alejandro

3 REPLIES 3

Former Member
0 Kudos

Deep,

Actually the code below does work. It doesnt depend on OO concept in BADI or other.

May be there may be a type mis match between the field in the internal table and the key in the db table.

Check.

Regards,

alejandro_lpez
Contributor
0 Kudos

Hi,

Try using this code:

1. Create a work area to internal table lt_selections.

data: wa_selections like line of lt_selections.

2. Change the loop:

Loop at lt_selections into wa_wa_selections.

select logsys from /bic/mzcs_unit where /bic/zcs_unit = wa_selections-cs_unit

endloop.

or use FOR ALL ENTRIES statement:

select logsys from /bic/mzcs_unit

FOR ALL ENTRIES IN lt_selections

where /bic/zcs_unit = lt_selections-cs_unit.

Regards,

Alejandro

0 Kudos

As Alejandro said, if you are getting a syntax error, it is probably because <b>header lines are not allow in OO</b>.

data: wa_selections like line of lt_selections.
Loop at lt_selections into wa_wa_selections.
select logsys from /bic/mzcs_unit 
     where /bic/zcs_unit = wa_selections-cs_unit.
endloop.

Regards,

Rich Heilman

Message was edited by: Rich Heilman