本人诚心接ABAP远程开发任务,价格公道,有需要的联系我,欢迎个人,甲方爸爸,乙方私信联系。
客制化的F4帮助 DEMO 如下
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_COTNO-LOW.
PERFORM FRM_F4_FOR_COTNO USING 'S_COTNO-LOW'.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR S_COTNO-HIGH.
PERFORM FRM_F4_FOR_COTNO USING 'S_COTNO-HIGH'.
FORM FRM_F4_FOR_COTNO USING P_FIELD TYPE HELP_INFO-DYNPROFLD.
TYPES: BEGIN OF TY_COTNO,
COTNO TYPE ZHKEDITR-COTNO,
END OF TY_COTNO.
DATA: LT_COTNO TYPE STANDARD TABLE OF TY_COTNO.
SELECT DISTINCT
COTNO
FROM ZHKEDITR
INTO CORRESPONDING FIELDS OF TABLE LT_COTNO.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
RETFIELD = 'COTNO'
DYNPPROG = SY-REPID
DYNPNR = SY-DYNNR
DYNPROFIELD = P_FIELD
VALUE_ORG = 'S'
TABLES
VALUE_TAB = LT_COTNO
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM. " FRM_F4_HELP
根据结构自动创建field catlog
* alv字段列表。
DATA: GT_FIELDCAT TYPE LVC_T_FCAT.
DATA: GS_FIELDCAT TYPE LVC_S_FCAT.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
I_STRUCTURE_NAME = 'ZSDS_UI_REPORTS_ALV' "alv 结构名
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
CT_FIELDCAT = GT_FIELDCAT
EXCEPTIONS
INCONSISTENT_INTERFACE = 1
PROGRAM_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
用户单击跳转标准tcode
"首先将需要单击的字段设置成hotspot
LOOP AT GT_FIELDCAT INTO GS_FIELDCAT.
IF GS_FIELDCAT-FIELDNAME = 'VGBEL'.
GS_FIELDCAT-HOTSPOT = 'X'.
ENDIF.
MODIFY GT_FIELDCAT FROM GS_FIELDCAT.
ENDLOOP.
" 这个form里面获取点击的行和字段的值
FORM FRM_ALV_USERCOMMAND USING IV_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
DATA:LS_STABLE TYPE LVC_S_STBL. " 稳定刷新
DATA LCL_ALV TYPE REF TO CL_GUI_ALV_GRID.
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
E_GRID = LCL_ALV.
CALL METHOD LCL_ALV->CHECK_CHANGED_DATA.
*
GV_OKCODE = IV_UCOMM.
CASE GV_OKCODE.
WHEN '&IC1'.
"获取行号
READ TABLE GT_DATA INTO GS_DATA INDEX RS_SELFIELD-TABINDEX.
IF RS_SELFIELD-FIELDNAME = 'VGBEL'.
SET PARAMETER ID 'VL' FIELD GS_DATA-VGBEL. "F1查看事务代码屏幕的parameter ID
CALL TRANSACTION 'VL33N' AND SKIP FIRST SCREEN. "调用事务代码跳过初始屏幕
ENDIF.
WHEN 'SEND'.
WHEN OTHERS.
ENDCASE.
LS_STABLE-ROW = 'X'.
LS_STABLE-COL = 'X'.
* 刷新ALV 基于行列的稳定刷新
CALL METHOD LCL_ALV->REFRESH_TABLE_DISPLAY
EXPORTING
IS_STABLE = LS_STABLE.
ENDFORM. "frm_alv_usercommand
设置单元格可编辑
*首先在这个结构中增加 CELTAB
DATA: BEGIN OF ty_data.
INCLUDE STRUCTURE zsds_sales_receipt_alv.
DATA: celtab TYPE lvc_t_styl.
DATA: BOX TYPE CHAR01.
DATA: END OF ty_data.
DATA: gs_data LIKE STANDARD TABLE OF ty_data.
DATA: gs_data LIKE ty_data.
*第二步在layout 中 设置
gs_layout-stylefname = 'CELTAB'. "将内表中的字段名存入显示格式(设置是否可编辑)
*第三步在field catlog中设置部分列全部可编辑
gs_fieldcat-edit = 'X'.
*第四步根据条件去设置是否具体某一行是否可编辑
"设置单元格不可输入
DATA: ls_celtab TYPE lvc_s_styl.
CLEAR: ls_celtab.
ls_celtab-fieldname = 'ZWRBTR'.
ls_celtab-style = cl_gui_alv_grid=>mc_style_disabled.
INSERT ls_celtab INTO TABLE gs_yys-celtab.
制定输入内容的弹窗,无需对话屏幕
实现效果如下:
实现代码如下:
DATA:lv_ret TYPE c,
lt_tab TYPE STANDARD TABLE OF sval WITH HEADER LINE.
CLEAR lt_tab.
lt_tab-tabname = 'ZMMS_HARDWARE_INVENTORY_ALV'.
lt_tab-fieldname = 'ZCWEI'.
APPEND lt_tab.
CLEAR lt_tab.
lt_tab-tabname = 'ZMMS_HARDWARE_INVENTORY_ALV'.
lt_tab-fieldname = 'ZKCSL'.
lt_tab-fieldtext = '转移数量'.
lt_tab-field_attr = ''.
* lt_tab-comp_tab = 'ZMMS_HARDWARE_INVENTORY_ALV'.
* lt_tab-comp_field = 'ZKCSL'.
APPEND lt_tab.
CALL FUNCTION 'POPUP_GET_VALUES_USER_HELP'
EXPORTING
f4_formname = 'ZCWEI_F4' "F4搜索帮助
f4_programname = 'ZMMR057'
programname = 'ZMMR057' "弹窗的程序
formname = 'FRM_ZCWEI_CHECK' "校验输入值
popup_title = '库存调整输入框' "弹窗名
IMPORTING
returncode = lv_ret
TABLES
fields = lt_tab
EXCEPTIONS
error_in_fields = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
READ TABLE lt_tab WITH KEY fieldname = 'ZCWEI'.
IF sy-subrc = 0.
CONDENSE lt_tab-value.
ev_zcwei = lt_tab-value.
ENDIF.
READ TABLE lt_tab WITH KEY fieldname = 'ZKCSL'.
IF sy-subrc = 0.
CONDENSE lt_tab-value.
ev_menge = lt_tab-value.
ENDIF.
ENDIF.
*F4 帮助
FORM zcwei_f4 USING tabname fieldname display
CHANGING returncode value.
DATA:ls_fields TYPE sval.
DATA: BEGIN OF f_tab OCCURS 10.
INCLUDE STRUCTURE help_value.
DATA: END OF f_tab,
BEGIN OF v_tab OCCURS 200,
value(40) TYPE c,
END OF v_tab.
DATA: help_fieldname LIKE help_info-fieldname. "B20K069688
IF fieldname = 'ZCWEI'.
MOVE fieldname TO help_fieldname. "B20K069688
f_tab-tabname = 'ZTM_CWXXB'.
f_tab-fieldname = 'ZCWEI'.
f_tab-selectflag = 'X'.
APPEND f_tab.
.
DATA lt_ztm_cwxxb TYPE TABLE OF ztm_cwxxb.
DATA ls_ztm_cwxxb TYPE ztm_cwxxb.
CLEAR:lt_ztm_cwxxb,ls_ztm_cwxxb.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_ztm_cwxxb
FROM ztm_cwxxb
WHERE werks = gs_data-werks
AND lgort = gs_data-lgort.
LOOP AT lt_ztm_cwxxb INTO ls_ztm_cwxxb.
v_tab = ls_ztm_cwxxb-zcwei.
APPEND v_tab.
ENDLOOP.
CALL FUNCTION 'HELP_VALUES_GET_WITH_TABLE'
EXPORTING
display = display "B20K011756
fieldname = help_fieldname "B20K069688
tabname = tabname
IMPORTING
select_value = value
TABLES
valuetab = v_tab
fields = f_tab.
gv_zcwei = value.
ENDIF.
ENDFORM.
*检查输入值
FORM frm_zcwei_check TABLES fields STRUCTURE sval
CHANGING error STRUCTURE svale.
*
DATA lt_ztm_cwxxb TYPE TABLE OF ztm_cwxxb.
DATA lv_zcwei TYPE ztm_cwxxb-zcwei.
DATA: lv_menge TYPE menge_d.
CLEAR:lv_zcwei,lt_ztm_cwxxb.
DATA: ls_fields TYPE sval.
READ TABLE fields INTO ls_fields WITH KEY fieldname = 'ZCWEI'.
IF sy-subrc = 0.
CONDENSE ls_fields-value.
lv_zcwei = ls_fields-value.
IF lv_zcwei = gs_data-zcwei.
CLEAR error.
error-errortab = 'ZMMS_HARDWARE_INVENTORY_ALV'. "*019i
error-errorfield = 'ZCWEI'. "*019i
error-msgty = 'E'.
error-msgid = 'ZMM01'.
error-msgno = '002'.
error-msgv1 = |转移仓位:{ lv_zcwei }与原仓位相同!|.
EXIT.
ELSE.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_ztm_cwxxb
FROM ztm_cwxxb
WHERE werks = gs_data-werks
AND lgort = gs_data-lgort
AND zcwei = lv_zcwei.
IF sy-subrc <> 0.
CLEAR error.
error-errortab = 'ZMMS_HARDWARE_INVENTORY_ALV'. "*019i
error-errorfield = 'ZCWEI'. "*019i
error-msgty = 'E'.
error-msgid = 'ZMM01'.
error-msgno = '002'.
error-msgv1 = |仓位:{ lv_zcwei }在仓位信息表中不存在!|.
EXIT.
ENDIF.
ENDIF.
ENDIF.
READ TABLE fields INTO ls_fields WITH KEY fieldname = 'ZKCSL'.
IF sy-subrc = 0.
CONDENSE ls_fields-value.
lv_menge = ls_fields-value.
IF lv_menge > gs_data-zkcsl.
CLEAR error.
error-errortab = 'ZMMS_HARDWARE_INVENTORY_ALV'. "*019i
error-errorfield = 'ZKCSL'. "*019i
error-msgty = 'E'.
error-msgid = 'ZMM01'.
error-msgno = '002'.
error-msgv1 = |转移数量:{ lv_menge }大于仓位内剩余数量!|.
EXIT.
ENDIF.
ENDIF.
ENDFORM.
F4帮助弹出选择框 供选择
实现效果如下
实现代码如下
FORM frm_get_zcwei_data USING p_fieldname TYPE lvc_fname
p_row_no TYPE lvc_s_roid
pr_event_data TYPE REF TO cl_alv_event_data.
TYPES: BEGIN OF ty_pop.
TYPES:c_sel TYPE char1.
INCLUDE TYPE ztm_sxhjkcb.
TYPES: maktx TYPE makt-maktx,
END OF ty_pop.
DATA: lt_popup TYPE TABLE OF ty_pop.
DATA: ls_selfield TYPE slis_selfield.
DATA: lv_tabname TYPE char20.
DATA: lv_structure TYPE dd02l-tabname.
DATA: lv_where TYPE string.
FIELD-SYMBOLS: TYPE lvc_t_modi.
DATA: lt_return TYPE STANDARD TABLE OF ddshretval,
ls_return TYPE ddshretval.
DATA: ls_mod_cell TYPE lvc_s_modi.
DATA: lt_item LIKE STANDARD TABLE OF ty_item.
CHECK p_fieldname = 'ZCWEI'.
READ TABLE gt_item INTO DATA(ls_item) INDEX p_row_no-row_id.
READ TABLE gt_head INTO DATA(ls_head) WITH KEY vbeln = ls_item-vbeln
posnr = ls_item-posnr.
IF ls_item-idnrk IS NOT INITIAL.
lv_where = 'MATNR EQ @LS_ITEM-IDNRK'.
ENDIF.
IF ls_head-werks IS NOT INITIAL.
lv_where = lv_where && ' AND ' && ' WERKS EQ @LS_HEAD-WERKS'.
ENDIF.
IF ls_head-lgort IS NOT INITIAL.
lv_where = lv_where && ' AND ' && ' LGORT EQ @LS_HEAD-LGORT'.
ENDIF.
IF ls_item-charg IS NOT INITIAL.
lv_where = lv_where && ' AND ' && ' CHARG EQ @LS_ITEM-CHARG'.
ENDIF.
* IF ls_zsmmr013n_i4-lifnr IS NOT INITIAL.
* lv_where = lv_where && ' AND ' && ' ZCSHA EQ @LS_ZSMMR013N_I4-LIFNR'.
* ENDIF.
IF ls_item-vbeln IS NOT INITIAL.
lv_where = lv_where && ' AND ' && ' VBELN EQ @LS_ITEM-VBELN'.
ENDIF.
IF ls_item-posnr IS NOT INITIAL.
lv_where = lv_where && ' AND ' && ' VBELP EQ @LS_ITEM-POSNR'.
ENDIF.
SELECT * FROM ztm_sxhjkcb WHERE (lv_where) INTO CORRESPONDING FIELDS OF TABLE @lt_popup.
lv_tabname = 'LT_POPUP'.
lv_structure = 'ZTM_SXHJKCB'.
CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_checkbox_fieldname = 'C_SEL'
i_tabname = lv_tabname
i_structure_name = lv_structure
i_screen_start_column = 10
i_screen_start_line = 10
i_screen_end_column = 200
i_screen_end_line = 30
IMPORTING
es_selfield = ls_selfield
TABLES
t_outtab = lt_popup
EXCEPTIONS
program_error = 1
OTHERS = 2.
READ TABLE lt_popup TRANSPORTING NO FIELDS WITH KEY c_sel = 'X'.
IF sy-subrc <> 0.
RETURN.
ENDIF.
LOOP AT lt_popup ASSIGNING FIELD-SYMBOL() WHERE c_sel = 'X'.
APPEND INITIAL LINE TO lt_item ASSIGNING FIELD-SYMBOL().
MOVE-CORRESPONDING ls_item TO .
-zcwei = -zcwei.
-zzjsl = -zkcsl.
-charg = -charg.
ENDLOOP.
DELETE gt_item INDEX p_row_no-row_id.
APPEND LINES OF lt_item TO gt_item.
pr_event_data->m_event_handled = 'X'.
CHECK sy-subrc IS INITIAL AND ls_return-fieldval IS NOT INITIAL.
ASSIGN pr_event_data->m_data->* TO .
ls_mod_cell-row_id = p_row_no-row_id.
ls_mod_cell-fieldname = p_fieldname.
ls_mod_cell-value = ls_return-fieldval.
APPEND ls_mod_cell TO .
ENDFORM.
SAP 标准消息的报错
DATA: gt_smesg TYPE tsmesg WITH HEADER LINE.
PERFORM frm_add_message USING 'E' lv_message '' .
FORM frm_add_message USING uv_msgty uv_msgv1 uv_msgv2 .
APPEND INITIAL LINE TO gt_smesg ASSIGNING FIELD-SYMBOL().
-msgty = uv_msgty.
-arbgb = 'ZMM01'.
-txtnr = '000'.
-msgv1 = uv_msgv1.
-msgv2 = uv_msgv2.
ENDFORM.
CALL FUNCTION 'FB_MESSAGES_DISPLAY_POPUP'
EXPORTING
it_smesg = gt_smesg[]
EXCEPTIONS
no_messages = 1
popup_cancelled = 2
OTHERS = 3.
自动设置全屏
DATA: GO_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER.
DATA: GO_CONTAINER TYPE REF TO CL_GUI_CONTAINER,
GO_GRID TYPE REF TO CL_GUI_ALV_GRID.
"自动设置全屏
IF GO_SPLITTER IS INITIAL .
CREATE OBJECT GO_SPLITTER
EXPORTING
PARENT = CL_GUI_CONTAINER=>SCREEN0
ROWS = 1
COLUMNS = 1.
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = GO_CONTAINER.
ENDIF .
CREATE OBJECT GO_GRID
EXPORTING
I_PARENT = GO_CONTAINER.
SPLITTER 设置分屏
DATA: GO_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER, "控件拆分
GO_CONTAINER1 TYPE REF TO CL_GUI_CONTAINER,
GO_CONTAINER2 TYPE REF TO CL_GUI_CONTAINER,
GO_GRID1 TYPE REF TO CL_GUI_ALV_GRID,
GO_GRID2 TYPE REF TO CL_GUI_ALV_GRID.
IF GO_SPLITTER IS INITIAL .
CREATE OBJECT GO_SPLITTER
EXPORTING
PARENT = CL_GUI_CONTAINER=>SCREEN0
ROWS = 2
COLUMNS = 1.
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = GO_CONTAINER1.
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = GO_CONTAINER2.
ENDIF .
设置屏幕不可输入
LOOP AT SCREEN.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDLOOP.