Chinaunix首页 | 论坛 | 博客
  • 博客访问: 402164
  • 博文数量: 120
  • 博客积分: 6000
  • 博客等级: 准将
  • 技术积分: 1266
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-16 16:04
文章分类

全部博文(120)

文章存档

2011年(4)

2010年(10)

2009年(38)

2008年(68)

我的朋友

分类:

2008-09-27 11:24:33

代码:
REPORT Z_ALV_HIERSEQ_LIST.
TYPE-POOLS: SLIS.                    " ALV Global types
*---------------------------------------------------------------------*
CONSTANTS :
  C_X VALUE 'X',
  C_GT_VBAP TYPE SLIS_TABNAME VALUE 'GT_VBAP',
  C_GT_VBAK TYPE SLIS_TABNAME VALUE 'GT_VBAK'.
*---------------------------------------------------------------------*
SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) V_1 FOR FIELD P_MAX.    "#EC NEEDED
PARAMETERS P_MAX(02) TYPE N DEFAULT '10' OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN :
  SKIP, BEGIN OF LINE,COMMENT 5(27) V_2 FOR FIELD P_EXPAND. "#EC NEEDED
PARAMETERS P_EXPAND AS CHECKBOX DEFAULT C_X.
SELECTION-SCREEN END OF LINE.
*---------------------------------------------------------------------*
TYPES :
* 1st Table
  BEGIN OF TY_VBAK,
    VBELN TYPE VBAK-VBELN,             " Sales document
    KUNNR TYPE VBAK-KUNNR,             " Sold-to party
    NETWR TYPE VBAK-NETWR,             " Net Value of the Sales Order
    ERDAT TYPE VBAK-ERDAT,             " Creation date
    WAERK TYPE VBAK-WAERK,             " SD document currency
    EXPAND TYPE XFELD,
  END OF TY_VBAK,
* 2nd Table
  BEGIN OF TY_VBAP,
    VBELN TYPE VBAP-VBELN,             " Sales document
    POSNR TYPE VBAP-POSNR,             " Sales document
    MATNR TYPE VBAP-MATNR,             " Material number
    ARKTX TYPE VBAP-ARKTX,             " Material description
    NETWR TYPE VBAP-NETWR,             " Net Value of the Sales Order
    WAERK TYPE VBAP-WAERK,             " SD document currency
  END OF TY_VBAP.
*---------------------------------------------------------------------*
DATA :
* 1st Table
  GT_VBAK TYPE TABLE OF TY_VBAK,
* 2nd Table
  GT_VBAP TYPE TABLE OF TY_VBAP.
*---------------------------------------------------------------------*
INITIALIZATION.
  V_1 = 'Maximum of records to read'.
  V_2 = 'With ''EXPAND'' field'.
*---------------------------------------------------------------------*
START-OF-SELECTION.
* Read Sales Document: Header Data
  SELECT VBELN KUNNR NETWR WAERK ERDAT
    FROM VBAK
      UP TO P_MAX ROWS
    INTO CORRESPONDING FIELDS OF TABLE GT_VBAK.
  IF GT_VBAK[] IS NOT INITIAL.
*   Read Sales Document: Item Data
    SELECT VBELN POSNR MATNR ARKTX NETWR WAERK
      FROM VBAP
      INTO CORRESPONDING FIELDS OF TABLE GT_VBAP
       FOR ALL ENTRIES IN GT_VBAK
     WHERE VBELN = GT_VBAK-VBELN.
  ENDIF.
*---------------------------------------------------------------------*
END-OF-SELECTION.
  PERFORM F_DISPLAY.
*---------------------------------------------------------------------*
*       Form  F_DISPLAY
*---------------------------------------------------------------------*
FORM F_DISPLAY.
* Macro definition
  DEFINE M_FIELDCAT.
    LS_FIELDCAT-TABNAME = &1.
    LS_FIELDCAT-FIELDNAME = &2.
    LS_FIELDCAT-REF_TABNAME = &3.
    LS_FIELDCAT-CFIELDNAME = &4.       " Field with currency unit
    APPEND LS_FIELDCAT TO LT_FIELDCAT.
  END-OF-DEFINITION.
  DEFINE M_SORT.
    LS_SORT-TABNAME = &1.
    LS_SORT-FIELDNAME = &2.
    LS_SORT-UP        = C_X.
    APPEND LS_SORT TO LT_SORT.
  END-OF-DEFINITION.
  DATA:
    LS_LAYOUT   TYPE SLIS_LAYOUT_ALV,
    LS_KEYINFO  TYPE SLIS_KEYINFO_ALV,
    LS_SORT     TYPE SLIS_SORTINFO_ALV,
    LT_SORT     TYPE SLIS_T_SORTINFO_ALV," Sort table
    LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
    LT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV." Field catalog
  LS_LAYOUT-GROUP_CHANGE_EDIT = C_X.
  LS_LAYOUT-COLWIDTH_OPTIMIZE = C_X.
  LS_LAYOUT-ZEBRA             = C_X.
  LS_LAYOUT-DETAIL_POPUP      = C_X.
  LS_LAYOUT-GET_SELINFOS      = C_X.
  IF P_EXPAND = C_X.
    LS_LAYOUT-EXPAND_FIELDNAME  = 'EXPAND'.
  ENDIF.
* Build field catalog and sort table
  M_FIELDCAT C_GT_VBAK 'VBELN' 'VBAK' ''.
  M_FIELDCAT C_GT_VBAK 'KUNNR' 'VBAK' ''.
  M_FIELDCAT C_GT_VBAK 'NETWR' 'VBAK' 'WAERK'.
  M_FIELDCAT C_GT_VBAK 'WAERK' 'VBAK' ''.
  M_FIELDCAT C_GT_VBAK 'ERDAT' 'VBAK' ''.
  M_FIELDCAT C_GT_VBAP 'POSNR' 'VBAP' ''.
  M_FIELDCAT C_GT_VBAP 'MATNR' 'VBAP' ''.
  M_FIELDCAT C_GT_VBAP 'ARKTX' 'VBAP' ''.
  M_FIELDCAT C_GT_VBAP 'NETWR' 'VBAP' 'WAERK'.
  M_FIELDCAT C_GT_VBAP 'WAERK' 'VBAP' ''.
  M_SORT C_GT_VBAK 'KUNNR'.
  M_SORT C_GT_VBAP 'NETWR'.
  LS_KEYINFO-HEADER01 = 'VBELN'.
  LS_KEYINFO-ITEM01 = 'VBELN'.
  LS_KEYINFO-ITEM02 = 'POSNR'.
* Dipslay Hierarchical list
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM      = SY-CPROG
      I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
      IS_LAYOUT               = LS_LAYOUT
      IT_FIELDCAT             = LT_FIELDCAT
      IT_SORT                 = LT_SORT
      I_TABNAME_HEADER        = C_GT_VBAK
      I_TABNAME_ITEM          = C_GT_VBAP
      IS_KEYINFO              = LS_KEYINFO
      I_SAVE                  = 'A'
    TABLES
      T_OUTTAB_HEADER         = GT_VBAK
      T_OUTTAB_ITEM           = GT_VBAP
    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.                               " F_LIST_DISPLAY
*---------------------------------------------------------------------*
*       Form USER_COMMAND                                             *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING I_UCOMM     TYPE SY-UCOMM
                        IS_SELFIELD TYPE SLIS_SELFIELD.     "#EC CALLED
  DATA LS_VBAK TYPE TY_VBAK.
  CASE I_UCOMM.
    WHEN '&IC1'.                       " Pick
      CASE IS_SELFIELD-TABNAME.
        WHEN C_GT_VBAP.
        WHEN C_GT_VBAK.
          READ TABLE GT_VBAK INDEX IS_SELFIELD-TABINDEX INTO LS_VBAK.
          IF SY-SUBRC EQ 0.
*           Sales order number
            SET PARAMETER ID 'AUN' FIELD LS_VBAK-VBELN.
*           Display Sales Order
            CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
          ENDIF.
      ENDCASE.
  ENDCASE.
ENDFORM.                               " USER_COMMAND
 
效果图:
阅读(3758) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~