首页 > 其他分享 >DEMO 双ALV 简单案例

DEMO 双ALV 简单案例

时间:2022-09-30 23:42:21浏览次数:54  
标签:gr DEMO 案例 alv ALV TYPE events salv &---------------------------------------

货铺QQ群号:834508274



简单案例,上面ALV是Header,下面是Item。


一个屏幕,俩控件

DEMO 双ALV 简单案例_数据

DEMO 双ALV 简单案例_微信_02

DEMO 双ALV 简单案例_码农_03


效果:

DEMO 双ALV 简单案例_数据_04


DEMO 双ALV 简单案例_微信_05

上面是BKPF数据,下面是BSEG数据.


完整代码:


*&---------------------------------------------------------------------**& Report ZLM_ALV_DEMO02*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*REPORT zlm_alv_demo02.

*&----------------------------------------------------------------*& ALV 定义*&----------------------------------------------------------------
DATA:gr_header TYPE REF TO cl_gui_custom_container,gr_item TYPE REF TO cl_gui_custom_container.
DATA: gr_alv_header TYPE REF TO cl_salv_table,gr_alv_item TYPE REF TO cl_salv_table.
CLASS lcl_handle_events DEFINITION DEFERRED.
DATA: gr_events TYPE REF TO lcl_handle_events.

*&---------------------------------------------------------------------**& Class lcl_handle_events DEFINITION*&---------------------------------------------------------------------** Text*----------------------------------------------------------------------*CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.METHODS:on_user_command FOR EVENT added_function OF cl_salv_eventsIMPORTING e_salv_function,
* hotspoton_link_click FOR EVENT link_click OF cl_salv_events_tableIMPORTING row column,
* double_clickon_double_click FOR EVENT double_click OF cl_salv_events_tableIMPORTING row column.ENDCLASS. "lcl_event_receiver DEFINITION
*---------------------------------------------------------------------** CLASS lcl_handle_events IMPLEMENTATION*---------------------------------------------------------------------** §5.2 implement the events for handling the events of cl_salv_table*---------------------------------------------------------------------*CLASS lcl_handle_events IMPLEMENTATION.METHOD on_user_command.ENDMETHOD. "on_user_command
METHOD on_link_click.* PERFORM refresh_data USING row column .ENDMETHOD.METHOD on_double_click.PERFORM frm_double_click USING row column .ENDMETHOD.ENDCLASS. "lcl_event_receiver

*&----------------------------------------------------------------*& 数据定义*&----------------------------------------------------------------DATA: gt_header TYPE TABLE OF bkpf.DATA: gt_item TYPE TABLE OF bseg.

DATA: g_okcode TYPE sy-ucomm,g_toggle TYPE i.CONSTANTS: con_ok TYPE sy-ucomm VALUE 'OK',con_exit TYPE sy-ucomm VALUE 'EXIT',con_canc TYPE sy-ucomm VALUE 'CANC',con_back TYPE sy-ucomm VALUE 'BACK'.*&----------------------------------------------------------------*& 屏幕定义*&----------------------------------------------------------------TABLES bkpf.SELECT-OPTIONS:s_bukrs FOR bkpf-bukrs DEFAULT '1001',s_belnr FOR bkpf-belnr,s_gjahr FOR bkpf-gjahr NO INTERVALS NO-EXTENSION .


START-OF-SELECTION.SELECT * FROM bkpf INTO TABLE gt_headerWHEREbukrs IN s_bukrs ANDbelnr IN s_belnr ANDgjahr IN s_gjahr .

CALL SCREEN 9001.

*&---------------------------------------------------------------------**& Module MDL_ALV OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE mdl_alv OUTPUT.
IF gr_header IS INITIAL.
IF cl_gui_alv_grid=>offline( ) IS INITIAL.CREATE OBJECT gr_headerEXPORTINGcontainer_name = 'HEADER'.ENDIF.
TRY.cl_salv_table=>factory(EXPORTINGr_container = gr_headercontainer_name = 'HEADER'IMPORTINGr_salv_table = gr_alv_headerCHANGINGt_table = gt_header ).CATCH cx_salv_msg. "#EC NO_HANDLERENDTRY.

DATA: lr_events TYPE REF TO cl_salv_events_table.
lr_events = gr_alv_header->get_event( ).
CREATE OBJECT gr_events.
*... §6.1 register to the event USER_COMMANDSET HANDLER gr_events->on_user_command FOR lr_events.SET HANDLER gr_events->on_link_click FOR lr_events.SET HANDLER gr_events->on_double_click FOR lr_events.
*... §7 display the tablegr_alv_header->display( ).
ENDIF.

IF gr_item IS INITIAL.IF cl_gui_alv_grid=>offline( ) IS INITIAL.CREATE OBJECT gr_itemEXPORTINGcontainer_name = 'ITEM'.ENDIF.ENDIF.
TRY.cl_salv_table=>factory(EXPORTINGr_container = gr_itemcontainer_name = 'ITEM'IMPORTINGr_salv_table = gr_alv_itemCHANGINGt_table = gt_item ).CATCH cx_salv_msg. "#EC NO_HANDLERENDTRY.
gr_alv_item->display( ).
ENDMODULE.*&---------------------------------------------------------------------**& Module STATUS_9001 OUTPUT*&---------------------------------------------------------------------**&*&---------------------------------------------------------------------*MODULE status_9001 OUTPUT.* SET PF-STATUS 'xxxxxxxx'.* SET TITLEBAR 'xxx'.ENDMODULE.

FORM frm_double_click USING i_row TYPE ii_column TYPE lvc_fname.
DATA:ls_header LIKE LINE OF gt_header.
READ TABLE gt_header INTO ls_headerINDEX i_row.
CHECK sy-subrc = 0.
SELECT * FROM bsegINTO TABLE gt_itemWHEREbukrs = ls_header-bukrs ANDbelnr = ls_header-belnr ANDgjahr = ls_header-gjahr.
TRY.gr_alv_item->set_data( CHANGING t_table = gt_item ).CATCH cx_salv_no_new_data_allowed cx_salv_not_found.ENDTRY.
gr_alv_item->refresh( refresh_mode = if_salv_c_refresh=>full ). "full refresh neceENDFORM. " REFRESH_DATA*&---------------------------------------------------------------------**& Module USER_COMMAND_9001 INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE user_command_9001 INPUT.
ENDMODULE.*&---------------------------------------------------------------------**& Module MDL_EXIT INPUT*&---------------------------------------------------------------------** text*----------------------------------------------------------------------*MODULE mdl_exit INPUT.
LEAVE PROGRAM.
ENDMODULE.


标签:gr,DEMO,案例,alv,ALV,TYPE,events,salv,&---------------------------------------
From: https://blog.51cto.com/u_15680210/5727530

相关文章

  • ALV :汇总,分类汇总(小计),排序,过滤
    货铺QQ群号:834508274下面开始干货部分……ALV标准功能汇总,分类汇总,排序,过滤这些功能除了可以直接使用它的标准功能按钮之外,你也可以在程序里设定,让ALV列表第一次显示出来就......
  • OLE Excel 按行列号赋值 demo
    货铺QQ群号:834508274下面开始干货:上篇OLE中Excel单元格赋值,使用的是PERFORMfill_range填充行PERFORMinsert_row添加新行其中FORMfill_rangeUSINGvalue(f_range)  ......
  • Demo:代码完成Excel数据并发送Email附件
    货铺QQ群号:834508274有时候没有上载操作,直接组织数据并生成Excel附件直接发送。效果图参考代码REPORTzlm_email03.TYPE-POOLS:ixml.TYPES:BEGINOFxml_line,......
  • DEMO:关闭采购订单 BAPI_PO_CHANGE(带增强字段)
    货铺QQ群号:834508274调用BAPI的时候注意DEMOREPORTZDEMO_CLOSE_PO.PARAMETERSP_POTYPEBAPIMEPOHEADER-PO_NUMBER..DATA:LT_RETURNLIKETABLEOFBAPIRET2,LS_RETURN......
  • DEMO:PR 添加新行项目 BAPI_PR_CHANGE
    货铺QQ群号:834508274REPORTZLM_PR_CHANGE.PARAMETERS:P_BANFNTYPEVBEP-BANFNOBLIGATORY.DATA:LS_PRHEADERLIKEBAPIMEREQHEADER,"LS_PRHEADERXLIKEBAPIMEREQ......
  • DEMO: ME51N 创建PR BAPI_REQUISITION_CREATE
    货铺QQ群号:834508274*&---------------------------------------------------------------------**&BAPI_REQUISITION_CREATE和BAPI_PR_CREATE相关问题查看NOTE*&49962......
  • DEMO: ME51N 创建PR BAPI_PR_CREATE
    货铺QQ群号:834508274*&---------------------------------------------------------------------**&BAPI_REQUISITION_CREATE和BAPI_PR_CREATE相关问题查看NOTE*&49962......
  • DEMO:修改外向交货单BAPI_OUTB_DELIVERY_CHANGE
    货铺QQ群号:834508274TABLES:LIKP,LIPS.PARAMETERS:P_VBELNTYPEVBELN_VL.PARAMETERS:P_SERNRTYPEOBJK-SERNR.DATA:LS_HEADER_DATALIKEBAPIOBDLVHDRCHG,LS_HEADER_C......
  • Demo:替代
    货铺QQ群号:834508274下面开始干货:Tcode:OBBH:新建步骤:选择替换字段:设置先决条件:这里demo输入常量:替换:维护出口代码:Tcode:Gcx2:代码由两部分构成:在form get_exit_titles先声明......
  • Demo:校验
    货铺QQ群号:834508274下面开始干货:tcode:GGB0设置先决条件设置检查点这里ZU01对应的代码是需要配置维护的。不然是显示不出来ZU01的。ZU01代码的相关配置维护点:Tcode:GCX2Co......