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

Output display from internal table

Former Member
0 Likes
781

Hi Experts,

I am having an internal table

itab 1 with fields

pernr

id(1,2,)

amount

Contents of itab

pernr id amount

100 1 200

100 2 300

But here each pernr can have around two id's (id1,id2)

But in the output table I have to give output as

pernr id1 amount. id2 amount.

100 1 200 2 300

Thanks in Advance,

IFF

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
743

Hi!

Check this code


REPORT z_sdn.



DATA:
  BEGIN OF fs_tab,
    pernr(4) TYPE n,
    id(2)     TYPE n,
    amt     TYPE i,
  END OF fs_tab.


DATA:
  t_tab LIKE
  TABLE OF
        fs_tab.


fs_tab-pernr = '100'.
fs_tab-id = '1'.
fs_tab-amt = 200.
APPEND fs_tab TO t_tab.

CLEAR fs_tab.
fs_tab-pernr = '100'.
fs_tab-id = '2'.
fs_tab-amt = 300.
APPEND fs_tab TO t_tab.


LOOP AT t_tab INTO fs_tab.
  AT NEW pernr.
    WRITE: / fs_tab-pernr.
  ENDAT.

    WRITE: / fs_tab-id,
             fs_tab-amt.

ENDLOOP.

Regards

Abhijeet

6 REPLIES 6
Read only

Former Member
0 Likes
743

Hi,

Try below Code:

LOOP AT itab.
  AT NEW pernr.
    write: 
      / itab-pernr.
  ENDAT.
    write:
        itab-id,
        itab-amount.
ENDLOOP.

Best Regards,

Sunil.

Read only

Former Member
0 Likes
743

Hi,



Loop at itab into wa.
  At new pernr.
    write:
       wa-pernr.
 end at.
 write:
     wa-id,
     wa-amoutn.
Endloop.

Read only

Former Member
0 Likes
743

data:begin of itab occurs 0,

pernr type n,

id type i,

amt type i,

end of itab .

itab-pernr = '001'.

itab-id = 1.

itab-amt = 1000.

append itab .

itab-pernr = '001'.

itab-id = 2.

itab-amt = 1000.

append itab .

itab-pernr = '002'.

itab-id = 1.

itab-amt = 1000.

append itab .

loop at itab .

at end of pernr .

write:/ itab-pernr .

loop at itab where pernr = itab-pernr .

write: itab-id, itab-amt.

endloop.

endat .

endloop.

Read only

Former Member
0 Likes
743

loop at itab.

v_count = v_count + 1.

at new pernr.

write : itab-pernr , itab-id , itab-amount.

endat.

at end of pernr.

if v_count > 1.

write 😕 itab-id , itab-amount.

endif.

clear : v_count.

endat.

endloop.

Read only

naveen_inuganti2
Active Contributor
0 Likes
743

Hi....

Declare one more internal table with additional fields and populate into that...

you can display the internal table as you wish...

and this can create no problem if you down load outputlist into excel sheet or any!

To suggest the detailed logic....

you must clear IDs are always 2 or not?

Thanks,

Naveen.I

Read only

Former Member
0 Likes
744

Hi!

Check this code


REPORT z_sdn.



DATA:
  BEGIN OF fs_tab,
    pernr(4) TYPE n,
    id(2)     TYPE n,
    amt     TYPE i,
  END OF fs_tab.


DATA:
  t_tab LIKE
  TABLE OF
        fs_tab.


fs_tab-pernr = '100'.
fs_tab-id = '1'.
fs_tab-amt = 200.
APPEND fs_tab TO t_tab.

CLEAR fs_tab.
fs_tab-pernr = '100'.
fs_tab-id = '2'.
fs_tab-amt = 300.
APPEND fs_tab TO t_tab.


LOOP AT t_tab INTO fs_tab.
  AT NEW pernr.
    WRITE: / fs_tab-pernr.
  ENDAT.

    WRITE: / fs_tab-id,
             fs_tab-amt.

ENDLOOP.

Regards

Abhijeet