ABAP程式示例3
一個很好的ALV示例。
[@more@]*&---------------------------------------------------------------------*
*& Report Z_TEST01
*&
*&---------------------------------------------------------------------*
REPORT Z_TEST01 NO STANDARD PAGE HEADING.
*--------------------------定義資料------------------------------------*
*WERKS=工廠,NAME1=工廠名稱,BUDAT=憑證日期,MBLNR=物料憑證編號,
*MJAHR=物料憑證年度,VGART=憑證型別----------*
DATA: BEGIN OF IT_RESULT OCCURS 0,
WERKS LIKE T001W-WERKS,
NAME1 LIKE T001W-NAME1,
BUDAT LIKE MKPF-BUDAT,
DMBTR LIKE MSEG-DMBTR,
ZWZXH TYPE P DECIMALS 3,
END OF IT_RESULT.
DATA: BEGIN OF IT_T001W OCCURS 0,
WERKS LIKE T001W-WERKS,
NAME1 LIKE T001W-NAME1,
END OF IT_T001W.
DATA: BEGIN OF IT_MKPF OCCURS 0,
MBLNR LIKE MKPF-MBLNR,
MJAHR LIKE MKPF-MJAHR,
BUDAT LIKE MKPF-BUDAT,
END OF IT_MKPF.
DATA: BEGIN OF IT_MSEG OCCURS 0,
MBLNR LIKE MSEG-MBLNR,
MJAHR LIKE MSEG-MJAHR,
ZEILE LIKE MSEG-ZEILE,
WERKS LIKE MSEG-WERKS,
DMBTR LIKE MSEG-DMBTR,
SHKZG LIKE MSEG-SHKZG,
END OF IT_MSEG.
TYPE-POOLS: SLIS.
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE,
IS_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: TMP_TITLE(70),
TMP_REPID LIKE SY-REPID.
*----------------初始選擇螢幕--------------------*
SELECT-OPTIONS: S_WERKS FOR IT_RESULT-WERKS,
S_BUDAT FOR IT_RESULT-BUDAT.
PARAMETERS: R1 RADIOBUTTON GROUP RAD1,
R2 RADIOBUTTON GROUP RAD1 DEFAULT 'X'.
*-------------------TOP-OF-PAGE------------------*
TOP-OF-PAGE.
PERFORM FRM_HEAD_OUTPUT .
*------------------START-OF-SELECTION-------------*
START-OF-SELECTION.
PERFORM FRM_GETDATA.
PERFORM FRM_PROCESS.
*------------------END-OF-SELECTION---------------*
END-OF-SELECTION.
PERFORM FRM_OUTPUT.
*&---------------------------------------------------------------------*
*& Form FRM_GETDATA
*&---------------------------------------------------------------------*
* 獲取資料
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM FRM_GETDATA .
SELECT * FROM T001W
INTO CORRESPONDING FIELDS OF TABLE IT_T001W
WHERE WERKS IN S_WERKS.
SELECT * FROM MKPF
INTO CORRESPONDING FIELDS OF TABLE IT_MKPF
WHERE VGART EQ 'WA' AND BUDAT IN S_BUDAT.
SELECT * FROM MSEG
INTO CORRESPONDING FIELDS OF TABLE IT_MSEG
WHERE WERKS IN S_WERKS
AND BWART IN ('201','202','261','262').
ENDFORM. " FRM_GETDATA
*&---------------------------------------------------------------------*
*& Form FRM_PROCESS
*&---------------------------------------------------------------------*
* 對資料進行處理
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM FRM_PROCESS .
LOOP AT IT_MSEG.
CLEAR IT_RESULT.
READ TABLE IT_MKPF WITH KEY MBLNR = IT_MSEG-MBLNR
MJAHR = IT_MSEG-MJAHR.
CHECK SY-SUBRC EQ 0.
READ TABLE IT_T001W WITH KEY WERKS = IT_MSEG-WERKS.
IT_RESULT-WERKS = IT_T001W-WERKS.
IT_RESULT-NAME1 = IT_T001W-NAME1.
IT_RESULT-BUDAT = IT_MKPF-BUDAT.
CASE IT_MSEG-SHKZG.
WHEN 'H'.
IT_RESULT-DMBTR = IT_MSEG-DMBTR.
WHEN 'S'.
IT_RESULT-DMBTR = 0 - IT_MSEG-DMBTR.
ENDCASE.
COLLECT IT_RESULT.
ENDLOOP.
ENDFORM. " FRM_PROCESS
*&---------------------------------------------------------------------*
*& Form FRM_OUTPUT
*&---------------------------------------------------------------------*
* 輸出資料
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM FRM_OUTPUT .
IF R2 = 'X' .
GT_FIELDCAT-FIELDNAME = 'WERKS'.
GT_FIELDCAT-SELTEXT_M = '物料號'.
APPEND GT_FIELDCAT.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-FIELDNAME = 'NAME1'.
GT_FIELDCAT-SELTEXT_M = '物料名稱'.
GT_FIELDCAT-OUTPUTLEN = 30.
APPEND GT_FIELDCAT.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-FIELDNAME = 'BUDAT'.
GT_FIELDCAT-SELTEXT_M = '記帳日期'.
GT_FIELDCAT-OUTPUTLEN = 10.
APPEND GT_FIELDCAT.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-FIELDNAME = 'DMBTR'.
GT_FIELDCAT-SELTEXT_M = '本位幣金額'.
GT_FIELDCAT-OUTPUTLEN = 20.
APPEND GT_FIELDCAT.
CLEAR GT_FIELDCAT.
GT_FIELDCAT-FIELDNAME = 'ZWZXH'.
GT_FIELDCAT-SELTEXT_M = '物資消耗(萬元/kwh)'.
GT_FIELDCAT-OUTPUTLEN = 30.
APPEND GT_FIELDCAT.
CLEAR GT_FIELDCAT.
TMP_TITLE = '庫存資金佔用額'.
TMP_REPID = SY-REPID.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = TMP_REPID
IT_FIELDCAT = GT_FIELDCAT[]
I_GRID_TITLE = TMP_TITLE
TABLES
T_OUTTAB = IT_RESULT.
ENDIF.
IF R1 = 'X'.
LOOP AT IT_RESULT.
WRITE: '|',(10) IT_RESULT-WERKS CENTERED,
'|',(40) IT_RESULT-NAME1,
'|',(15) IT_RESULT-BUDAT CENTERED,
'|',(21) IT_RESULT-DMBTR,
'|',(22) IT_RESULT-ZWZXH ,
'|'.
ULINE /.
ENDLOOP.
ENDIF.
ENDFORM. " FRM_OUTPUT
*&---------------------------------------------------------------------*
*& Form FRM_HEAD_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* *----------------------------------------------------------------------*
FORM FRM_HEAD_OUTPUT .
ULINE .
WRITE: '|',(10) '物料號' CENTERED,
'|',(40) '物料名稱' CENTERED,
'|',(15) '記賬期間' CENTERED,
'|',(21) '本位幣金額' CENTERED ,
'|',(22) '物資消耗(萬元/kwh)' CENTERED ,
'|'.
ULINE /.
ENDFORM. " FRM_HEAD_OUTPUT
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/8356764/viewspace-929419/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- ABAP程式示例
- ABAP程式示例4
- ABAP中文示例1
- ABAP中文示例2
- ABAP程式Hello World
- 【MyBatis】3:MyBatis環境搭建及入門程式示例MyBatis
- S2S3H4 整合程式碼示例S3
- 如何使用 ABAP 程式消費 SAP ABAP OData 服務
- flutter3示例頁Flutter
- BDC程式示例C程式
- ABAP 程式比對(Compare)
- ABAP初學者如何系統地學習ABAP程式設計?程式設計
- SAP ABAP 程式之間的呼叫
- RabbitMQ 程式碼示例MQ
- lisp 程式碼示例Lisp
- 排序程式碼示例排序
- R/3 ABAP開發學習筆記(轉)筆記
- 在SAP雲平臺ABAP程式設計環境上編寫第一段ABAP程式程式設計
- 一些通過SAP ABAP程式碼審查得出的ABAP程式設計最佳實踐程式設計
- ABAP的程式碼規範標準
- 如何使用ABAP程式碼反序列化JSON字串成ABAP結構JSON字串
- Java NIO 程式碼示例Java
- ALVALV程式示例
- java SPI 程式碼示例Java
- ABAP面試題系列:寫一組會出現死鎖(Deadlock)的ABAP程式面試題
- 視窗程式框架示例程式碼框架
- ABAP程式碼分析工具 - 事務碼SQF
- 如何使用ABAP程式碼建立SAP Product CategoryGo
- 如何使用 ABAP 程式碼解析 XML 檔案XML
- 使用 Prometheus 監控 SAP ABAP 應用程式Prometheus
- [原]解除ABAP程式編輯鎖的方法
- 利用abap寫程式寄email給客戶AI
- ABAP 動態程式設計-FIELD-SYMBOLS程式設計Symbol
- ABAP動態程式設計-DESCRIBE FIELD程式設計
- 備份ABAP程式碼 (分模組儲存)
- [轉載]ABAP中查詢程式碼的標準程式
- Kafka 1.0.0 d程式碼示例Kafka
- 靜態代理程式碼示例