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

Internal Table

Former Member
0 Likes
350

Hi,

I have written this code to retrive data from DB table and use collect to add all numeric fields having similar non-numeric fields.

Still frnds i need to know is there any other logic which can be written using (collect) to get the same output.

i m giving u my code.

<code>

REPORT Z521 line-size 100 line-count 10 no standard page heading.

*write : sy-uline.

data : begin of itab occurs 0,

name like z739-name,

amount like z739-amount,

end of rams.

data : jtab like itab occurs 0 with header line.

data : sum type i.

perform get_data.

loop at itab.

write : itab-name,itab-amount,/ sy-uline.

endloop.

loop at itab.

collect itab into jtab.

endloop.

loop at jtab.

write : / jtab-name, jtab-amount. "code for subtotals using collect

endloop.

*loop at rams.

*

*sum = sum + rams-amount.

*

*at end of name. "code for sub totals using control brk statements.

*write: rams-name,sum,sy-uline.

*clear sum.

*endat.

*

*endloop.

form get_data.

select name

amount from z739

into table itab.

endform.

2 REPLIES 2
Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
312

Hi,

Using collect on STANDARD tables is OBSOLETE, so either make your table Hashed table or Make it sorted table with Unique key.


REPORT Z521 line-size 100 line-count 10 no standard page heading.

*write : sy-uline.

types : begin of itab_type,
name like z739-name,
amount like z739-amount,
end of rams.

data : jtab type hashed table of itab_type with headerline,
         itab type hashed table of itab_type with headerline.

data : sum type i.

perform get_data.
loop at itab.
write : itab-name,itab-amount,/ sy-uline.
endloop.



loop at itab.
collect itab into jtab.
endloop.

loop at jtab.
write : / jtab-name, jtab-amount. "code for subtotals using collect
endloop.



*loop at rams.

*

*sum = sum + rams-amount.

*

*at end of name. "code for sub totals using control brk statements.

*write: rams-name,sum,sy-uline.

*clear sum.

*endat.

*

*endloop.



form get_data.

select name

amount from z739

into table itab.

endform. 

Regards,

Sesh

Read only

Former Member
0 Likes
312

HI,

see this simple code.this is the way how we use collect.

DATA: BEGIN OF seats,

carrid TYPE sflight-carrid,

connid TYPE sflight-connid,

seatsocc TYPE sflight-seatsocc,

END OF seats.

DATA seats_tab LIKE HASHED TABLE OF seats

WITH UNIQUE KEY carrid connid with header line.

SELECT carrid connid seatsocc

FROM sflight

INTO seats.

COLLECT seats INTO seats_tab.

ENDSELECT.

loop at seats_tab.

write:/ seats_tab-carrid,seats_tab-connid,seats_tab-seatsocc.

ENDLOOP.

<b>reward if helpful</b>

rgds,

bharat.