‎2008 Jun 20 7:09 AM
hi
i would like to have coding for total and subtotal in alv using oops concept and (not using function module).
also i would like to have coding for cell color and heading and footer.
thanx in adv
rocky
‎2008 Jun 20 7:11 AM
Hi,
go throu this link
u vl find lot of examples
[http://saptechnical.com/Tutorials/ALV/ALVMainPage.htm]
Reward if useful
Redards,
priya
‎2008 Jun 20 7:14 AM
get_subtotals
Use
Returns the current subtotals of the ALV Grid Control. Having created totals for at least one column, users can calculate at most nine subtotals. The list is sorted by the values of one or several columns (called the subtotals column). If a value is changed in the subtotals column, the subtotal is displayed (this is also referred to as control level change).
Integration
Before you access the subtotals value, you use the method get_sort_criteria Page 80 to get the sort table http://Ext. One row of this table describes properties of a column in the output table.
If the field SUBTOT is set for a column in this table, the column is a subtotals column.
The field SPOS then indicates at which level (see below) the subtotal has been calculated.
The field FIELDNAME contains the name of the subtotals column in the output table.
Based on this information, you specifically access the values of the tables passed (using reference variables COLLECT01 to COLLECT09).
Features
code
CALL METHOD .
In order to access the values of EP_COLLECT00 to EP_COLLECT09, you use ASSIGN to dereference the relevant reference variable in a field symbol of your output table type (see below).
Parameters
Meaning
EP_COLLECT00
Points to the totals line. Since there is only one totals line which, in addition, has a unique totalling area, no further information is available for this table in table ET_GROUPLEVELS.
get_subtotals
EP_COLLECT01 to EP_COLLECT09
Point to the subtotals line. For each subtotals level, there is one reference variable. Each of these variables points to an internal table that has the type of the output table. EP_COLLECT01 points to the subtotal at the hightest level, while EP_COLLECT02 points to the subtotal at the second highest level, and so on. The levels are derived from the sort priority (field SPOS in the sort table http://Ext.). The column by which the data was sorted first, is the highest subtotals level.
ET_GROUPLEVELS
Manages all indexes for the individual control levels. The fields of the table have the following meaning:
INDEX_FROM, INDEX_TO: Rows of the output table for which the subtotal was created
LEVEL: Subtotals level (see above)
COUNTER: Number of rows for which the subtotal was created
COMPRESS: For this subtotals line, the user has hidden the associated rows.
COLLECT: Indicates the subtotals table (01-09) in which the values are stored
For an overview, see Methods of Class CL_GUI_ALV_GRID Page 66
Activities
Access the subtotals tables (in our example, only the totals and the first subtotals level) using field symbols:
data: total type ref to data, subtotal1 type ref to data.
field-symbols .
hi check the program BCALV_GRID_04
check this ..
Reward Points..
‎2008 Jun 20 7:29 AM
Hi,
Please refer the code below for subtotal and grand total.
"For grand total.
"while building fieldcatalog for amount or any desrired field, you need to use:
gs_fieldcat-do_sum = 'X'.
"For subtotal.
* ALV data declarations
data: it_sortcat type LVC_T_SORT,
it_sortcatdb type LVC_T_SORT.
perform build_sortcat.
*&------------------------------------------------------------------*
*& Form build_sortcat
*&------------------------------------------------------------------*
* Build Sort catalog
*-------------------------------------------------------------------*
FORM build_sortcat .
wa_sort-spos = 1.
wa_sort-fieldname = 'EBELN'.
wa_sort-SUBTOT = 'X'. "subtotals any totals column by this field
* gd_sortcat-tabname
APPEND wa_sort TO it_sortcat.
wa_sort-spos = 2.
wa_sort-fieldname = 'EBELP'.
* gd_sortcat-tabname
APPEND wa_sort TO it_sortcat.
ENDFORM. " build_sortcat
CALL METHOD gd_tree->set_table_for_first_display
EXPORTING
is_layout = gd_layout
CHANGING
it_fieldcatalog = gd_fieldcat
it_sort = it_sortcat
it_outtab = it_report.
Thanks,
Sriram Ponna.
‎2008 Jun 20 7:35 AM
hi ,
Please check the below code
REPORT ydemo_alv.
DATA:
w_alv_grid TYPE REF TO cl_gui_alv_grid,
w_cust_container TYPE REF TO cl_gui_custom_container,
w_alv_cust_container TYPE scrfname VALUE 'CUST_CONTAINER',
w_fcat TYPE lvc_t_fcat,
w_layout TYPE lvc_s_layo.
DATA:
BEGIN OF t_spfli OCCURS 0.
INCLUDE STRUCTURE spfli.
DATA END OF t_spfli.
SELECT *
FROM spfli
INTO TABLE t_spfli.
CALL SCREEN 100.
&----
*& Module display_alv OUTPUT
&----
text
----
MODULE display_alv OUTPUT.
PERFORM display_alv.
ENDMODULE. " display_alv OUTPUT
&----
*& Form display_alv
&----
text
----
--> p1 text
<-- p2 text
----
FORM display_alv .
IF w_alv_grid IS INITIAL.
CREATE OBJECT w_cust_container
EXPORTING
PARENT =
container_name = w_alv_cust_container
STYLE =
LIFETIME = lifetime_default
REPID =
DYNNR =
NO_AUTODEF_PROGID_DYNNR =
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
CREATE_ERROR = 3
LIFETIME_ERROR = 4
LIFETIME_DYNPRO_DYNPRO_LINK = 5
others = 6
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CREATE OBJECT w_alv_grid
EXPORTING
I_SHELLSTYLE = 0
I_LIFETIME =
i_parent = w_cust_container
I_APPL_EVENTS = space
I_PARENTDBG =
I_APPLOGPARENT =
I_GRAPHICSPARENT =
I_NAME =
I_FCAT_COMPLETE = SPACE
EXCEPTIONS
ERROR_CNTL_CREATE = 1
ERROR_CNTL_INIT = 2
ERROR_CNTL_LINK = 3
ERROR_DP_CREATE = 4
others = 5
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
for layout
w_layout-zebra = 'X'.
w_layout-grid_title = 'Title'.
w_alv_grid->set_table_for_first_display(
EXPORTING
I_BUFFER_ACTIVE = I_BUFFER_ACTIVE
I_BYPASSING_BUFFER = I_BYPASSING_BUFFER
I_CONSISTENCY_CHECK = I_CONSISTENCY_CHECK
i_structure_name = 'SPFLI'
IS_VARIANT = IS_VARIANT
I_SAVE = I_SAVE
I_DEFAULT = 'X'
is_layout = w_layout
IS_PRINT = IS_PRINT
IT_SPECIAL_GROUPS = IT_SPECIAL_GROUPS
IT_TOOLBAR_EXCLUDING = IT_TOOLBAR_EXCLUDING
IT_HYPERLINK = IT_HYPERLINK
IT_ALV_GRAPHICS = IT_ALV_GRAPHICS
IT_EXCEPT_QINFO = IT_EXCEPT_QINFO
IR_SALV_ADAPTER = IR_SALV_ADAPTER
CHANGING
it_outtab = t_spfli[]
IT_FIELDCATALOG = w_FCAT
IT_SORT = IT_SORT
IT_FILTER = IT_FILTER
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
).
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDIF.
ENDFORM. " display_alv
Regards,
Jaya Vani
‎2008 Jun 20 7:41 AM
‎2008 Jun 20 7:45 AM
Hi,
The process of totlas and subtotals are same as that of Noramal alv.
Just fill the sort and fieldcat.
And pass those tables to the
CALL METHOD GC_PUR_GRID->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME =
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT =
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
IR_SALV_ADAPTER =
CHANGING
IT_OUTTAB = I_EKKO
IT_FIELDCATALOG = gt_fieldcat_EKKO
IT_SORT = i_sort
IT_FILTER =
EXCEPTIONS
INVALID_PARAMETER_COMBINATION = 1
PROGRAM_ERROR = 2
TOO_MANY_LINES = 3
others = 4
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Go to the tcode DWDM for more information about all the OOALV related programs.
I think it is useful for you.
Reward points if useful.
Thanks & regards
Deepika.