简单ALV

*&---------------------------------------------------------------------*
*& Report ZFIR0129
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZFIR0129.
TABLES:ACDOCA.
TYPE-POOLS:ABAP,SLIS,ICON.
*----------------------------------------------------------------
*INTERNAL TABLES
*----------------------------------------------------------------

TYPES: BEGIN OF I_OUT.
         INCLUDE STRUCTURE ACDOCA.
TYPES:   SEL(1) TYPE C,
         BUDATX TYPE SY-DATUM,
         TCODE  TYPE SY-TCODE,
       END OF I_OUT.

" 输出
DATA:I_ACDOCA TYPE TABLE OF I_OUT WITH HEADER LINE.
DATA: FIELDCAT TYPE LVC_T_FCAT WITH HEADER LINE.
DATA:GT_BKPF LIKE TABLE OF BKPF WITH HEADER LINE.   "
*&---------------------------------------------------------------------*
*& PROGRAM VARIABLES程序变量
*&---------------------------------------------------------------------*

DATA: WA_LAYOUT TYPE LVC_S_LAYO,
      GT_EVENTS TYPE SLIS_T_EVENT,
      GS_EVENT  LIKE LINE OF GT_EVENTS.
DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.

*&---------------------------------------------------------------------*
*& Definition
*&---------------------------------------------------------------------*
DEFINE FILL_FIELD.
  CLEAR FIELDCAT.
  FIELDCAT-FIELDNAME     = &1.
  FIELDCAT-SCRTEXT_L     = &2.
  FIELDCAT-CFIELDNAME    = &3.
  FIELDCAT-OUTPUTLEN     = &4.
  FIELDCAT-EDIT          = &5.
  APPEND FIELDCAT.
END-OF-DEFINITION.


*----------------------------------------------------------------
* SELECTION-SCREEN
*----------------------------------------------------------------
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

  SELECT-OPTIONS: S_RACCT FOR ACDOCA-RACCT,
                  S_BUDATX FOR ACDOCA-BUDAT,
                  S_BUDAT FOR ACDOCA-BUDAT,
                  S_RBUKRS FOR ACDOCA-RBUKRS,
                  S_USNAM FOR ACDOCA-USNAM .

SELECTION-SCREEN: END OF BLOCK B1.

*----------------------------------------------------------------
* INITIALIZATION
*----------------------------------------------------------------
INITIALIZATION.

*----------------------------------------------------------------
* AT SELECTION-SCREEN
*----------------------------------------------------------------
AT SELECTION-SCREEN.
*  PERFORM FRM_AUTHORIZATION_CHECK.

*----------------------------------------------------------------
* START-OF-SELECTION
*----------------------------------------------------------------
START-OF-SELECTION.
  PERFORM FRM_GET_DATA.
  PERFORM FRM_DATA_PROCESS.
*----------------------------------------------------------------
*END-OF-SELECTION
*----------------------------------------------------------------
END-OF-SELECTION.

  PERFORM FRM_DISPLAY_DATA.


*----------------------------------------------------------------
*
*----------------------------------------------------------------
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_GET_DATA .

  SELECT *
    INTO CORRESPONDING FIELDS OF TABLE I_ACDOCA
    FROM ACDOCA
    WHERE RACCT IN  S_RACCT
      AND RBUKRS IN S_RBUKRS
      AND USNAM IN S_USNAM
      AND BUDAT IN S_BUDAT

  .
  DATA:LV_TIME(15).
  LOOP AT I_ACDOCA.
    LV_TIME =  I_ACDOCA-TIMESTAMP.
    I_ACDOCA-BUDATX =  LV_TIME+0(8).
    MODIFY I_ACDOCA.
    CLEAR:LV_TIME.
  ENDLOOP.


*  S_BUDAT FOR ACDOCA-BUDAT,

  DELETE I_ACDOCA WHERE BUDATX NOT IN S_BUDATX.


  IF I_ACDOCA[] IS NOT INITIAL.

    SELECT BUKRS
           BELNR
           GJAHR
           TCODE
      INTO CORRESPONDING FIELDS OF TABLE GT_BKPF
      FROM BKPF
      FOR ALL ENTRIES IN I_ACDOCA
      WHERE BUKRS = I_ACDOCA-RBUKRS
      AND   BELNR = I_ACDOCA-BELNR
      AND   GJAHR = I_ACDOCA-GJAHR.
    SORT GT_BKPF BY BUKRS BELNR GJAHR.
  ENDIF.



ENDFORM.                    " FRM_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_DATA_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DATA_PROCESS .
  LOOP AT I_ACDOCA ASSIGNING FIELD-SYMBOL(<FS_ACDOCA>).
    READ TABLE  GT_BKPF ASSIGNING FIELD-SYMBOL(<FS_BKPF>) WITH KEY  BUKRS = <FS_ACDOCA>-RBUKRS
                                                                    BELNR = <FS_ACDOCA>-BELNR
                                                                    GJAHR = <FS_ACDOCA>-GJAHR.
    IF SY-SUBRC = 0.
      <FS_ACDOCA>-TCODE = <FS_BKPF>-TCODE.
    ENDIF.
  ENDLOOP.
ENDFORM.                    " FRM_DATA_PROCESS
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_DISPLAY_DATA .
  PERFORM FRM_LAYOUT.
  PERFORM FRM_FILL_FIELD.
  PERFORM FRM_BUILD_EVENT.
  PERFORM FRM_ALV_DISPLAY.
ENDFORM.                    " FRM_DISPLAY_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_LAYOUT .
  CLEAR: WA_LAYOUT."它用来定义ALV报表的整体属性
*  WA_LAYOUT-ZEBRA         = 'X' ."ZBbra
*  WA_LAYOUT-DETAILINIT         = 'X' . "initial values on detail screen
  WA_LAYOUT-CWIDTH_OPT    = 'X'."优化列宽选项是否设置
*  WA_LAYOUT-DETAILTITL      = 'Detail Information' ."设置弹出窗口的标题栏
  WA_LAYOUT-BOX_FNAME = 'SEL'.
*  WA_LAYOUT-INFO_FNAME = 'ROWCOLOR'.
*  WA_LAYOUT-GRID_TITLE = 'Alv grid title test'.
ENDFORM.                    " FRM_LAYOUT
*&---------------------------------------------------------------------*
*&      Form  FRM_FILL_FIELD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_FILL_FIELD .
  REFRESH FIELDCAT.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
    EXPORTING
      I_STRUCTURE_NAME = 'ACDOCA'
    CHANGING
      CT_FIELDCAT      = FIELDCAT[].


  CLEAR FIELDCAT.
  FIELDCAT-FIELDNAME     = 'BUDATX'.
  FIELDCAT-SCRTEXT_L     = '时戳'.
  FIELDCAT-CFIELDNAME    = ''.
  FIELDCAT-OUTPUTLEN     = '8'.
  APPEND FIELDCAT.
  CLEAR FIELDCAT.
  FIELDCAT-FIELDNAME     = 'TCODE'.
  FIELDCAT-SCRTEXT_L     = '事务代码'.
  FIELDCAT-CFIELDNAME    = ''.
  FIELDCAT-OUTPUTLEN     = '20'.
  APPEND FIELDCAT.

*
ENDFORM.                    " FRM_FILL_FIELD
*&---------------------------------------------------------------------*
*&      Form  FRM_BUILD_EVENT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_BUILD_EVENT .
  REFRESH:GT_EVENTS.
*  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
*    EXPORTING
*      I_LIST_TYPE = 0
*    IMPORTING
*      ET_EVENTS   = GT_EVENTS.

  GS_EVENT-NAME = SLIS_EV_PF_STATUS_SET.
  GS_EVENT-FORM = 'PF_STATUS'.
  APPEND GS_EVENT TO GT_EVENTS.
  CLEAR  GS_EVENT.


ENDFORM.                    " FRM_BUILD_EVENT

*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_ALV_DISPLAY .
  DATA: IS_VARIANT      LIKE DISVARIANT,
        I_GRID_SETTINGS TYPE LVC_S_GLAY.
*  I_GRID_SETTINGS-EDT_CLL_CB = 'X'.
*  IS_VARIANT-VARIANT = P_VARI.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM      = SY-REPID
*     I_GRID_SETTINGS         = I_GRID_SETTINGS
      IT_FIELDCAT_LVC         = FIELDCAT[]
      IT_EVENTS               = GT_EVENTS
*     IS_VARIANT              = IS_VARIANT
      I_SAVE                  = 'A'
*     I_DEFAULT               = 'X'
      IS_LAYOUT_LVC           = WA_LAYOUT
*     I_GRID_TITLE            = 'Alv test-FM'
      I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
    TABLES
      T_OUTTAB                = I_ACDOCA
    EXCEPTIONS
      OTHERS                  = 2.
ENDFORM.                    " FRM_ALV_DISPLAY

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->UCOMM        text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM USER_COMMAND USING UCOMM  LIKE SY-UCOMM
                        RS_SELFIELD TYPE SLIS_SELFIELD.     "#EC CALLED
  DATA: L_LINE  TYPE I,
        L_INDEX TYPE I.
  DATA: L_VALID  TYPE CHAR01.

  RS_SELFIELD-REFRESH    = 'X'.
  RS_SELFIELD-COL_STABLE = 'X'.
  RS_SELFIELD-ROW_STABLE = 'X'.
ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  pf_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->LT_EXTAB   text
*----------------------------------------------------------------------*
FORM PF_STATUS USING LT_EXTAB.                              "#EC NEEDED
  SET PF-STATUS 'MENU'."SAPLKKBL STANDARD
  "SET PF-STATUS 'MENU_01'."SAPLKKBL STANDARD
ENDFORM.                    "PF_STATUS

*&---------------------------------------------------------------------*
*&      Form  frm_authorization_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_AUTHORIZATION_CHECK .

ENDFORM.                    " frm_authorization_check
ALV报表知识点

树状ALV DEMO

2019-9-3 17:48:17

ALV报表面试

面试问题整理1-ALV,数据处理,优化

2020-9-21 15:46:15

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索