*&---------------------------------------------------------------------*
*& Report ZBCRP12_DJ_TOTAL_F_ALV
*&
*&---------------------------------------------------------------------*
*& 1.meins单位列可编辑(complete)
*& 2.brgew gross weigh 乘-1,符号提前(complete)
*& 3.gross weigh 小计,后面有单位,相同单位的才能相加(complete)
*& 4.gross weigh 总计,后面有单位,相同单位的才能相加(complete)
*& 5.双击(complete),I_CALLBACK_USER_COMMAND,I_CALLBACK_PROGRAM
*& 6.单击(complete)
*& 7.表头(complete)I_CALLBACK_TOP_OF_PAGE,I_CALLBACK_PROGRAM;
*& 表尾(complete):IT_EVENTS,END_OF_LIST,编辑信息时同表头
*& 8.page list两种
*& 9.新增一个删除按钮,需复制标准的status,再增加,user_command,如果直接增加会覆盖(complete)
*& 10.默认值(complete)
*& 11.数据列用红色强调(complete)
*& 12.主键设置主键色,不受斑马条纹的影响(complete)
*& 13.使用斑马条纹zebra(complete)
*& 14.保存修改(complete)
*& 15.设置行颜色(complete)
*&---------------------------------------------------------------------*
REPORT ZBCRP12_DJ_TOTAL_F_ALV.
types: begin of gts_mara,
CHECK type c LENGTH 1, "做checkbox要添加一个字段,大写
matnr type mara-matnr,
ersda type mara-ersda,
brgew type mara-brgew,
meins type mara-meins,
color type c LENGTH 4, "用作设置行颜色
end of gts_mara.
data: GDT_MARA type standard table of gts_mara,
GDW_MARA type gts_mara,
gdt_copy type standard table of gts_mara,
gdw_copy type gts_mara.
*--------------------------------------------------------------------*
*screen
*--------------------------------------------------------------------*
selection-screen: begin of block blk1 with frame title text-001.
* parameters: p_matnr type gts_mara-matnr MATCHCODE OBJECT.
select-options: s_matnr for gdw_mara-matnr.
selection-screen: end of block blk1.
*--------------------------------------------------------------------*
*initialization.
*--------------------------------------------------------------------*
initialization.
s_matnr-low = '98'.
s_matnr-high = '697'.
* s_matnr-
append s_matnr.
*--------------------------------------------------------------------*
*start-of-selection.
*--------------------------------------------------------------------*
start-of-selection.
perform data_select.
perform alv_output.
*&---------------------------------------------------------------------*
*& Form DATA_SELECT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM DATA_SELECT .
select matnr
ersda
brgew
meins
into corresponding fields of table GDT_MARA
from mara
where matnr in s_matnr.
LOOP AT gdt_mara into gdw_mara.
IF gdw_mara-brgew > 0.
gdw_mara-brgew = gdw_mara-brgew * ( -1 ).
modify gdt_mara from gdw_mara transporting brgew.
ENDIF.
IF gdw_mara-matnr < 500.
gdw_mara-color = 'C110'.
modify gdt_mara from gdw_mara TRANSPORTING color.
ENDIF.
ENDLOOP.
* gdt_copy = gdt_mara.
move gdt_mara to gdt_copy.
ENDFORM. " DATA_SELECT
*&---------------------------------------------------------------------*
*& Form ALV_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM ALV_OUTPUT .
data: it_fieldcat type standard table of slis_fieldcat_alv.
* data: ldt_fieldcat type standard table of SLIS_T_FIELDCAT_ALV.
data: it_sort type standard table of slis_sortinfo_alv,
w_layout type slis_layout_alv,
it_event type STANDARD TABLE OF slis_alv_event.
perform alv_edit tables it_sort it_fieldcat
changing w_layout.
perform process_event tables it_event.
perform alv_display tables it_fieldcat it_sort it_event
changing w_layout.
ENDFORM. " ALV_OUTPUT
*&---------------------------------------------------------------------*
*& Form ALV_EDIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM ALV_EDIT tables ldt_sort
ldt_fieldcat type slis_t_fieldcat_alv "带表头
changing ldw_layout type slis_layout_alv. "定义一下
data: ldw_sort type slis_sortinfo_alv,
ldw_event type slis_alv_event.
*----layout----------------------------*
ldw_layout-zebra = 'X'.
* ldw_layout-edit = 'X'. "定义所有的字段为可编辑
ldw_layout-colwidth_optimize = 'X'.
ldw_layout-box_fieldname = 'CHECK'. "要大写
ldw_layout-info_fieldname = 'COLOR'.
*------sort--------------------------*
ldw_sort-spos = '1'. "Sort sequence排序列
* ldw_sort-down = 'X'.
ldw_sort-up = 'X'. "排序的方式,从小到大
ldw_sort-fieldname = 'MATNR'.
* ldw_sort-subtot = 'X'. "Output subtotal 小计
append ldw_sort to ldt_sort.
clear ldw_sort.
*-------------fieldcat-----------------*
* ldt_fieldcat-col_pos = '1'.
ldt_fieldcat-row_pos = '3'.
ldt_fieldcat-fieldname = 'MATNR'.
ldt_fieldcat-seltext_l = '物料号'.
ldt_fieldcat-key = 'X'. "column with key-color 主键颜色,不受zebra的影响
ldt_fieldcat-hotspot = 'X'. "在双击事件的基础上增加此字段,变为单击,其余相同
append ldt_fieldcat to ldt_fieldcat[].
clear ldt_fieldcat.
* ldt_fieldcat-col_pos = '2'.
ldt_fieldcat-row_pos = '3'.
ldt_fieldcat-fieldname = 'ERSDA'.
ldt_fieldcat-seltext_l = '创建时间'.
* ldt_fieldcat-key = 'X'. "主键颜色
* ldt_fieldcat-checkbox = 'X'.
append ldt_fieldcat to ldt_fieldcat[].
clear ldt_fieldcat.
* ldt_fieldcat-col_pos = '3'.
ldt_fieldcat-row_pos = '3'.
ldt_fieldcat-fieldname = 'BRGEW'.
ldt_fieldcat-seltext_l = '毛重'.
ldt_fieldcat-edit_mask = '==DSIGN'. "做符号提前,调用CONBERSION_EXIT_DSIGN_OUTPUT函数
* ldt_fieldcat-tech = 'X'. "
ldt_fieldcat-decimals_out = 2. "设置小数位,但是没效果,,与qfieldname字段冲突
ldt_fieldcat-do_sum = 'X'. "总计
ldt_fieldcat-NO_ZERO = 'X'. "不输出零项
ldt_fieldcat-emphasize = 'C600'. "此列底色为红色
* ldt_fieldcat-key = ''. "主键颜色
* ldt_fieldcat-qfieldname = 'MEINS'. "指定单位列,有此字段相才会同单位的相加,
append ldt_fieldcat to ldt_fieldcat[].
clear ldt_fieldcat.
* ldt_fieldcat-col_pos = '4'.
ldt_fieldcat-row_pos = '3'.
ldt_fieldcat-fieldname = 'MEINS'.
ldt_fieldcat-seltext_l = '单位'.
ldt_fieldcat-edit = 'X'. "编辑
append ldt_fieldcat to ldt_fieldcat[].
clear ldt_fieldcat.
ENDFORM. " ALV_EDIT
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM ALV_DISPLAY tables ldt_fieldcat
ldt_sort
ldt_event
changing ldw_layout.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid "I_call_back 的需放开次参数
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = '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 = ldw_layout
IT_FIELDCAT = ldt_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
IT_SORT = ldt_sort[]
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
IT_EVENTS = ldt_event[]
* 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
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = gdt_mara
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " ALV_DISPLAY
FORM top_of_page.
DATA: ldt_header type standard table of slis_listheader,
ldt_header2 type SLIS_T_LISTHEADER,
ldw_header type slis_listheader,
tline type i .
ldw_header-typ = 'H'.
ldw_header-info = '物料主数据'.
append ldw_header to ldt_header.
clear ldw_header.
write sy-datum to ldw_header-info using edit mask '____年__月__日'.
ldw_header-typ = 'S'.
ldw_header-key = '日期:'.
append ldw_header to ldt_header.
clear ldw_header.
describe table gdt_mara lines tline.
ldw_header-typ = 'S'.
ldw_header-key = '行数:'.
ldw_header-info = tline.
append ldw_header to ldt_header.
clear ldw_header.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ldt_header.
ENDFORM.
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
READ TABLE GDT_MARA INTO GDW_MARA INDEX rs_selfield-tabindex.
CASE R_UCOMM.
WHEN '&IC1'.
IF rs_selfield-fieldname = 'MATNR' and rs_selfield-tabindex <> 0."排除字段名行
SET PARAMETER ID 'MAT' FIELD GDW_MARA-MATNR.
CALL TRANSACTION 'MM02' AND SKIP FIRST SCREEN.
ENDIF.
WHEN 'DELETE'.
LOOP AT gdt_mara into gdw_mara where check = 'X'.
* delete gdt_mara index rs_selfield-tabindex."删除单条数据
delete table gdt_mara from gdw_mara .
* DELETE TABLE it WITH TABLE KEY carrid = p_carrid.
* DELETE TABLE it FROM workarea.
ENDLOOP.
rs_selfield-refresh = 'X'. "刷新屏幕显示和内表
WHEN '&DATA_SAVE'.
perform save_data.
* rs_selfield-refresh = 'X'."由此一句代码即可将修改刷新到内表中,不用调用方法。
* 或者直接增加layout的box_fieldname,得到选中的行,进行loop循环保存。
WHEN OTHERS.
ENDCASE.
endform.
FORM set_pf_status USING rt_extab TYPE slis_t_extab.
SET TITLEBAR '物料清单'.
SET PF-STATUS 'PF_STATUS_TOTAL'.
endform.
FORM PROCESS_EVENT TABLES P_IT_EVENT type slis_t_event. "要声明一下,不然后面有错
data: ldw_event type slis_alv_event.
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 4
IMPORTING
ET_EVENTS = P_IT_EVENT[]
EXCEPTIONS
LIST_TYPE_WRONG = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
read table p_it_event into ldw_event with key = 'END_OF_LIST'.
IF sy-subrc = 0.
ldw_event-form = 'EDIT_OF_LIST'.
modify p_it_event[] from ldw_event transporting FORM WHERE NAME = SLIS_EV_END_OF_LIST."transproting限制修改的字段
ENDIF.
ENDFORM. " PROCESS_EVENT
form EDIT_OF_LIST.
DATA: LDT_LIST TYPE STANDARD TABLE OF slis_listheader,
LDW_LIST TYPE slis_listheader.
LDW_LIST-typ = 'S'.
ldw_list-key = '作者:'.
ldw_list-info = sy-uname.
* ldw_list-info = 'sky'.
append ldw_list to ldt_list.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY = ldt_list.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SAVE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM SAVE_DATA .
data: ldt_grid type ref to CL_GUI_ALV_GRID.
*--------------------------------------------------------------------*
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = ldt_grid.
CALL METHOD LDT_GRID->CHECK_CHANGED_DATA.
*----使用上面的方法和函数:内表GDT_MARA的值得到改变--------------------------------------*
*与GDT_CHECK对比,找出改变的值,然后modify数据库表
ENDFORM. " SAVE_DATA