SAP

ABAP更新ALV后自适应列宽

2021-12-25  本文已影响0人  JayDragon

有些操作会更新ALV的某个字段值,例如消息字段,此时会希望ALV的消息字段会根据内容自动调整列宽:

FORM frm_user_command USING r_ucomm TYPE sy-ucomm
                            rs_selfield TYPE slis_selfield.

  DATA: lr_grid   TYPE REF TO cl_gui_alv_grid,
        ls_layout TYPE lvc_s_layo.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      e_grid = lr_grid.
  CASE r_ucomm.
    WHEN 'ZCANCEL'.
      PERFORM frm_cancel.
    WHEN 'ZSAVE'.
      PERFORM frm_save.
  ENDCASE.
  CALL METHOD lr_grid->get_frontend_layout
    IMPORTING
      es_layout = ls_layout.
  ls_layout-cwidth_opt = 'X'.    "最优宽
  CALL METHOD lr_grid->set_frontend_layout
    EXPORTING
      is_layout = ls_layout.
  CALL METHOD lr_grid->check_changed_data.
  rs_selfield-refresh = 'X' .
ENDFORM. "FRM_USER_COMMAND
上一篇下一篇

猜你喜欢

热点阅读