ABAP ALV中设置CHECKBOX同时选中事件

自己测试内容,仅供参考。

直接上代码:

DATA : LS_LAYOUT               TYPE   SLIS_LAYOUT_ALV .
DATA : CT_FIELDCAT             TYPE   SLIS_T_FIELDCAT_ALV .
DATA : GT_FIELDCATALOG         TYPE  SLIS_T_FIELDCAT_ALV  .
DATA : LS_CT_FIELDCAT          LIKE  LINE  OF  CT_FIELDCAT .
DATA : LS_IT_FIELDCATALOG      LIKE  LINE  OF  GT_FIELDCATALOG .
DATA : LV_GRID_TITLE           TYPE   LVC_TITLE  .
DATA : LV_ALV_STRUCTURE        TYPE  DD02L - TABNAME  VALUE  'ZLM_SPFLI' .

DATA : GT_ALV                  TYPE  TABLE  OF  ZLM_SPFLI .
DATA : GS_ALV                  TYPE   ZLM_SPFLI .
FIELD-SYMBOLS         LIKE  LINE  OF  GT_ALV .


START-OF-SELECTION .

   "get data
   PERFORM  FRM_GET_DATA .

   "alv show
   PERFORM  FRM_ALV_SHOW .


*&---------------------------------------------------------------------*
*&      Form  ZFORM_SET_PF_STATUS_FC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM  ZFORM_SET_PF_STATUS  USING  RT_EXTAB  TYPE  SLIS_T_EXTAB .
   SET  PF-STATUS  'STATUS'  .
ENDFORM .                     "zform_set_PF_STATUS

*&---------------------------------------------------------------------*
*&      Form  alv_user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM   ALV_USER_COMMAND  USING   R_UCOMM  LIKE   SY - UCOMM
      RS_SELFIELD  TYPE   SLIS_SELFIELD .

   DATA :  L_GRID  TYPE  REF  TO  CL_GUI_ALV_GRID .
   DATA :  LV_VALUE  TYPE  CHAR20 .


   CALL  FUNCTION  'GET_GLOBALS_FROM_SLVC_FULLSCR'
     IMPORTING
      E_GRID  =  L_GRID .

   CALL  METHOD  L_GRID -> CHECK_CHANGED_DATA .
   CALL  METHOD  L_GRID -> REFRESH_TABLE_DISPLAY .

  RS_SELFIELD - REFRESH  =  'X' .

  RS_SELFIELD - COL_STABLE  =  'X' .
  RS_SELFIELD - ROW_STABLE  =  'X' .

   CASE   R_UCOMM .

     WHEN  '&IC1' . "热键

       CASE  RS_SELFIELD - FIELDNAME .

         WHEN  'CHECKBOX'  .

           PERFORM  FRM_CHECK_BOX  USING  RS_SELFIELD .

         WHEN  OTHERS .

       ENDCASE .

     WHEN  'BACK' .
       LEAVE  TO  SCREEN  0 .
     WHEN  'LEAVE' .
       LEAVE  PROGRAM .
   ENDCASE  .


   CALL  METHOD  L_GRID -> CHECK_CHANGED_DATA .
   CALL  METHOD  L_GRID -> REFRESH_TABLE_DISPLAY .
ENDFORM .


*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_BOX
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM  FRM_CHECK_BOX  USING  RS_SELFIELD  TYPE   SLIS_SELFIELD .  .
   READ  TABLE  GT_ALV  INTO  GS_ALV  INDEX  RS_SELFIELD - TABINDEX .

   CHECK  SY - SUBRC  =  0 .

   LOOP  AT  GT_ALV  ASSIGNING 
     WHERE
      CARRID  =  GS_ALV - CARRID  .

     IF  - CHECKBOX  =  'X' .
       CLEAR  - CHECKBOX .
     ELSE .
       - CHECKBOX  =  'X' .
     ENDIF .

   ENDLOOP .
ENDFORM .
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM  FRM_GET_DATA  .
   "get data
   SELECT  *  FROM  SPFLI  INTO  CORRESPONDING  FIELDS  OF  TABLE  GT_ALV .

ENDFORM .
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM  FRM_ALV_SHOW  .
   CALL  FUNCTION  'REUSE_ALV_FIELDCATALOG_MERGE'
     EXPORTING
      I_STRUCTURE_NAME        =  LV_ALV_STRUCTURE
     CHANGING
      CT_FIELDCAT             =  CT_FIELDCAT
     EXCEPTIONS
      INCONSISTENT_INTERFACE  =  1
      PROGRAM_ERROR           =  2
       OTHERS                  =  3 .

   CLEAR  GT_FIELDCATALOG[] .

   LOOP  AT  CT_FIELDCAT  INTO  LS_CT_FIELDCAT  .
     MOVE-CORRESPONDING  LS_CT_FIELDCAT  TO  LS_IT_FIELDCATALOG .

    LS_IT_FIELDCATALOG - SELTEXT_L  =  LS_CT_FIELDCAT - SELTEXT_L .
    LS_IT_FIELDCATALOG - SELTEXT_M  =  LS_CT_FIELDCAT - SELTEXT_M .
    LS_IT_FIELDCATALOG - SELTEXT_S  =  LS_CT_FIELDCAT - SELTEXT_S .

     CASE  LS_IT_FIELDCATALOG - FIELDNAME  .
         "如果有复选框
       WHEN  'CHECKBOX' .
        LS_IT_FIELDCATALOG - OUTPUTLEN  =  8 .
        LS_IT_FIELDCATALOG - DDICTXT  =  '选择' .
        LS_IT_FIELDCATALOG - SELTEXT_L  =  '选择' .
        LS_IT_FIELDCATALOG - SELTEXT_M  =  '选择' .
        LS_IT_FIELDCATALOG - SELTEXT_S  =  '选择' .
        LS_IT_FIELDCATALOG - REPTEXT_DDIC  =  '选择' .
        LS_IT_FIELDCATALOG - CHECKBOX  =  'X' .
        LS_IT_FIELDCATALOG - EDIT  =  'X' .

        LS_IT_FIELDCATALOG - HOTSPOT  =  'X' .

       WHEN  OTHERS .
     ENDCASE .

    LS_IT_FIELDCATALOG - DDICTXT  = 'L' .
     APPEND  LS_IT_FIELDCATALOG  TO  GT_FIELDCATALOG .
   ENDLOOP .

  LS_LAYOUT - COLWIDTH_OPTIMIZE  =  'X' .
  LS_LAYOUT - ZEBRA  =  'X' .
  LS_LAYOUT - DETAIL_INITIAL_LINES  =  'X' .

   CALL  FUNCTION  'REUSE_ALV_GRID_DISPLAY'
     EXPORTING
      I_GRID_TITLE              =  LV_GRID_TITLE
      IS_LAYOUT                 =  LS_LAYOUT
      IT_FIELDCAT               =  GT_FIELDCATALOG
      I_CALLBACK_PROGRAM        =  SY - REPID                       "
*      I_CALLBACK_PF_STATUS_SET = 'ZFORM_SET_PF_STATUS'
      I_CALLBACK_USER_COMMAND   =  'ALV_USER_COMMAND'
     TABLES
      T_OUTTAB                  =  GT_ALV
     EXCEPTIONS
      PROGRAM_ERROR             =  1
       OTHERS                    =  2 .
   IF  SY - SUBRC <>  0 .
     MESSAGE  ID  SY - MSGID  TYPE  SY - MSGTY  NUMBER  SY - MSGNO
             WITH  SY - MSGV1 SY - MSGV2 SY - MSGV3 SY - MSGV4 .
   ENDIF .              " FRM_SHOW_FC

ENDFORM . 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值