2007 Dec 26 1:18 PM
Hi Experts,
I have created a Report with ALV using objects and also am able to get SUM for some fields using do_sum = 'X'.
My problem is i want to do some calculation using the total amount which i have got, how can i do that (or can it be done??).
Thanks in Advance...
Santosh
Edited by: Santosh (INDIA) on Dec 26, 2007 6:58 PM
2007 Dec 26 4:33 PM
Do_sum option will display ar run time. If you want to do calculations based on the total, you need to sum up the totals in your program before displaying. This cannot be done using Do_sum function of ALV.
2007 Dec 26 4:33 PM
Do_sum option will display ar run time. If you want to do calculations based on the total, you need to sum up the totals in your program before displaying. This cannot be done using Do_sum function of ALV.
2007 Dec 27 4:19 AM
Hi Just follow the code u can find solution for ur problem
TABLES : vbak.
TYPE-POOLS: slis. " ALV Global types
*SELECT-OPTIONS :
s_vkorg FOR vbak-vkorg, " Sales organization
s_kunnr FOR vbak-kunnr, " Sold-to party
s_vbeln FOR vbak-vbeln. " Sales documentmsgnr lo pampu
*
*SELECTION-SCREEN :
SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.
*PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
*SELECTION-SCREEN END OF LINE.
DATA:
BEGIN OF gt_vbak OCCURS 0,
vkorg LIKE vbak-vkorg, " Sales organization
kunnr LIKE vbak-kunnr, " Sold-to party
vbeln LIKE vbak-vbeln, " Sales document
netwr LIKE vbak-netwr, " Net Value of the Sales Order
waerk LIKE vbak-waerk, " Document currency
END OF gt_vbak.
----
*INITIALIZATION.
*
v_1 = 'Maximum of records to read'.
----
START-OF-SELECTION.
PERFORM f_read_data.
PERFORM f_display_data.
----
Form f_read_data
----
FORM f_read_data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_vbak
FROM vbak
UP TO 20 ROWS.
WHERE kunnr IN s_kunnr
AND vbeln IN s_vbeln
AND vkorg IN s_vkorg.
ENDFORM. " F_READ_DATA
----
Form f_display_data
----
FORM f_display_data.
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = 'VBAK'.
ls_fieldcat-do_sum = &2.
ls_fieldcat-cfieldname = &3. "currency unit field name
"(Value set: SPACE, output table field name)
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
DEFINE m_sort.
add 1 to ls_sort-spos.
ls_sort-fieldname = &1.
ls_sort-up = 'X'.
ls_sort-subtot = &2.
append ls_sort to lt_sort.
END-OF-DEFINITION.
DATA:
ls_fieldcat TYPE slis_fieldcat_alv,
lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_sort TYPE slis_t_sortinfo_alv,
ls_sort TYPE slis_sortinfo_alv,
ls_layout TYPE slis_layout_alv.
m_fieldcat 'VKORG' '' ''.
m_fieldcat 'KUNNR' '' ''.
m_fieldcat 'VBELN' '' ''.
m_fieldcat 'NETWR' 'X' 'WAERK'.
m_fieldcat 'WAERK' '' ''.
m_sort 'VKORG' 'X'. " Sort by vkorg and subtotal
m_sort 'KUNNR' 'X'. " Sort by kunnr and subtotal
m_sort 'VBELN' ''. " Sort by vbeln
ls_layout-cell_merge = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = ls_layout
it_fieldcat = lt_fieldcat
it_sort = lt_sort
TABLES
t_outtab = gt_vbak.
ENDFORM. " F_DISPLAY_DATA
Reward points if it is useful.
thank you
chandu
2007 Dec 27 5:09 AM
calculated sum separately using Loop...sum. endloop and displayed in the screen fields.
2007 Dec 27 5:12 AM
hi Santosh,
I will send a sample code fisrt and also i will send a small program for u .check it once.
-
*SubTotal on the Field NETWR
wa_fieldcat-col_pos = '3'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Tab
wa_fieldcat-fieldname = 'NETWR'. "Field Name
wa_fieldcat-do_sum = 'X'. "Sum
wa_fieldcat-seltext_m = 'Net Value'. "Display Text In APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
-
program code:
&----
*& Report YSALESORDER_ALV_SUBTOTALS *
*& *
&----
*& DEVELOPER : KIRAN KUMAR.G *
*& PURPOSE : DISPLAYING SUBTOTALS FOR A PARTICULAR SALES DOC NO *
*& CREATION DT: 26/11/2007 *
*& REQUEST : ERPK900035 *
&----
REPORT ysalesorder_alv_subtotals.
----
Type Pools
----
TYPE-POOLS:slis.
----
Tables
----
TABLES: vbak, "Sales Document: Header Data
vbap. "Sales Document: Item Data
----
Global Structures
----
DATA:gt_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat TYPE slis_fieldcat_alv,
gt_sortcat TYPE slis_t_sortinfo_alv,
wa_sortcat LIKE LINE OF gt_sortcat.
----
Internal Table
----
DATA: BEGIN OF gt_salesorder OCCURS 0,
vbeln LIKE vbak-vbeln, " Sales Document Number
posnr LIKE vbap-posnr, " Sales Doc Item
netwr LIKE vbap-netwr, " Net Value
END OF gt_salesorder.
----
SELECT OPTIONS
----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln. " Sales Document Number.
SELECTION-SCREEN END OF BLOCK b1.
----
Initialization
----
INITIALIZATION.
PERFORM initialization.
----
Start Of Selection
----
START-OF-SELECTION.
PERFORM field_catalog. "For Structure Creation
PERFORM fetch_data. "Get the Data From DB Table
PERFORM sorting USING gt_sortcat.
----
End Of Selection
----
END-OF-SELECTION.
PERFORM display_data.
&----
*& Form initialization
&----
text
----
--> p1 text
<-- p2 text
----
FORM initialization .
s_vbeln-sign = 'I'.
s_vbeln-option = 'BT'.
s_vbeln-low = '4969'.
s_vbeln-high = '5000'.
APPEND s_vbeln.
ENDFORM. " initialization
&----
*& Form field_catalog
&----
text
----
--> p1 text
<-- p2 text
----
FORM field_catalog .
REFRESH : gt_fieldcat.
CLEAR : wa_fieldcat.
wa_fieldcat-col_pos = '1'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table
wa_fieldcat-fieldname = 'VBELN'. "Field Name
wa_fieldcat-key = 'X'. "Blue Color
wa_fieldcat-seltext_m = 'Sales Doc No'. "Display Text In Screen
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = '2'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table Name
wa_fieldcat-fieldname = 'POSNR'. "Field Name
wa_fieldcat-seltext_m = 'Sales Doc Item'."Display Text In Screen
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
*SubTotal on the Field NETWR
wa_fieldcat-col_pos = '3'. "Column Position
wa_fieldcat-tabname = 'IT_SALESORDER'. "Internal Table
wa_fieldcat-fieldname = 'NETWR'. "Field Name
wa_fieldcat-do_sum = 'X'. "Sum
wa_fieldcat-seltext_m = 'Net Value'. "Display Text In Screen
APPEND wa_fieldcat TO gt_fieldcat.
CLEAR wa_fieldcat.
ENDFORM. " field_catalog
&----
*& Form sorting
&----
text
----
-->P_IT_SORTCAT text
----
FORM sorting USING p_it_sortcat TYPE slis_t_sortinfo_alv.
CLEAR wa_sortcat.
wa_sortcat-fieldname = 'VBELN'.
wa_sortcat-up ='X'.
wa_sortcat-subtot = 'X'.
APPEND wa_sortcat TO p_it_sortcat.
ENDFORM. " sorting
&----
*& Form display_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM display_data .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
I_CALLBACK_PF_STATUS_SET = ' '
I_CALLBACK_USER_COMMAND = ' '
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT =
it_fieldcat = gt_fieldcat
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
it_sort = gt_sortcat
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
I_HTML_HEIGHT_TOP =
I_HTML_HEIGHT_END =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = gt_salesorder
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_data
&----
*& Form fetch_data
&----
text
----
--> p1 text
<-- p2 text
----
FORM fetch_data .
REFRESH : gt_salesorder.
CLEAR : gt_salesorder.
SELECT a~vbeln
posnr
b~netwr
FROM vbak AS a
INNER JOIN vbap AS b ON avbeln = bvbeln
INTO TABLE gt_salesorder
WHERE a~vbeln IN s_vbeln.
ENDFORM. " fetch_data
Award points if helpful.
Kiran Kumar.g
Have a Nice Day...