‎2007 Jul 20 6:03 AM
Hello to all viewers and thanks in advance and reward also.(URGENT)
I have this type of table
Column1 column2
-
-
A 10
D 20
B 10
D 30
A 40
E 20
I want to report in this way. How can solve this issues in coding.
Column1 column 2 < c column 2 > c
-
-
-
A 10
40
-
Subtotal 50
-
B 10
D 20
30
-
Subtotal 50
-
E 20
-
Grand total 60 70
-
Thanks I advance.
Regard : deep.
‎2007 Jul 20 6:18 AM
Hi,
have a look at this program
REPORT ZPRASUBR1.
TABLES: ekko.
type-pools: slis. "ALV Declarations
*Data Declaration
*----
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekpo-ebeln,
ebelp TYPE ekpo-ebelp,
statu TYPE ekpo-statu,
aedat TYPE ekpo-aedat,
matnr TYPE ekpo-matnr,
menge TYPE ekpo-menge,
meins TYPE ekpo-meins,
netpr TYPE ekpo-netpr,
peinh TYPE ekpo-peinh,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko.
*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
gd_tab_group type slis_t_sp_group_alv,
gd_layout type slis_layout_alv,
gd_repid like sy-repid.
************************************************************************
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.
&----
*& Form BUILD_FIELDCATALOG
&----
Build Fieldcatalog for ALV Report
----
form build_fieldcatalog.
There are a number of ways to create a fieldcat.
For the purpose of this example i will build the fieldcatalog manualy
by populating the internal table fields individually and then
appending the rows. This method can be the most time consuming but can
also allow you more control of the final product.
Beware though, you need to ensure that all fields required are
populated. When using some of functionality available via ALV, such as
total. You may need to provide more information than if you were
simply displaying the result
I.e. Field type may be required in-order for
the 'TOTAL' function to work.
fieldcatalog-fieldname = 'EBELN'.
fieldcatalog-seltext_m = 'Purchase Order'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-emphasize = 'X'.
fieldcatalog-key = 'X'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-no_zero = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'EBELP'.
fieldcatalog-seltext_m = 'PO Item'.
fieldcatalog-col_pos = 1.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'STATU'.
fieldcatalog-seltext_m = 'Status'.
fieldcatalog-col_pos = 2.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AEDAT'.
fieldcatalog-seltext_m = 'Item change date'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Material Number'.
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MENGE'.
fieldcatalog-seltext_m = 'PO quantity'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MEINS'.
fieldcatalog-seltext_m = 'Order Unit'.
fieldcatalog-col_pos = 6.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Net Price'.
fieldcatalog-col_pos = 7.
fieldcatalog-outputlen = 15.
fieldcatalog-do_sum = 'X'. "Display column total
fieldcatalog-datatype = 'CURR'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'PEINH'.
fieldcatalog-seltext_m = 'Price Unit'.
fieldcatalog-col_pos = 8.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
&----
*& Form BUILD_LAYOUT
&----
Build layout for ALV grid report
----
form build_layout.
gd_layout-no_input = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-totals_text = 'Totals'(201).
gd_layout-totals_only = 'X'.
gd_layout-f2code = 'DISP'. "Sets fcode for when double
"click(press f2)
gd_layout-zebra = 'X'.
gd_layout-group_change_edit = 'X'.
gd_layout-header_text = 'helllllo'.
endform. " BUILD_LAYOUT
&----
*& Form DISPLAY_ALV_REPORT
&----
Display report using ALV grid
----
form display_alv_report.
gd_repid = sy-repid.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
i_callback_top_of_page = 'TOP-OF-PAGE' "see FORM
i_callback_user_command = 'USER_COMMAND'
i_grid_title = outtext
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_special_groups = gd_tabgroup
IT_EVENTS = GT_XEVENTS
i_save = 'X'
is_variant = z_template
tables
t_outtab = it_ekko
exceptions
program_error = 1
others = 2.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
endform. " DISPLAY_ALV_REPORT
&----
*& Form DATA_RETRIEVAL
&----
Retrieve data form EKPO table and populate itab it_ekko
----
form data_retrieval.
select ebeln ebelp statu aedat matnr menge meins netpr peinh
up to 10 rows
from ekpo
into table it_ekko.
endform. " DATA_RETRIEVAL
Rgds,
Prajith
‎2007 Jul 20 6:19 AM
Hi
By using the control break statements of Internal table (AT NEW, AT END of) you can get like that
SORT ITAB BY f1.
loop at itab.
at new f1.
read table index sy-tabix.
write : / itab-field1, itab-field2.
endat.
write:/ itab-field2.
at end of f1.
sum.
write: / itab-field2.
endat.
endloop.
see the sample code
All this AT NEW, AT FIRST, AT END OF and AT LAST are called control break statements of Internal tables and are used to calculate the TOTALS based on sertain key fields in that internal table
FIrst to use these statements the ITAB has to be sorted by the key fields on whcih you need the SUM of the fields.
Some time you will get * when mopving data from this int table to other table using these commands
so you have to use
READ TABLE ITAB INDEX SY-TABIX in AT..ENDAT..if you are using other fields between them
DATA: sflight_tab TYPE SORTED TABLE OF sflight
WITH UNIQUE KEY carrid connid fldate,
sflight_wa LIKE LINE OF sflight_tab.
SELECT *
FROM sflight
INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
AT NEW connid.
WRITE: / sflight_wa-carrid,
sflight_wa-connid.
ULINE.
ENDAT.
WRITE: / sflight_wa-fldate,
sflight_wa-seatsocc.
AT END OF connid.
SUM.
ULINE.
WRITE: / 'Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
SKIP.
ENDAT.
AT END OF carrid.
SUM.
ULINE.
WRITE: / 'Carrier Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
NEW-PAGE.
ENDAT.
AT LAST.
SUM.
WRITE: / 'Overall Sum',
sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
ENDAT.
ENDLOOP.
<b>Reward points for useful Answers</b>
Regards
Anji
‎2007 Jul 20 6:21 AM
Hi,
Do like this.
DATA: v_subtotal TYPE column2 . (wat ever the data type for column2)
DATA: v_total TYPE column2.
DATA: v_clm1 TYPE column1.
DATA: v_clm2 TYPE column1.
SORT it_itab BY column1.
LOOP AT it_tab.
v_clm1 = it_tab-column1.
v_subtotal = v_subtotal + it_itab-column2.
v_total = v_total + it_itab-column2.
IF v_clm2 <> v_clm1.
Write:/ it_itab-column1
it_itab-column2.
v_clm2 = v_clm1.
ELSE.
it_itab-column1 = SPACE.
Write:/ it_itab-column1
it_itab-column2.
ENDIF.
iF ANY QUERY PING ME.
Reagrd
Azad.
‎2007 Jul 20 6:23 AM
hi,
first sort your internal table by column 1. like
sort itab by column1.
then use control break at end of.
at end of coloumn 1.
---
--
sum.
--
---
endat.
this will surely work.
regards
vijay
‎2007 Jul 20 6:24 AM
Hello Deep Sama,
first, sort your internal table with column1.
and use <b>at end of </b> for the total.
Example:
sort itab by column1.
loop at itab.
at end of column1.
sum.
write: / itab-column1, itab-column 2.
end at.
endloop.
reward if helpful.
Thanks and Regards
--
Sasidhar Reddy Matli
Message was edited by:
Sasidhar Reddy Matli
‎2007 Jul 20 6:36 AM
REPORT zkris_sdn_total.
TYPES: BEGIN OF itab_type,
name,
num TYPE i,
flag,
END OF itab_type.
DATA: itab TYPE itab_type OCCURS 0.
DATA: itab_wa1 LIKE LINE OF itab.
DATA: itab_wa2 LIKE LINE OF itab.
itab_wa1-name = 'A'.
itab_wa1-num = 10.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'D'.
itab_wa1-num = 20.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'B'.
itab_wa1-num = 10.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'D'.
itab_wa1-num = 30.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'A'.
itab_wa1-num = 40.
APPEND itab_wa1 TO itab.
itab_wa1-name = 'E'.
itab_wa1-num = 20.
APPEND itab_wa1 TO itab.
SORT itab BY name.
DATA: lv_tabix LIKE sy-tabix.
DATA: total TYPE i.
DATA: subtotal TYPE i.
LOOP AT itab INTO itab_wa1 WHERE flag = ''.
WRITE:/ itab_wa1-name , itab_wa1-num.
lv_tabix = sy-tabix + 1.
subtotal = itab_wa1-num..
LOOP AT itab INTO itab_wa2 FROM lv_tabix WHERE name = itab_wa1-name.
subtotal = subtotal + itab_wa2-num.
WRITE:/ itab_wa2-num.
itab_wa2-flag = 'X'.
MODIFY itab FROM itab_wa2.
ENDLOOP.
IF sy-subrc = 0.
WRITE:/ 'subtotal = ' , subtotal.
ENDIF.
total = total + subtotal.
ENDLOOP.
‎2007 Jul 20 6:37 AM
Hi
Do u want this in report or through alv??
u can do subtotals in alv.
Just add SUBTOTAL in the fieldcatalog of the particular field.
I_FIELDCAT-DO_SUM = 'X'.<b>Or Try This:</b>
---------
Data: I_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_SORT TYPE SLIS_SORTINFO_ALV.
*---Sort
WA_SORT-SPOS = '1'.
WA_SORT-FIELDNAME = 'LINE'.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X'.
APPEND WA_SORT TO I_SORT.
CLEAR WA_SORT.Pass this in FM,
IT_SORT = I_SORT<b>Or Try This:</b>
-
Use FM REUSE_ALV_EVENTS_GET to get all events in ur ALV report.then use event SUBTOTAL_TEXT to print subtotal.
following are the events that u can use in ALV :
CALLER_EXIT
USER_COMMAND
TOP_OF_PAGE
TOP_OF_COVERPAGE
END_OF_COVERPAGE
FOREIGN_TOP_OF_PAGE
FOREIGN_END_OF_PAGE
PF_STATUS_SET
LIST_MODIFY
TOP_OF_LIST
END_OF_PAGE
END_OF_LIST
AFTER_LINE_OUTPUT
BEFORE_LINE_OUTPUT
REPREP_SEL_MODIFY
SUBTOTAL_TEXT
GROUPLEVEL_CHANGERegards
Pavan
‎2007 Jul 20 6:43 AM
hi
types:begin of it,
zch(1) type c,
zint type i,
end of it.
data itab type table of it with header line.
data wa type it.
itab-zch = 'A'.
itab-zint = 10.
append itab.
itab-zch = 'A'.
itab-zint = 40.
append itab.
itab-zch = 'B'.
itab-zint = 20.
append itab.
itab-zch = 'B'.
itab-zint = 30.
append itab.
sort itab.
loop at itab.
at end of zch.
sum.
write:/ 'sub total:', itab-zint.
endat.
endloop.
data zsum type i.
loop at itab.
zsum = zsum + itab-zint.
endloop.
write:/ 'Grand total:' , zsum.
Message was edited by:
abapuser