• ABAP alv report


    *&---------------------------------------------------------------------*
    *& Report  YTST_FF_011
    *&
    *&---------------------------------------------------------------------*
    *& DEMO_ALVGRID_EDIT.
    *&
    *&---------------------------------------------------------------------*

    REPORT YTST_FF_011.

    TABLES:EKKO.

    TYPE-POOLS: SLIS.                                 "ALV Declarations
    *Data Declaration
    *----------------
    TYPES:BEGIN OF T_EKKO,
            EBELN       TYPE EKPO-EBELN,
            EBELP       TYPE EKPO-EBELP,
            STATU       TYPE EKPO-STATU,
            AEDAT       TYPE EKPO-AEDAT,
            MATNR       TYPE EKPO-MATNR,
            MENGE       TYPE EKPO-MENGE,
            MEINS       TYPE EKPO-MEINS,
            NETPR       TYPE EKPO-NETPR,
            PEINH       TYPE EKPO-PEINH,
            FIELD_STYLE TYPE LVC_T_STYL"FOR DISABLE
          END OF T_EKKO.

    DATA: IT_EKKO TYPE STANDARD TABLE OF T_EKKO INITIAL SIZE 0,
          WA_EKKO TYPE T_EKKO.

    *ALV data declarations
    DATA: FIELDCATALOG TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
    DATA: IT_FIELDCAT  TYPE LVC_T_FCAT,     "slis_t_fieldcat_alv WITH HEADER LINE,
          WA_FIELDCAT  TYPE LVC_S_FCAT,
          GD_TAB_GROUP TYPE SLIS_T_SP_GROUP_ALV,
          GD_LAYOUT    TYPE LVC_S_LAYO,     "slis_layout_alv,
          GD_REPID     LIKE SY-REPID.


    ************************************************************************
    *Start-of-selection.
    START-OF-SELECTION.

      PERFORM DATA_RETRIEVAL.
      PERFORM SET_SPECIFIC_FIELD_ATTRIBUTES.
      PERFORM BUILD_FIELDCATALOG.
      PERFORM BUILD_LAYOUT.
      PERFORM DISPLAY_ALV_REPORT.


    *&---------------------------------------------------------------------*
    *&      Form  BUILD_FIELDCATALOG
    *&---------------------------------------------------------------------*
    *       Build Fieldcatalog for ALV Report
    *----------------------------------------------------------------------*
    FORM BUILD_FIELDCATALOG.

      WA_FIELDCAT-FIELDNAME   'EBELN'.
      WA_FIELDCAT-SCRTEXT_M   'Purchase Order'.
      WA_FIELDCAT-COL_POS     0.
      WA_FIELDCAT-OUTPUTLEN   10.
      WA_FIELDCAT-EMPHASIZE   'X'.
      WA_FIELDCAT-KEY         'X'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'EBELP'.
      WA_FIELDCAT-SCRTEXT_M   'PO Item'.
      WA_FIELDCAT-COL_POS     1.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'STATU'.
      WA_FIELDCAT-SCRTEXT_M   'Status'.
      WA_FIELDCAT-COL_POS     2.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'AEDAT'.
      WA_FIELDCAT-SCRTEXT_M   'Item change date'.
      WA_FIELDCAT-COL_POS     3.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'MATNR'.
      WA_FIELDCAT-SCRTEXT_M   'Material Number'.
      WA_FIELDCAT-COL_POS     4.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'MENGE'.
      WA_FIELDCAT-SCRTEXT_M   'PO quantity'.
      WA_FIELDCAT-COL_POS     5.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'MEINS'.
      WA_FIELDCAT-SCRTEXT_M   'Order Unit'.
      WA_FIELDCAT-COL_POS     6.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'NETPR'.
      WA_FIELDCAT-SCRTEXT_M   'Net Price'.
      WA_FIELDCAT-EDIT        'X'"sets whole column to be editable
      WA_FIELDCAT-COL_POS     7.
      WA_FIELDCAT-OUTPUTLEN   15.
      WA_FIELDCAT-DATATYPE     'CURR'.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.

      WA_FIELDCAT-FIELDNAME   'PEINH'.
      WA_FIELDCAT-SCRTEXT_M   'Price Unit'.
      WA_FIELDCAT-COL_POS     8.
      APPEND WA_FIELDCAT TO IT_FIELDCAT.
      CLEAR  WA_FIELDCAT.
    ENDFORM.                    " BUILD_FIELDCATALOG


    *&---------------------------------------------------------------------*
    *&      Form  BUILD_LAYOUT
    *&---------------------------------------------------------------------*
    *       Build layout for ALV grid report
    *----------------------------------------------------------------------*
    FORM BUILD_LAYOUT.
    * Set layout field for field attributes(i.e. input/output)
      GD_LAYOUT-STYLEFNAME 'FIELD_STYLE'.
      GD_LAYOUT-ZEBRA             'X'.
    ENDFORM.                    " BUILD_LAYOUT


    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_ALV_REPORT
    *&---------------------------------------------------------------------*
    *       Display report using ALV grid
    *----------------------------------------------------------------------*
    FORM DISPLAY_ALV_REPORT.
      GD_REPID = SY-REPID.

    *  call function 'REUSE_ALV_GRID_DISPLAY'
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
        EXPORTING
          I_CALLBACK_PROGRAM       = GD_REPID
    *     i_callback_user_command  = 'USER_COMMAND'
          IS_LAYOUT_LVC            = GD_LAYOUT
          IT_FIELDCAT_LVC          = IT_FIELDCAT
          I_CALLBACK_USER_COMMAND  'FRM_UCOMM'         "实现双击事件
          I_CALLBACK_PF_STATUS_SET 'SET_STATUS'
          I_SAVE                   'X'
        TABLES
          T_OUTTAB                 = IT_EKKO
        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.
    ENDFORM.                    " DISPLAY_ALV_REPORT


    *&---------------------------------------------------------------------*
    *&      Form  DATA_RETRIEVAL
    *&---------------------------------------------------------------------*
    *       Retrieve data form EKPO table and populate itab it_ekko
    *----------------------------------------------------------------------*
    FORM DATA_RETRIEVAL.
      SELECT EBELN EBELP STATU AEDAT MATNR MENGE MEINS NETPR PEINH
       UP TO 10 ROWS
        FROM EKPO
        INTO  CORRESPONDING FIELDS OF TABLE IT_EKKO.

    ENDFORM.                    " DATA_RETRIEVAL


    *&---------------------------------------------------------------------*
    *&      Form  set_specific_field_attributes
    *&---------------------------------------------------------------------*
    *       populate FIELD_STYLE table with specific field attributes
    *----------------------------------------------------------------------*
    FORM SET_SPECIFIC_FIELD_ATTRIBUTES .
      DATA LS_STYLEROW TYPE LVC_S_STYL .
      DATA LT_STYLETAB TYPE LVC_T_STYL .

    * Populate style variable (FIELD_STYLE) with style properties
    *
    * The NETPR field/column has been set to editable in the fieldcatalog...
    * The following code sets it to be disabled(display only) if 'NETPR'
    * is gt than 10.
      LOOP AT IT_EKKO INTO WA_EKKO.
        IF WA_EKKO-NETPR GT 10.
          LS_STYLEROW-FIELDNAME 'NETPR' .
          LS_STYLEROW-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
          "set field to disabled
          APPEND LS_STYLEROW  TO WA_EKKO-FIELD_STYLE.
          MODIFY IT_EKKO FROM WA_EKKO.
        ENDIF.
      ENDLOOP.

    ENDFORM.                    " set_specific_field_attributes

    FORM FRM_UCOMM USING F_UCOMM    LIKE SY-UCOMM
                         F_SELFIELD TYPE SLIS_SELFIELD.
      DATA:L_FLAG(1.

      DATA: LR_GRID      TYPE REF TO CL_GUI_ALV_GRID,
            LIT_FIELDCAT TYPE LVC_T_FCAT,
            LIW_FIELDCAT TYPE LVC_S_FCAT.
      CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
        IMPORTING
          E_GRID = LR_GRID.
      CALL METHOD LR_GRID->CHECK_CHANGED_DATA.
      F_SELFIELD-REFRESH 'X'.
    *  READ TABLE it_edidc  INDEX f_selfield-tabindex.
      IF F_UCOMM '&IC1'.
    *    IF f_selfield-fieldname = 'DOCNUM'.
    *      SET PARAMETER ID 'DCN' FIELD f_selfield-value .
    *      CALL TRANSACTION 'WE02' AND SKIP FIRST SCREEN.
    *    ENDIF.
      ENDIF.

    ENDFORM.                    "FRM_UCOMM

    FORM SET_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB .
      SET PF-STATUS 'ZSTANDARD_FULLSCREEN' .             "EXCLUDING RT_EXTAB.
    ENDFORM.                               " SET_STATUS2

  • 相关阅读:
    Redis 主从复制
    LESSON THREE
    SSIS OLEDB COMMAND RULES
    Hadoop step by step _ install and configuration environment
    repcached的安装练习
    Check list
    简单对象定位——xpath定位
    简单对象定位
    Python webdriver API- 浏览器的操作
    第一个自动化脚本示例
  • 原文地址:https://www.cnblogs.com/rainysblog/p/3573239.html
Copyright © 2020-2023  润新知