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

How to loop through an internal table?

Former Member
0 Likes
36,630

I am a newbie in ABAP. Someone told me that Internal table is Array in ABAP.

Ok, now I need to do this:

How do I loop through a given internal table of name-value pairs?

Please teach me <REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 14, 2008 5:45 PM

11 REPLIES 11
Read only

Former Member
0 Likes
9,176

Hi,

You can do as below :


"Assuming  you have some data in the itab.

loop at itab.
   write : / itab-field1, itab-field2, itab3-field3. etc.
endloop

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
9,176

Hi Dude,

Declare ur internal table as follows.

data: itab type table of mara with header line.

Select * from MARA into table itab .

loop at itab.

write: itab-matnr,..........

endloop.

Regards,

Nishant

Read only

Former Member
0 Likes
9,176

wait wait...

look at your suggestion, do you assume that I already know the name of the field in the internal table?

actually i do not know what fields are available in the internal table (array). can you suggestion still work?

Please advice. i am really a newbie in abap.

Read only

0 Likes
9,176

Hi Dude,

Declare ur internal table as follows.

data: itab type table of mara with header line.

Select * from MARA into table itab .

loop at itab.

write: itab-matnr,..........

endloop.

(By double clicking on MARA, u can get field names)

Regards,

Nishant

Read only

0 Likes
9,176

Hi,

Try like this:



data : begin of itab occurs 0.
           include structure lfa1.
data : end of itab.

select * from lfa1 into itab.

loop at itab.
  write : itab.
endloop.

Thanks,

Sriram Ponna.

Read only

Former Member
0 Likes
9,176

Sorry guys, I am given this information:

The internal table is MY_PARA type TT_MY_PARA of interface IF_PDL_APP

So now, how do I declare something in my ABAP to loop through the given internal table?

Please pardon my poor knowledge in ABAP. I am only an art graduate who just learnt WinXp last year.

Please help.

Read only

0 Likes
9,176

Hi,

Can you post your code here?

Regards,

Raghu

Read only

0 Likes
9,176

Hi,

I do not have any code.

I am only told that an Internal Table defined as

MY_PARA type TT_MY_PARA of interface IF_PDL_APP

contains the information I need.

So I am requesting you guys to give me an ABAP code to loop through the internal table.

Please help. <REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Apr 14, 2008 5:46 PM

Read only

0 Likes
9,176

hi,

TT_MY_PARA this is not standard table.

so, we don't the fields in it.

if u declere like "MY_PARA type TT_MY_PARA of interface IF_PDL_APP"

is my_para have only work area no body for that.

if u need an internal table body u can define like "type table of".

with out knowing the fields there is no use in looping..

first u must know the fields in internal table and then do print/changes to that values...

ex:

types: begin of ty_mara,

matnr type matnr,

ersda type ersda,

.........

end of ty_mara.

data: it_mara type table of ty_mara.

"for creating internal table body

data: wa_mara type ty_mara.

"for creating work area.

select matnr ersda .... into table it_mara from mara where<...>.

"select fetches the data from mara into u'r internal table.

loop at it_mara into wa_mara.

"here one record is moved from body to work area.

write 😕 wa_mara-matnr,wa_mara-ersda,..... .

" here we print the data in work area.

endloop.

regars,

chandu.

Read only

Former Member
0 Likes
9,176

Hi,

First of all I welcome you in the wonderfull world of ABAP

I will not send you any solution since most of the others has already sent you some of example.

But instead I will give you a usefull transaction that helps me a lot when I have some porblem in ABAP.

it's ABAPDOCU transaction. It will provide you specific ABAP example code over all what is possible to find in ABAP

Have a look at it, and I thing that you will appreciate a lot this transaction

Regards and have fun

Read only

0 Likes
9,176

Thanks bro,

I typed ABAPDOCU but then I got "You are not authorized to use Transaction ABAPDOCU" error.

Anyway I tried my step:

LOOP at IF_PDL_APP~MYPARA

ENDLOOP.

When I compiled, I got this error message:

With "LOOP AT itab", one of the additions "INTO", "ASSIGNING", or 'TRANSPORTING NO FIELDS" is required in the OO context.

Please help.

Thanks