CSDN博客

img opparts

SAP ABAP/4学习---ALV的简单例子3-单击某行调用事务码

发表于2004/10/17 20:17:00  5784人阅读

分类: SAP ABAP

Report ZTEST_102_ALV_3 .


*&---------------------------------------------------------------------*
*& Report        : ALV                                                 *
*& Creation Date : 2004.09.01                                          *
*& Created by    :                                                     *
*& Description   : ALV test .                                          *
*&---------------------------------------------------------------------*
*** Define AVL Parameters .

*DEFINE AN TYPE POOL
TYPE-POOLS: SLIS.


DATA:
FIELDCAT      TYPE   SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN   LIKE   LINE OF FIELDCAT,
SORTCAT       TYPE   SLIS_T_SORTINFO_ALV,
SORTCAT_LN   LIKE   LINE OF SORTCAT,
EVENTCAT     TYPE   SLIS_T_EVENT,
EVENTCAT_LN  LIKE   LINE OF EVENTCAT.


TABLES : MARA.

* Internal table for storing line item data per document number
data: begin of itab occurs 10,
        MATNR like MARA-MATNR,
        MTART LIKE MARA-MTART,
        BISMT LIKE MARA-BISMT,
      end of itab.

START-OF-SELECTION.
SELECTION-SCREEN BEGIN OF BLOCK BA WITH FRAME TITLE TTL1.
   SELECT-OPTIONS: P_MATNR FOR MARA-MATNR.
SELECTION-SCREEN END OF BLOCK BA.

*&--------------------------------------------------------------------*
* INITIALIZATION.
*&--------------------------------------------------------------------*
INITIALIZATION.
 ttl1 = 'Input Condition'.

*&--------------------------------------------------------------------*
* AT SELECTION-SCREEN.
*&--------------------------------------------------------------------*
* CHECK INPUT VALUE OF USER
AT SELECTION-SCREEN.
* SELECT single *
*  bukrs  INTO t001-bukrs
*               FROM t001
*               WHERE bukrs IN bukrs.
*    PERform authority_check(zscfiglr003) USING t001-bukrs.
*  butxt = t001-butxt.
*  ENDSELECT.

*&--------------------------------------------------------------------*
* START-OF-SELECTION.
*&--------------------------------------------------------------------*

START-OF-SELECTION.

* DEFINE PAGE LEFT MARGIN AND TOP MARGIN
 SET MARGIN 7 5.
* DEFINE PIRNT FORMATE
 PRINT-CONTROL FUNCTION: 'SABLD' LINE 1,
                         'SAOFF' LINE 2,
                         'SAULN' LINE 3.
* The above sentence print-control function used to define print format
* Find document header data and line item data from given parameters.
 PERform find_document .
 PERform ALVDISPLAY.

*------------------------------------------------*
* GET DATA FROM SOME SYSTEM TABLE
* THEN ,PUT THESE DATA INTO INTERNAL TABLE.
*------------------------------------------------*
form find_document .
  SELECT MATNR
         MTART
         BISMT
    INTO CORRESPONDING FIELDS OF TABLE ITAB
    FROM MARA
   WHERE MATNR IN P_MATNR.
endform .
*---------------ALV Disply Function ---------------------*
form alvdisplay .
  DATA: COL_POS TYPE I.
  DATA:  PGM  LIKE  SY-REPID.
  PGM = SY-REPID.
*Add The 1th column :company code .
ADD  1  TO  COL_POS.
FIELDCAT_LN-REF_TABNAME  =  'MARA'.
FIELDCAT_LN-FIELDNAME     =  'MTART'.
FIELDCAT_LN-KEY             = SPACE.
FIELDCAT_LN-DO_SUM         = SPACE.
FIELDCAT_LN-COL_POS        = COL_POS.
FIELDCAT_LN-NO_OUT        = SPACE.
FIELDCAT_LN-QFIELDNAME   = SPACE.
FIELDCAT_LN-HOTSPOT       = SPACE.
APPEND  FIELDCAT_LN  TO FIELDCAT.

ADD  1  TO  COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME   = 'MATNR'.
FIELDCAT_LN-KEY          = SPACE.
FIELDCAT_LN-DO_SUM      = SPACE.
FIELDCAT_LN-COL_POS     = COL_POS.
FIELDCAT_LN-NO_OUT      = SPACE.
FIELDCAT_LN-QFIELDNAME  =  SPACE.
FIELDCAT_LN-HOTSPOT     = SPACE.
APPEND  FIELDCAT_LN  TO  FIELDCAT.

ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME  =  'MARA'.
FIELDCAT_LN-FIELDNAME     =  'BISMT'.
FIELDCAT_LN-KEY            =  SPACE.
*DEFINE AN SUM
FIELDCAT_LN-DO_SUM        =  'X'.
FIELDCAT_LN-COL_POS        =  COL_POS.
FIELDCAT_LN-NO_OUT        =  SPACE.
FIELDCAT_LN-QFIELDNAME   =  SPACE.
FIELDCAT_LN-HOTSPOT       =  SPACE.
APPEND  FIELDCAT_LN  TO  FIELDCAT.


SORTCAT_LN-SPOS         =  '1'.
SORTCAT_LN-FIELDNAME  =  'MATNR'.
SORTCAT_LN-UP           =  'X'.
SORTCAT_LN-DOWN       =  SPACE.
SORTCAT_LN-SUBTOT      =  'X'.
APPEND  SORTCAT_LN  TO  SORTCAT.

**** Call Function to response user command event .
CALL  FUNCTION  'REUSE_ALV_LIST_DISPLAY'
EXPORTING
  I_CALLBACK_PROGRAM             =  PGM
  I_CALLBACK_USER_COMMAND        =  'USER_COMMAND'
  IT_FIELDCAT                    =  FIELDCAT
  IT_SORT                        =  SORTCAT
  I_SAVE                         =  'A'
  IT_EVENT                       = EVENTCAT
TABLES
  T_OUTTAB  =  ITAB
EXCEPTIONS
  PROGRAM_ERROR  =  1
  OTHERS            =  2.
endform.

form USER_COMMAND USING UCOMM LIKE SY-UCOMM
  SELFIELD TYPE SLIS_SELFIELD.
  READ TABLE ITAB INDEX SELFIELD-TABINDEX.
  CHECK SY-SUBRC = 0.
  CASE UCOMM.
    WHEN '&IC1'.
       CASE SELFIELD-SEL_TAB_FIELD.
          WHEN  'ITAB-MATNR'.
            SET  PARAMETER  ID  'MAT'  FIELD  ITAB-MATNR.
            CALL  TRANSACTION  'MM03'  AND  SKIP  FIRST  SCREEN.      
       ENDCASE.
  ENDCASE.
 
 

*SELECT * FROM bseg WHERE bukrs EQ ht-bukrs
*                          AND belnr EQ ht-belnr
*                          AND gjahr EQ ht-gjahr.
*   CLEAR it.
*   MOVE : ht-waers   TO it-waers, "Currency code
*          ht-kursf   TO it-kursf, "Exchange rate
*          ht-bukrs   TO it-bukrs, "Company code
*          ht-gjahr   TO it-gjahr. "Fiscal year
*   MOVE : bseg-belnr TO it-belnr, "Document No
*          bseg-buzei TO it-buzei, "Line Item number
*          bseg-hkont TO it-hkont, "Account No.
*          bseg-gsber TO it-gsber, "Business area
*          bseg-kostl TO it-kostl, "Cost center
*          bseg-lifnr TO it-lifnr, "Vendor
*          bseg-anln1 TO it-anln1, "Asset main number
*          bseg-anln2 TO it-anln2, "Asset sub number
*          bseg-bzdat TO it-bzdat, "Asset value date
*          bseg-kunnr TO it-kunnr, "customer no
*          bseg-zuonr TO it-zuonr, "allocation
*          bseg-sgtxt TO it-sgtxt, "Line item description
*          bseg-wrbtr TO it-wrbtr, "Document curr. line item amt.
*          bseg-bschl TO it-bschl. "Posting Key
*          it-dmbtr = bseg-dmbtr.
*   APPEND it.
* ENDSELECT.
ENDform.

阅读全文
0 0

相关文章推荐

img
取 消
img