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

internaltables

Former Member
0 Likes
485

when i am out of loop of an internaltable i have to go to print last record of an internal table.

can any body help me for this.

thanks $ regards

prahap

5 REPLIES 5
Read only

Former Member
0 Likes
458

Hi Prathap

When you have made a loop continously, work area will have the last record. So you can use that orelse you can use below records for all cases.

<b>

DATA: l_lines TYPE I.
  DESCRIBE TABLE <itab> LINE l_lines.
  if l_lines > 0.
     READ TABLE <itab> into <wa> index l_lines.
  endif.

</b>

Now <wa> will have the last record of the internal table.

Hope this helps.

Kind Regards

Eswar

Read only

gopi_narendra
Active Contributor
0 Likes
458

sort itab by <fld> descending.

read table itab index 1.

write itab.

or

describe table itab lines fill.

read table itab index fill.

if sy-subrc = 0.

write itab.

endif.

Regards

- Gopi

Read only

Former Member
0 Likes
458

Hi Prathap,

Use At last command.

Loop at itab into wa_itab.

.

.

.

.

.

at last.

move wa_itab-<field_name> to field.

end at.

endloop.

write field.

field is a varible( you have to declare) that contains the last record.

Regards,

Guru

*Mark helpfull answers

Read only

Former Member
0 Likes
458

hi,

jus consider the following example

in this n gives the last record

report zodd_number_recs.

tables: zemp.

data : t1 type i value 1,

t2 type i value 0,

n type i.

data: begin of itab occurs 0,

empno like zemp-empno,

end of itab.

select empno from zemp into table itab .

loop at itab.

n = sy-tabix.

t1 = sy-tabix.

t2 = t1 mod 2.

if t2 <> 0.

write:/ itab-empno.

endif.

t1 = t1 + 2.

endloop.

write: / n.

Read only

Former Member
0 Likes
458

Prathap,

another way is to by the use of work areas.

loop at itab into istab.

your loop processing.

endloop.

after the loop istab would have the details of last record.(make sure you dont use clear istab in the loop).