*&———————————————————————*
*& Include ZPUB_LVC_FUNC
*&———————————————————————*
*** FORM show_data.
**
*** alv_set_title ‘dfsafsfsf’.
**
*** alv_clear_data.
*** alv_add_data ‘IT_SHOW ” ” ” ” ’18’ ‘MATNR’ ‘物料号’ ‘X’.
*** PERFORM alv_add_data2 USING ‘IT_SHOW’ ” ‘X’ ” ” ’18 ” ‘MATNR’ ‘物料号1’ ‘MARA’ ‘MATNR’.
**
*** PERFORM GET_LENG TABLES ITAB I_FIELDCAT. “使ALV长度默认为其本身的字段
**
*** alv_show_data it_show.
*** ENDFORM. “show_data
*&———————————————————————*
*& Form user_command
*&———————————————————————*
* text
*———————————————————————-*
* –>R_UCOMM text
* –>RS_SELFIELD text
*———————————————————————-*
*FORM user_command USING r_ucomm LIKE sy-ucomm
* rs_selfield TYPE slis_selfield.
*
* CASE r_ucomm.
* WHEN ‘&IC1’.
* ENDCASE.
*ENDFORM. “user_command
*&———————————————————————*
*& INCLUDE Y_ALV_FUNC
*&———————————————————————*
TYPE-POOLS: slis.
DATA: i_fieldcat TYPE lvc_t_fcat WITH HEADER LINE,
“DATA: i_fieldcat TYPE slis_t_fieldcat_alv WITH HEADER LINE,
fieldcat_ln LIKE LINE OF i_fieldcat.
DATA: i_events TYPE slis_t_event.
DATA: i_layout TYPE slis_layout_alv.
DATA: g_variant LIKE disvariant.
DATA: l_title TYPE lvc_title,
l_window_titlebar LIKE sy-title,
l_ls_event TYPE slis_alv_event.
DATA: gs_layout TYPE lvc_s_layo.
DATA: it_sort TYPE lvc_t_sort WITH HEADER LINE, “ALV 排序内表
gs_print TYPE lvc_s_prnt. “occurs 0 with header line. “ALV打印格式
DATA: ls_stylerow TYPE lvc_s_styl .
DATA: ref_grid TYPE REF TO cl_gui_alv_grid. “回车事件之用
DATA: l_fm_button(2) TYPE c. ” 触发回车事件
DATA: gt_list_top_of_page TYPE slis_t_listheader, “定义标题列表 add 2014-10-09.
g_top_of_page TYPE slis_formname VALUE ‘ALV_TOP_OF_PAGE’, “定义top of page相应参数
lv_top_page(2) TYPE c. ” = ‘X’ 表示显示TOP.
FIELD-SYMBOLS: <fsevnt> LIKE LINE OF i_events.
DATA: it_fc TYPE slis_t_fieldcat_alv WITH HEADER LINE.
DATA: p_hotspot.
DATA: col_pos LIKE sy-cucol .
DATA: g_user_command TYPE slis_formname.” VALUE ‘USER_COMMAND’. “处理双击事件
DATA:status TYPE c.”是否使用自定一状态栏。
DATA:helpf4 .
CONSTANTS: icon_green TYPE icon_l4 VALUE [email protected]@’, ” Green light; positive
icon_yellow TYPE icon_l4 VALUE [email protected]@’, ” Yellow light; neutral
icon_red TYPE icon_l4 VALUE [email protected]@’. ” Red light; negative
DATA: l_o_grid1 TYPE REF TO cl_gui_alv_grid. “ALV编辑,通过事件获取AVL编辑的值
************* 在对应的程序代码中,调用以下功能,获取ALV上 新增的值****************
**** CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR’
**** IMPORTING
**** e_grid = l_o_grid1.
**** CALL METHOD l_o_grid1->check_changed_data.
*******建造数据*********************************
DEFINE alv_add_data.
COL_POS = COL_POS + 1.
FIELDCAT_LN-COL_POS = COL_POS .
FIELDCAT_LN-TABNAME = &1.”待显示的内表名
FIELDCAT_LN-DO_SUM = &2.”是否按该列求和
FIELDCAT_LN-EDIT = &3. “使其呈可输入状态
FIELDCAT_LN-CHECKBOX = &4. “checkbox
FIELDCAT_LN-EMPHASIZE = &5. “颜色
**” fieldcat_ln-ddictxt = ‘L’.
FIELDCAT_LN-COLDDICTXT = ‘L’.
FIELDCAT_LN-OUTPUTLEN = &6. “长度
*** fieldcat_ln-outputlen = ’40’.
**** fieldcat_ln-datatype = &6. “冻结列
FIELDCAT_LN-KEY = &7.”固定列不移动
FIELDCAT_LN-FIELDNAME = &8.”字段名
**”””” “fieldcat_ln-seltext_l = &9. “字段描述
FIELDCAT_LN-SCRTEXT_L = &9. “字段描述reptext
FIELDCAT_LN-JUST = ‘L’. ” 字段左对齐 2014-09-19.
APPEND FIELDCAT_LN TO I_FIELDCAT.
CLEAR: FIELDCAT_LN.
END-OF-DEFINITION.
“—- 有F4帮助内容选择的字段:ref_fieldname。
*&———————————————————————*
*& Form alv_add_data2
*&———————————————————————*
* text
*———————————————————————-*
* –>ZTBNAME text
* –>ZDOSUM text
* –>ZEDIT text
* –>ZDTTYPE text
* –>ZCOLOR text
* –>ZINPUT text
* –>ZFLDNAME text
* –>ZTEXT text
* –>ZOPTLEN text
* –>ZKEY text
* –>ZREFTBNAME text
* –>ZREFLDNAME text
*———————————————————————-*
FORM alv_add_data2 USING ztbname zdosum zedit zcheckbox zcolor zoptlen zkey
zfldname ztext zreftbname zrefldname.
col_pos = col_pos + 1.
fieldcat_ln-col_pos = col_pos .
fieldcat_ln-tabname = ztbname. “待显示的内表名
fieldcat_ln-do_sum = zdosum. “是否按该列求和
fieldcat_ln-edit = zedit. “使其呈可输入状态
fieldcat_ln-checkbox = zcheckbox. “checkbox
fieldcat_ln-emphasize = zcolor. “颜色
fieldcat_ln-colddictxt = ‘L’.
fieldcat_ln-outputlen = zoptlen.
fieldcat_ln-key = zkey.
fieldcat_ln-fieldname = zfldname. “字段名
** “””””fieldcat_ln-seltext_l = ztext. “字段描述
fieldcat_ln-scrtext_l = ztext. “字段描述
fieldcat_ln-ref_table = zreftbname.
fieldcat_ln-ref_field = zrefldname.
fieldcat_ln-just = ‘L’. ” 字段左对齐
APPEND fieldcat_ln TO i_fieldcat.
CLEAR: fieldcat_ln.
ENDFORM. “alv_add_data2
DEFINE alv_clear_data.
CLEAR : G_VARIANT,I_EVENTS,I_LAYOUT,I_FIELDCAT[].
END-OF-DEFINITION.
DEFINE alv_set_status.
STATUS = ‘X’.
END-OF-DEFINITION.
DEFINE alv_set_title.
L_TITLE = &1.
END-OF-DEFINITION.
****DEFINE alv_set_title.
**** i_grid_title = &1.
****END-OF-DEFINITION.
DEFINE alv_show_data.
******启动命令功能********************************
REFRESH I_EVENTS.
CALL FUNCTION ‘REUSE_ALV_EVENTS_GET’
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS.
READ TABLE I_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND
INTO L_LS_EVENT.
***** BREAK-POINT.
IF SY-SUBRC = 0.
MOVE G_USER_COMMAND TO L_LS_EVENT-FORM.
APPEND L_LS_EVENT TO I_EVENTS.
ENDIF.
IF L_FM_BUTTON = ‘X’.
****** 一定要在报表程序中定义此Form: FORM fm_button USING e_grid TYPE slis_data_caller_exit.
L_LS_EVENT-NAME = ‘CALLER_EXIT’.
L_LS_EVENT-FORM = ‘FM_BUTTON’.
APPEND L_LS_EVENT TO I_EVENTS.
ENDIF.
********为alv添加top_of_page
IF LV_TOP_PAGE = ‘X’.
CLEAR L_LS_EVENT.
READ TABLE I_EVENTS INTO L_LS_EVENT WITH KEY NAME = G_TOP_OF_PAGE.
IF SY-SUBRC = 0.
MOVE G_TOP_OF_PAGE TO L_LS_EVENT-FORM.
MODIFY I_EVENTS FROM L_LS_EVENT INDEX SY-TABIX.
ELSE.
L_LS_EVENT-FORM = G_TOP_OF_PAGE.
L_LS_EVENT-NAME = G_TOP_OF_PAGE.
APPEND L_LS_EVENT TO I_EVENTS.
ENDIF.
ENDIF.
IF HELPF4 = ‘X’.
PERFORM CREATE_F4EVENT_EXITS.
ENDIF.
******** Control data ************************************
I_LAYOUT-ZEBRA = ‘X’.
I_LAYOUT-GET_SELINFOS = ‘X’.
I_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.
I_LAYOUT-DETAIL_POPUP = ‘X’.
I_LAYOUT-NO_KEYFIX = ”.
I_LAYOUT-GET_SELINFOS = ‘X’.
GS_LAYOUT-ZEBRA = ‘X’.
GS_LAYOUT-CWIDTH_OPT = ‘X’.
“gs_layout-detailinit = ‘X’. ” 初始值
GS_LAYOUT-SEL_MODE = ‘A’ .
IF L_TITLE IS NOT INITIAL.
I_LAYOUT-WINDOW_TITLEBAR = L_WINDOW_TITLEBAR. “抬头显示
ENDIF.
******* Begin Output Display data.
IF STATUS IS INITIAL.
IF LV_TOP_PAGE = ‘X’. “
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = GS_LAYOUT
IT_FIELDCAT_LVC = I_FIELDCAT[]
I_SAVE = ‘A’
I_CALLBACK_USER_COMMAND = G_USER_COMMAND
I_CALLBACK_TOP_OF_PAGE = G_TOP_OF_PAGE
*** “i_callback_pf_status_set = ‘SET_PF_STATUS’
IS_VARIANT = G_VARIANT
IT_EVENTS = I_EVENTS
IT_SORT_LVC = IT_SORT[]
IS_PRINT_LVC = GS_PRINT
I_GRID_TITLE = L_TITLE ” 报表TITLE
TABLES
T_OUTTAB = &1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ELSE.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = GS_LAYOUT
IT_FIELDCAT_LVC = I_FIELDCAT[]
I_SAVE = ‘A’
I_CALLBACK_USER_COMMAND = G_USER_COMMAND
*** “i_callback_pf_status_set = ‘SET_PF_STATUS’
IS_VARIANT = G_VARIANT
IT_EVENTS = I_EVENTS
IT_SORT_LVC = IT_SORT[]
IS_PRINT_LVC = GS_PRINT
I_GRID_TITLE = L_TITLE ” 报表TITLE
TABLES
T_OUTTAB = &1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDIF.
**************** 增加状态按钮
ELSE. ” if status is initial.
IF LV_TOP_PAGE = ‘X’.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = GS_LAYOUT
IT_FIELDCAT_LVC = I_FIELDCAT[]
I_SAVE = ‘A’
I_CALLBACK_USER_COMMAND = G_USER_COMMAND
I_CALLBACK_TOP_OF_PAGE = G_TOP_OF_PAGE
I_CALLBACK_PF_STATUS_SET = ‘SET_PF_STATUS’
IS_VARIANT = G_VARIANT
IT_EVENTS = I_EVENTS
IT_SORT_LVC = IT_SORT[]
IS_PRINT_LVC = GS_PRINT
I_GRID_TITLE = L_TITLE ” 报表TITLE
TABLES
T_OUTTAB = &1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ELSE.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT_LVC = GS_LAYOUT
IT_FIELDCAT_LVC = I_FIELDCAT[]
I_SAVE = ‘A’
I_CALLBACK_USER_COMMAND = G_USER_COMMAND
I_CALLBACK_PF_STATUS_SET = ‘SET_PF_STATUS’
IS_VARIANT = G_VARIANT
IT_EVENTS = I_EVENTS
IT_SORT_LVC = IT_SORT[]
IS_PRINT_LVC = GS_PRINT
I_GRID_TITLE = L_TITLE ” 报表TITLE
TABLES
T_OUTTAB = &1
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
ENDIF.
ENDIF.
******* End Begin Output Display data.
END-OF-DEFINITION.
*&———————————————————————*
*& Form fm_button
*&———————————————————————*
* text 回车事件
*———————————————————————-*
* –>E_GRID text
*———————————————————————-*
*&———————————————————————*
*& Form user_command
*&———————————————————————*
* text
*———————————————————————-*
* –>R_UCOMM text
* –>ENDFORM text
*———————————————————————-*
FORM user_command1 USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
ENDFORM. “user_command1
*&———————————————————————*
*& Form GET_LENG
*&———————————————————————*
* text
*———————————————————————-*
* –>STAB text
* –>SIT text
*———————————————————————-*
FORM get_leng TABLES stab sit STRUCTURE i_fieldcat .
*—————————————————————————–
DATA: descr_ref TYPE REF TO cl_abap_structdescr.
DATA: l_length TYPE i.
FIELD-SYMBOLS:
<comp_wa> TYPE abap_compdescr.
descr_ref ?= cl_abap_typedescr=>describe_by_data( stab ).
LOOP AT descr_ref->components ASSIGNING <comp_wa>.
LOOP AT sit.
IF sit-fieldname = <comp_wa>-name AND <comp_wa>-type_kind = ‘C’.
sit-outputlen = <comp_wa>-length / 2.
MODIFY sit.
ENDIF.
IF sit-fieldname = ‘ICON’.
sit-icon = ‘X’.
MODIFY sit.
ENDIF.
IF sit-fieldname = ‘CHKBOX’.
* “sit-seltext_m = ‘SELECT’.
sit-reptext = ‘SELECT’.
sit-checkbox = ‘X’.
sit-outputlen = 1.
sit-edit = ‘X’.
sit-icon = ‘X’.
MODIFY sit.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. “get_leng
*&———————————————******************************
*& Form SUB_F4_HELP
*& 定义SUB_F4_HELP
* 弹出f4
*———————————————*******************************
FORM create_f4event_exits.
DATA: wa_events TYPE slis_alv_event.
wa_events-name = ‘CALLER_EXIT’.
wa_events-form = ‘CALLER_EXIT’.
APPEND wa_events TO i_events.
ENDFORM. “create_f4event_exits
*&———————————————————————*
*& Form SET_GOS
*&———————————————————————*
* text
*———————————————————————-*
* –>P_TYPE text
* –>P_KEY text
*———————————————————————-*
FORM set_gos USING p_type
p_key.
*The function only for dialog user.
DATA: lo_manager TYPE REF TO cl_gos_manager,
la_obj TYPE borident.
*Set object Key
la_obj-objtype = p_type.
la_obj-objkey = p_key.
*
* GOS toolbar
CREATE OBJECT lo_manager
EXPORTING
is_object = la_obj
ip_no_commit = space
EXCEPTIONS
OTHERS = 1.
ENDFORM. ” FULL_HEAD_CHKBOX
*&———————————————————————*
*& Form FILL_FIELD
*&———————————————————————*
* text
*———————————————————————-*
* –>PF_FIELD text
* –>PF_DESC text
*———————————————————————-*
FORM fill_field USING pf_field pf_desc.
* TRANSLATE PF_FIELD TO UPPER CASE.
it_fc-fieldname = pf_field.
it_fc-seltext_l = pf_desc.
APPEND it_fc.
ENDFORM. “FILL_FIELD
FORM log_data_create.
DATA
l_s_log TYPE bal_s_log.
l_s_log-aldate = sy-datum.
l_s_log-aluser = sy-uname.
l_s_log-altime = sy-uzeit.
l_s_log-object = ‘Z000’.
l_s_log-subobject = ‘ADDON’.
l_s_log-aldate_del = sy-datum + 30.
l_s_log-del_before = ”.
l_s_log-alstate = ‘1’.
CALL FUNCTION ‘BAL_LOG_CREATE’
EXPORTING
i_s_log = l_s_log
* IMPORTING
* e_log_handle = p_log_handle
EXCEPTIONS
OTHERS = 0.
ENDFORM.
FORM log_data_save.
CALL FUNCTION ‘BAL_DB_SAVE’
EXPORTING
* I_IN_UPDATE_TASK = ‘ ‘
i_save_all = ‘X’
* I_T_LOG_HANDLE =
* IMPORTING
* E_NEW_LOGNUMBERS =
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.
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 log_msg_add USING
p_msgty TYPE symsgty
p_msgv1 TYPE symsgv
p_msgv2 TYPE symsgv
p_msgv3 TYPE symsgv
p_msgv4 TYPE symsgv.
.
DATA:
l_s_msg TYPE bal_s_msg.
l_s_msg-msgty = p_msgty.
l_s_msg-msgid = ‘Z01’.
l_s_msg-msgno = ‘000’.
l_s_msg-msgv1 = p_msgv1.
l_s_msg-msgv2 = p_msgv2.
l_s_msg-msgv3 = p_msgv3.
l_s_msg-msgv4 = p_msgv4.
l_s_msg-probclass = 4.
CALL FUNCTION ‘BAL_LOG_MSG_ADD’
EXPORTING
* i_log_handle = p_log_handle
i_s_msg = l_s_msg
* IMPORTING
* E_S_MSG_HANDLE =
* E_MSG_WAS_LOGGED =
* E_MSG_WAS_DISPLAYED =
* EXCEPTIONS
* LOG_NOT_FOUND = 1
* MSG_INCONSISTENT = 2
* OTHERS = 3
.
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.
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19571.html