alv - 事件详解

 

TYPE-POOLS: SLIS.

DATA: G_COMMAND   TYPE SLIS_FORMNAME VALUE 'FRM_PROCESS_USER_COMMAND',
      g_fieldcat  TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
      GD_REPID    LIKE SY-REPID VALUE 'SY-REPID',
      GD_LAYOUT   TYPE SLIS_LAYOUT_ALV.

 

  
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID
      I_CALLBACK_PF_STATUS_SET ='FRM_SET_PF'          " status 设定
      I_CALLBACK_USER_COMMAND  = G_COMMAND            " 这里可以写操作事件(status)
      i_callback_html_top_of_page = 'ALV_TOP_OF_PAGE' " alv 头设置
      I_SAVE                   = 'A'                  " 设定 status 显示或者隐藏
      IS_LAYOUT                = GD_LAYOUT            " alv  的格式
      IT_FIELDCAT              = g_fieldcat[]         " alv 字段设置
    TABLES
      T_OUTTAB                 = IT_ITAB.

 

*---------------------------------------------
 status 响应事件
*---------------------------------------------
form  FRM_PROCESS_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
                                     RS_SELFIELD TYPE SLIS_SELFIELD.

  CASE R_UCOMM.
    WHEN 'BACK' OR 'CANC' OR 'EXIT'.

    WHEN 'PNT'.

    WHEN 'EXPORT'.

  ENDCASE.

ENDform.                    "FRM_PROCESS_USER_COMMAND


*---------------------------------------------
"设置alv 界面的status
*---------------------------------------------
FORM frm_set_pf USING extab TYPE slis_t_extab .

  SET PF-STATUS 'STANDARD'.

ENDFORM.                    "frm_set_pf


*---------------------------------------------
"alv 头信息
*---------------------------------------------
FORM alv_top_of_page USING cl_dd TYPE REF TO cl_dd_document.
  DATA: m_p TYPE i.
  DATA: m_buff TYPE string.
  DATA: M_BUFF1 TYPE STRING,
        M_BUFF2 TYPE STRING.

  DATA: NAME TYPE STRING.
  LOOP AT IT_OUTPUT INTO WA_OUTPUT.
    NAME = WA_OUTPUT-BUTXT.
  ENDLOOP.
  LOOP AT RA_BUKRS .
    CONCATENATE M_BUFF1 RA_BUKRS-LOW INTO M_BUFF1 SEPARATED BY SPACE.
  ENDLOOP.
  IF NAME = '建运部汇总'.
    CONCATENATE '<table width =1024 HIGHT =10 ><tr><td width=400>编制单位:'NAME '</td><td width=400>'textqj'</td><td width=200>单位:元</td></tr><tr><td width = 400>汇总单位:'M_BUFF1'</td></tr></table>'
          INTO M_BUFF2.
  ELSE.
    CONCATENATE '<table width =1024 HIGHT =10 ><tr><td width=400>编制单位:'NAME '</td><td width=400>'textqj'</td><td width=200>单位:元</td></tr></table>'
          INTO M_BUFF2.
 ENDIF.

 

    m_buff = '<html>'.
    CALL METHOD cl_dd->html_insert
      EXPORTING
        contents = m_buff
      CHANGING
        position = m_p.

    m_buff = '<center><H3>资产负债表</H3></center>'.
    CALL METHOD cl_dd->html_insert
      EXPORTING
        contents = m_buff
      CHANGING
        position = m_p.

    CALL METHOD cl_dd->html_insert
      EXPORTING
        contents = m_buff2
      CHANGING
        position = m_p.


    m_buff = '</html>'.
    CALL METHOD cl_dd->html_insert
      EXPORTING
        contents = m_buff
      CHANGING
        position = m_p.

  ENDFORM .                    "alv_top_of_page

*---------------------------------------------
* alv 显示格式
*---------------------------------------------
FORM FRM_LAYOUT .

  GD_LAYOUT-ZEBRA = 'X'.
  GD_LAYOUT-DETAIL_POPUP = 'X'.
  GD_REPID = SY-REPID.
  GD_LAYOUT-F2CODE = '&ETA'.
  GD_LAYOUT-NO_VLINE             = ' '.
  GD_LAYOUT-COLWIDTH_OPTIMIZE    = 'X'.
  GD_LAYOUT-DETAIL_INITIAL_LINES = 'X'.
  GD_LAYOUT-DETAIL_TITLEBAR      = ''.

ENDFORM.                    "FRM_LAYOUT

 

*---------------------------------------------
* alv 的单元格和 字段之间的关联
*---------------------------------------------
FORM FRM_G_FIELDCAT  USING P_FIELDNAME    TYPE slis_fieldname
                           p_reptext_ddic LIKE dd03p-reptext
                           P_JUST
                           P_NO.

  g_fieldcat-fieldname = p_fieldname .
  g_fieldcat-reptext_ddic = p_reptext_ddic .
  g_fieldcat-just = P_JUST.
  G_FIELDCAT-NO_ZERO = P_NO.
  APPEND g_fieldcat.

ENDFORM.                   " FRM_G_FIELDCAT

你可能感兴趣的:(alv - 事件详解)