ITPub博客

首页 > 应用开发 > IT综合 > ABAP学习

ABAP学习

原创 IT综合 作者:jiang2008 时间:2007-03-07 12:49:47 0 删除 编辑
ABAP学习[@more@]

关键词ABAP

根据公司的需要,由MM学习转为ABAP学习。以前做过ASP,做过JAVA,我想学习ABAP不是什么太难的事情,最近两天写了两个程序,把源码粘贴上来,供以后参考。

报表一:根据输入发电量统计物资消耗情况。

*&---------------------------------------------------------------------*
*& 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: P_ZFDL TYPE P DECIMALS 2 OBLIGATORY.
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
* <-- p2 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
* <-- p2 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.
IF NOT P_ZFDL IS INITIAL.
IT_RESULT-ZWZXH = IT_RESULT-DMBTR / P_ZFDL.
ELSE.
IT_RESULT-ZWZXH = 0.
ENDIF.
COLLECT IT_RESULT.
ENDLOOP.
ENDFORM. " FRM_PROCESS
*&---------------------------------------------------------------------*
*& Form FRM_OUTPUT
*&---------------------------------------------------------------------*
* 输出数据
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 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
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_HEAD_OUTPUT .

ULINE .
WRITE: '|' ,(10) '电厂编号' CENTERED, '|' , (40) '电厂名称' CENTERED, '|' , (15) '计算期间' CENTERED, '|' ,
(21) '物资消耗(万元)' CENTERED , '|' , (22) '物资消耗(万元/kwh)' CENTERED , '|'.
ULINE /.

ENDFORM. " FRM_HEAD_OUTPUT

报表二:统计库存资金占用情况

*&---------------------------------------------------------------------*
*& Report Z_TEST03
*&
*&---------------------------------------------------------------------*
*&Author : chenyanjun
*&
*&---------------------------------------------------------------------*

REPORT Z_TEST03 NO STANDARD PAGE HEADING.
*----------------定义工厂表所需信息-----------------*
DATA: BEGIN OF IT_T001W OCCURS 0,
WERKS LIKE T001W-WERKS ,
NAME1 LIKE T001W-NAME1 ,
PFACH LIKE T001W-PFACH ,
END OF IT_T001W.
*---------------定义总库存额信息------------------------*
DATA: BEGIN OF IT_S032 OCCURS 0,
WBWBEST LIKE S032-WBWBEST,
WERKS LIKE S032-WERKS,
END OF IT_S032.
*--------------------定义结果数据信息-----------------------------*
DATA: BEGIN OF IT_RESULT OCCURS 0,
NAME1 LIKE T001W-NAME1,
PFACH LIKE T001W-PFACH,
WBWBEST LIKE S032-WBWBEST,
END OF IT_RESULT.

DATA PWBWBEST TYPE P DECIMALS 3.

SELECT-OPTIONS S_WERKS FOR IT_T001W-WERKS.
*--------------------输出面眉HEADING-------------------*
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_HEAD_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_HEAD_OUTPUT .
ULINE.
WRITE: '|' , (30) '电厂' CENTERED,'|', (25) '装机容量(kwh)' CENTERED,'|',
(28) '库存资金(万元)' CENTERED, '|' , (28) '库存资金占用额(万元/kwh)' CENTERED , '|'.
ULINE /.
ENDFORM. " FRM_HEAD_OUTPUT
*&---------------------------------------------------------------------*
*& Form FRM_GETDATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_GETDATA .

SELECT * FROM T001W
INTO CORRESPONDING FIELDS OF TABLE IT_T001W
WHERE FABKL EQ 'ZT'.

SELECT * FROM S032
INTO CORRESPONDING FIELDS OF TABLE IT_S032
WHERE WERKS IN S_WERKS.
ENDFORM. " FRM_GETDATA
*&---------------------------------------------------------------------*
*& Form FRM_PROCESS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_PROCESS .
LOOP AT IT_S032.
CLEAR IT_RESULT.
READ TABLE IT_T001W WITH KEY
WERKS = IT_S032-WERKS.
IT_RESULT-NAME1 = IT_T001W-NAME1.
IT_RESULT-PFACH = IT_T001W-PFACH * 10000.
IT_RESULT-WBWBEST = IT_S032-WBWBEST / 10000.
* IT_RESULT-PWBWBEST = IT_RESULT-WBWBEST / IT_RESULT-PFACH.
COLLECT IT_RESULT.
ENDLOOP.
ENDFORM. " FRM_PROCESS
*&---------------------------------------------------------------------*
*& Form FRM_OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FRM_OUTPUT .
LOOP AT IT_RESULT.
PWBWBEST = IT_RESULT-WBWBEST * 10000 / IT_RESULT-PFACH.
WRITE: '|', (30) IT_RESULT-NAME1 , '|' , (25) IT_RESULT-PFACH CENTERED , '|' ,
(28) IT_RESULT-WBWBEST, '|', (28) PWBWBEST , '|'.
ULINE /.
ENDLOOP.
ENDFORM. " FRM_OUTPUT

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/581999/viewspace-903185/,如需转载,请注明出处,否则将追究法律责任。

上一篇: ASP增删改查函数
请登录后发表评论 登录
全部评论
  • 博文量
    171
  • 访问量
    2895746