成本中心预算查询

*&----------------------------------------------------------------------------------------------------
*&  程序名称: *****
*&-------------------------------------------- 更改记录 -----------------------------------------------

REPORT  ZFIR*** NO STANDARD PAGE HEADING LINE-SIZE 334.
*-----------------------------------------------------------*
*定义变量                                                    *
*-----------------------------------------------------------*
*  权限检查表
TABLES: USREFUS,ADRP,ADCP,BKPF.

TABLES: T001,   "公司代码名称
        CSKT,   "成本中心说明文本
        SKAT,   "总帐科目主记录
        FMBDT,  "预算值
        COSP,   "实际发生值
        FMIOI.  "承诺值
DATA: BEGIN OF CHARGE OCCURS 0,
        KOSTL LIKE CSKT-KOSTL,  "成本中心
        SAKNR LIKE SKAT-SAKNR,  "承诺项目
        HSLVT LIKE FMBDT-HSLVT, "年度总预算(已下达)
        HSL01 LIKE FMBDT-HSL01, "
        HSL02 LIKE FMBDT-HSL02, "
        HSL03 LIKE FMBDT-HSL03, "
        HSL04 LIKE FMBDT-HSL04, "
        HSL05 LIKE FMBDT-HSL05, "
        HSL06 LIKE FMBDT-HSL06, "
        HSL07 LIKE FMBDT-HSL07, "
        HSL08 LIKE FMBDT-HSL08, "
        HSL09 LIKE FMBDT-HSL09, "
        HSL10 LIKE FMBDT-HSL10, "
        HSL11 LIKE FMBDT-HSL11, "
        HSL12 LIKE FMBDT-HSL12, "
        HSLEND LIKE FMBDT-HSLVT, "
        WOG001 LIKE COSP-WOG001,  "实际消费预算
        WOG002 LIKE COSP-WOG002,  "
        WOG003 LIKE COSP-WOG003,  "
        WOG004 LIKE COSP-WOG004,  "
        WOG005 LIKE COSP-WOG005,  "
        WOG006 LIKE COSP-WOG006,  "
        WOG007 LIKE COSP-WOG007,  "
        WOG008 LIKE COSP-WOG008,  "
        WOG009 LIKE COSP-WOG009,  "
        WOG010 LIKE COSP-WOG010,  "
        WOG011 LIKE COSP-WOG011,  "
        WOG012 LIKE COSP-WOG012,  "
        WOGEND LIKE COSP-WOG012,  "
        FKBTR LIKE FMIOI-FKBTR,   "承诺消费预算
      END OF CHARGE.
DATA: BEGIN OF GT_OUT OCCURS 0,
        KOSTL LIKE CSKT-KOSTL,  "成本中心
        KTEXT LIKE CSKT-KTEXT,  "成本中心名称
        SAKNR LIKE SKAT-SAKNR,  "承诺项目
        TXT20 LIKE SKAT-TXT20,  "名称
        SHOW_HEJI(20),"显示合计项
        HSL LIKE FMBDT-HSL01,
        WOG LIKE COSP-WOG001,
        CHA LIKE FMBDT-HSLVT,"可用金额
     END OF GT_OUT.

DATA: BEGIN OF ITAB_CSKT OCCURS 0,
        KOSTL LIKE CSKT-KOSTL,  "成本中心
        KTEXT LIKE CSKT-KTEXT,  "成本中心名称
      END OF ITAB_CSKT.


DATA: G_BUTXT LIKE T001-BUTXT,
      G_KTEXT_LIST(200),
      G_TEXT(200) .


DATA: TMPALIAS    LIKE USREFUS-USERALIAS,
      TMPNAME     LIKE ADRP-NAME_LAST,
      TMPNUMBER   LIKE ADCP-PERSNUMBER,
      TMPROOM     LIKE ADCP-ROOMNUMBER,
      TMPBUKRS    LIKE T001-BUKRS.


*-----------------------------------------------------------*
*导入包含文件                                                *
*-----------------------------------------------------------*
INCLUDE ZFIR***_ALV.

*-----------------------------------------------------------*
*定义选择屏幕                                                *
*-----------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETER: BUKRS LIKE T001-BUKRS OBLIGATORY MODIF ID S1.
PARAMETERS: GJAHR LIKE FMBDT-RYEAR DEFAULT SY-DATUM+0(4),
            P_MONTH LIKE BKPF-MONAT OBLIGATORY DEFAULT SY-DATUM+4(2),
            P_MONTH1 LIKE BKPF-MONAT OBLIGATORY DEFAULT SY-DATUM+4(2)."月
SELECT-OPTIONS: FUNDSCTR FOR CSKT-KOSTL OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK B1.

INITIALIZATION.
  GET PARAMETER ID 'BUK' FIELD BUKRS.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    IF SCREEN-GROUP1 = 'S1'.
      SCREEN-INPUT = '0'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

*-----------------------------------------------------------*
*START-OF-SELECTION                                         *
*-----------------------------------------------------------*
START-OF-SELECTION.
**获取数据
  PERFORM PF_GET_DATA.
**处理数据
  PERFORM PF_EDIT_DATA.
**显示数据
  IF GT_OUT[] IS INITIAL.
    MESSAGE  '未找到可用数据,请检查输入的查询条件!' TYPE 'I'.
  ELSE.
    PERFORM PF_SHOW_DATA TABLES GT_OUT.
  ENDIF.


*&---------------------------------------------------------------------*
*&      Form  PF_GET_DATA
*&---------------------------------------------------------------------*
*       获取数据
*----------------------------------------------------------------------*
FORM PF_GET_DATA.


**** 加入查询权限检查  
*** 权限检查不从角色中取得,而是由维护个人信息中的房间号控制其查询所在公司代码之权限
  BUKRS = FUNDSCTR+3(4).
  SELECT SINGLE * FROM USREFUS WHERE BNAME = SY-UNAME.
  IF SY-SUBRC = 0.
    TMPALIAS = USREFUS-USERALIAS.
  ENDIF.
  SELECT SINGLE * FROM ADRP WHERE NAME_LAST = TMPALIAS.
  IF SY-SUBRC = 0.
    TMPNUMBER = ADRP-PERSNUMBER.
  ENDIF.
  SELECT SINGLE * FROM ADCP WHERE  PERSNUMBER = TMPNUMBER.
  IF SY-SUBRC = 0.
    TMPROOM = ADCP-ROOMNUMBER.
  ENDIF.

  CASE TMPROOM.
    WHEN '***'.TMPBUKRS = '5110'.
    WHEN '***'.TMPBUKRS = '5210'.
    WHEN '***'.TMPBUKRS = '5120'.
    WHEN '***'.TMPBUKRS = '5230'.
    WHEN '***'.TMPBUKRS = '5310'.
    WHEN '***'.TMPBUKRS = '****'.
  ENDCASE.

  DATA : L_OBJNR LIKE COSP-OBJNR.

  CLEAR CHARGE.
  SELECT * FROM FMBDT WHERE RYEAR = GJAHR AND RFUNDSCTR IN FUNDSCTR AND VALTYPE_9 = 'R1'.
    CHARGE-KOSTL = FMBDT-RFUNDSCTR.
    CHARGE-SAKNR = FMBDT-RCMMTITEM.
    CHARGE-HSLVT = - FMBDT-HSLVT.
    CHARGE-HSL01 = - FMBDT-HSL01.
    CHARGE-HSL02 = - FMBDT-HSL02.
    CHARGE-HSL03 = - FMBDT-HSL03.
    CHARGE-HSL04 = - FMBDT-HSL04.
    CHARGE-HSL05 = - FMBDT-HSL05.
    CHARGE-HSL06 = - FMBDT-HSL06.
    CHARGE-HSL07 = - FMBDT-HSL07.
    CHARGE-HSL08 = - FMBDT-HSL08.
    CHARGE-HSL09 = - FMBDT-HSL09.
    CHARGE-HSL10 = - FMBDT-HSL10.
    CHARGE-HSL11 = - FMBDT-HSL11.
    CHARGE-HSL12 = - FMBDT-HSL12.
    COLLECT CHARGE.
    CLEAR CHARGE.
  ENDSELECT.

  RANGES: OBJECT FOR COSP-OBJNR.
  LOOP AT FUNDSCTR.
    IF FUNDSCTR-LOW <> '' AND FUNDSCTR-HIGH <> ''.
      MOVE 'I' TO OBJECT-SIGN.
      MOVE 'BT' TO OBJECT-OPTION.
      IF TMPBUKRS = '1120'.
        CONCATENATE 'KS2000' FUNDSCTR-LOW INTO OBJECT-LOW.
        CONCATENATE 'KS2000' FUNDSCTR-HIGH INTO OBJECT-HIGH.
      ELSE.
        CONCATENATE 'KS1000' FUNDSCTR-LOW INTO OBJECT-LOW.
        CONCATENATE 'KS1000' FUNDSCTR-HIGH INTO OBJECT-HIGH.
      ENDIF.
      APPEND OBJECT.
    ELSEIF FUNDSCTR-LOW <> '' AND FUNDSCTR-HIGH = ''.
      MOVE 'I' TO OBJECT-SIGN.
      MOVE 'EQ' TO OBJECT-OPTION.
      IF TMPBUKRS = '1120'.
        CONCATENATE 'KS2000' FUNDSCTR-LOW INTO OBJECT-LOW.
      ELSE.
        CONCATENATE 'KS1000' FUNDSCTR-LOW INTO OBJECT-LOW.
      ENDIF.
      APPEND OBJECT.
    ENDIF.
  ENDLOOP.

  SELECT * FROM COSP WHERE OBJNR IN OBJECT AND GJAHR = GJAHR AND WRTTP = '04'.
    CHARGE-KOSTL  = COSP-OBJNR+6(10).
    CHARGE-SAKNR  = COSP-KSTAR.
    CHARGE-WOG001 = COSP-WOG001 .
    CHARGE-WOG002 = COSP-WOG002 .
    CHARGE-WOG003 = COSP-WOG003 .
    CHARGE-WOG004 = COSP-WOG004 .
    CHARGE-WOG005 = COSP-WOG005 .
    CHARGE-WOG006 = COSP-WOG006 .
    CHARGE-WOG007 = COSP-WOG007 .
    CHARGE-WOG008 = COSP-WOG008 .
    CHARGE-WOG009 = COSP-WOG009 .
    CHARGE-WOG010 = COSP-WOG010 .
    CHARGE-WOG011 = COSP-WOG011 .
    CHARGE-WOG012 = COSP-WOG012 .
    COLLECT CHARGE.
    CLEAR CHARGE.
  ENDSELECT.

  SELECT * FROM FMIOI WHERE GJAHR = GJAHR AND FISTL IN FUNDSCTR .
    CHARGE-KOSTL = FMIOI-FISTL.
    CHARGE-SAKNR = FMIOI-FIPEX.
    CHARGE-FKBTR = - FMIOI-FKBTR + CHARGE-FKBTR.
    COLLECT CHARGE.
    CLEAR CHARGE.
  ENDSELECT.

  "获取公司与部门名称
  SELECT SINGLE BUTXT INTO G_BUTXT FROM T001 WHERE BUKRS = BUKRS.
  SELECT KOSTL KTEXT FROM CSKT INTO CORRESPONDING FIELDS OF TABLE
    ITAB_CSKT WHERE KOSTL IN FUNDSCTR AND ( KOKRS = '1000' OR KOKRS = '2000' ).
  LOOP AT ITAB_CSKT.
    CONCATENATE G_KTEXT_LIST '、 ' ITAB_CSKT-KTEXT INTO G_KTEXT_LIST.
  ENDLOOP.
  G_KTEXT_LIST = G_KTEXT_LIST+1().
  CONCATENATE GJAHR '年 ' P_MONTH '月至' P_MONTH1 '月' INTO G_TEXT.

ENDFORM.                    "PF_GET_DATA

*&---------------------------------------------------------------------*
*&      Form  PF_GET_DATA
*&---------------------------------------------------------------------*
*       获取数据
*----------------------------------------------------------------------*
FORM PF_EDIT_DATA.
  DATA: L_RECORD LIKE GT_OUT,
      L_HSL LIKE FMBDT-HSL01,
      L_WOG LIKE COSP-WOG001.

  "汇总到输出内表
  LOOP AT CHARGE.
    CLEAR L_HSL.
    CLEAR L_WOG.
    PERFORM PF_GET_HSL_BYMONTH USING CHARGE CHANGING L_HSL.
    PERFORM PF_GET_WOG_BYMONTH USING CHARGE CHANGING L_WOG.
    "汇总各成本中心
    GT_OUT-KOSTL = CHARGE-KOSTL.  "成本中心
    GT_OUT-HSL = L_HSL.
    GT_OUT-WOG = L_WOG.
    COLLECT GT_OUT.
    CLEAR GT_OUT.
    "汇总各项目
    GT_OUT-KOSTL = CHARGE-KOSTL.  "成本中心
    GT_OUT-SAKNR = CHARGE-SAKNR.  "承诺项目
    GT_OUT-HSL = L_HSL.
    GT_OUT-WOG = L_WOG.
    COLLECT GT_OUT.
    CLEAR GT_OUT.
  ENDLOOP.
  DELETE GT_OUT WHERE SAKNR = '' AND KOSTL = ''.

  LOOP AT GT_OUT .
    "获取费用名称
    SELECT SINGLE TXT20 INTO GT_OUT-TXT20 FROM SKAT WHERE SAKNR = GT_OUT-SAKNR AND ( KTOPL = '1000' OR KTOPL = '2000' ).
    "获取成本中心名称
    SELECT SINGLE KTEXT FROM CSKT INTO GT_OUT-KTEXT WHERE KOSTL = GT_OUT-KOSTL  AND ( KOKRS = '1000' OR KOKRS = '2000' ).
    "计算差值
    GT_OUT-CHA = GT_OUT-HSL - GT_OUT-WOG.
    "为空的是各成本中心合计
    IF GT_OUT-SAKNR = ''.
      CONCATENATE GT_OUT-KTEXT '合计' INTO GT_OUT-SHOW_HEJI.
      GT_OUT-SAKNR = '0000000000'.
    ENDIF.
    MODIFY GT_OUT.
    CLEAR GT_OUT.
  ENDLOOP.

  SORT GT_OUT BY KOSTL SAKNR .

  DATA LT_OUT LIKE TABLE OF GT_OUT WITH HEADER LINE.
  LOOP AT GT_OUT WHERE SAKNR <> '0000000000' .
    ON CHANGE OF GT_OUT-SAKNR(4).
      CASE GT_OUT-SAKNR(4) .
        WHEN '5102'.
          LT_OUT-SAKNR = '5102000000'.
          LT_OUT-TXT20 = '--管理用人费--'.
        WHEN '5103'.
          LT_OUT-SAKNR = '5103000000'.
          LT_OUT-TXT20 = '--设备费--'.
        WHEN '5104'.
          LT_OUT-SAKNR = '5104000000'.
          LT_OUT-TXT20 = '--管理事务费--' .
        WHEN OTHERS.
          LT_OUT-SAKNR = '5105000000'.
          LT_OUT-TXT20 = '--其他费用--'.
      ENDCASE.
      LT_OUT-KOSTL = GT_OUT-KOSTL.
      APPEND LT_OUT.
    ENDON.
  ENDLOOP.
  APPEND LINES OF LT_OUT TO GT_OUT.

  "求总计
  LOOP AT GT_OUT WHERE SAKNR = '0000000000'.
    L_RECORD-HSL = L_RECORD-HSL + GT_OUT-HSL.
    L_RECORD-WOG = L_RECORD-WOG + GT_OUT-WOG.
    L_RECORD-CHA = L_RECORD-CHA + GT_OUT-CHA.
  ENDLOOP.
  L_RECORD-KOSTL = '9999000000'.
  L_RECORD-SAKNR = '9999000000'.
  L_RECORD-SHOW_HEJI = '合计'.
  APPEND L_RECORD TO GT_OUT.

  SORT GT_OUT BY KOSTL SAKNR .
ENDFORM.                    "PF_EDIT_DATA

*&---------------------------------------------------------------------*
*&      Form  PF_GET_HSL_BYMONTH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->L_LINE     text
*----------------------------------------------------------------------*
FORM PF_GET_HSL_BYMONTH USING L_LINE LIKE CHARGE CHANGING L_HSL.
  DATA : I TYPE I.
  I = P_MONTH.
  WHILE I <= P_MONTH1.
    CASE  I.
      WHEN 1.
        L_HSL = L_HSL + L_LINE-HSL01.
      WHEN 2.
        L_HSL = L_HSL + L_LINE-HSL02.
      WHEN 3.
        L_HSL = L_HSL + L_LINE-HSL03.
      WHEN 4.
        L_HSL = L_HSL + L_LINE-HSL04.
      WHEN 5.
        L_HSL = L_HSL + L_LINE-HSL05.
      WHEN 6.
        L_HSL = L_HSL + L_LINE-HSL06.
      WHEN 7.
        L_HSL = L_HSL + L_LINE-HSL07.
      WHEN 8.
        L_HSL = L_HSL + L_LINE-HSL08.
      WHEN 9.
        L_HSL = L_HSL + L_LINE-HSL09.
      WHEN 10.
        L_HSL = L_HSL + L_LINE-HSL10.
      WHEN 11.
        L_HSL = L_HSL + L_LINE-HSL11.
      WHEN 12.
        L_HSL = L_HSL + L_LINE-HSL12.
    ENDCASE.
    I = I + 1.
  ENDWHILE.

ENDFORM.                    "PF_GET_HSL_BYMONTH
*&---------------------------------------------------------------------*
*&      Form  PF_GET_WOG_BYMONTH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM PF_GET_WOG_BYMONTH USING L_LINE LIKE CHARGE CHANGING L_WOG.
  DATA : I TYPE I.
  I = P_MONTH.
  WHILE I <= P_MONTH1.
    CASE  I.
      WHEN 1.
        L_WOG = L_WOG + L_LINE-WOG001.
      WHEN 2.
        L_WOG = L_WOG + L_LINE-WOG002.
      WHEN 3.
        L_WOG = L_WOG + L_LINE-WOG003.
      WHEN 4.
        L_WOG = L_WOG + L_LINE-WOG004.
      WHEN 5.
        L_WOG = L_WOG + L_LINE-WOG005.
      WHEN 6.
        L_WOG = L_WOG + L_LINE-WOG006.
      WHEN 7.
        L_WOG = L_WOG + L_LINE-WOG007.
      WHEN 8.
        L_WOG = L_WOG + L_LINE-WOG008.
      WHEN 9.
        L_WOG = L_WOG + L_LINE-WOG009.
      WHEN 10.
        L_WOG = L_WOG + L_LINE-WOG010.
      WHEN 11.
        L_WOG = L_WOG + L_LINE-WOG011.
      WHEN 12.
        L_WOG = L_WOG + L_LINE-WOG012.
    ENDCASE.
    I = I + 1.
  ENDWHILE.
ENDFORM.                    "PF_GET_WOG_BYMONTH

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值