ITPub博客

首页 > Linux操作系统 > Linux操作系统 > alv修改数据模板

alv修改数据模板

原创 Linux操作系统 作者:fivezhuo 时间:2009-08-01 02:47:55 0 删除 编辑

alv修改数据模板

SAP   2009-07-03 09:47   阅读15   评论0  
字号:    
*-----------------------------------------------------------------------
* Program Name  :ZPPP030
* T-CODE        :ZPPP030
*-----------------------------------------------------------------------
* CREATED DATE  :2009/07/01
* CREATED BY    :LUO
* DESCRIPTION   :生产单工序计划日期输入
*
*-----------------------------------------------------------------------
* MODIFICATION  :
* DATE MODIFIED       MODIFIED BY     DESCRIPTION
*
*-----------------------------------------------------------------------

REPORT  ZPPP030.

TYPES: BEGIN OF TY_ZAFVV,
  AUFNR TYPE AFKO-AUFNR,
  APLZL TYPE ZAFVV-APLZL,
  VORNR TYPE AFVC-VORNR,
  ARBPL TYPE CRHD-ARBPL,
  LTXA1 TYPE AFVC-LTXA1,
  SSAVD TYPE ZAFVV-SSAVD,
  SSEDD TYPE ZAFVV-SSEDD,
  CELLTAB TYPE LVC_T_STYL.
TYPES: END OF TY_ZAFVV.
DATA : GT_ZAFVV TYPE STANDARD TABLE OF TY_ZAFVV WITH HEADER LINE.

DATA : G_AUFPL TYPE AFKO-AUFPL.

*主grid
DATA: OK_CODE TYPE SY-UCOMM,
      SAVE_OK TYPE SY-UCOMM,
      G_CONTAINER        TYPE SCRFNAME VALUE 'ZAFVV_GRID_0100_CONT1',
      G_GRID             TYPE REF TO CL_GUI_ALV_GRID,
      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
      GT_FIELDCAT        TYPE LVC_T_FCAT,
      GS_LAYOUT          TYPE LVC_S_LAYO,
      GS_TOOLBAR         TYPE STB_BUTTON.

* local class
CLASS LCL_EVENT_RECEIVER DEFINITION DEFERRED.
DATA: G_EVENT_RECEIVER TYPE REF TO LCL_EVENT_RECEIVER.
INCLUDE .

*----------------------------------------------------------------------*
*  Define and implement event handler to handle event                  *
*----------------------------------------------------------------------*
CLASS LCL_EVENT_RECEIVER DEFINITION.
  PUBLIC SECTION.
    METHODS:
      HANDLE_DATA_CHANGED
         FOR EVENT DATA_CHANGED OF CL_GUI_ALV_GRID
             IMPORTING ER_DATA_CHANGED,

      IS_ERROR
        RETURNING VALUE(P_ERROR) TYPE I .

  PRIVATE SECTION.
    DATA: ERROR_IN_DATA TYPE C.


ENDCLASS.                    "lcl_event_receiver DEFINITION

*---------------------------------------------------------
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
  METHOD HANDLE_DATA_CHANGED.
    FIELD-SYMBOLS: TYPE STANDARD TABLE,
                             TYPE TY_ZAFVV.

    ERROR_IN_DATA = SPACE.
    IF NOT ER_DATA_CHANGED->MP_MOD_ROWS IS INITIAL.
      ASSIGN ER_DATA_CHANGED->MP_MOD_ROWS->* TO .
      LOOP AT ASSIGNING .
        IF -SSAVD GT -SSEDD.
          CALL METHOD ER_DATA_CHANGED->ADD_PROTOCOL_ENTRY
            EXPORTING
              I_MSGID     = '0K'
              I_MSGNO     = '000'
              I_MSGTY     = 'E'
              I_MSGV1     = -VORNR
              I_MSGV2     = TEXT-001
              I_MSGV3     = ''
              I_FIELDNAME = 'SSAVD'.

          ERROR_IN_DATA = 'X'.
        ENDIF.
      ENDLOOP.
      IF ERROR_IN_DATA EQ 'X'.
        CALL METHOD ER_DATA_CHANGED->DISPLAY_PROTOCOL.
      ENDIF.
    ENDIF.

  ENDMETHOD.                    "handle_data_changed

  METHOD IS_ERROR.
    IF ERROR_IN_DATA EQ 'X'.
      P_ERROR = 1.
    ELSE.
      P_ERROR = 0.
    ENDIF.
  ENDMETHOD.                    "IS_ERROR

ENDCLASS.                    "lcl_event_receiver IMPLEMENTATION

*----------------------------------------------------------------------*
*  SELECTION SCREEN                                                    *
*----------------------------------------------------------------------*

PARAMETERS: P_AUFNR TYPE AFKO-AUFNR OBLIGATORY.


*----------------------------------------------------------------------*
*  MAIN                                                                *
*----------------------------------------------------------------------*
START-OF-SELECTION.
  PERFORM. GET_DATA.
*CALL SCREEN 100 STARTING AT 1 1.
  CALL SCREEN 100 .

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. GET_DATA .
  TABLES: AFVC.

  CLEAR G_AUFPL.
  SELECT SINGLE AUFPL INTO G_AUFPL FROM AFKO WHERE AUFNR EQ P_AUFNR.
  CHECK SY-SUBRC EQ 0.
  SELECT * FROM AFVC WHERE AUFPL EQ G_AUFPL ORDER BY VORNR.
    CLEAR GT_ZAFVV.
    GT_ZAFVV-AUFNR = P_AUFNR.
    GT_ZAFVV-APLZL = AFVC-APLZL.
    GT_ZAFVV-VORNR = AFVC-VORNR.
    GT_ZAFVV-LTXA1 = AFVC-LTXA1.
    SELECT SINGLE ARBPL INTO GT_ZAFVV-ARBPL FROM CRHD WHERE OBJTY EQ 'A' AND OBJID EQ AFVC-ARBID.
    SELECT SINGLE SSAVD SSEDD INTO (GT_ZAFVV-SSAVD, GT_ZAFVV-SSEDD) FROM ZAFVV
    WHERE AUFPL EQ G_AUFPL AND APLZL EQ AFVC-APLZL.
    APPEND GT_ZAFVV.
  ENDSELECT.

  PERFORM. INIT_STYLE.

ENDFORM.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
  SET PF-STATUS 'MAIN100'.
  SET TITLEBAR  'MAIN100'.

  IF G_CUSTOM_CONTAINER IS INITIAL.
    PERFORM. CREATE_AND_INIT_ALV.
  ENDIF.

ENDMODULE.                 " STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
  SAVE_OK = OK_CODE.
  CLEAR OK_CODE.
  CASE SAVE_OK.
    WHEN 'EXIT'.
      PERFORM. EXIT_PROGRAM.
    WHEN 'SWITCH'.
      PERFORM. SWITCH_EDIT_MODE.
    WHEN 'SAVE'.
      PERFORM. SAVE_DATA.
    WHEN OTHERS.
*     do nothing
  ENDCASE.


ENDMODULE.                 " USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*&      Form  CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. CREATE_AND_INIT_ALV .
  DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.

  CREATE OBJECT G_CUSTOM_CONTAINER
    EXPORTING
      CONTAINER_NAME = G_CONTAINER.
  CREATE OBJECT G_GRID
    EXPORTING
      I_PARENT = G_CUSTOM_CONTAINER.

  GS_LAYOUT-EDIT = 'X'.
  GS_LAYOUT-NO_TOOLBAR = 'X'.
  GS_LAYOUT-STYLEFNAME = 'CELLTAB'.

  PERFORM. BUILD_FIELDCAT.

  CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
*      I_BUFFER_ACTIVE               =
*      I_BYPASSING_BUFFER            =
*      I_CONSISTENCY_CHECK           =
*      I_STRUCTURE_NAME              =
*      IS_VARIANT                    =
*      I_SAVE                        =
*      I_DEFAULT                     = 'X'
      IS_LAYOUT                     = GS_LAYOUT
*      IS_PRINT                      =
*      IT_SPECIAL_GROUPS             =
*      IT_TOOLBAR_EXCLUDING          = LT_EXCLUDE
*      IT_HYPERLINK                  =
*      IT_ALV_GRAPHICS               =
*      IT_EXCEPT_QINFO               =
*      IR_SALV_ADAPTER               =
    CHANGING
      IT_OUTTAB                     = GT_ZAFVV[]
      IT_FIELDCATALOG               = GT_FIELDCAT
*      IT_SORT                       =
*      IT_FILTER                     =
*    EXCEPTIONS
*      INVALID_PARAMETER_COMBINATION = 1
*      PROGRAM_ERROR                 = 2
*      TOO_MANY_LINES                = 3
*      OTHERS                        = 4
      .
  IF SY-SUBRC <> 0.
*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.


  CALL METHOD G_GRID->SET_READY_FOR_INPUT
    EXPORTING
      I_READY_FOR_INPUT = 0.

  CALL METHOD G_GRID->REGISTER_EDIT_EVENT
    EXPORTING
      I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
*      I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_MODIFIED. "单元格更改触发

  CREATE OBJECT G_EVENT_RECEIVER.
  SET HANDLER: G_EVENT_RECEIVER->HANDLE_DATA_CHANGED FOR G_GRID.

ENDFORM.                    " CREATE_AND_INIT_ALV
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. BUILD_FIELDCAT .
  DATA LS_FIELDCAT TYPE LVC_S_FCAT.

  DEFINE APPFIELD.
    LS_FIELDCAT-FIELDNAME = &1.
    LS_FIELDCAT-SELTEXT = &2.
    LS_FIELDCAT-COLTEXT = &2.
    LS_FIELDCAT-JUST = 'L'.
    LS_FIELDCAT-REF_TABLE = &3.
    LS_FIELDCAT-REF_FIELD = &4.
    LS_FIELDCAT-EDIT = &5.    "列可编辑
    APPEND LS_FIELDCAT TO GT_FIELDCAT.
    CLEAR LS_FIELDCAT.
  END-OF-DEFINITION.

  APPFIELD 'AUFNR' '生产订单'   '' '' ''.
  APPFIELD 'VORNR' '工序'       '' '' ''.
  APPFIELD 'ARBPL' '工作中心'   '' '' ''.
  APPFIELD 'LTXA1' '工序短文本' '' '' ''.
  APPFIELD 'SSAVD' '计划开始日期' 'ZAFVV' 'SSAVD' 'X'.
  APPFIELD 'SSEDD' '计划完成日期' 'ZAFVV' 'SSEDD' 'X'.

ENDFORM.                    " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  EXIT_PROGRAM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. EXIT_PROGRAM .
  CALL METHOD G_CUSTOM_CONTAINER->FREE.
  CALL METHOD CL_GUI_CFW=>FLUSH.

  LEAVE PROGRAM.

ENDFORM.                    " EXIT_PROGRAM
*&---------------------------------------------------------------------*
*&      Form  SWITCH_EDIT_MODE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. SWITCH_EDIT_MODE .
  IF G_GRID->IS_READY_FOR_INPUT( ) EQ 0.
    CALL METHOD G_GRID->SET_READY_FOR_INPUT
      EXPORTING
        I_READY_FOR_INPUT = 1.
  ELSE.
    CALL METHOD G_GRID->SET_READY_FOR_INPUT
      EXPORTING
        I_READY_FOR_INPUT = 0.
  ENDIF.

ENDFORM.                    " SWITCH_EDIT_MODE
*&---------------------------------------------------------------------*
*&      Form  INIT_STYLE
*&---------------------------------------------------------------------*
*       行风格控制
*----------------------------------------------------------------------*
FORM. INIT_STYLE. .
  DATA: LT_CELLTAB TYPE LVC_T_STYL,
        L_INDEX TYPE I.

  LOOP AT GT_ZAFVV.
    L_INDEX = SY-TABIX.
    REFRESH LT_CELLTAB.
    PERFORM. FILL_CELLTAB USING 'RO'
                         CHANGING LT_CELLTAB.
    INSERT LINES OF LT_CELLTAB INTO TABLE GT_ZAFVV-CELLTAB.
    MODIFY GT_ZAFVV INDEX L_INDEX.
  ENDLOOP.

ENDFORM.                    " INIT_STYLE

*&---------------------------------------------------------------------*
*&      Form  FILL_CELLTAB
*&---------------------------------------------------------------------*
*       填写行风格控制的值(设定行可编辑)
*----------------------------------------------------------------------*
*       PT_CELLTAB  text
*----------------------------------------------------------------------*
FORM. FILL_CELLTAB USING VALUE(P_MODE)
                  CHANGING PT_CELLTAB TYPE LVC_T_STYL.
  DATA: LS_CELLTAB TYPE LVC_S_STYL,
        L_MODE TYPE RAW4.

  IF P_MODE EQ 'RW'.
    L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
  ELSE. "p_mode eq 'RO'
    L_MODE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
  ENDIF.

  LS_CELLTAB-FIELDNAME = 'AUFNR'.
  LS_CELLTAB-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
  INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

  LS_CELLTAB-FIELDNAME = 'VORNR'.
  LS_CELLTAB-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
  INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

  LS_CELLTAB-FIELDNAME = 'ARBPL'.
  LS_CELLTAB-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
  INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

  LS_CELLTAB-FIELDNAME = 'LTXA1'.
  LS_CELLTAB-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
  INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

  LS_CELLTAB-FIELDNAME = 'SSAVD'.
  LS_CELLTAB-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
  INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

  LS_CELLTAB-FIELDNAME = 'SSEDD'.
  LS_CELLTAB-STYLE. = CL_GUI_ALV_GRID=>MC_STYLE_ENABLED.
  INSERT LS_CELLTAB INTO TABLE PT_CELLTAB.

ENDFORM.                               " FILL_CELLTAB
*&---------------------------------------------------------------------*
*&      Form  SAVE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM. SAVE_DATA .
  DATA: LS_STABLE TYPE LVC_S_STBL.
  DATA: L_VALID(1) TYPE C.

  LS_STABLE-ROW = 'X'.
  LS_STABLE-COL = 'X'.

  IF G_GRID->IS_READY_FOR_INPUT( ) EQ 0.
    CALL METHOD G_GRID->SET_READY_FOR_INPUT
      EXPORTING
        I_READY_FOR_INPUT = 1.
  ELSE.
    CALL METHOD G_GRID->CHECK_CHANGED_DATA
      IMPORTING
        E_VALID = L_VALID.
    IF G_EVENT_RECEIVER->IS_ERROR( )  EQ 0.
      PERFORM. SAVE.
      MESSAGE TEXT-002 TYPE 'I'.
      CALL METHOD G_GRID->SET_READY_FOR_INPUT
        EXPORTING
          I_READY_FOR_INPUT = 0.

      CALL METHOD G_GRID->REFRESH_TABLE_DISPLAY
        EXPORTING
          IS_STABLE = LS_STABLE
        EXCEPTIONS
          FINISHED  = 1
          OTHERS    = 2.
    ENDIF.
  ENDIF.


ENDFORM.                    " SAVE_DATA
*&---------------------------------------------------------------------*
*&      Form  SAVE
*&---------------------------------------------------------------------*
*       SAVE TO     ENTITY TABLE
*----------------------------------------------------------------------*
FORM. SAVE .
  DATA LT_ZAFVV TYPE ZAFVV OCCURS 0 WITH HEADER LINE .

  DELETE FROM ZAFVV WHERE  AUFPL EQ G_AUFPL.
  LOOP AT GT_ZAFVV.
    LT_ZAFVV-AUFPL = G_AUFPL.
    LT_ZAFVV-APLZL = GT_ZAFVV-APLZL.
    LT_ZAFVV-SSAVD = GT_ZAFVV-SSAVD.
    LT_ZAFVV-SSEDD = GT_ZAFVV-SSEDD.
    APPEND LT_ZAFVV.
  ENDLOOP.

  INSERT ZAFVV FROM TABLE LT_ZAFVV ACCEPTING DUPLICATE KEYS.

ENDFORM.                    " SAVE

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/14397246/viewspace-611026/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2009-08-01

  • 博文量
    110
  • 访问量
    46354