当前位置:编程学习 > 网站相关 >>

ALV DataChange EVENT

在CX项目中,根据需求,自定义一个表,维护供应商的银行账号信息,当输入供应商编号时,自动在供应商名称列里自动填写供应商名称,用到了ALV  DataChange 事件 ,下面是源代码:

 


*&---------------------------------------------------------------------*
*& REPORT  ZMM_LIFNR_BANK
*&
*&---------------------------------------------------------------------*
*& PROGRAM NAME     : ZMM_LIFNR_BANK
*& DESCRIPTION      :
*& AUTHOR           :
*& DATE WRITTEN     :
*& TCODE            :
*& NOTE             :
*&---------------------------------------------------------------------*

REPORT ZMM_LIFNR_BANK.
*INCLUDE ZMMLIFNRBANKTOP.

 

TABLES:ZXK001.
TYPE-POOLS:SLIS.

TYPES BEGIN OF TY_ITAB.
TYPES CHK.
      INCLUDE TYPE ZXK001.
TYPES END OF TY_ITAB.


DATA: IT_ZXK001 TYPE TABLE OF  TY_ITAB WITH HEADER LINE.
DATA: WA_IT_ZXK001 TYPE TY_ITAB.

DATA: ITZXK001 LIKE TABLE OF ZXK001 WITH HEADER LINE.

DATA: GT_FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE.
DATA: GC_GLAY TYPE LVC_S_GLAY.
DATA: GS_LAYOUT    TYPE LVC_S_LAYO,     "SLIS_LAYOUT_ALV,
      WK_REPID     LIKE SY-REPID.
DATA GS_GRID TYPE LVC_S_GLAY.
DATA TEM_GRID TYPE REF TO CL_GUI_ALV_GRID.
DATA GT_EVENTS TYPE SLIS_T_EVENT.
DATA GS_EVENTS LIKE LINE OF GT_EVENTS.


*----------------------------------------------------------------------*
*       CLASS LCL_EVENT_RECEIVER DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION. "定义类 捕捉各种事件
  PUBLIC SECTION.
    METHODS HANDLE_MODIFY                   "回车
    FOR EVENT DATA_CHANGED_FINISHED OF CL_GUI_ALV_GRID
    IMPORTING E_MODIFIED ET_GOOD_CELLS.

    METHODS HANDLE_ONF4                     "F4
    FOR EVENT ONF4 OF CL_GUI_ALV_GRID
    IMPORTING E_FIELDNAME ES_ROW_NO ER_EVENT_DATA.
ENDCLASS.                    "LCL_EVENT_RECEIVER DEFINITION
DATA GT_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER .


SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-B01.
SELECT-OPTIONS:
         S_LIFNR FOR ZXK001-LIFNR.
SELECTION-SCREEN END OF BLOCK B1.

 

START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM DISPLAY_DATA.

*&---------------------------------------------------------------------*
*&      FORM  GET_DATA
*&---------------------------------------------------------------------*
*       TEXT
*----------------------------------------------------------------------*
FORM GET_DATA.


  SELECT * INTO CORRESPONDING FIELDS OF TABLE IT_ZXK001 FROM ZXK001 WHERE LIFNR IN S_LIFNR.


ENDFORM.                    "GET_DATA

*&---------------------------------------------------------------------*
*&      FORM  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       TEXT
*----------------------------------------------------------------------*
*  -->  P1        TEXT
*  <--  P2        TEXT
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
  DEFINE FILL_ALV.
    CLEAR GT_FIELDCAT.
    GT_FIELDCAT-FIELDNAME = &1.
    GT_FIELDCAT-SCRTEXT_M = &2 .
*    GT_FIELDCAT-OUTPUTLEN = &3.
    GT_FIELDCAT-NO_ZERO   = &3.
    GT_FIELDCAT-DECIMALS_O   = &4.
    APPEND GT_FIELDCAT.
  END-OF-DEFINITION.

  FILL_ALV 'LIFNR'   '供应商编号    '  '' ''.
  FILL_ALV 'NAME1'   '供应商名称    '  '' ''.
  FILL_ALV 'BANKN'   '开户银行 '    '  ' ''.
  FILL_ALV 'IBAN'    '银行账号    '   '' ''.

  LOOP AT GT_FIELDCAT WHERE FIELDNAME = 'LIFNR'
                         OR  FIELDNAME = 'BANKN'
                         OR  FIELDNAME = 'NAME1'
                         OR  FIELDNAME = 'IBAN'.

    IF GT_FIELDCAT-FIELDNAME <> 'NAME1'.
       GT_FIELDCAT-EDIT = 'X'.
    ENDIF.

    IF GT_FIELDCAT-FIELDNAME = 'NAME1'.
       GT_FIELDCAT-OUTPUTLEN = '30'.
    ENDIF.
    IF GT_FIELDCAT-FIELDNAME = 'LIFNR'.
*      GT_FIELDCAT-REF_FIELD = 'LIFNR'.
*      GT_FIELDCAT-REF_TABLE = 'LFA1'.
      GT_FIELDCAT-OUTPUTLEN = '20'.

    ENDIF.
    IF GT_FIELDCAT-FIELDNAME = 'BANKN'.
      GT_FIELDCAT-REF_FIELD = 'BANKN'.
      GT_FIELDCAT-REF_TABLE = 'TIBAN'.
      GT_FIELDCAT-OUTPUTLEN = '35'.

    ENDIF.
    IF GT_FIELDCAT-FIELDNAME = 'IBAN'.
      GT_FIELDCAT-REF_FIELD = 'IBAN'.
      GT_FIELDCAT-REF_TABLE = 'TIBAN'.
      GT_FIELDCAT-OUTPUTLEN = '34'.
    ENDIF.


    MODIFY GT_FIELDCAT.
  ENDLOOP.

  GS_LAYOUT-STYLEFNAME   = 'FSTYLE'.
  GS_LAYOUT-ZEBRA        = 'X'.
*  GS_LAYOUT-CWIDTH_OPT   = 'X'.
  GS_LAYOUT-BOX_FNAME = 'CHK'.

  GS_GRID-EDT_CLL_CB = &#

补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,