代码如下
PARAMETERS p_layout TYPE disvariant-variant.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_layout.
PERFORM f4_layout CHANGING p_layout.
FORM f4_layout CHANGING p_variant TYPE disvariant-variant.
DATA: l_exit TYPE char1.
is_variant-report = sy-repid.
CALL FUNCTION 'REUSE_ALV_VARIANT_F4'
EXPORTING
is_variant = is_variant
i_save = 'A'
IMPORTING
e_exit = l_exit
es_variant = is_variant
EXCEPTIONS
not_found = 1.
IF sy-subrc = 1.
MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
IF l_exit IS INITIAL.
p_variant = is_variant-variant.
ENDIF.
ENDIF.
ENDFORM. "f4_layout