ALV & SMARTFORMS

(一) Realization:

1. ALV connect smartforms layout
2. Choose column
3. Print Button
4. From ekko & ekpo procure data

(二) 流程
不会上图... 留着吧

看代码实现。



*&---------------------------------------------------------------------*
*& Report  ZT_XLI_001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZT_XLI_001.

TYPE-POOLS : SLIS.

TABLES : EKKO,
  EKPO.

DATA : C_TABIX LIKE SY-TABIX.
DATA : L_FM_NAME(30) TYPE C.

TYPES : BEGIN OF TY_PURNM,
  PURNM TYPE EKKO-EBELN,
  END OF TY_PURNM.
TYPES : BEGIN OF TY_EKKO,
  PUR_NUM  TYPE EKKO-EBELN,
  CRT_DATE TYPE EKKO-AEDAT,
  VEND_NUM TYPE EKKO-LIFNR,
  PAY_KEY  TYPE EKKO-ZTERM,
  END OF TY_EKKO.
TYPES : BEGIN OF TY_EKPO,
  PUR_NO   TYPE EKPO-EBELN,
  MAT_NUM  TYPE EKPO-MATNR,
  PUR_TXT  TYPE EKPO-TXZ01,
  PLT_NUM  TYPE EKPO-WERKS,
  STOR_LOC TYPE EKPO-LGORT,
  END OF TY_EKPO.

TYPES : BEGIN OF TY_DATA,
  SEL      TYPE SEL,
  PUR_NUM  TYPE EKKO-EBELN,
  CRT_DATE TYPE EKKO-AEDAT,
  VEND_NUM TYPE EKKO-LIFNR,
  PAY_KEY  TYPE EKKO-ZTERM,
  MAT_NUM  TYPE EKPO-MATNR,
  PUR_TXT  TYPE EKPO-TXZ01,
  PLT_NUM  TYPE EKPO-WERKS,
  STOR_LOC TYPE EKPO-LGORT,
  END OF TY_DATA.

TYPES : BEGIN OF TY_SELS,
  PUR_NUM  TYPE EKKO-EBELN,
  CRT_DATE TYPE EKKO-AEDAT,
  VEND_NUM TYPE EKKO-LIFNR,
  PAY_KEY  TYPE EKKO-ZTERM,
  MAT_NUM  TYPE EKPO-MATNR,
  PUR_TXT  TYPE EKPO-TXZ01,
  PLT_NUM  TYPE EKPO-WERKS,
  STOR_LOC TYPE EKPO-LGORT,
  END OF TY_SELS.

DATA : IT_PURNM TYPE STANDARD TABLE OF TY_PURNM WITH HEADER LINE.

DATA : WA_EKKO TYPE TY_EKKO.
DATA : IT_EKKO TYPE STANDARD TABLE OF TY_EKKO WITH HEADER LINE.

DATA : WA_EKPO TYPE TY_EKPO.
DATA : IT_EKPO TYPE STANDARD TABLE OF TY_EKPO WITH HEADER LINE.

DATA : WA_DATA TYPE TY_DATA.
DATA : CT_DATA TYPE STANDARD TABLE OF TY_DATA WITH HEADER LINE.
DATA : IT_DATA TYPE STANDARD TABLE OF TY_DATA WITH HEADER LINE.

DATA : WA_SELS TYPE TY_SELS.
DATA : IT_SELS TYPE STANDARD TABLE OF TY_SELS WITH HEADER LINE.

DATA : I_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
DATA : I_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA : WA_REPID LIKE SY-REPID.


SELECTION-SCREEN BEGIN OF BLOCK BLK1.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (20) TEXT-A01.
SELECT-OPTIONS : S_PURNUM FOR EKKO-EBELN OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLK1.


START-OF-SELECTION.
  PERFORM GET_EKKO_EKPO.
  PERFORM GETDATA.
  PERFORM CATALOG.
  PERFORM ALVSHOW.

*&---------------------------------------------------------------------*
*&      Form  GET_EKKO_EKPO
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GET_EKKO_EKPO.
  IF S_PURNUM IS NOT INITIAL.
    SELECT EBELN
      FROM EKKO INTO TABLE IT_PURNM
      WHERE EKKO~EBELN IN S_PURNUM.

    SELECT EBELN AEDAT LIFNR ZTERM
      FROM EKKO INTO TABLE IT_EKKO
      WHERE EKKO~EBELN IN S_PURNUM.
    SELECT EBELN MATNR TXZ01 WERKS LGORT
      FROM EKPO INTO TABLE IT_EKPO
      WHERE EKPO~EBELN IN S_PURNUM.
    DELETE IT_EKPO WHERE MAT_NUM = SPACE.
  ENDIF.
ENDFORM.                    "GET_EKKO_EKPO

*&---------------------------------------------------------------------*
*&      Form  GETDATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM GETDATA.
  LOOP AT IT_EKKO INTO WA_EKKO WHERE PUR_NUM <> SPACE.
    LOOP AT IT_EKPO INTO WA_EKPO WHERE PUR_NO = WA_EKKO-PUR_NUM.
      WA_DATA-PUR_NUM  = WA_EKKO-PUR_NUM.
      WA_DATA-CRT_DATE = WA_EKKO-CRT_DATE.
      WA_DATA-VEND_NUM = WA_EKKO-VEND_NUM.
      WA_DATA-PAY_KEY  = WA_EKKO-PAY_KEY.
      WA_DATA-MAT_NUM  = WA_EKPO-MAT_NUM.
      WA_DATA-PUR_TXT  = WA_EKPO-PUR_TXT.
      WA_DATA-PLT_NUM  = WA_EKPO-PLT_NUM.
      WA_DATA-STOR_LOC = WA_EKPO-STOR_LOC.
      APPEND WA_DATA TO IT_DATA.
    ENDLOOP.
  ENDLOOP.

ENDFORM.                    "GETDATA

*&---------------------------------------------------------------------*
*&      Form  CATALOG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM CATALOG.
  WA_REPID = SY-REPID.
  CLEAR I_FIELDCAT.

  DEFINE MAC_SET.
    I_FIELDCAT-REF_TABNAME = 'IT_DATA'.
    I_FIELDCAT-FIELDNAME   = &1.
    I_FIELDCAT-SELTEXT_S   = &2.
    I_FIELDCAT-SELTEXT_M   = &2.
    I_FIELDCAT-SELTEXT_S   = &2.
    I_FIELDCAT-COL_POS     = &3.
    I_FIELDCAT-OUTPUTLEN   = &4.
    APPEND I_FIELDCAT.
  END-OF-DEFINITION.
  MAC_SET 'PUR_NUM ' 'Purchase Number' C_TABIX '14'.
  MAC_SET 'CRT_DATE' 'Created Date'    C_TABIX '11'.
  MAC_SET 'VEND_NUM' 'Vendor Number'   C_TABIX '13'.
  MAC_SET 'PAY_KEY ' 'Payment Key'     C_TABIX '10'.
  MAC_SET 'MAT_NUM ' 'Material Number' C_TABIX '14'.
  MAC_SET 'PUR_TXT ' 'Short Text'      C_TABIX '20'.
  MAC_SET 'PLT_NUM ' 'Plant'           C_TABIX '4'.
  MAC_SET 'STOR_LOC' 'Location'        C_TABIX '6'.
*  I_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  I_LAYOUT-BOX_FIELDNAME = 'SEL'.
ENDFORM.                    "CATALOG

*&---------------------------------------------------------------------*
*&      Form  ALVSHOW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM ALVSHOW.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PF_STATUS_SET = 'FM_SET_STATUS'
      I_CALLBACK_USER_COMMAND  = 'FM_USER_COMMAND'
      I_CALLBACK_PROGRAM       = WA_REPID
      IS_LAYOUT                = I_LAYOUT
      I_GRID_TITLE             = 'PURCHASE LIST'
      IT_FIELDCAT              = I_FIELDCAT[]
    TABLES
      T_OUTTAB                 = IT_DATA
    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.                    "ALVSHOW


*&---------------------------------------------------------------------*
*&      Form  FM_SET_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->EXTAB      text
*----------------------------------------------------------------------*
FORM FM_SET_STATUS USING EXTAB TYPE SLIS_T_EXTAB.
  SET PF-STATUS 'BUTTON' .
ENDFORM.                    "FM_SET_STATUS

*&---------------------------------------------------------------------*
*&      Form  FM_USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM FM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
      RS_SELFIELD TYPE SLIS_SELFIELD.
  CASE R_UCOMM.
    WHEN 'PRINT'.
      PERFORM FM_BUTTON_PRT.
    WHEN OTHERS.
  ENDCASE.
ENDFORM.                    "FM_USER_COMMAND

*&---------------------------------------------------------------------*
*&      Form  FM_BUTTON_PRT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM FM_BUTTON_PRT.
  LOOP AT IT_DATA INTO WA_DATA.
    IF WA_DATA-SEL = 'X'.
      WA_SELS-PUR_NUM  = WA_DATA-PUR_NUM.
      WA_SELS-CRT_DATE = WA_DATA-CRT_DATE.
      WA_SELS-VEND_NUM = WA_DATA-VEND_NUM.
      WA_SELS-PAY_KEY  = WA_DATA-PAY_KEY .
      WA_SELS-MAT_NUM  = WA_DATA-MAT_NUM .
      WA_SELS-PUR_TXT  = WA_DATA-PUR_TXT .
      WA_SELS-PLT_NUM  = WA_DATA-PLT_NUM .
      WA_SELS-STOR_LOC = WA_DATA-STOR_LOC.
      APPEND WA_SELS TO IT_SELS.
    ENDIF.
  ENDLOOP.
  CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
      FORMNAME           = 'ZXLI_TEST_003'
    IMPORTING
      FM_NAME            = L_FM_NAME
    EXCEPTIONS
      NO_FORM            = 1
      NO_FUNCTION_MODULE = 2
      OTHERS             = 3.
  CALL FUNCTION L_FM_NAME
    TABLES
      IT_DATA = IT_SELS.
*  CLEAR IT_SELS[].
ENDFORM.                    "FM_BUTTON_PRT

你可能感兴趣的:(C++,c,C#)