ALV中滑鼠雙擊事件

ZCLouis發表於2007-10-09

*&---------------------------------------------------------------------*
*& Report ZMM71 *
*&---------------------------------------------------------------------*
* &Program : ZMM71 *
* &Author : Louis(ZhouCong) *
* &CreateDate : 10/04/2006 *
* &Change Author : Louis(ZhouCong) *
* &ChangeDate : 10/04/2006/-11/04/2006 *
* &Last ChangeDate : 11/05/2006 *
* &Code type : Report *
* &Description : ???????? *
* &--------------------------------------------------------------------*

REPORT zmm71
NO STANDARD PAGE HEADING LINE-SIZE 255 .

***********************************************************************
***>Include TYPE-POOLS
***********************************************************************
TYPE-POOLS: slis.
CLASS cl_mmim_auth DEFINITION LOAD.

***********************************************************************
***>Include Tables
***********************************************************************
TABLES: ekko, "Purchasing Document Header
ekpo, "Purchasing Document Item
ekbe, "History per Purchasing Document
ekkn, "Account Assignment in Purchasing Document
lfa1, "Vendor Master (General Section)
t023t, "Material Group Descriptions
t001. "Company Codes

***********************************************************************
***>Define Intervals tables
***********************************************************************
* working table for the entries of all Po tables
DATA: BEGIN OF wa_line,
ebeln LIKE ekko-ebeln, "?????'
lifnr LIKE ekko-lifnr, "?????'
waers LIKE ekko-waers, "????'
wkurs LIKE ekko-wkurs, "??'
* wkurc(15) TYPE c, "????'
ebelp LIKE ekpo-ebelp, "?????????'
matkl LIKE ekpo-matkl, "???'
txz01 LIKE ekpo-txz01, "???'
meins LIKE ekpo-meins, "????'
menge LIKE ekpo-menge, "????'
netwr LIKE ekpo-netwr, "PO??'
peinh LIKE ekpo-peinh, "????
netpr LIKE ekpo-netpr, "??'
netps(13) TYPE p DECIMALS 6, "????'
mwskz LIKE ekpo-mwskz, "??'

belnr LIKE ekbe-belnr, "??????'
bwart LIKE ekbe-bwart, "???? (????)'
budat LIKE ekbe-budat, "????????'
mengs LIKE ekbe-menge, "????'
dmbts LIKE ekbe-dmbtr, "????'
wrbtr LIKE ekbe-wrbtr, "????
mengi LIKE ekbe-menge, "??????'
dmbti LIKE ekbe-dmbtr, "??????'
shkzg LIKE ekbe-shkzg, "??/????'

sakto LIKE ekkn-sakto, "?????'
kostl LIKE ekkn-kostl, "????'
wgbez LIKE t023t-wgbez, "?????'
name1 LIKE lfa1-name1, "?????'

color TYPE slis_t_specialcol_alv,
END OF wa_line,
it_line LIKE TABLE OF wa_line WITH HEADER LINE,
itab LIKE TABLE OF wa_line WITH HEADER LINE.

DATA: BEGIN OF it_ekbe OCCURS 0,
ebeln LIKE ekbe-ebeln, "?????'
ebelp LIKE ekbe-ebelp, "?????????'
zekkn LIKE ekbe-zekkn, "????????'
vgabe LIKE ekbe-vgabe, "????/????'
belnr LIKE ekbe-belnr, "??????'
buzei LIKE ekbe-buzei, "????????'
bewtp LIKE ekbe-bewtp, "????????'
bwart LIKE ekbe-bwart, "???? (????)'
menge LIKE ekbe-menge, "??'
dmbtr LIKE ekbe-dmbtr, "????????'
shkzg LIKE ekbe-shkzg, "??/????'
END OF it_ekbe.

DATA: tab_lines TYPE i,
color TYPE slis_t_specialcol_alv WITH HEADER LINE.

DATA: g_menge LIKE ekbe-menge, "????'
g_dmbtr LIKE ekbe-dmbtr, "????'
g_mengt LIKE ekbe-menge, "????'
g_dmbtt LIKE ekbe-dmbtr. "????'

***>Uses For ALV
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
it_event TYPE slis_t_event,
wa_event TYPE slis_alv_event,
it_listhead TYPE slis_t_listheader,
sortcat TYPE slis_t_sortinfo_alv,
sortcat_ln LIKE LINE OF sortcat,
wa_listhead TYPE slis_listheader,
wa_layout TYPE slis_layout_alv,
wk_repid LIKE sy-repid,
g_command_form TYPE slis_formname VALUE 'USER_COMMAND',
gt_list_top_of_page TYPE slis_t_listheader,
g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE'.

*********************************************************
***>Parameters Selection-screen
*********************************************************
* Selection Conditions OBLIGATORY
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_ekorg FOR ekko-ekorg,
s_budat FOR ekbe-budat MEMORY ID but,
s_lifnr FOR ekko-lifnr MEMORY ID lif,
s_ebeln FOR ekko-ebeln MEMORY ID ebl,
s_matnr FOR ekpo-matnr MEMORY ID mat,
s_belnr FOR ekbe-belnr MEMORY ID mbl.
SELECTION-SCREEN END OF BLOCK b1.

*************************************************************
*INITIALIZATION
*************************************************************
INITIALIZATION.
wk_repid = sy-repid.

AT SELECTION-SCREEN.
CALL FUNCTION 'MMIM_ENTRYCHECK_MAIN'
TABLES
it_lifnr = s_lifnr
it_ekorg = s_ekorg.

**************************************************************
*START-OF-SELECTION
**************************************************************
START-OF-SELECTION.
IF ( s_ekorg IS INITIAL ) AND ( s_budat IS INITIAL ) AND
( s_lifnr IS INITIAL ) AND ( s_ebeln IS INITIAL ) AND
( s_matnr IS INITIAL ) AND ( s_belnr IS INITIAL ).
MESSAGE text-inf TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.

PERFORM account_list_01.

CLEAR tab_lines.
DESCRIBE TABLE itab LINES tab_lines.
IF tab_lines EQ 0 OR tab_lines LT 0 .
MESSAGE text-msg TYPE 'S'.
EXIT.
ENDIF.

SORT itab BY lifnr ebeln ebelp belnr bwart.
PERFORM comment_build USING gt_list_top_of_page[].
PERFORM alv_field_cat_01.
PERFORM alv_show_01.

END-OF-SELECTION.


*&--------------------------------------------------------------------*
*& Form account_list_01
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM account_list_01 .

REFRESH : it_line, itab, it_ekbe.
SELECT ekko~ebeln ekko~lifnr ekko~waers ekko~wkurs ekpo~ebelp
ekpo~matkl ekpo~txz01 ekpo~meins ekpo~menge ekpo~netwr
ekpo~peinh ekpo~netpr ekpo~mwskz ekbe~belnr ekbe~bwart
ekbe~budat ekbe~menge AS mengs ekbe~dmbtr AS dmbts ekbe~wrbtr
ekbe~shkzg
INTO CORRESPONDING FIELDS OF TABLE it_line
FROM ekko
INNER JOIN ekpo ON ekko~ebeln = ekpo~ebeln
INNER JOIN ekbe ON ekpo~ebeln = ekbe~ebeln AND ekpo~ebelp =
ekbe~ebelp
WHERE ekko~ebeln IN s_ebeln AND ekko~bstyp = 'F' AND
* ekko~bsart = 'ZSPO' AND ekko~loekz = space AND
ekko~lifnr IN s_lifnr AND ekko~ekorg IN s_ekorg AND
ekpo~matnr IN s_matnr AND ekpo~loekz = space AND
* ekbe~zekkn = '00' AND ekbe~vgabe = '1' AND
* ekbe~belnr IN s_belnr AND ekbe~bewtp = 'E' AND
ekbe~budat IN s_budat.
IF sy-subrc NE 0.
MESSAGE text-msg TYPE 'S'.
EXIT.
ENDIF.

SORT it_line BY ebeln ebelp belnr bwart.
REFRESH itab.
LOOP AT it_line INTO wa_line.
IF wa_line-bwart = '101'.
MOVE-CORRESPONDING wa_line TO itab.
APPEND itab.
ELSEIF wa_line-bwart = '102'.
LOOP AT itab WHERE ebeln = wa_line-ebeln AND ebelp = wa_line-ebelp
.
itab-mengs = itab-mengs - wa_line-mengs.
itab-dmbts = itab-dmbts - wa_line-dmbts.
itab-wrbtr = itab-wrbtr - wa_line-wrbtr.
MODIFY itab.
ENDLOOP.
ENDIF.
IF wa_line-bwart = '122'.
MOVE-CORRESPONDING wa_line TO itab.
APPEND itab.
ELSEIF wa_line-bwart = '123'.
LOOP AT itab WHERE ebeln = wa_line-ebeln AND ebelp = wa_line-ebelp
.
itab-mengs = itab-mengs - wa_line-mengs.
itab-dmbts = itab-dmbts - wa_line-dmbts.
itab-wrbtr = itab-wrbtr - wa_line-wrbtr.
MODIFY itab.
ENDLOOP.
ENDIF.
ENDLOOP.

SELECT ekbe~ebeln ekbe~ebelp ekbe~zekkn ekbe~vgabe ekbe~belnr
ekbe~buzei ekbe~bewtp ekbe~bwart ekbe~menge ekbe~dmbtr
ekbe~shkzg
INTO CORRESPONDING FIELDS OF TABLE it_ekbe
FROM ekbe
FOR ALL ENTRIES IN itab
WHERE ekbe~ebeln = itab-ebeln AND ekbe~ebelp = itab-ebelp AND
ekbe~zekkn = '01' AND ekbe~vgabe = '2' AND ekbe~bewtp = 'Q'.
SORT it_ekbe BY ebeln ebelp.

LOOP AT itab.
* ?????'
SELECT SINGLE wgbez INTO itab-wgbez
FROM t023t WHERE spras = sy-langu AND matkl = itab-matkl.
* ?????'
SELECT SINGLE name1 INTO itab-name1
FROM lfa1 WHERE lifnr = itab-lifnr.
* ?????/????'
SELECT SINGLE sakto kostl INTO (itab-sakto,itab-kostl)
FROM ekkn
WHERE ebeln = itab-ebeln AND ebelp = itab-ebelp AND zekkn = '01'.
* ??'
itab-netps = itab-netpr / itab-peinh.

CLEAR: itab-mengi, itab-dmbti.
LOOP AT it_ekbe WHERE ebeln = itab-ebeln AND ebelp = itab-ebelp.
* ??????/??????'
IF it_ekbe-zekkn = '01'.
IF it_ekbe-shkzg = 'S'.
itab-mengi = itab-mengi + it_ekbe-menge.
itab-dmbti = itab-dmbti + it_ekbe-dmbtr.
ENDIF.
IF it_ekbe-shkzg = 'H'.
itab-mengi = itab-mengi - it_ekbe-menge.
itab-dmbti = itab-dmbti - it_ekbe-dmbtr.
ENDIF.
ENDIF.
ENDLOOP.
REFRESH color.
IF itab-shkzg = 'H'.
itab-mengs = - itab-mengs.
itab-dmbts = - itab-dmbts.
itab-wrbtr = - itab-wrbtr.
* CLEAR:itab-mengi, itab-dmbti.
color-color-col = '6'.
ELSE.
color-color-col = '5'.
ENDIF.
color-fieldname = 'MENGE'. APPEND color.
color-fieldname = 'MEINS'. APPEND color.
color-fieldname = 'NETPS'. APPEND color.
color-fieldname = 'NETWR'. APPEND color.
color-fieldname = 'WAERS'. APPEND color.
color-fieldname = 'WKURS'. APPEND color.
color-fieldname = 'MWSKZ'. APPEND color.
color-fieldname = 'BELNR'. APPEND color.
color-fieldname = 'MENGS'. APPEND color.
color-fieldname = 'DMBTS'. APPEND color.
color-fieldname = 'WRBTR'. APPEND color.
color-fieldname = 'BUDAT'. APPEND color.
color-fieldname = 'MENGI'. APPEND color.
color-fieldname = 'DMBTI'. APPEND color.
itab-color[] = color[].
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
EXPORTING
input = itab-lifnr
IMPORTING
output = itab-lifnr.
MODIFY itab.
ENDLOOP.
ENDFORM. " account_list_01

*&--------------------------------------------------------------------*
*& Form comment_build
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* --&gtLT_TOP_OF_Ptext
*---------------------------------------------------------------------*
FORM comment_build USING lt_top_of_page TYPE
slis_t_listheader.
DATA:g_budat(25) TYPE c,
g_lifnr(25) TYPE c,
ls_line TYPE slis_listheader.

CLEAR ls_line.
ls_line-typ = 'H'.
ls_line-info = text-h01.
APPEND ls_line TO lt_top_of_page.
CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = text-h02.
IF s_budat IS INITIAL.
g_budat = sy-datum.
CONCATENATE sy-datum+6(2) '.' sy-datum+4(2) '.' sy-datum+0(4)
INTO g_budat.
ELSE.
CONCATENATE s_budat-low+6(2) '.' s_budat-low+4(2) '.'
s_budat-low+0(4) ' To ' INTO g_budat.
CONCATENATE g_budat s_budat-high+6(2) '.' s_budat-high+4(2)
'.' s_budat-high+0(4) INTO g_budat.
ENDIF.
WRITE g_budat TO ls_line-info.
APPEND ls_line TO lt_top_of_page.
ls_line-key = text-h03.
ls_line-info = sy-uname.
APPEND ls_line TO lt_top_of_page.
ENDFORM. " COMMENT_BUILD

*&---------------------------------------------------------------------*
*& Form alv_field_cat_01
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --&gt p1 text
* *----------------------------------------------------------------------*
FORM alv_field_cat_01 .
DATA:wa_fieldcat TYPE slis_fieldcat_alv.

REFRESH it_fieldcat.
PERFORM field_cat USING 'LIFNR' 'Verdor' '08' '' '' ''.
PERFORM field_cat USING 'NAME1' 'Vendor N' '08' '' '' ''.
PERFORM field_cat USING 'EBELN' 'Po.' '08' '' '' ''.
PERFORM field_cat USING 'EBELP' 'Po.Item' '06' '' '' ''.
PERFORM field_cat USING 'MATKL' 'M.Group' '10' '' '' ''.
PERFORM field_cat USING 'WGBEZ' 'M.Group.D' '20' '' '' ''.
PERFORM field_cat USING 'TXZ01' 'Text' '20' '' '' ''.
PERFORM field_cat USING 'MENGE' 'Qty' '10' 'MEINS' '' ''.
PERFORM field_cat USING 'MEINS' 'Unit' '08' '' '' ''.
PERFORM field_cat USING 'NETPS' 'Price' '08' '' '' ''.
PERFORM field_cat USING 'NETWR' 'PO.Am' '08' 'MEINS' '' ''.
PERFORM field_cat USING 'WAERS' 'Curr' '04' '' '' ''.
PERFORM field_cat USING 'WKURS' 'Rate' '04' '' '' ''.
PERFORM field_cat USING 'MWSKZ' 'Tax' '04' '' '' ''.
PERFORM field_cat USING 'BELNR' 'Gr.No' '08' '' '' ''.
PERFORM field_cat USING 'MENGS' 'Gr.Qty' '10' 'MEINS' 'X' ''.
PERFORM field_cat USING 'DMBTS' 'Gr.Am(L)' '14' 'MEINS' 'X' ''.
PERFORM field_cat USING 'WRBTR' 'Gr.Am(F)' '14' 'MEINS' 'X' ''.
PERFORM field_cat USING 'MENGI' 'Ir.Qty' '10' 'MEINS' '' ''.
PERFORM field_cat USING 'DMBTI' 'Ir.Am' '10' 'MEINS' '' ''.
PERFORM field_cat USING 'SAKTO' 'G/L Ac' '10' '' '' ''.
PERFORM field_cat USING 'KOSTL' 'Cost.C' '08' '' '' ''.
ENDFORM. " alv_field_cat_01


*&--------------------------------------------------------------------*
*& Form alv_show_01
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM alv_show_01 .

* wa_layout-zebra = 'X'.
CLEAR : sortcat, sortcat_ln.
sortcat_ln-spos = '1'.
sortcat_ln-fieldname = 'LIFNR'.
sortcat_ln-fieldname = 'EBELN'.
sortcat_ln-up = 'X'.
sortcat_ln-down = space.
sortcat_ln-subtot = 'X'.
APPEND sortcat_ln TO sortcat.

wa_layout-coltab_fieldname = 'COLOR'.
* wa_layout-totals_text = 'Test'.
* wa_layout-subtotals_text = 'Test'.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = wk_repid
it_fieldcat = it_fieldcat
is_layout = wa_layout
i_callback_top_of_page = g_top_of_page
i_callback_user_command = g_command_form
i_default = 'X'
i_save = 'X'
it_events = it_event
it_sort = sortcat
TABLES
t_outtab = itab[]
EXCEPTIONS
program_error = 1
OTHERS = 2.

ENDFORM. " alv_show_01

*&--------------------------------------------------------------------*
*& Form field_cat
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* --&gtP_FIELD text
* --&gtP_TEXT text
* --&gtP_LEN text
* --&gtP_MEINS text
* --&gtP_SUM text
* --&gtP_FIX text
*---------------------------------------------------------------------*
FORM field_cat USING p_field
p_text
p_len
p_meins
p_sum
p_fix.

DATA:wa_fieldcat TYPE slis_fieldcat_alv.

wa_layout-colwidth_optimize = 'X'.

CLEAR wa_fieldcat.
wa_fieldcat-fieldname = p_field.
wa_fieldcat-tabname = 'ITAB'.
wa_fieldcat-seltext_l = p_text.
wa_fieldcat-outputlen = p_len.
wa_fieldcat-qfieldname = p_meins.
wa_fieldcat-do_sum = p_sum.
wa_fieldcat-fix_column = p_fix.
APPEND wa_fieldcat TO it_fieldcat.

ENDFORM. "field_cat

*&--------------------------------------------------------------------*
*& Form top_of_page
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = gt_list_top_of_page.
ENDFORM. " TOP_OF_PAGE

*&--------------------------------------------------------------------*
*& Form user_command
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* --&gtR_UCOMM text
* --&gtRS_SELFIELDtext
*---------------------------------------------------------------------*
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'. "doubleclick
READ TABLE itab INDEX rs_selfield-tabindex.
IF sy-subrc = 0.
CASE rs_selfield-fieldname.
WHEN 'BELNR'.
IF itab-belnr IS INITIAL.
EXIT.
ENDIF.
SET PARAMETER ID 'MBN' FIELD itab-belnr.
SET PARAMETER ID 'MJA' FIELD ''.
CALL TRANSACTION 'MB03' AND SKIP FIRST SCREEN.
WHEN 'EBELN'.
IF itab-ebeln IS INITIAL.
EXIT.
ENDIF.
SET PARAMETER ID 'BES' FIELD itab-ebeln.
CALL TRANSACTION 'ME23N' AND SKIP FIRST SCREEN.
ENDCASE.
ENDIF.
ENDCASE.
CLEAR r_ucomm.
ENDFORM. "user_command

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7941665/viewspace-975471/,如需轉載,請註明出處,否則將追究法律責任。

相關文章