2009年11月19日 星期四

彈出訊息視窗

在程式編寫時希望在USER對執行某個事件時
回傳一個資訊給USER詢問是否要再向下執行
這時我們可以拋出一個視窗給USER決定與選擇

  CALL FUNCTION 'POPUP_TO_CONFIRM'
    EXPORTING
TITLEBAR  = '確認視窗'
 TEXT_QUESTION    = '確認是否執行'
START_COLUMN    = 25
START_ROW      = 6
   IMPORTING
ANSWER        = L_IO
   EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS      = 2
    .
  IF L_IO = '1'.
    PERFORM TRANSFER_DATA.
  ENDIF.
  IF L_IO = '2'.
    MESSAGE S001(00) WITH '已終止傳送...'.
  ENDIF.

2009年11月10日 星期二

BAPI_GOODSMVT_CREATE

庫存盤點在作SCAN BARCODE之後依盤虧盤盈的結果依相同的PLANTStorage Location BY BATCH 去作311 Movement
使用BAPI_GOODSMVT_CREATE 來處理異動
基本結構為六項:Headergm_codegm_head_retmat_docgm_itemreturn


REPORT  ZBEN_AUTO_GT.
************************************************************************
* Data type definition segment
************************************************************************
*Header
DATA: GM_HEADER LIKE BAPI2017_GM_HEAD_01.
*GM_code
DATA: BEGIN OF GM_CODE.
    INCLUDE STRUCTURE BAPI2017_GM_CODE.
DATA: END OF GM_CODE.
*GM_head_ret
DATA: BEGIN OF GM_HEADRET.
    INCLUDE STRUCTURE BAPI2017_GM_HEAD_RET.
DATA: END OF GM_HEADRET.
*Mat_doc
DATA: MAT_DOC LIKE BAPI2017_GM_HEAD_RET-MAT_DOC.
*GM_item
DATA: BEGIN OF GM_ITEM OCCURS 100.
    INCLUDE STRUCTURE BAPI2017_GM_ITEM_CREATE.
DATA: END OF GM_ITEM.
*Return Msg
DATA: BEGIN OF ERRMSG OCCURS 10.
    INCLUDE STRUCTURE BAPIRET2.
DATA: END OF ERRMSG.

************************************************************************
* Selection screen definition segment
************************************************************************
PARAMETERS: P_MATNR LIKE MCHB-MATNR OBLIGATORY.
PARAMETERS: P_WERKS LIKE MCHB-WERKS OBLIGATORY.
PARAMETERS: P_LGORT LIKE MCHB-LGORT OBLIGATORY.

************************************************************************
* Main program entry
************************************************************************
**Header
GM_HEADER-PSTNG_DATE = '20091031'. "SY-DATUM.
GM_HEADER-DOC_DATE   = '20091031'. "SY-DATUM.
** IF PACK_NO NE SPACE.
*    GM_HEADER-REF_DOC_NO = POITEM-PACK_NO "DELIVER NOTE - GR
*    GM_HEADER-HEADER_TXT = POITEM-PACK_NO " FOR GT
** ENDIF.
**Code
GM_CODE-GM_CODE = '04'.
**Item
GM_ITEM-MATERIAL = ' 2C P 906011A F001'.
GM_ITEM-PLANT = 1000.
GM_ITEM-STGE_LOC = ' 14A 1'.
GM_ITEM-BATCH = ' 5M C1680002'.
GM_ITEM-MOVE_TYPE = '311'.
GM_ITEM-MVT_IND = ''.
GM_ITEM-ENTRY_QNT = 2.
GM_ITEM-ENTRY_UOM = 'EA'.
GM_ITEM-MOVE_STLOC = ' 1A 01'.
GM_ITEM-NO_TRANSFER_REQ = 'X'.
APPEND GM_ITEM.

CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
GOODSMVT_HEADER    = GM_HEADER
GOODSMVT_CODE = GM_CODE   "Transfer posting
*   IMPORTING
*    GOODSMVT_HEADRET = GM_HEADRET
*    MATERIALDOCUMENT = MAT_DOC
*    MATDOCUMENTYEAR   =
  TABLES
GOODSMVT_ITEM = GM_ITEM
RETURN     = ERRMSG
  EXCEPTIONS
OTHERS     = 1.

IF ERRMSG[] IS INITIAL.
  REFRESH: GM_ITEM, ERRMSG.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
  WAIT = 'X'.
ELSE.
*  MESSAGE = ERRMSG-MESSAGE.
  EXIT.
ENDIF.

2009年11月7日 星期六

ALV自訂工具按鈕控制

於ALV的STATUS SET內新增一個自訂的按鈕設定好圖示與回傳CODE
在EVENT這邊呼叫
並讀取 RT_EVENTS的KEY值為SLIS_EV_USER_COMMAND傳回的CODE
這時如果有值時..於內編寫程式要作那些事件

  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
    EXPORTING
  I_LIST_TYPE = 0
    IMPORTING
  ET_EVENTS   = RT_EVENTS.
  READ TABLE RT_EVENTS WITH KEY NAME = SLIS_EV_USER_COMMAND
   INTO LS_EVENT.
  IF SY-SUBRC = 0.

  ENDIF.

2009年11月2日 星期一

ALV架構

呼叫前必須先完成TYPE-POOLS與ALV的欄位宣告
再程式輸出時呼叫CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'來完成


*&---------------------------------------------------------------------*
*& Report  ZBEN_TEST01
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  ZBEN_TEST01 .
************************************************************************
* TYPES and TYPE-POOLS *
************************************************************************
TYPE-POOLS: SLIS.
************************************************************************
* Working Area & Internal Tables    *
************************************************************************
*ITAB
DATA: BEGIN OF GW_RPT,
    EBELN LIKE EKPO-EBELN,
    EBELP LIKE EKPO-EBELP,
  END OF GW_RPT.
DATA: GT_RPT LIKE GW_RPT OCCURS 0 WITH HEADER LINE.

*ALV
DATA: GT_FIELDCAT  TYPE SLIS_T_FIELDCAT_ALV,
  GT_SORTINFO  TYPE SLIS_T_SORTINFO_ALV,
  GT_EVENTS    TYPE SLIS_T_EVENT,
  G_REPID   TYPE SY-REPID,
  L_LAYOUT TYPE SLIS_LAYOUT_ALV,
  L_SELFIELD   TYPE SLIS_SELFIELD,
  SAV_SY_REPID TYPE SY-REPID,
  L_PRINT   TYPE SLIS_PRINT_ALV,
  GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
DATA: BEGIN OF SELTAB OCCURS 0.
    INCLUDE STRUCTURE RSPARAMS.
DATA: END OF SELTAB.
************************************************************************
* Selection Screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_EBELN LIKE EKKO-EBELN OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
* START-OF-SELECTION Event *
************************************************************************
START-OF-SELECTION.
  PERFORM GET_DATA.
  PERFORM PROCESS_DATA.
  PERFORM PRINT_DATA.

************************************************************************
* END-OF-SELECTION Event    *
************************************************************************
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*&   Form  GET_DATA
*&---------------------------------------------------------------------*
FORM GET_DATA.
  SELECT EBELN EBELP FROM EKPO
    INTO CORRESPONDING FIELDS OF TABLE GT_RPT
   WHERE EBELN = P_EBELN.
ENDFORM.     " GET_DATA
*&---------------------------------------------------------------------*
*&   Form  PROCESS_DATA
*&---------------------------------------------------------------------*
FORM PROCESS_DATA.
ENDFORM.     " PROCESS_DATA
*&---------------------------------------------------------------------*
*&   Form  PRINT_DATA
*&---------------------------------------------------------------------*
FORM PRINT_DATA.
  G_REPID = SY-REPID.
  PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].
  PERFORM SORTINFO_INIT USING GT_SORTINFO[].
  PERFORM EVENTS_INIT   USING GT_EVENTS[].
  PERFORM LAYOUT_INIT   USING L_LAYOUT.
  PERFORM PRINT_INIT    USING L_PRINT.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
    I_CALLBACK_PROGRAM    = G_REPID
    IT_FIELDCAT   = GT_FIELDCAT[]
    IT_SORT   = GT_SORTINFO[]
    IT_EVENTS     = GT_EVENTS
    IS_LAYOUT     = L_LAYOUT
    I_SAVE    = 'A'
    IS_PRINT = L_PRINT
   TABLES
    T_OUTTAB = GT_RPT.
  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.     " PRINT_DATA
*---------------------------------------------------------------------*
*    FORM fieldcat_inite    *
*---------------------------------------------------------------------*
FORM FIELDCAT_INIT USING IT_FIELDCATE TYPE SLIS_T_FIELDCAT_ALV.
  DATA: ST_FIELDCATE TYPE SLIS_FIELDCAT_ALV.
  ST_FIELDCATE-TABNAME = 'IT_RPT'.
  ST_FIELDCATE-FIELDNAME   = 'EBELN'.
  ST_FIELDCATE-SELTEXT_L   = '單號'.
  ST_FIELDCATE-OUTPUTLEN   = 10.
  ST_FIELDCATE-KEY = 'X'.
  APPEND ST_FIELDCATE TO IT_FIELDCATE.
  CLEAR  ST_FIELDCATE.
  ST_FIELDCATE-TABNAME = 'IT_RPT'.
  ST_FIELDCATE-FIELDNAME   = 'EBELP'.
  ST_FIELDCATE-SELTEXT_L   = '項次'.
  ST_FIELDCATE-OUTPUTLEN   = 10.
  ST_FIELDCATE-KEY = 'X'.
  APPEND ST_FIELDCATE TO IT_FIELDCATE.
  CLEAR  ST_FIELDCATE.
ENDFORM.
*---------------------------------------------------------------------*
*    FORM sortinfo_init     *
*---------------------------------------------------------------------*
FORM SORTINFO_INIT  USING IT_SORTINFOE TYPE SLIS_T_SORTINFO_ALV.
  DATA: ST_SORTE TYPE SLIS_SORTINFO_ALV.
ENDFORM.
*---------------------------------------------------------------------*
*    FORM events_init   *
*---------------------------------------------------------------------*
FORM EVENTS_INIT USING RT_EVENTS TYPE SLIS_T_EVENT.
  DATA: LS_EVENT TYPE SLIS_ALV_EVENT.
  CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
   EXPORTING
    I_LIST_TYPE = 0
   IMPORTING
    ET_EVENTS   = RT_EVENTS.
  READ TABLE RT_EVENTS WITH KEY NAME = SLIS_EV_TOP_OF_PAGE
   INTO LS_EVENT.
  IF SY-SUBRC = 0.
    MOVE 'TOP_OF_PAGE' TO LS_EVENT-FORM.
    MODIFY RT_EVENTS FROM LS_EVENT INDEX SY-TABIX.
  ENDIF.
ENDFORM.
*---------------------------------------------------------------------*
*    FORM USER_COMMAND *
*---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
    RS_SELFIELD TYPE SLIS_SELFIELD.
  L_SELFIELD = RS_SELFIELD.
ENDFORM.
*&---------------------------------------------------------------------*
*&   Form  LAYOUT_INIT
*&---------------------------------------------------------------------*
FORM LAYOUT_INIT USING P_L_LAYOUT TYPE SLIS_LAYOUT_ALV.
  P_L_LAYOUT-ZEBRA  = 'X'.
ENDFORM.     " LAYOUT_INIT
*&---------------------------------------------------------------------*
*&   Form  PRINT_INIT
*&---------------------------------------------------------------------*
FORM PRINT_INIT USING  P_L_PRINT TYPE SLIS_PRINT_ALV.
ENDFORM.     " PRINT_INIT