REPORT ZTEST_ALV2.
*定义所需要的报表
tables : EINE,LFA1,EKPO,eina.
*for alv
type-pools: slis.
data:
i_fieldcat_alv type slis_t_fieldcat_alv, "定义列标题(属性/信息)
i_layout type slis_layout_alv, "alv格式
i_fieldcat type slis_fieldcat_alv, "
i_events type slis_t_event, "alv事件
w_events like line of i_events,
i_list_comments type slis_t_listheader, "alv表单标题区域设置
w_list_comments like line of i_list_comments,
w_repid like sy-repid. "当前程序
*定义内表字段
*1.选择屏幕
data:
begin of hd_itab occurs 0,
infnr like eine-infnr, "采购信息记录
ekorg like eine-ekorg, "采购组织
matnr like eina-matnr, "物料号码
lifnr like eina-lifnr, "供应商
erdat like eine-erdat, "记录建立时间
loekz like eine-loekz, "删除标记
urznr like eina-urznr, "批准号
color(4) type c, "颜色
*2.显示屏幕
aplfz like eine-aplfz, "计划交货时间
netpr like eine-netpr, "净价
peinh like eine-peinh, "价格单位
dwjj like eine-netpr, "单位净价
bprme like eine-bprme, "计量单位
MAKTX like MAKT-MAKTX, "物料名称
name1 like lfa1-name1, "供应商名称
end of hd_itab.
*定义选择屏幕
selection-screen begin of block b1 with frame title t1.
select-options:s_infnr for eine-infnr memory id INF. "信息记录号码
PARAMETERS: PR_LOEKZ TYPE C AS CHECKBOX DEFAULT ' '. "显示有删除标记的信息记录
select-options:s_ekorg for eine-ekorg memory id EKO. "采购组织
select-options:s_matnr for eina-matnr memory id MAT. "物料号码
select-options:s_lifnr for eina-lifnr memory id LIF. "供应商号码
select-options:s_erdat for eine-erdat memory id s_erdat. "创建日期
select-options:s_urznr for eina-urznr memory id s_urznr. "批准号
selection-screen end of block b1.
*程序初始化
initialization.
t1 = '采购查询'.
*数据选择
start-of-selection.
perform getdata. "读取数据
perform events_build. "alv事件
perform layout_build. "定义alv格式属性
perform fields_build. "定义列标题信息
perform display_data. "显示数据
end-of-selection.
data:
pagenum type i value 1. "报表页码
end-of-page.
pagenum = pagenum + 1.
*行项目双击事件
at line-selection.
*&--------------------------------------------------------------------*
*& Form getdata
*&--------------------------------------------------------------------*
* 获取数据 从数据库表中选择相应字段
*---------------------------------------------------------------------*
form getdata.
clear hd_itab.
clear hd_itab[].
*hd_itab表
if PR_LOEKZ = ' '.
select * from eine
inner join eina on eine~infnr = eina~infnr
into corresponding fields of hd_itab
where eine~infnr in s_infnr
and eine~ekorg in s_ekorg
and eina~matnr in s_matnr
and eina~lifnr in s_lifnr
and eina~loekz <> 'X'
and eine~erdat in s_erdat
and eina~urznr in s_urznr
order by eine~infnr descending.
select single MAKTX from MAKT
into corresponding fields of hd_itab
where matnr = hd_itab-matnr.
select single name1 from lfa1
into corresponding fields of hd_itab
where lifnr = hd_itab-lifnr.
append hd_itab.
clear hd_itab.
endselect.
else.
select * from eine
inner join eina on eine~infnr = eina~infnr
into corresponding fields of hd_itab
where eine~infnr in s_infnr
and eine~ekorg in s_ekorg
and eina~matnr in s_matnr
and eina~lifnr in s_lifnr
and eine~erdat in s_erdat
and eina~urznr in s_urznr
order by eine~infnr descending.
select single MAKTX from MAKT
into corresponding fields of hd_itab
where matnr = hd_itab-matnr.
select single name1 from lfa1
into corresponding fields of hd_itab
where lifnr = hd_itab-lifnr.
append hd_itab.
clear hd_itab.
endselect.
endif.
loop at hd_itab.
if hd_itab-loekz = 'X'.
hd_itab-color = 'C610'. "如果此采购信息记录被删除,则显示红色
endif.
hd_itab-dwjj = hd_itab-netpr / hd_itab-peinh.
modify hd_itab.
clear hd_itab.
endloop.
endform. "getdata
*
*&--------------------------------------------------------------------*
*& Form layout_build
*&--------------------------------------------------------------------*
* 定义ALV格式属性
*---------------------------------------------------------------------*
form layout_build .
i_layout-zebra = 'X'.
* i_layout-detail_popup = 'X'.
i_layout-no_vline = ' '.
* i_layout-colwidth_optimize = 'X'.
* i_layout-detail_initial_lines = 'X'.
* i_layout-detail_titlebar = '详细内容'.
* i_layout-box_fieldname = 'LINE'.
* i_layout-f2code = '&ETA'.
* i_layout-f2code = '&IC1'.
i_layout-info_fieldname = 'COLOR'. "颜色值
i_layout-no_colhead = ' '.
w_repid = sy-repid.
endform. " layout_build
*&--------------------------------------------------------------------*
*& Form fields_build
*&--------------------------------------------------------------------*
* 设置报表显示列属性信息
*---------------------------------------------------------------------*
form fields_build .
refresh i_fieldcat_alv.
clear i_fieldcat.
data colnum type i value 1.
i_fieldcat-col_pos = colnum.
* "i_fieldcat-tabname = 'hd_itab'.
* i_fieldcat-ref_tabname = 'zorder_purchase'.
* i_fieldcat-outputlen ='14'.
i_fieldcat-fieldname = 'INFNR'.
i_fieldcat-seltext_s = '采购信息记录号'.
i_fieldcat-seltext_m = '采购信息记录号'.
i_fieldcat-seltext_l = '采购信息记录号'.
i_fieldcat-reptext_ddic = '采购信息记录号'.
i_fieldcat-lzero = 'X'.
i_fieldcat-key = 'X'.
i_fieldcat-hotspot = 'X'.
* i_fieldcat-emphasize = 'X'.
* i_fieldcat-tech = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
*i_fieldcat-ref_tabname = 'zorder_purchase'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'LIFNR'.
i_fieldcat-seltext_s = '供应商号码'.
i_fieldcat-seltext_m = '供应商号码'.
i_fieldcat-seltext_l = '供应商号码'.
i_fieldcat-reptext_ddic = '供应商号码'.
i_fieldcat-lzero = 'X'.
i_fieldcat-key = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
*i_fieldcat-ref_tabname = 'zorder_purchase'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'NAME1'.
i_fieldcat-seltext_s = '供应商名称'.
i_fieldcat-seltext_m = '供应商名称'.
i_fieldcat-seltext_l = '供应商名称'.
i_fieldcat-reptext_ddic = '供应商名称'.
i_fieldcat-lzero = 'X'.
i_fieldcat-key = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'MATNR'.
* i_fieldcat-ref_tabname = 'zorder_purchase'.
i_fieldcat-seltext_s = '物料代码'.
i_fieldcat-seltext_m = '物料代码'.
i_fieldcat-seltext_l = '物料代码'.
i_fieldcat-reptext_ddic = '物料代码'.
i_fieldcat-lzero = 'X'.
* i_fieldcat-key = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
* "i_fieldcat-tabname = 'hd_itab'.
*i_fieldcat-ref_tabname = 'zorder_purchase'.
i_fieldcat-col_pos = colnum.
i_fieldcat-outputlen ='30'.
i_fieldcat-fieldname = 'MAKTX'.
i_fieldcat-seltext_s = '物料名称'.
i_fieldcat-seltext_m = '物料名称'.
i_fieldcat-seltext_l = '物料名称'.
i_fieldcat-reptext_ddic = '物料名称'.
i_fieldcat-lzero = 'X'.
* i_fieldcat-key = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
* i_fieldcat-outputlen ='30'.
i_fieldcat-fieldname = 'NETPR'.
i_fieldcat-seltext_s = '净价'.
i_fieldcat-seltext_m = '净价'.
i_fieldcat-seltext_l = '净价'.
i_fieldcat-reptext_ddic = '净价'.
* i_fieldcat-no_sum = 'X'.
* i_fieldcat-icon = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'PEINH'.
i_fieldcat-seltext_s = '价格单位'.
i_fieldcat-seltext_m = '价格单位'.
i_fieldcat-seltext_l = '价格单位'.
i_fieldcat-reptext_ddic = '价格单位'.
* i_fieldcat-no_sum = 'X'.
* i_fieldcat-icon = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'DWJJ'.
i_fieldcat-seltext_s = '单位净价'.
i_fieldcat-seltext_m = '单位净价'.
i_fieldcat-seltext_l = '单位净价'.
i_fieldcat-reptext_ddic = '单位净价'.
* i_fieldcat-no_sum = 'X'.
* i_fieldcat-icon = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'BPRME'.
i_fieldcat-seltext_s = '计量单位'.
i_fieldcat-seltext_m = '计量单位'.
i_fieldcat-seltext_l = '计量单位'.
i_fieldcat-reptext_ddic = '计量单位'.
* i_fieldcat-no_sum = 'X'.
* i_fieldcat-icon = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'EKORG'.
i_fieldcat-seltext_s = '采购组织'.
i_fieldcat-seltext_m = '采购组织'.
i_fieldcat-seltext_l = '采购组织'.
i_fieldcat-reptext_ddic = '采购组织'.
i_fieldcat-Emphasize = 'X'.
* i_fieldcat-do_sum = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'APLFZ'.
i_fieldcat-seltext_s = '计划交货时间'.
i_fieldcat-seltext_m = '计划交货时间'.
i_fieldcat-seltext_l = '计划交货时间'.
i_fieldcat-reptext_ddic = '计划交货时间'.
* i_fieldcat-do_sum = 'X'.
i_fieldcat-Emphasize = 'C211'.
* i_fieldcat-do_sum = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'ERDAT'.
i_fieldcat-seltext_s = '信息记录创建日期'.
i_fieldcat-seltext_m = '信息记录创建日期'.
i_fieldcat-seltext_l = '信息记录创建日期'.
i_fieldcat-reptext_ddic = '信息记录创建日期'.
* i_fieldcat-do_sum = 'X'.
i_fieldcat-Emphasize = 'C211'.
* i_fieldcat-do_sum = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'LOEKZ'.
i_fieldcat-seltext_s = '删除标记'.
i_fieldcat-seltext_m = '删除标记'.
i_fieldcat-seltext_l = '删除标记'.
i_fieldcat-reptext_ddic = '删除标记'.
* i_fieldcat-do_sum = 'X'.
i_fieldcat-Emphasize = 'C211'.
* i_fieldcat-do_sum = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
colnum = colnum + 1.
"i_fieldcat-tabname = 'hd_itab'.
i_fieldcat-col_pos = colnum.
i_fieldcat-fieldname = 'URZNR'.
i_fieldcat-seltext_s = '批准标记'.
i_fieldcat-seltext_m = '批准标记'.
i_fieldcat-seltext_l = '批准标记'.
i_fieldcat-reptext_ddic = '批准标记'.
* i_fieldcat-do_sum = 'X'.
i_fieldcat-Emphasize = 'C211'.
* i_fieldcat-do_sum = 'X'.
append i_fieldcat to i_fieldcat_alv.
clear i_fieldcat.
endform. " fields_build
*&--------------------------------------------------------------------*
*& Form display_data
*&--------------------------------------------------------------------*
* 显示报表内容
*---------------------------------------------------------------------*
form display_data .
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = w_repid
is_layout = i_layout
it_fieldcat = i_fieldcat_alv[]
it_events = i_events[]
i_grid_title = ' 采购信息记录汇总查询表'
i_callback_user_command = 'USER_COMMAND'
* i_save = 'A'
tables
t_outtab = hd_itab.
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 USER_COMMAND *
*---------------------------------------------------------------------*
FORM user_command USING i_ucomm LIKE sy-ucomm
is_selfield TYPE slis_selfield. "#EC CALLED
CASE i_ucomm.
WHEN '&IC1'. " Pick
READ TABLE hd_itab INDEX is_selfield-tabindex.
IF sy-subrc EQ 0.
SET PARAMETER ID 'INF' FIELD hd_itab-infnr.
SET PARAMETER ID 'MAT' FIELD hd_itab-matnr.
SET PARAMETER ID 'LIF' FIELD hd_itab-lifnr.
SET PARAMETER ID 'EKO' FIELD hd_itab-ekorg.
CALL TRANSACTION 'ME13' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM. " USER_COMMAND
*&--------------------------------------------------------------------*
*& Form whole_toolbar
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
* -->EXTAB text
*---------------------------------------------------------------------*
form whole_toolbar using extab type slis_t_extab. "#EC CALLED
set pf-status 'WHOLE_TOOLBAR' excluding extab.
endform. "whole_toolbar
*&--------------------------------------------------------------------*
*& Form alv_top_of_page
*&--------------------------------------------------------------------*
* 页头格式设置
*---------------------------------------------------------------------*
form alv_top_of_page.
clear: i_list_comments.
w_list_comments-typ = 'H'.
w_list_comments-key = ''.
w_list_comments-info = '采购信息记录查询报表'.
append w_list_comments to i_list_comments.
clear w_list_comments.
data: data_temp(16).
write sy-datum to: data_temp mm/dd/yyyy.
concatenate '日期: ' data_temp into data_temp.
concatenate data_temp ' IT部' into data_temp.
w_list_comments-typ = 'S'.
w_list_comments-key = ''.
w_list_comments-info = data_temp.
append w_list_comments to i_list_comments.
clear w_list_comments.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_list_comments
I_LOGO = 'ENJOYSAP_LOGO' "标题图标.
i_end_of_list_grid = 'X'.
* i_logo = 'ENJOYSAP_LOGO'. "标题图标
endform. "alv_top_of_page
*&--------------------------------------------------------------------*
*& Form alv_end_of_list
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
form alv_end_of_list.
clear: i_list_comments.
w_list_comments-typ = 'S'.
w_list_comments-info = '制作单:IT部'.
append w_list_comments to i_list_comments.
clear w_list_comments.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = i_list_comments
i_end_of_list_grid = 'X'. "I_LOGO = 'ENJOYSAP_LOGO' "标题图标
CLEAR: i_list_comments.
w_list_comments-typ = 'S'.
w_list_comments-info = '确认: ______________ 采购申请分配员: ______________ '.
APPEND w_list_comments TO i_list_comments.
CLEAR w_list_comments.
w_list_comments-typ = 'S'.
w_list_comments-info = '制表单位: IT部'.
APPEND w_list_comments TO i_list_comments.
CLEAR w_list_comments.
* CLEAR data_temp.
* CONCATENATE '打 印 者 :' sy-uname INTO data_temp.
w_list_comments-typ = 'S'.
* w_list_comments-info = data_temp.
APPEND w_list_comments TO i_list_comments.
CLEAR w_list_comments.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
it_list_commentary = i_list_comments
I_LOGO = 'ENJOYSAP_LOGO' "标题图标
i_end_of_list_grid = 'X'.
endform. "alv_end_of_list
*
*&--------------------------------------------------------------------*
*& Form events_build
*&--------------------------------------------------------------------*
* 定义ALV事件
*---------------------------------------------------------------------*
FORM events_build .
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = i_events.
READ TABLE i_events WITH KEY name = 'TOP_OF_PAGE'
INTO w_events.
IF sy-subrc = 0.
MOVE 'ALV_TOP_OF_PAGE' TO w_events-form.
MODIFY i_events FROM w_events INDEX sy-tabix.
ENDIF.
READ TABLE i_events INTO w_events WITH KEY name = 'USER_COMMAND'.
IF sy-subrc EQ 0.
w_events-name = 'USER_COMMAND'.
MODIFY i_events FROM w_events INDEX sy-tabix.
ENDIF.
READ TABLE i_events WITH KEY name = 'END_OF_LIST'"slis_ev_end_of_page
INTO w_events.
IF sy-subrc = 0.
MOVE 'ALV_END_OF_LIST' TO w_events-form.
MODIFY i_events FROM w_events INDEX sy-tabix.
ENDIF.
ENDFORM. " events_build
阅读(969) | 评论(0) | 转发(0) |