`
touchinsert
  • 浏览: 1329558 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

ABAP--如何在'REUSE_ALV_GRID_DISPLAY'使用自定义F4帮助,返回多个字段以及计算修改其他字段

UP 
阅读更多

REPORT ZTEST7.
************************************************************************
* DATEN DEFINITION *
************************************************************************
TYPE-POOLS: slis.
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*---------------------------------------------------------------------*
class lcl_event_receiver definition.
public section.
class-methods:
on_f4 for event onf4 of cl_gui_alv_grid
importing sender
e_fieldname
e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display,
on_data_changed for event data_changed of cl_gui_alv_grid
importing e_onf4
e_onf4_before
e_onf4_after
er_data_changed
e_ucomm
sender.
private section.
types: ddshretval_table type table of ddshretval.
class-methods: my_f4
importing sender type ref to cl_gui_alv_grid
et_bad_cells type lvc_t_modi
es_row_no type lvc_s_roid
er_event_data type ref to cl_alv_event_data
e_display type c
e_fieldname type lvc_fname
exporting IM_lt_f4 type ddshretval_table.
endclass. "lcl_event_receiver DEFINITION

tables: mara.
TYPES:
BEGIN OF t_alv,
matnr TYPE makt-matnr,
MTART type mara-MTART,
MTBEZ type t134t-MTBEZ,
maktx TYPE makt-maktx,
spras TYPE makt-spras,
Value Type i,
END OF t_alv.
DATA:
gt_fieldcatalog TYPE slis_t_fieldcat_alv,
gt_events TYPE slis_t_event,
gw_events TYPE slis_alv_event,
gt_data TYPE TABLE OF t_alv,
gw_data TYPE t_alv,
g_repid TYPE sy-repid VALUE sy-repid.
data: g_grid type ref to cl_gui_alv_grid.
data: gt_bad_cells type lvc_t_modi.
data: gt_fieldcat type lvc_t_fcat.
data: g_row_id type lvc_s_roid-row_id.
field-symbols: <gs_outtab> type any.
************************************************************************
* SELECTION SCREEN *
************************************************************************
SELECT-OPTIONS: s_matnr FOR mara-matnr .
************************************************************************
* START-OF-SELECTION *
************************************************************************
START-OF-SELECTION.
SELECT mara~matnr makt~maktx mara~MTART t134t~MTBEZ makt~spras
INTO CORRESPONDING FIELDS OF TABLE gt_data up to 50 rows
FROM mara
inner join makt on mara~matnr = makt~matnr and makt~SPRAS = 'EN'
inner join t134t on mara~MTART = t134t~MTART and t134t~SPRAS = 'EN'
WHERE mara~matnr IN s_matnr.

PERFORM creat_fieldcat.
PERFORM creat_event_exits.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = g_repid
it_fieldcat = gt_fieldcatalog
it_events = gt_events
TABLES
t_outtab = gt_data.
*---------------------------------------------------------------------*
* Create Output Field Format
*---------------------------------------------------------------------*
FORM creat_fieldcat.
data gw_fieldcatalog TYPE slis_fieldcat_alv.

CLEAR gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'MATNR'.
gw_fieldcatalog-ref_fieldname = 'MATNR'.
gw_fieldcatalog-ref_tabname = 'MAKT'.
APPEND gw_fieldcatalog TO gt_fieldcatalog.

CLEAR gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'MAKTX'.
gw_fieldcatalog-ref_fieldname = 'MAKTX'.
gw_fieldcatalog-ref_tabname = 'MAKT'.
APPEND gw_fieldcatalog TO gt_fieldcatalog.

CLEAR gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'MTART'.
gw_fieldcatalog-ref_fieldname = 'MTART'.
gw_fieldcatalog-ref_tabname = 'MARA'.
gw_fieldcatalog-EDIT = 'X'.
APPEND gw_fieldcatalog TO gt_fieldcatalog.

CLEAR gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'MTBEZ'.
gw_fieldcatalog-ref_fieldname = 'MTBEZ'.
gw_fieldcatalog-ref_tabname = 'T134T'.
APPEND gw_fieldcatalog TO gt_fieldcatalog.

CLEAR gw_fieldcatalog.
gw_fieldcatalog-fieldname = 'VALUE'.
gw_fieldcatalog-seltext_s = 'VALUE'.
gw_fieldcatalog-outputlen = 13.
APPEND gw_fieldcatalog TO gt_fieldcatalog.
ENDFORM. " creat_fieldcat
*---------------------------------------------------------------------*
* Form creat_event_exits
*---------------------------------------------------------------------*
FORM creat_event_exits .
gw_events-name = 'CALLER_EXIT'.
gw_events-form = 'CALLER_EXIT'.
APPEND gw_events TO gt_events.
ENDFORM. " creat_event_exits
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
FORM caller_exit USING ls_data TYPE slis_data_caller_exit.
DATA: l_ref_alv TYPE REF TO cl_gui_alv_grid.
data: lt_wa_f4 type lvc_s_f4,
lt_f4 type lvc_t_f4.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = l_ref_alv.
set handler lcl_event_receiver=>on_f4 for l_ref_alv.
set handler lcl_event_receiver=>on_data_changed for l_ref_alv.
lt_wa_f4-fieldname = 'MTART'.
lt_wa_f4-register = 'X'.
lt_wa_f4-getbefore = 'X'.
lt_wa_f4-chngeafter = 'X'.
append lt_wa_f4 to lt_f4.
call method l_ref_alv->register_f4_for_fields
EXPORTING
it_f4 = lt_f4.
ENDFORM. "CALLER_EXIT
*&---------------------------------------------------------------------*
*& Form f4_set
*----------------------------------------------------------------------*
form f4_set using r_grid type ref to cl_gui_alv_grid
rt_fieldcat type lvc_t_fcat
rt_bad_cells type lvc_t_modi
r_row_id type lvc_s_roid-row_id
rs_outtab.
g_grid = r_grid.
gt_fieldcat = rt_fieldcat.
gt_bad_cells = rt_bad_cells.
g_row_id = r_row_id.
assign rs_outtab to <gs_outtab>.
endform. "f4_set
*&---------------------------------------------------------------------*
*& Form f4
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
form f4 tables it_dummy structure seahlpres
changing r_shlp type shlp_descr_t
r_callcontrol like ddshf4ctrl.
data: ls_interface type ddshiface.
data: ls_fieldcat type lvc_s_fcat.
data: ls_bad_cells type lvc_s_modi.
data: l_tabix type sy-tabix.
field-symbols: <l_field>.
ls_interface-shlpfield = 'MTBEZ'.
ls_interface-valfield = 'MTBEZ'.
append ls_interface to r_shlp-interface.
loop at r_shlp-interface into ls_interface.
l_tabix = sy-tabix.
check ls_interface-f4field is initial
and not ls_interface-valtabname is initial.
read table gt_fieldcat into ls_fieldcat
with key ref_table = ls_interface-valtabname
ref_field = ls_interface-valfield.
if sy-subrc = 0.
read table gt_bad_cells into ls_bad_cells
with key fieldname = ls_fieldcat-fieldname
row_id = g_row_id.
if sy-subrc = 0.
ls_interface-value = ls_bad_cells-value.
ls_interface-internal = ' '.
modify r_shlp-interface from ls_interface index l_tabix.
else.
assign component ls_fieldcat-fieldname of structure
<gs_outtab> to <l_field>.
if sy-subrc = 0 and
not ( <l_field> is initial and
ls_fieldcat-no_init_ch ca 'FB' ).
ls_interface-value = <l_field>.
ls_interface-internal = 'X'.
modify r_shlp-interface from ls_interface index l_tabix.
endif.
endif.
endif.
endloop.
endform. "f4
*---------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*---------------------------------------------------------------------*
class lcl_event_receiver implementation.
method on_f4.
data: ls_f4 type ddshretval,
lt_f4 type table of ddshretval.
field-symbols: <itab> type lvc_t_modi.
data: ls_modi type lvc_s_modi.
call method my_f4
EXPORTING
sender = sender
es_row_no = es_row_no
er_event_data = er_event_data
et_bad_cells = et_bad_cells
e_display = e_display
e_fieldname = e_fieldname
IMPORTING
IM_lt_f4 = lt_f4.
assign er_event_data->m_data->* to <itab>.
read table lt_f4 into ls_f4 with key fieldname = 'MTART'.
if not ls_f4 is initial.
ls_modi-row_id = es_row_no-row_id.
ls_modi-fieldname = 'MTART'.
ls_modi-value = ls_f4-fieldval.
append ls_modi to <itab>.
ls_modi-row_id = es_row_no-row_id.
ls_modi-fieldname = 'VALUE'.
if ls_f4-fieldval < 'D'.
ls_modi-value = 100.
elseif ls_f4-fieldval < 'R'.
ls_modi-value = 1000.
else.
ls_modi-value = 10000.
endif.
append ls_modi to <itab>.
endif.
read table lt_f4 into ls_f4 with key fieldname = 'MTBEZ'.
if not ls_f4 is initial.
ls_modi-row_id = es_row_no-row_id.
ls_modi-fieldname = 'MTBEZ'.
ls_modi-value = ls_f4-fieldval.
append ls_modi to <itab>.
endif.
er_event_data->m_event_handled = 'X'.
endmethod. "on_f4
*---------------------------------------------------------------------*
* METHOD on_data_changed *
*---------------------------------------------------------------------*
method on_data_changed.
endmethod. "on_data_changed
*---------------------------------------------------------------------*
* METHOD my_f4 insert here your own f4-help *
*---------------------------------------------------------------------*
method my_f4.
data: lw_tab like line of gt_data,
lt_fcat type lvc_t_fcat,
ls_fieldcat type lvc_s_fcat,
l_tabname type dd03v-tabname,
l_fieldname type dd03v-fieldname,
l_help_valu type help_info-fldvalue,
lt_bad_cell type lvc_t_modi,
lp_wa type ref to data.
field-symbols: <l_field_value> type any,
<ls_wa> type any.
call method sender->get_frontend_fieldcatalog
IMPORTING
et_fieldcatalog = lt_fcat.
read table gt_data index es_row_no-row_id into lw_tab.
create data lp_wa like line of gt_data.
assign lp_wa->* to <ls_wa>.
<ls_wa> = lw_tab.
read table lt_fcat with key fieldname = e_fieldname into ls_fieldcat.
move ls_fieldcat-ref_table to l_tabname.
move ls_fieldcat-fieldname to l_fieldname.
assign component ls_fieldcat-fieldname of structure lw_tab to <l_field_value>.
write <l_field_value> to l_help_valu.
perform f4_set using sender
lt_fcat
lt_bad_cell
es_row_no-row_id
<ls_wa>.
call function 'F4IF_FIELD_VALUE_REQUEST'
EXPORTING
tabname = l_tabname
fieldname = l_fieldname
display = e_display
value = l_help_valu
callback_program = 'ZTEST7'
callback_form = 'F4'
TABLES
return_tab = IM_lt_f4
exceptions
parameter_error = 1
no_values_found = 2
others = 3.
endmethod. "my_f4
endclass. "lcl_event_receiver IMPLEMENTATION

分享到:
评论

相关推荐

    abap-ALV.rar_ABAP系统ALV_abap_abap开发alv

    描述中提到“ABAP ALV总结,ALV格式,REUSE_ALV_GRID_DISPLAY_LVC函数使用”,这表明我们将重点关注ALV的基本概念、数据格式以及如何通过REUSE_ALV_GRID_DISPLAY_LVC函数来实现ALV的显示。 ALV格式通常涉及如何组织...

    REUSE_ALV_GRID_DISPLAY超详细讲解

    REUSE_ALV_GRID_DISPLAY是一个功能强大的ABAP函数模块,主要用于在ABAP程序中显示ALV网格控件。该函数模块提供了大量的参数和事件,使得开发者可以根据需要自定义ALV网格控件的外观和行为。 功能模块的调用: CALL...

    ABAP开发ALV中自定义按钮实现

    总结来说,自定义ALV按钮的关键在于理解GUI状态的概念,以及如何通过`SET PF-STATUS`和`CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'`的参数设置来控制这些状态。同时,编写响应事件的处理程序是实现按钮功能的核心。...

    REUSE_ALV_FIELDCATALOG_MERGE注意点.docx

    在 SAP 开发环境中,"REUSE_ALV_FIELDCATALOG_MERGE" 是一个非常重要的函数,用于合并和创建用于 ALV (ABAP List Viewer) 输出的字段目录。然而,在使用这个函数时,可能存在一些陷阱和注意事项,导致程序出错或者...

    ALV EDIT_MASK字段的使用.rar_ABAP EDIT_MASK_ALV EDIT_MASK字段的使用_ALVEDIT

    这通常通过在`CALL REPORT`或`CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'`等语句中使用`SET_EDIT_MASK`方法来实现。例如: ``` DATA: ls_edit_mask TYPE lvc_s_fdef, lv_fieldname LIKE LINE OF it_fieldname. ls...

    ABAP_ALV_知识整理

    - **调用REUSE_ALV_GRID_DISPLAY**: 使用此函数模块来创建标准ALV网格显示。 - **设置列属性**: 设置列的标题、宽度、对齐方式等。 - **设置数据源**: 指定数据源表。 - **设置排序**: 可以设置默认排序规则。 **...

    ALV.rar_SAP_abaP ALV_abap_alv_sap alv

    在ABAP中,ALV的使用通常涉及以下步骤: 1. **创建数据结构**:定义要显示在ALV中的字段结构,这可以通过定义内表或数据结构完成。例如,你可以创建一个包含多个字段(如物料号、描述、数量等)的数据结构来存储...

    SAP ABAP ALV分页显示

    3. **ALV调用**:通过调用函数`REUSE_ALV_GRID_DISPLAY`来显示`IT_ZZP2`中的数据。此函数接收多个参数,包括字段目录(`IT_FIELDCAT`)、回调程序ID(`GD_REPID`)以及输出表(`T_OUTTAB`)等。 4. **分页控制**:使用`SET...

    ABAP中的ALV操作

    - `CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'`: 调用标准函数来显示ALV网格,并传递容器名称和数据表。 2. **ALV的列布局设置**: - `DATA: WA_LAYOUT TYPE LVC_S_LAYO`: 创建一个`LVC_S_LAYO`类型的变量来存储列...

    ABAP--ALV

    - 调用`REUSE_ALV_FIELDCATALOG_MERGE`函数模块来合并字段目录。 - `I_PROGRAM_NAME`:程序名。 - `I_INTERNAL_TABNAME`:内部表名。 - `I_INCLNAME`:包含文件名。 - `I_BYPASSING_BUFFER`:是否绕过缓冲区,...

    abap_alv工具栏修改

    这通常是通过在`REUSE_ALV_GRID_DISPLAY`的参数`I_CALLBACK_USER_COMMAND`中指定一个Form名称来实现的。 - **代码示例**: ```abap * Form user_command FORM user_command USING r_ucomm LIKE sy-ucomm rs_...

    ABAP-ALV进阶

    "ABAP-ALV进阶知识点详解" ABAP-ALV进阶是指在SAP系统中使用ABAP语言开发的高级列表查看器(ALV)...面向对象的 ALV GRID 必须存在于一个容器当中,就是 FUNCTION 的 ALV,实际上也是使用 CL_GUI_ALV_GRID 这个类的。

    绝版的从实例到精通abap 学习--ALV控件的使用

    此外,教程可能还会介绍如何使用其他相关类和接口,如`IF_GUI_ALV_COLUMN`(用于定义列行为)、`IF_ABAP_ALV_GRID_DISPLAY`(用于显示和控制ALV行为)等,以及如何实现个性化定制,如更改颜色、添加按钮、自定义排序...

    [ABAP]Function实现ALV Table 二:ALV的弹出窗口形式

    在ALV上下文中,我们主要会使用到两个关键的Function模块:`REUSE_ALV_GRID_DISPLAY` 和 `REUSE_ALV_LIST_DISPLAY`。这两个函数分别用于在屏幕内和弹出窗口中显示ALV表格。 首先,我们需要准备输入数据结构。ALV将...

    abap_alv去掉标准按钮

    例如,`CL_GUI_ALV_GRID=&gt;MC_FC_MAXIMUM`表示最大值计算功能,而`CL_GUI_ALV_GRID=&gt;MC_MB_VARIANT`则代表了变体视图功能。 #### 3. 调用ALV网格控件方法 在设置好排除列表后,需要在ALV网格控件的初始化过程中传递...

    ABAP OO去掉ALV中的标准工具栏

    在ABAP面向对象编程(ABAP OO)中,经常需要对ALV(Application List Viewer)进行定制化的控制,包括移除或隐藏某些默认显示的工具栏功能。这通常是为了提供更简洁、更符合业务需求的用户界面。本文将详细介绍如何...

    在ALV里编写回车事件

    其中,ALV(Application List Viewer)是SAP ABAP平台上一个强大的列表显示工具,它允许开发者创建高度自定义的列表,支持多种列类型、排序、筛选等功能。在ALV中,编写回车事件是一项常见需求,尤其是在需要响应...

    SAP-ABAP-OO-实现-CL-SALV-TABLE

    传统的 ALV 显示通常采用的是面向过程的方式,即通过函数模块 `REUSE_ALV_GRID_DISPLAY` 来实现。但是随着 ABAP 面向对象技术的发展,现在可以通过面向对象的方式来实现 ALV 的显示。 面向对象的 ALV 显示主要依赖...

    ABAP OOALV

    - **构造器**:实例化ALV时使用的构造器,通常是指`CL_GUI_ALV_GRID`的构造函数,用于创建ALV对象。 - **容器实例化**:首先实例化容器`CL_GUI_CUSTOM_CONTAINER`,用于容纳ALV组件。 - ```abap CREATE OBJECT ...

Global site tag (gtag.js) - Google Analytics