10-20-2005 1:08 PM
hi please correct this...
i wanted to add the rows of netpr and nerwr...i wanted to show the total as a new field...i have done but not coming the result..
EPORT ZKAGTB .
TABLES: vbap, vbak, MARA, mbew , KNA1.
type-pools: slis. "ALV Declarations
data : BEGIN OF itabVBAK occurs 0,
matnr type mara-matnr,
-
-
NETWR type vbap-netwr,
BATOT LIKE VBAP-NETPR, <b>(new field)</b>
NAME1 type kna1-name1,
end of itabvbak.
data: batot like VBAP-NETPR.
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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
endform. " BUILD_FIELDCATALOG
form build_fieldcatalog.
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
fieldcatalog-fieldname = 'VBELN'.
-
-
-
-
-
fieldcatalog-fieldname = 'BATOT'.
fieldcatalog-seltext_m = 'BALANCE'.
fieldcatalog-col_pos = 11.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
endform. " BUILD_FIELDCATALOG
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-info_fieldname = 'LINE_COLOR'.
gd_layout-info_fieldname = 'WS_COLOR'.
gd_layout-zebra = 'X'.
endform. " BUILD_LAYOUT
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'
is_layout = gd_layout
it_fieldcat = fieldcatalog[]
it_events = gt_events
is_print = gd_prntparams
i_save = 'X'
tables
t_outtab = itabvbak
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.
data: ld_color(1) type C.
select mara~matnr
-
-
-
KNA1~name1
into corresponding fields of table itabvbak from VBAP
inner join VBAK
on VBAPvbeln = VBAKvbeln
inner join mara
on VBAPmatnr = maramatnr
inner join mbew
on VBAPmatnr = mbewmatnr
inner join KNA1
on VBAKKUNNR = KNA1KUNNR
where VBAK~kunnr in s_kunn1
<b>LOOP AT ITABVBAK.
READ TABLE ITABVBAK WITH KEY VBELN = VBAP-VBELN.
IF SY-SUBRC = 0.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
ENDIF.
ENDLOOP.
endform. " DATA_RETRIEVAL</b>
can u correct this..
raju
Message was edited by: mpr raju
10-20-2005 1:14 PM
hi,
LOOP AT ITABVBAK.
READ TABLE ITABVBAK WITH KEY VBELN = VBAP-VBELN.
IF SY-SUBRC = 0.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
>>> Modify ITABVBAK
ENDIF.
ENDLOOP.
10-20-2005 1:13 PM
Hi
Or you use LOOP or READ command:
LOOP AT ITABVBAK WHERE VBELN = VBAP-VBELN.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
MODIFY READ TABLE ITABVBAK
ENDLOOP.
But I don't know how you find out VBAP-VBELN and I think you have as many rows as positions are for every document in ITABVBAK.
Max
Message was edited by: max bianchi
10-20-2005 1:14 PM
hi,
LOOP AT ITABVBAK.
READ TABLE ITABVBAK WITH KEY VBELN = VBAP-VBELN.
IF SY-SUBRC = 0.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
>>> Modify ITABVBAK
ENDIF.
ENDLOOP.
10-20-2005 1:26 PM
I tried both of ur suggestions but not worked...this is my entire code ..pls correct this..
REPORT ZKAGTB .
TABLES: vbap, vbak, MARA, mbew , KNA1.
type-pools: slis. "ALV Declarations
*Data Declaration
*----
-
data : BEGIN OF itabVBAK occurs 0,
matnr type mara-matnr,
LBKUM type mbew-lbkum,
VTWEG type vbak-vtweg,
VKORG type vbak-vkorg,
KUNNR type vbak-kunnr,
AUART type vbak-auart,
AUDAT type vbap-audat,
NETPR type vbap-netpr,
ARKTX type vbap-arktx,
VBELN type vbap-vbeln,
VRKME type vbap-vrkme,
WAERK type vbap-waerk,
NETWR type vbap-netwr,
BATOT LIKE VBAP-NETPR,
NAME1 type kna1-name1,
line_color(1) type c, "Used to store row color attributes
color_line(2) TYPE c, " Line color
color_cell TYPE lvc_t_scol, " Cell color
celltab type LVC_T_STYL,
end of itabvbak.
*ALV data declarations
*data: batot like VBAP-NETPR.
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,
gt_events type slis_t_event,
gd_prntparams type slis_print_alv.
**********************SELECTION SCEREEN*******************************
************************************************************************
******************************************BLOCK 2*********************
SELECTION-SCREEN begin of block blk5 with frame title text-004.
********CHECK BOX******
*parameter: P_c2 as checkbox USER-COMMAND CHECK.
*data: cursorfield(20) type c.
*****************************************BLOCK 2 SUB******************
SELECTION-SCREEN begin of block 6 with frame title text-005.
SELECT-OPTIONS:
s_audat for vbap-audat no-extension, "Document Date.
s_kunn1 for vbak-kunnr no-extension ,
"DEFAULT '5525' .
s_LBKUM for mbew-lbkum no-extension no-display,
s_matnr for mara-matnr no-extension.
SELECTION-SCREEN end of block 6.
*****************************************BLOCK 2 SUB******************
SELECTION-SCREEN begin of block 7 with frame title text-006.
SELECT-OPTIONS:
s_auart for vbak-auart no-extension no intervals,
s_vtweg for vbak-vtweg no-extension no intervals ,
s_vkorg for vbak-vkorg no-extension no intervals,
s_netpr for vbap-netpr no-extension no intervals no-display.
SELECTION-SCREEN end of block 7.
SELECTION-SCREEN end of block blk5.
************************************************************************
*********************************************************test********
color management.
DATA : wa_color TYPE lvc_s_scol.
Internal table for color management.
DATA : it_color TYPE TABLE OF lvc_s_scol.
itab for input enabling.
DATA: lt_celltab TYPE lvc_t_styl. "
***********************************************************endtest***
*Start-of-selection.
START-OF-SELECTION.
perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform build_events.
perform build_print_params.
perform display_alv_report.
*&----
*
*& Form BUILD_FIELDCATALOG
*&----
*
Build Fieldcatalog for ALV Report
*----
*
form build_fieldcatalog.
DEFINE m_fieldcat.
add 1 to ls_fieldcat-col_pos.
ls_fieldcat-fieldname = &1.
ls_fieldcat-ref_tabname = &2.
append ls_fieldcat to lt_fieldcat.
END-OF-DEFINITION.
fieldcatalog-fieldname = 'VBELN'.
fieldcatalog-seltext_m = 'Verkaufsbeleg'.
fieldcatalog-col_pos = 0.
fieldcatalog-outputlen = 10.
fieldcatalog-hotspot = 'X'.
fieldcatalog-emphasize = 'C511'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'MATNR'.
fieldcatalog-seltext_m = 'Materialnummer'.
fieldcatalog-col_pos = 1.
fieldcatalog-emphasize = 'C511'.
fieldcatalog-hotspot = 'X'.
fieldcatalog-key = 'X'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'ARKTX'.
fieldcatalog-seltext_m = 'Bezeichnung'.
fieldcatalog-col_pos = 2.
fieldcatalog-key = ' '.
fieldcatalog-emphasize = 'C110'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETPR'.
fieldcatalog-seltext_m = 'Nettopries'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-col_pos = 3.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'VRKME'.
fieldcatalog-seltext_m = 'Mengeneinheit'.
fieldcatalog-emphasize = 'C300'. "Column colur, Bold and Inverse off
fieldcatalog-col_pos = 4.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'WAERK'.
fieldcatalog-seltext_m = 'Währung'.
fieldcatalog-emphasize = 'C600'.
fieldcatalog-col_pos = 5.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AUDAT'.
fieldcatalog-seltext_m = 'Belegdatum'.
fieldcatalog-col_pos = 6.
fieldcatalog-emphasize = 'C500'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NETWR'.
fieldcatalog-seltext_m = 'Nettowert'.
fieldcatalog-do_sum = 'X'.
fieldcatalog-col_pos = 7.
fieldcatalog-emphasize = 'C400'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'AUART'.
fieldcatalog-seltext_m = 'Verkaufsbelegart'.
fieldcatalog-col_pos = 8.
fieldcatalog-key = ' '.
fieldcatalog-emphasize = 'C110'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'KUNNR'.
fieldcatalog-seltext_m = 'Kunde'.
fieldcatalog-col_pos = 9.
fieldcatalog-key = 'X'.
fieldcatalog-hotspot = 'X'.
fieldcatalog-emphasize = 'C500'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'NAME1'.
fieldcatalog-seltext_m = 'Kunde name'.
fieldcatalog-col_pos = 10.
fieldcatalog-key = 'X'.
fieldcatalog-hotspot = 'X'.
fieldcatalog-emphasize = 'C500'.
append fieldcatalog to fieldcatalog.
clear fieldcatalog.
fieldcatalog-fieldname = 'BATOT'.
fieldcatalog-seltext_m = 'BALANCE'.
fieldcatalog-col_pos = 11.
fieldcatalog-key = 'X'.
fieldcatalog-hotspot = 'X'.
fieldcatalog-emphasize = 'C500'.
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-info_fieldname = 'LINE_COLOR'.
gd_layout-info_fieldname = 'WS_COLOR'.
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_events
is_print = gd_prntparams
i_save = 'X'
is_variant = z_template
tables
t_outtab = itabvbak
exceptions
program_error = 1
others = 2.
CALL FUNCTION REUSE_ALV_COMMENTARY_WRITE
EXPORTING
I_LOGO = 'W3MI'.
*
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 VBAK table and populate itab it_VBAK
*----
*
form data_retrieval.
data: ld_color(1) type C.
select mara~matnr
MBEW~lbkum
VBAK~VTWEG
VBAK~VKORG
VBAK~KUNNR
VBAK~AUART
VBAP~AUDAT
VBAP~NETPR
VBAP~ARKTX
VBAP~VRKME
VBAP~WAERK
VBAP~NETWR
VBAP~vbeln
KNA1~name1
into corresponding fields of table itabvbak from VBAP
inner join VBAK
on VBAPvbeln = VBAKvbeln
inner join mara
on VBAPmatnr = maramatnr
inner join mbew
on VBAPmatnr = mbewmatnr
inner join KNA1
on VBAKKUNNR = KNA1KUNNR
where VBAK~kunnr in s_kunn1
and VBAP~AUDAT in s_AUDAT
and MBEW~LBKUM in s_LBKUM
and MARA~MATNR in s_MATNR
and VBAK~AUART in s_AUART
and VBAK~VTWEG in s_VTWEG
and VBAK~VKORG in s_VKORG
and VBAP~NETPR in s_NETPR.
LOOP AT ITABVBAK WHERE VBELN = VBAP-VBELN.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
MODIFY ITABVBAK.
ENDLOOP.
endform. " DATA_RETRIEVAL
*----
*
Form TOP-OF-PAGE *
*----
*
ALV Report Header *
*----
*
Form top-of-page.
*ALV Header declarations
data: t_header type slis_t_listheader,
wa_header type slis_listheader,
t_line like wa_header-info,
ld_lines type i,
ld_linesc(10) type c.
Title
wa_header-typ = 'H'.
wa_header-info = 'Kundenanalyse'.
append wa_header to t_header.
clear wa_header.
Date
wa_header-typ = 'S'.
wa_header-key = 'Date: '.
CONCATENATE sy-datum+6(2) '.'
sy-datum+4(2) '.'
sy-datum(4) INTO wa_header-info. "todays date
append wa_header to t_header.
clear: wa_header.
Total No. of Records Selected
describe table itabvbak lines ld_lines.
ld_linesc = ld_lines.
concatenate 'Total No. of Records Selected: ' ld_linesc
into t_line separated by space.
wa_header-typ = 'A'.
wa_header-info = t_line.
append wa_header to t_header.
clear: wa_header, t_line.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = t_header
i_logo = 'ENJOYSAP_LOGO'.
endform.
*----
*
FORM USER_COMMAND *
*----
*
--> R_UCOMM *
--> RS_SELFIELD *
*----
*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
Check function code
CASE r_ucomm.
WHEN '&IC1'.
Check field clicked on within ALVgrid report
IF rs_selfield-fieldname = 'VBELN'.
Read data table, using index of row user clicked on
READ TABLE itabvbak INTO itabvbak INDEX rs_selfield-tabindex.
with key VBELN = rs_selfield-value
Set parameter ID for transaction screen field
SET PARAMETER ID 'AUN' FIELD itabvbak-vbeln.
Sxecute transaction VL02N, and skip initial data entry screen
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
IF rs_selfield-fieldname = 'MATNR'.
READ TABLE itabvbak INTO itabvbak INDEX rs_selfield-tabindex.
Set parameter ID for transaction screen field
SET PARAMETER ID 'MAT' FIELD itabvbak-matnr.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDIF.
IF rs_selfield-fieldname = 'KUNNR'.
READ TABLE itabvbak INTO itabvbak INDEX rs_selfield-tabindex.
Set parameter ID for transaction screen field
SET PARAMETER ID 'KUN' FIELD itabvbak-matnr.
CALL TRANSACTION 'VD03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM.
*&----
*
*& Form BUILD_EVENTS
*&----
*
Build events table
*----
*
form build_events.
data: ls_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 1
importing
et_events = gt_events[].
read table gt_events with key name = slis_ev_end_of_page
into ls_event.
if sy-subrc = 0.
move 'END_OF_PAGE' to ls_event-form.
append ls_event to gt_events.
endif.
read table gt_events with key name = slis_ev_end_of_list
into ls_event.
if sy-subrc = 0.
move 'END_OF_LIST' to ls_event-form.
append ls_event to gt_events.
endif.
endform. " BUILD_EVENTS
*&----
*
*& Form BUILD_PRINT_PARAMS
*&----
*
Setup print parameters
*----
*
form build_print_params.
gd_prntparams-reserve_lines = '9'. "Lines reserved for footer
gd_prntparams-no_coverpage = 'X'.
endform. " BUILD_PRINT_PARAMS
*&----
*
*& Form END_OF_PAGE
*&----
*
form END_OF_PAGE.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
write: sy-uline(50).
skip.
write:/40 'Page:', sy-pagno .
endform.
*&----
*
*& Form END_OF_LIST
*&----
*
form END_OF_LIST.
data: listwidth type i,
ld_pagepos(10) type c,
ld_page(10) type c.
skip.
write:/40 'Page:', sy-pagno .
endform.
raju.................
10-20-2005 1:34 PM
In the form data retrieval, you are doing this
LOOP AT ITABVBAK WHERE VBELN = VBAP-VBELN.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
MODIFY ITABVBAK.
ENDLOOP.
I don't think you have the value of VBAP-VBELN in there. Why did you even use VBAP-VBELN where condition there. You can just do the following.
LOOP AT ITABVBAK.
ITABVBAK-BATOT = ITABVBAK-NETPR + ITABVBAK-NETWR.
MODIFY ITABVBAK.
ENDLOOP.