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

Regarding collect

Former Member
0 Likes
737

selection screen has 2 options

detail

summary

already one internal table is getting the detailed values.

now i have write code for summary

when summary is clicked

the output shoul be sorted by matnr and all the similar

matnr should be consolidated .ie all the qunatity

and price values should be totalled for similar matnr.

please let me knwo ur suggestions for logic of this

FORM SUMMARY_REPORT .

sort tbl_output by matnr.

loop at tbl_output.

MOVE-CORRESPONDING tbl_output TO tbl_output1.

append tbl_output1.

ENDLOOP.

sort tbl_output1 by matnr.

loop at tbl_output1.

at end of matnr.

sum.

endat.

endloop.

1 ACCEPTED SOLUTION
Read only

guilherme_frisoni
Contributor
0 Likes
708

Hi Revanth,

try this way:


" sort tbl_output by matnr. -> you dont need, unsell you want for output
LOOP AT tbl_output.
  tbl_output1-matnr =  tbl_output-matnr.
  tbl_output1-value_field =  tbl_output-value_field.
  " next velues fileds
  collect tbl_output1.
ENDLOOP.

Collect will sum all value fields comparing all non-numeric fields.

So, using move-corresponding won't work, unless you have just matnr field as non-numerica.

Regards,

Frisoni

5 REPLIES 5
Read only

guilherme_frisoni
Contributor
0 Likes
709

Hi Revanth,

try this way:


" sort tbl_output by matnr. -> you dont need, unsell you want for output
LOOP AT tbl_output.
  tbl_output1-matnr =  tbl_output-matnr.
  tbl_output1-value_field =  tbl_output-value_field.
  " next velues fileds
  collect tbl_output1.
ENDLOOP.

Collect will sum all value fields comparing all non-numeric fields.

So, using move-corresponding won't work, unless you have just matnr field as non-numerica.

Regards,

Frisoni

Read only

0 Likes
708

hi thanks for your info but i want to do it with alv functions

i can use do_sum = x for the fields to be consolidated.

but what option should i use for consolidating based on matnr??

ie at similar matnr the consolidation should take place in alv

Read only

0 Likes
708

So you should set do_sum = 'X' in your fieldcatalog, for each field you want do sum.

Then you have to sort by matnr and set SUBTOT = 'X' for this field.

Frisoni

Read only

0 Likes
708

hi i have put teh do_sum = x

but where should i sort matnr and put subtot = x??

PERFORM write_fieldcat1 USING 'WERKS' 'TBL_OUTPUT' 'AUFK' 'X' 1 ' ' ' '.

PERFORM write_fieldcat1 USING 'AUFNR' 'TBL_OUTPUT' 'AUFK' ' ' 2 ' ' ' '.

PERFORM write_fieldcat1 USING 'MATNR' 'TBL_OUTPUT' 'AFPO' ' ' 3 ' ' ' '.

if p_sum = 'X'.

PERFORM write_fieldcat1 USING 'WKG010' 'TBL_OUTPUT' ' ' ' ' 4 'PV Alum' 'X'.

PERFORM write_fieldcat1 USING 'WKG0102' 'TBL_OUTPUT' ' ' ' ' 5 'PV Cemt' 'X'.

PERFORM write_fieldcat1 USING 'WKG0103' 'TBL_OUTPUT' ' ' ' ' 6 'PV Ceno' 'X'.

PERFORM write_fieldcat1 USING 'WKG0104' 'TBL_OUTPUT' ' ' ' ' 7 'PV Pulp' 'X'.

PERFORM write_fieldcat1 USING 'WKG0105' 'TBL_OUTPUT' ' ' ' ' 8 'PV Silica' 'X'.

PERFORM write_fieldcat1 USING 'WKG0106' 'TBL_OUTPUT' ' ' ' ' 9 'PV MACDO' 'X'.

PERFORM write_fieldcat1 USING 'WKG0107' 'TBL_OUTPUT' ' ' ' ' 10 'PV NonFM' 'X'.

endif.

FORM WRITE_FIELDCAT1 USING name tab st key pos desc sum.

st_fieldcat-fieldname = name.

st_fieldcat-tabname = tab.

st_fieldcat-ref_tabname = st.

st_fieldcat-key = key.

st_fieldcat-col_pos = pos.

st_fieldcat-seltext_m = desc.

st_fieldcat-do_sum = sum.

APPEND st_fieldcat TO tbl_fieldcat.

CLEAR st_fieldcat.

ENDFORM. " WRITE_FIELDCAT1

Read only

0 Likes
708

You have to set your SORT order in SORT table for ALV.

Take a look here:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a41...

Frisoni