ALV控制,ABAP编程使ALV支持OO方法

ALV控制,ABAP编程使ALV支持OO方法
源代码如下: [@more@]

ALV控制,ABAP编程使ALV支持OO方法
源代码如下:

REPORT ZPO_PHOTO_CONFIRM.
*---------------------------------------------------------------------
* Program Nname : ZPO_PHOTO_CONFIRM
* Application Name : MM
* Subsystem : 46C
* Author : hans
* Transaction : zdevlop
* Program Type : Report
* Program ID : ZPO_PHOTO_CONFIRM
* Program Description :

*---------------------------------------------------------------------
* REVISION LOG
* LOG# DATE AUTHOR DESCRIPTION
* 0001 2006/12/15 hans New create
*----------------------------------------------------------------------
* tables
*----------------------------------------------------------------------
tables: ekko,
ekpo,
eket,
zpoconfirm,
makt,
t001w,
t006a,
lfa1.
TYPE-POOLS: SLIS,VRM.
INCLUDE .
*for droplist
DATA: NAME TYPE VRM_ID,
LIST TYPE VRM_VALUES,
VALUE LIKE LINE OF LIST.
class lcl_event_receiver definition deferred. "for event handling
data: ok_code like sy-ucomm,
save_ok like sy-ucomm,
g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
g_grid type ref to cl_gui_alv_grid,
g_custom_container type ref to cl_gui_custom_container,
g_event_receiver type ref to lcl_event_receiver,
gt_fieldcat type lvc_t_fcat,
gs_layout type lvc_s_layo.
types: begin of gs_outtab.
types: checkbox type c. "field for checkbox
types: celltab type lvc_t_styl. "field to switch editability
include structure ZPOSTR.
types: end of gs_outtab.
data: gt_outtab type gs_outtab occurs 0 with header line.
data: outtab_backup type gs_outtab occurs 0 with header line.
data: begin of zrow occurs 0,
rownum like sy-tabix,
end of zrow.
***********************************************************************
* LOCAL CLASSES
***********************************************************************
*
* This local class only handles event DOUBLE_CLICK.
class lcl_event_receiver definition.
public section.
methods: catch_doubleclick
for event double_click of cl_gui_alv_grid
importing
e_column
es_row_no
sender.
endclass.
*-----
class lcl_event_receiver implementation.
method catch_doubleclick.
data: ls_outtab type gs_outtab,
ls_celltab type lvc_s_styl.
*--
* Function:
* Switch between 'editable' and 'not editable' checkbox.

if e_column-fieldname ne 'CHECKBOX'.
exit.
endif.
read table gt_outtab into ls_outtab index es_row_no-row_id.

loop at ls_outtab-celltab into ls_celltab.
if ls_celltab-fieldname eq 'CHECKBOX'.
* ?4.Switch the style to dis- or enable a cell for input
if ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
else.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
endif.
modify ls_outtab-celltab from ls_celltab.
endif.
endloop.
modify gt_outtab from ls_outtab index es_row_no-row_id.
call method sender->refresh_table_display.
endmethod.
endclass.
*-------------------------------------------------------------------
* SELECT-OPTIONS AND PARAMETERS
*-------------------------------------------------------------------
* Main options block
SELECTION-SCREEN: BEGIN OF BLOCK FRAME01
WITH FRAME TITLE Text-001.
select-options:
s_ebeln for ekko-ebeln,
s_ebelp for ekpo-ebelp,
s_lifnr for ekko-lifnr,
s_matnr for ekpo-matnr,
s_eindt for eket-eindt,
s_bedat for eket-bedat,
s_werks for ekpo-werks.
parameters: aaflag(10) type c as listbox visible length 10.
SELECTION-SCREEN: END OF BLOCK FRAME01.
*SELECTION-SCREEN: BEGIN OF BLOCK FRAME03
* WITH FRAME TITLE TEXT-004.
*SELECTION-SCREEN COMMENT /5(79) TEXT-005.
*SELECTION-SCREEN: END OF BLOCK FRAME03.
*-----------------------------------------
* initialization
*-----------------------------------------
initialization.
perform initialization.
*------------------------------------------
* start-of-selection
*------------------------------------------
start-of-selection.
call function 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
TEXT = text-008
EXCEPTIONS
OTHERS = 1.
perform check_condition.
end-of-selection.
call screen 0100.
* perform FRM_LISTADO.
**&---------------------------------------------------------------------
**& Form INITIALIZATION
**&---------------------------------------------------------------------
form initialization.
REFRESH LIST.
VALUE-KEY = 'Y'.
VALUE-TEXT = text-005.
APPEND VALUE TO LIST.
VALUE-KEY = 'N'.
VALUE-TEXT = text-006.
APPEND VALUE TO LIST.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
ID = 'aaflag'
VALUES = LIST.
endform. " INITIALIZATION
**&---------------------------------------------------------------------
**
**& Form check_condition.
**&---------------------------------------------------------------------
form check_condition.
select single count( * ) from ekko
where ebeln in s_ebeln.
if sy-subrc NE 0.
message W018(zwwerrors) with text-001.
endif.
select single count( * ) from lfa1
where lifnr in s_lifnr.
if sy-subrc NE 0.
message W018(zwwerrors) with text-002.
endif.
select single count( * ) from makt
where spras = sy-langu and matnr in s_matnr.
if sy-subrc NE 0.
message W018(zwwerrors) with text-004.
endif.
select single count( * ) from t001w
where werks in s_werks.
if sy-subrc NE 0.
message W018(zwwerrors) with text-003.
endif.
endform. "check_condition
*---------------------------------------------------------------------*
* MODULE PBO OUTPUT *
*---------------------------------------------------------------------*
module pbo output.
set pf-status 'MAIN100'.
set titlebar 'MAIN100'.
if g_custom_container is initial.
perform create_and_init_alv.
endif.
endmodule.
*---------------------------------------------------------------------*
* MODULE PAI INPUT *
*---------------------------------------------------------------------*
module pai input.
save_ok = ok_code.
clear ok_code.
case save_ok.
when 'EXIT'.
perform exit_program.
when 'SELECT'.
perform select_all_entries changing gt_outtab[].
when 'DESELECT'.
perform deselect_all_entries changing gt_outtab[].
when 'RESET'.
perform reset_selected_entries changing gt_outtab[].
when 'SWITCH'.
perform switch_activation changing gt_outtab[].
endcase.
endmodule.
*---------------------------------------------------------------------*
* FORM EXIT_PROGRAM *
*---------------------------------------------------------------------*
form exit_program.
leave program.
endform.
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* *----------------------------------------------------------------------*
form build_fieldcat changing pt_fieldcat type lvc_t_fcat.
data ls_fcat type lvc_s_fcat.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = 'ZPOSTR'
changing
ct_fieldcat = pt_fieldcat.

*?2.Add an entry for the checkbox in the fieldcatalog
clear ls_fcat.
ls_fcat-fieldname = 'CHECKBOX'.
* Essential: declare field as checkbox and
* mark it as editable field:
ls_fcat-checkbox = 'X'.
ls_fcat-edit = 'X'.
* do not forget to provide texts for this extra field
ls_fcat-coltext = text-f01.
ls_fcat-tooltip = text-f02.
ls_fcat-seltext = text-f03.
* optional: set column width
ls_fcat-outputlen = 10.
append ls_fcat to pt_fieldcat.
endform.
*&---------------------------------------------------------------------*
*& Form CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* * * *----------------------------------------------------------------------*
form create_and_init_alv.
data: lt_exclude type ui_functions.
data: g_exclude type ui_func.
create object g_custom_container
exporting container_name = g_container.
create object g_grid
exporting i_parent = g_custom_container.
perform build_fieldcat changing gt_fieldcat.
perform build_data.
*Use the layout structure to aquaint additional field to ALV.
gs_layout-stylefname = 'CELLTAB'.
** 修改
g_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
append g_exclude to lt_exclude.
g_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
append g_exclude to lt_exclude.
g_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
append g_exclude to lt_exclude.
g_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
append g_exclude to lt_exclude.
*** 修改
call method g_grid->set_table_for_first_display
exporting is_layout = gs_layout
it_toolbar_excluding = lt_exclude
changing it_fieldcatalog = gt_fieldcat
it_outtab = gt_outtab[].
create object g_event_receiver.
set handler g_event_receiver->catch_doubleclick for g_grid.
* Set editable cells to ready for input initially
call method g_grid->set_ready_for_input
exporting
i_ready_for_input = 1.
endform. "CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*& Form build_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --&gt p1 text
* *----------------------------------------------------------------------*
form build_data.
data: lt_zpostr type table of ZPOSTR,
ls_zpostr type ZPOSTR,
ls_celltab type lvc_s_styl,
lt_celltab type lvc_t_styl,
l_index type i.
data:begin of tekpo occurs 0,
ebeln like ekpo-ebeln,
ebelp like ekpo-ebelp,
ekorg like ekko-ekorg,
ekgrp like ekko-ekgrp,
werks like ekpo-werks,
loekz like ekpo-loekz,
bsart like ekko-bsart,
lifnr like ekko-lifnr,
matnr like ekpo-matnr,
txz01 like ekpo-txz01,
menge like ekpo-menge,
meins like ekpo-meins,
netpr like ekpo-netpr,
mwskz like ekpo-mwskz,
matkl like ekpo-matkl,
eindt like eket-eindt,
bedat like eket-bedat,
wemng like eket-wemng,
end of tekpo.
data:tekpo2 like tekpo occurs 0 with header line.
data:begin of ttitem occurs 0,
EBELN like ekpo-ebeln,
EBELP like ekpo-ebelp,
EKORG like ekko-ekorg,
EKGRP like ekko-ekgrp,
WERKS like ekpo-werks,
LOEKZ like ekpo-loekz,
BSART like ekko-bsart,
LIFNR like ekko-lifnr,
NAME1 like lfa1-name1,
MATNR like ekpo-matnr,
TXZ01 like ekpo-txz01,
MENGE like ekpo-menge,
msehl like t006a-msehl,
NETPR like ekpo-netpr,
MWSKZ like ekpo-mwskz,
EINDT like eket-eindt,
BEDAT like eket-bedat,
WEMNG like eket-wemng,
MATKL like ekpo-matkl,
ZCONFIRM like ZPOCONFIRM-zconfirm,
end of ttitem.
data:qr like ZPOCONFIRM-zconfirm.
select ekpo~ebeln ekpo~ebelp ekko~ekorg ekko~ekgrp ekpo~werks
ekpo~loekz ekko~bsart ekko~lifnr ekpo~matnr ekpo~txz01
ekpo~menge ekpo~meins ekpo~netpr ekpo~mwskz ekpo~matkl
eket~eindt eket~bedat eket~wemng
into corresponding fields of table tekpo
from ( ekpo inner join ekko
on ekpo~ebeln = ekko~ebeln
left outer join eket
on eket~ebeln = ekpo~ebeln
and eket~ebelp = ekpo~ebelp )
where ekpo~ebeln in s_ebeln
and ekpo~ebelp in s_ebelp
and ekko~lifnr in s_lifnr
and ekpo~matnr in s_matnr
and ekpo~werks in s_werks.
loop at tekpo.
check tekpo-eindt in s_eindt.
check tekpo-bedat in s_bedat.
move-corresponding tekpo to tekpo2.
append tekpo2.
endloop.
if aaflag is initial.
loop at tekpo2.
ttitem-ebeln = tekpo2-ebeln.
ttitem-ebelp = tekpo2-ebelp.
ttitem-ekorg = tekpo2-ekorg.
ttitem-ekgrp = tekpo2-ekgrp.
ttitem-werks = tekpo2-werks.
ttitem-loekz = tekpo2-loekz.
ttitem-bsart = tekpo2-bsart.
ttitem-lifnr = tekpo2-lifnr.
select single name1 into ttitem-name1 from lfa1
where lifnr = tekpo2-lifnr.
ttitem-matnr = tekpo2-matnr.
ttitem-txz01 = tekpo2-txz01.
ttitem-menge = tekpo2-menge.
select single msehl into ttitem-msehl from t006a
where spras = sy-langu and msehi = tekpo2-meins.
ttitem-netpr = tekpo2-netpr.
ttitem-mwskz = tekpo2-mwskz.
ttitem-eindt = tekpo2-eindt.
ttitem-bedat = tekpo2-bedat.
ttitem-wemng = tekpo2-wemng.
ttitem-matkl = tekpo2-matkl.
select single ZCONFIRM into ttitem-zconfirm from ZPOCONFIRM
where ebeln = tekpo2-ebeln and ebelp = tekpo2-ebelp.
append ttitem.
clear ttitem-zconfirm.
endloop.
elseif aaflag EQ 'Y'.
loop at tekpo2.
ttitem-ebeln = tekpo2-ebeln.
ttitem-ebelp = tekpo2-ebelp.
ttitem-ekorg = tekpo2-ekorg.
ttitem-ekgrp = tekpo2-ekgrp.
ttitem-werks = tekpo2-werks.
ttitem-loekz = tekpo2-loekz.
ttitem-bsart = tekpo2-bsart.
ttitem-lifnr = tekpo2-lifnr.
select single name1 into ttitem-name1 from lfa1
where lifnr = tekpo2-lifnr.
ttitem-matnr = tekpo2-matnr.
ttitem-txz01 = tekpo2-txz01.
ttitem-menge = tekpo2-menge.
select single msehl into ttitem-msehl from t006a
where spras = sy-langu and msehi = tekpo2-meins.
ttitem-netpr = tekpo2-netpr.
ttitem-mwskz = tekpo2-mwskz.
ttitem-eindt = tekpo2-eindt.
ttitem-bedat = tekpo2-bedat.
ttitem-wemng = tekpo2-wemng.
ttitem-matkl = tekpo2-matkl.
select single ZCONFIRM into ttitem-zconfirm from ZPOCONFIRM
where ebeln = tekpo2-ebeln and ebelp = tekpo2-ebelp.
check ttitem-zconfirm = 'Y'.
append ttitem.
clear ttitem-zconfirm.
endloop.
elseif aaflag EQ 'N'.
loop at tekpo2.
ttitem-ebeln = tekpo2-ebeln.
ttitem-ebelp = tekpo2-ebelp.
ttitem-ekorg = tekpo2-ekorg.
ttitem-ekgrp = tekpo2-ekgrp.
ttitem-werks = tekpo2-werks.
ttitem-loekz = tekpo2-loekz.
ttitem-bsart = tekpo2-bsart.
ttitem-lifnr = tekpo2-lifnr.
select single name1 into ttitem-name1 from lfa1
where lifnr = tekpo2-lifnr.
ttitem-matnr = tekpo2-matnr.
ttitem-txz01 = tekpo2-txz01.
ttitem-menge = tekpo2-menge.
select single msehl into ttitem-msehl from t006a
where spras = sy-langu and msehi = tekpo2-meins.
ttitem-netpr = tekpo2-netpr.
ttitem-mwskz = tekpo2-mwskz.
ttitem-eindt = tekpo2-eindt.
ttitem-bedat = tekpo2-bedat.
ttitem-wemng = tekpo2-wemng.
ttitem-matkl = tekpo2-matkl.

append ttitem.
clear ttitem-zconfirm.
endloop.
endif.
loop at ttitem.
gt_outtab-ebeln = ttitem-ebeln.
gt_outtab-ebelp = ttitem-ebelp.
gt_outtab-ekorg = ttitem-ekorg.
gt_outtab-ekgrp = ttitem-ekgrp.
gt_outtab-werks = ttitem-werks.
gt_outtab-loekz = ttitem-loekz.
gt_outtab-bsart = ttitem-bsart.
gt_outtab-lifnr = ttitem-lifnr.
gt_outtab-name1 = ttitem-name1.
gt_outtab-matnr = ttitem-matnr.
gt_outtab-txz01 = ttitem-txz01.
gt_outtab-menge = ttitem-menge.
gt_outtab-msehl = ttitem-msehl.
gt_outtab-netpr = ttitem-netpr.
gt_outtab-mwskz = ttitem-mwskz.
gt_outtab-eindt = ttitem-eindt.
gt_outtab-bedat = ttitem-bedat.
gt_outtab-wemng = ttitem-wemng.
gt_outtab-matkl = ttitem-matkl.
if ttitem-zconfirm eq 'Y'.
gt_outtab-checkbox = 'X'.
endif.
append gt_outtab.
clear gt_outtab-checkbox.
endloop.
ls_celltab-fieldname = 'CHECKBOX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.

loop at gt_outtab.
l_index = sy-tabix.
refresh lt_celltab.

ls_celltab-fieldname = 'CHECKBOX'.
if gt_outtab-checkbox = 'X'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
else.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
endif.
insert ls_celltab into table lt_celltab.
insert lines of lt_celltab into table gt_outtab-celltab.
modify gt_outtab index l_index.
endloop.
outtab_backup[] = gt_outtab[].
endform. " build_data
*&---------------------------------------------------------------------*
*& Form select_all_entries
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* *----------------------------------------------------------------------*
form select_all_entries changing pt_outtab type standard table.
data: ls_outtab type gs_outtab.
data: l_valid type c,
l_locked type c.

call method g_grid->check_changed_data
importing
e_valid = l_valid.

if l_valid eq 'X'.

loop at pt_outtab into ls_outtab.
perform check_lock using ls_outtab
changing l_locked.
if l_locked is initial
and not ls_outtab-checkbox eq '-'.
ls_outtab-checkbox = 'X'.
endif.
modify pt_outtab from ls_outtab.
endloop.

call method g_grid->refresh_table_display.

endif.

endform. " select_all_entries
*&---------------------------------------------------------------------*
*& Form deselect_all_entries
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* *----------------------------------------------------------------------*
form deselect_all_entries changing pt_outtab type standard table.
data: ls_outtab type gs_outtab.
data: l_valid type c,
l_locked type c.
call method g_grid->check_changed_data
importing
e_valid = l_valid.
if l_valid eq 'X'.
loop at pt_outtab into ls_outtab.
perform check_lock using ls_outtab
changing l_locked.
if l_locked is initial
and not ls_outtab-checkbox eq '-'.
ls_outtab-checkbox = ' '.
endif.

modify pt_outtab from ls_outtab.
endloop.
call method g_grid->refresh_table_display.
endif.
endform. " deselect_all_entries
*&---------------------------------------------------------------------*
*& Form reset_selected_entries
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* *----------------------------------------------------------------------*
form reset_selected_entries changing pt_outtab type standard table.


data: ls_outtab type gs_outtab.
data: l_valid type c,
lt_row_no type lvc_t_roid with header line.
data: ls_celltab type lvc_s_styl,
lt_celltab type lvc_t_styl.
data: wa type zpoconfirm.
call method g_grid->check_changed_data
importing
e_valid = l_valid.
if l_valid eq 'X'.
call method g_grid->get_selected_rows
importing
et_row_no = lt_row_no[].
ls_celltab-fieldname = 'CHECKBOX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
loop at lt_row_no.
refresh lt_celltab.
read table pt_outtab into ls_outtab index lt_row_no-row_id.
loop at ls_outtab-celltab into ls_celltab.
if ls_celltab-fieldname eq 'CHECKBOX'.
if ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
else.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
endif.
modify ls_outtab-celltab from ls_celltab.
endif.
endloop.
insert ls_celltab into table lt_celltab.
* insert lines of lt_celltab into table ls_outtab-celltab.
ls_outtab-CELLTAB = lt_celltab.
modify pt_outtab from ls_outtab index lt_row_no-row_id.
endloop.
call method g_grid->refresh_table_display.
endif.
endform. " reset_selected_entries
*-----------------------------
form switch_activation changing pt_outtab type standard table.
data: ls_outtab type gs_outtab.
data: l_valid type c,
lt_row_no type lvc_t_roid with header line.
data: ls_celltab type lvc_s_styl,
lt_celltab type lvc_t_styl.
data: wa type zpoconfirm.


call method g_grid->check_changed_data
importing
e_valid = l_valid.

if l_valid eq 'X'.
call method g_grid->get_selected_rows
importing
et_row_no = lt_row_no[].
ls_celltab-fieldname = 'CHECKBOX'.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
loop at lt_row_no.
refresh lt_celltab.
read table pt_outtab into ls_outtab index lt_row_no-row_id.

select single * from zpoconfirm
where ebeln = ls_outtab-ebeln and ebelp = ls_outtab-ebelp.
if sy-subrc = 0.
if ls_outtab-checkbox is initial.
delete from zpoconfirm where
ebeln = ls_outtab-ebeln and ebelp = ls_outtab-ebelp.
endif.
ls_celltab-style = cl_gui_alv_grid=>mc_style_enabled.
else.
wa-ebeln = ls_outtab-ebeln.
wa-ebelp = ls_outtab-ebelp.
wa-zconfirm = 'Y'.
wa-pdata = sy-datum.
wa-bname = sy-uname.
insert into zpoconfirm values wa.
ls_celltab-style = cl_gui_alv_grid=>mc_style_disabled.
endif.
insert ls_celltab into table lt_celltab.
* insert lines of lt_celltab into table ls_outtab-celltab.
ls_outtab-CELLTAB = lt_celltab.
modify pt_outtab from ls_outtab index lt_row_no-row_id.
endloop.
call method g_grid->refresh_table_display.
endif.
endform. " switch_activation

*&---------------------------------------------------------------------*
*& Form check_lock
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --&gtP_LS_OUTTAB text
* *----------------------------------------------------------------------*
form check_lock using ps_outtab type gs_outtab
changing p_locked.
data ls_celltab type lvc_s_styl.

loop at ps_outtab-celltab into ls_celltab.
if ls_celltab-fieldname = 'CHECKBOX'.
if ls_celltab-style eq cl_gui_alv_grid=>mc_style_disabled.
p_locked = 'X'.
else.
p_locked = space.
endif.
endif.
endloop.

endform. " check_lock

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/581999/viewspace-899561/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/581999/viewspace-899561/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值