ALV报表和SMARTFORM的结合

 

ALV报表和SMARTFORM的结合

*&---------------------------------------------------------------------*
*& Report  ZALV_DGY
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZALV_DGY.

TYPE-POOLS: SLIS.

TABLES:MARA.


*
DATABEGIN OF IT_ST OCCURS 10,
       MATNR LIKE MARA-MATNR,
       WESCH LIKE MARA-WESCH,
       WRKST LIKE MARA-WRKST,
       END OF IT_ST.

*DATA IT_ST LIKE MARA OCCURS 0.

PARAMETERS:P_ERSDA LIKE MARA-ERSDA.
SELECT-OPTIONS:S_MATNR FOR MARA-MATNR.


* Internal Tables and Variants for ALV output
CONSTANTS:  C_DDICTXT_M(1TYPE C VALUE 'M'.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA: GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
      GS_VARIANT LIKE DISVARIANT.
DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER,
      G_TOP_OF_PAGE TYPE SLIS_FORMNAME VALUE 'TOP_OF_PAGE'.
DATA: G_REPID TYPE SY-REPID,
      G_STATUS_FORM TYPE SLIS_FORMNAME VALUE 'PF_STATUS_SET',
      G_COMMAND_FORM TYPE SLIS_FORMNAME VALUE 'USER_COMMAND',
      G_SAVE(1).
DATA: IT_SORT_LINE TYPE SLIS_SORTINFO_ALV,
      IT_SORT_TAB TYPE SLIS_T_SORTINFO_ALV.


START-OF-SELECTION.
   PERFORM READ_IT_ST.


END-OF-SELECTION.
   PERFORM OUTPUT_RESULT_AS_ALV TABLES IT_ST
                          USING  'IT_ST'.


*&---------------------------------------------------------------------

*&      Form  READ_IT_ST
*&---------------------------------------------------------------------

*       text
*----------------------------------------------------------------------

*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------

FORM READ_IT_ST .
  SELECT MATNR WESCH WRKST FROM MARA
   INTO CORRESPONDING FIELDS OF TABLE IT_ST
     WHERE MATNR IN S_MATNR
           AND ERSDA > P_ERSDA.

  IF SY-SUBRC NE 0.
    EXIT.
  ENDIF.

ENDFORM.                    " READ_IT_ST


*&---------------------------------------------------------------------

*&      Form  OUTPUT_RESULT_AS_ALV
*&---------------------------------------------------------------------

*       Output result to screen using ALV format
*----------------------------------------------------------------------

*      -->T_ITAB  text
*      -->P_ITABNAME  text
*----------------------------------------------------------------------

FORM OUTPUT_RESULT_AS_ALV TABLES T_ITAB
                          USING  P_ITABNAME TYPE SLIS_TABNAME.
  G_REPID = SY-REPID.
  REFRESH IT_FIELDCAT.

* pass over structure for output list
  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
       EXPORTING
            I_PROGRAM_NAME         = G_REPID
            I_INTERNAL_TABNAME     = P_ITABNAME
            I_INCLNAME             = G_REPID
       CHANGING
            CT_FIELDCAT            = IT_FIELDCAT
       EXCEPTIONS
            INCONSISTENT_INTERFACE = 1
            PROGRAM_ERROR          = 2
            OTHERS                 = 3.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT IT_FIELDCAT INTO WA_FIELDCAT.
    CASE WA_FIELDCAT-FIELDNAME.
      WHEN 'MATNR' OR 'MAKTX'.
        WA_FIELDCAT-KEY = 'X'.
      WHEN 'TOTAL'.
        WA_FIELDCAT-SELTEXT_S = TEXT-T01.
        WA_FIELDCAT-SELTEXT_M = TEXT-T01.
        WA_FIELDCAT-SELTEXT_L = TEXT-T01.
        WA_FIELDCAT-REPTEXT_DDIC = TEXT-T01.
        WA_FIELDCAT-DDICTXT   = C_DDICTXT_M.
    ENDCASE.
    MODIFY IT_FIELDCAT FROM WA_FIELDCAT.
  ENDLOOP.

  G_SAVE = 'A'.
  GS_LAYOUT-zebra = 'X'.
*  GS_LAYOUT-BOX_FIELDNAME = 'SELKZ'.
  GS_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.

* Build sort info
*  REFRESH IT_SORT_TAB.
*  CLEAR IT_SORT_LINE.
*  IT_SORT_LINE-FIELDNAME = 'EKGRP'.
*  IT_SORT_LINE-UP = 'X'.
*  IT_SORT_LINE-SUBTOT ='X'.
*  APPEND IT_SORT_LINE TO IT_SORT_TAB.

*"List Header for Top-Of-Page
*  PERFORM COMMENT_BUILD USING GT_LIST_TOP_OF_PAGE[].

* Display data in ALV Grid
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      I_CALLBACK_PROGRAM                = G_REPID
      I_CALLBACK_PF_STATUS_SET          = G_STATUS_FORM
       I_CALLBACK_USER_COMMAND           = G_COMMAND_FORM
*      I_CALLBACK_TOP_OF_PAGE            = G_TOP_OF_PAGE
      IS_LAYOUT                         = GS_LAYOUT
      IT_FIELDCAT                       = IT_FIELDCAT[]
      I_SAVE                            = G_SAVE
      IS_VARIANT                        = GS_VARIANT
      IT_SORT                           = IT_SORT_TAB
    TABLES
      T_OUTTAB                          = T_ITAB[]
    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.                    " OUTPUT_RESULT_AS_ALV
*&---------------------------------------------------------------------

*&      Form  TOP_OF_PAGE
*&---------------------------------------------------------------------

*       Top of page, called by ALV function
*----------------------------------------------------------------------

FORM TOP_OF_PAGE.
  CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
       EXPORTING
           IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
ENDFORM.                    " TOP_OF_PAGE
*&---------------------------------------------------------------------

*&      Form  COMMENT_BUILD
*&---------------------------------------------------------------------

*       Filling long text of top into a table
*----------------------------------------------------------------------

*       <-->LT_TOP_OF_PAGE  text
*----------------------------------------------------------------------

FORM COMMENT_BUILD USING LT_TOP_OF_PAGE TYPE
                                     SLIS_T_LISTHEADER.
  DATA: LS_LINE TYPE SLIS_LISTHEADER.

* LIST HEADING LINE: TYPE H
  CLEAR LS_LINE.
  LS_LINE-TYP  = 'H'.
* LS_LINE-KEY:  NOT USED FOR THIS TYPE
  LS_LINE-INFO = 'TITLE'.
  APPEND LS_LINE TO LT_TOP_OF_PAGE.

* STATUS LINE: TYPE S
  CLEAR LS_LINE.
  LS_LINE-TYP  = 'S'.
  LS_LINE-KEY  = 'Date:'.
  LS_LINE-INFO = SY-DATUM.
  APPEND LS_LINE TO LT_TOP_OF_PAGE.
  LS_LINE-KEY  = 'User:'.
  LS_LINE-INFO = SY-UNAME.
  APPEND LS_LINE TO LT_TOP_OF_PAGE.

* ACTION LINE: TYPE A
  CLEAR LS_LINE.
  LS_LINE-TYP = 'A'.
  LS_LINE-INFO = 'Some other text'.
  APPEND LS_LINE TO LT_TOP_OF_PAGE.
ENDFORM.                    " COMMENT_BUILD


*以下是加按钮的过程.
FORM  PF_STATUS_SET USING rt_extab TYPE slis_t_extab.
   SET PF-STATUS '1001' .
 ENDFORM.



 FORM user_command  using  r_ucomm LIKE sy-ucomm  rs_selfield TYPE
slis_selfield.

  DATA : ld_sammg LIKE vbsk-sammg.
  CASE r_ucomm.
    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN 'ENTER' OR 'CANCEL'.
      SET SCREEN 0.
      LEAVE SCREEN .
*    WHEN 'UPDATE_RQ'.
*      LOOP AT itab.
*      ENDLOOP.
    WHEN 'ZU01'.
*      CALL SCREEN 200.
*      WRITE: 'OUT'.
     " MESSAGE 'HI 你好这是按钮事件' TYPE 'I'.
     PERFORM OutPutSmart .

  ENDCASE.
ENDFORM.

FORM OutPutSmart .


DATA: LF_FM_NAME            TYPE RS38L_FNAM.
DATA: LF_FORMNAME           TYPE TDSFNAME.

*DATA: BEGIN OF WA,
*      MATNR LIKE MARA-MATNR,
*      WESCH LIKE MARA-WESCH,
*      WRKST LIKE MARA-WRKST,
*      END OF WA.
DATA ITab like mara OCCURS 0.
data lien like mara.

LOOP AT IT_ST.
   lien-matnr = it_st-matnr.
   lien-WESCH = it_st-WESCH.
   lien-wrkst = it_st-wrkst.
   APPEND lien TO itab.

ENDLOOP.


*DATA ITab LIKE WA OCCURS 0 WITH HEADER LINE.

*
*SELECT MATNR WESCH WRKST
*    into CORRESPONDING FIELDS OF TABLE ITab
*    FROM MARA.

  LF_FORMNAME = 'ZSMARTFORM_DGY'.
* determine smartform function module for delivery note
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
         EXPORTING  FORMNAME           = LF_FORMNAME
*                 variant            = ' '
*                 direct_call        = ' '
         IMPORTING  FM_NAME            = LF_FM_NAME
         EXCEPTIONS NO_FORM            = 1
                    NO_FUNCTION_MODULE = 2
                    OTHERS             = 3.



    CALL FUNCTION LF_FM_NAME
      EXPORTING
*       ARCHIVE_INDEX              =
*       ARCHIVE_INDEX_TAB          =
*       ARCHIVE_PARAMETERS         =
*       CONTROL_PARAMETERS         =
*       MAIL_APPL_OBJ              =
*       MAIL_RECIPIENT             =
*       MAIL_SENDER                =
*       OUTPUT_OPTIONS             =
*       USER_SETTINGS              = 'X'
        CODE                       = 'AA'
*     IMPORTING
*       DOCUMENT_OUTPUT_INFO       =
*       JOB_OUTPUT_INFO            =
*       JOB_OUTPUT_OPTIONS         =
      TABLES
        IT_TABLE1                  = ITAB
*     EXCEPTIONS
*       FORMATTING_ERROR           = 1
*       INTERNAL_ERROR             = 2
*       SEND_ERROR                 = 3
*       USER_CANCELED              = 4
*       OTHERS                     = 5
              .
    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.  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值