ABAP 明细alv跳转到汇总alv一般模板
2023-12-14 14:42:47
需求描述:做开发的同时,经常会有遇到,根据明细表进行逻辑汇总,在两个屏幕进行跳转,然后按钮还要做功能的情况,我这边记录一下最简单点模板,给新手可以直接复制使用的。
一、源代码
TYPE-POOLS: slis.
TYPE-POOLS: kcde.
TABLES:ekko,ekpo,lfa1."
TYPES : BEGIN OF typ_alv ,
ebeln TYPE ekko-ebeln, "订单编号
ebelp TYPE ekpo-ebelp, "行项目
lifnr TYPE ekko-lifnr, "供应商编号
name1 TYPE name1_gp, "供应商名称
bsart TYPE esart, "采购订单类型
bukrs TYPE ekko-bukrs,
menge TYPE ekpo-menge, "数量
sel TYPE c, "选择
END OF typ_alv .
DATA : gs_alv TYPE typ_alv,
gt_alv TYPE TABLE OF typ_alv.
TYPES : BEGIN OF typ_HZ ,
lifnr TYPE ekko-lifnr, "供应商编号
name1 TYPE name1_gp, "供应商名称
bsart TYPE esart, "采购订单类型
bukrs TYPE ekko-bukrs,
menge TYPE ekpo-menge, "数量
sel TYPE c, "选择
END OF typ_HZ .
DATA : gs_HZ TYPE typ_HZ,
gt_HZ TYPE TABLE OF typ_HZ.
* ALV 用
DATA:
gs_layout TYPE lvc_s_layo,
gv_repid TYPE repid,
gt_fieldcat TYPE lvc_t_fcat,
gt_fieldcat_HZ TYPE lvc_t_fcat,
ls_fieldcat TYPE lvc_S_fcat.
DATA: g_grid TYPE REF TO cl_gui_alv_grid.
DATA: g_grid_hz TYPE REF TO cl_gui_alv_grid.
*创建字段宏定义
DEFINE add_field.
ls_fieldcat-fieldname = '&1' . "字段名称
ls_fieldcat-ref_table = &2. "关联表格
ls_fieldcat-ref_field = &3."参考字段
ls_fieldcat-coltext = &4. "描述文本
APPEND ls_fieldcat TO gt_fieldcat.
CLEAR ls_fieldcat.
END-OF-DEFINITION.
*创建字段宏定义
DEFINE add_field_HZ.
ls_fieldcat-fieldname = '&1' . "字段名称
ls_fieldcat-ref_table = &2. "关联表格
ls_fieldcat-ref_field = &3."参考字段
ls_fieldcat-coltext = &4. "描述文本
ls_fieldcat-EDIT = &5.
APPEND ls_fieldcat TO gt_fieldcat_HZ.
CLEAR ls_fieldcat.
END-OF-DEFINITION.
*--------选择条件
*选择屏幕。
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: s_bukrs FOR ekko-bukrs ,
s_ebeln FOR ekko-ebeln,
s_lifnr FOR ekko-lifnr.
SELECTION-SCREEN END OF BLOCK b1.
INITIALIZATION .
AT SELECTION-SCREEN OUTPUT .
*----------------------------------------------------------------------*
* EVENT OCCURS AFTER THE SELECTION SCREEN HAS BEEN PROCESSED
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM frm_auth_check. "权限检查
PERFORM frm_getdata . "获取数据 --GETTING DATA
PERFORM frm_display_data. "展示ALV
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form frm_auth_check
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_auth_check .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_getdata
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_getdata .
SELECT
ekko~ebeln ,
ekpo~ebelp ,
ekko~lifnr ,
lfa1~name1 ,"供应商名称
ekko~bsart ,"采购订单类型
ekko~bukrs,
ekpo~menge
INTO CORRESPONDING FIELDS OF TABLE @gt_alv
FROM ekko
LEFT JOIN ekpo ON ekko~ebeln EQ ekpo~ebeln
LEFT JOIN lfa1 ON ekko~lifnr EQ lfa1~lifnr
WHERE ekko~bukrs IN @s_bukrs
AND ekko~ebeln IN @s_ebeln
AND ekko~lifnr IN @s_lifnr
.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_display_data
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_display_data .
*定义输出模式
CLEAR:gs_layout,gt_fieldcat.
gs_layout-cwidth_opt = 'X'.
gs_layout-zebra = 'X'.
gs_layout-box_fname = 'SEL'.
gv_repid = sy-repid.
PERFORM frm_set_fieldcat.
.
* TRY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = gv_repid
i_callback_user_command = 'FRM_USER_COMMAND'
i_callback_pf_status_set = 'FRM_PF_STATUS'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat
i_save = 'A'
TABLES
t_outtab = gt_alv
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.
*&---------------------------------------------------------------------*
*& Form frm_set_fieldcat
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM frm_set_fieldcat .
add_field:
ebeln 'EKKO' 'EBELN' '订单编号',
ebelp 'EKPO' 'EBELP' '行项目',
lifnr 'EKKO' 'LIFNR' '供应商编号',
name1 '' '' '供应商名称',
bsart '' '' '采购订单类型',
bukrs 'EKKO' 'BUKRS' '公司',
menge 'EKPO' 'MENGE' '数量'.
ENDFORM.
FORM frm_pf_status USING extab TYPE slis_t_extab.
DATA: fcode TYPE TABLE OF sy-ucomm.
CLEAR:fcode[].
SET PF-STATUS 'STANDARD' EXCLUDING fcode[] .
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM FRM_USER_COMMAND
*&---------------------------------------------------------------------*
* 自定义用户动作
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
*自定义用户动作
FORM frm_user_command USING p_ucomm TYPE sy-ucomm rs_selfield TYPE slis_selfield.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = g_grid.
ENDIF.
"失去焦点触发更新内表
CALL METHOD g_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD g_grid->check_changed_data.
rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.
DATA : l_ucomm TYPE sy-ucomm .
l_ucomm = p_ucomm .
CLEAR p_ucomm .
CASE l_ucomm.
WHEN 'HZ'."选择汇总
PERFORM handle_SELECT_DATA."处理选中的数据
PERFORM display_hz."显示汇总数据
WHEN '&IC1'. "单击复选框 勾选(取消)后同一预留号都自动勾选(取消)
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form handle_SELECT_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM handle_SELECT_DATA .
SELECT l~lifnr ,
l~name1 ,"供应商名称
l~bsart ,"采购订单类型
l~bukrs,
SUM( L~menge ) AS menge
FROM @gt_alv AS l
WHERE sel = 'X'
GROUP BY l~lifnr, l~name1,l~bsart , l~bukrs
INTO CORRESPONDING FIELDS OF TABLE @gt_HZ.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_HZ
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM display_hz .
*定义输出模式
CLEAR:gs_layout,gt_fieldcat.
gs_layout-cwidth_opt = 'X'.
gs_layout-zebra = 'X'.
gs_layout-box_fname = 'SEL'.
gv_repid = sy-repid.
PERFORM frm_set_fieldcat_HZ.
.
* TRY .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_callback_program = gv_repid
i_callback_user_command = 'FRM_USER_COMMAND_HZ'
i_callback_pf_status_set = 'FRM_PF_STATUS_HZ'
is_layout_lvc = gs_layout
it_fieldcat_lvc = gt_fieldcat_HZ
i_save = 'A'
TABLES
t_outtab = gt_HZ
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.
FORM frm_set_fieldcat_HZ .
CLEAR:gt_fieldcat_HZ.
add_field_HZ:
lifnr 'EKKO' 'LIFNR' '供应商编号' '',
name1 '' '' '供应商名称' '',
bsart '' '' '采购订单类型' '',
bukrs 'EKKO' 'BUKRS' '公司' '',
menge 'EKPO' 'MENGE' '汇总数量' 'X'.
ENDFORM.
FORM frm_pf_status_HZ USING extab TYPE slis_t_extab.
DATA: fcode TYPE TABLE OF sy-ucomm.
CLEAR:fcode[].
SET PF-STATUS 'STANDARD_HZ' EXCLUDING fcode[] .
ENDFORM.
*&---------------------------------------------------------------------*
*& FORM FRM_USER_COMMAND
*&---------------------------------------------------------------------*
* 自定义用户动作
*----------------------------------------------------------------------*
* --> P1 TEXT
* <-- P2 TEXT
*----------------------------------------------------------------------*
*自定义用户动作
FORM frm_user_command_hz USING p_ucomm TYPE sy-ucomm rs_selfield TYPE slis_selfield.
DATA : l_ucomm TYPE sy-ucomm .
IF cl_gui_alv_grid=>offline( ) IS INITIAL.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = g_grid_hz.
ENDIF.
"失去焦点触发更新内表
CALL METHOD g_grid_hz->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD g_grid_hz->check_changed_data.
rs_selfield-refresh = 'X'.
rs_selfield-col_stable = 'X'.
rs_selfield-row_stable = 'X'.
l_ucomm = p_ucomm .
CLEAR p_ucomm .
DATA : l_uname TYPE sy-uname,
l_datum TYPE sy-datum,
l_uzeit TYPE sy-uzeit.
CASE l_ucomm.
WHEN 'CREATE'."创建单据
PERFORM create_rsnum.
WHEN '&IC1'. "单击复
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_RSNUM
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM create_rsnum .
MESSAGE '创建成功' TYPE 'I' .
ENDFORM.
二、其中的状态和按钮设置截图
1.创建状态的时候,标准按钮如何点出来的?按我截图走
2.明细表的状态设置和按钮设置,添加了个HZ的按钮
3.汇总表状态和按钮设置,添加了创建单据的按钮
激活就可以改造为你自己的程序了。
分享使我快乐,我是寒武青锋~!如果觉得还挺不错的话,记得点个赞吧。
文章来源:https://blog.csdn.net/lmf496891416/article/details/134993275
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!