Chinaunix首页 | 论坛 | 博客
  • 博客访问: 286361
  • 博文数量: 62
  • 博客积分: 2966
  • 博客等级: 少校
  • 技术积分: 615
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-07 23:16
个人简介

Be a simple man

文章分类

全部博文(62)

文章存档

2012年(6)

2011年(15)

2010年(6)

2009年(3)

2008年(5)

2007年(27)

我的朋友

分类:

2007-11-27 09:49:49

*&---------------------------------------------------------------------*
*& Report  ZTEST999
*&---------------------------------------------------------------------*
*& jason.zhang@ciber.cn
*&---------------------------------------------------------------------*
REPORT  ztest999.
DATA: BEGIN OF gt_test OCCURS 0,
      flag,
      xh    TYPE i,
      item(2),
      saknr LIKE skb1-saknr,
*      belnr LIKE bsis-belnr,
      hbkid LIKE t012-hbkid,
      bankl LIKE t012-bankl,
      banka LIKE bnka-banka,
      c     LIKE bsis-dmbtr,
      d     LIKE bsis-dmbtr,
      e     LIKE bsis-dmbtr,
      f     LIKE bsis-dmbtr,
      g     LIKE bsis-dmbtr,
      h     LIKE bsis-dmbtr,
      i     LIKE bsis-dmbtr,
      j     LIKE bsis-dmbtr,
      k     LIKE bsis-dmbtr,
      l     LIKE bsis-dmbtr,
      m     LIKE bsis-dmbtr,
      n     LIKE bsis-dmbtr,
      o     LIKE bsis-dmbtr,
      p     LIKE bsis-dmbtr,
      q     LIKE bsis-dmbtr,
      r     LIKE bsis-dmbtr,
      s     LIKE bsis-dmbtr,
      t     LIKE bsis-dmbtr,
      u     LIKE bsis-dmbtr,
      v     LIKE bsis-dmbtr,
      w     LIKE bsis-dmbtr,
      x     LIKE bsis-dmbtr,
      y     LIKE bsis-dmbtr,
      END OF gt_test.
DATA: BEGIN OF gt_itab OCCURS 0,
      flag,
      flag2,
      xh    TYPE i,
      item(2),
      banka LIKE bnka-banka,
            c     LIKE bsis-dmbtr,
      d     LIKE bsis-dmbtr,
      e     LIKE bsis-dmbtr,
      f     LIKE bsis-dmbtr,
      g     LIKE bsis-dmbtr,
      h     LIKE bsis-dmbtr,
      i     LIKE bsis-dmbtr,
      j     LIKE bsis-dmbtr,
      k     LIKE bsis-dmbtr,
      l     LIKE bsis-dmbtr,
      m     LIKE bsis-dmbtr,
      n     LIKE bsis-dmbtr,
      o     LIKE bsis-dmbtr,
      p     LIKE bsis-dmbtr,
      q     LIKE bsis-dmbtr,
      r     LIKE bsis-dmbtr,
      s     LIKE bsis-dmbtr,
      t     LIKE bsis-dmbtr,
      u     LIKE bsis-dmbtr,
      v     LIKE bsis-dmbtr,
      w     LIKE bsis-dmbtr,
      x     LIKE bsis-dmbtr,
      y     LIKE bsis-dmbtr,
      END OF gt_itab.
DATA: wa LIKE LINE OF gt_test.
DATA: BEGIN OF gt_result OCCURS 0,
      item(2),
      c     LIKE bsis-dmbtr,
      d     LIKE bsis-dmbtr,
      e     LIKE bsis-dmbtr,
      f     LIKE bsis-dmbtr,
      g     LIKE bsis-dmbtr,
      h     LIKE bsis-dmbtr,
      i     LIKE bsis-dmbtr,
      j     LIKE bsis-dmbtr,
      k     LIKE bsis-dmbtr,
      l     LIKE bsis-dmbtr,
      m     LIKE bsis-dmbtr,
      n     LIKE bsis-dmbtr,
      o     LIKE bsis-dmbtr,
      p     LIKE bsis-dmbtr,
      q     LIKE bsis-dmbtr,
      r     LIKE bsis-dmbtr,
      s     LIKE bsis-dmbtr,
      t     LIKE bsis-dmbtr,
      u     LIKE bsis-dmbtr,
      v     LIKE bsis-dmbtr,
      w     LIKE bsis-dmbtr,
      x     LIKE bsis-dmbtr,
      y     LIKE bsis-dmbtr,
      END OF gt_result.
DATA: BEGIN OF gt_bsis OCCURS 0,
      hkont LIKE bsis-hkont,
      dmbtr LIKE bsis-dmbtr,
      END OF gt_bsis.
DATA: BEGIN OF gt_temp OCCURS 0,
      hkont LIKE bsis-hkont,
      dmbtr LIKE bsis-dmbtr,
      gsber LIKE bsis-gsber,
      END OF gt_temp.
DATA: BEGIN OF wa_bsis ,
      shkzg LIKE bsis-shkzg.
        INCLUDE STRUCTURE gt_bsis.
DATA: END OF wa_bsis.
DATA: BEGIN OF gt_bsis2 OCCURS 0,
        flag,
        belnr LIKE bsis-belnr.
        INCLUDE STRUCTURE wa_bsis.
DATA: END OF gt_bsis2.
PARAMETER: p_bukrs LIKE t012-bukrs.
PARAMETER: p_gjahr LIKE bkpf-gjahr.
SELECT-OPTIONS: p_date FOR sy-datum.
PERFORM getdata.
PERFORM fixdata.
*&---------------------------------------------------------------------*
*&      Form  getdata
*&---------------------------------------------------------------------*
FORM getdata .
  SELECT t012~bankl skb1~saknr skb1~hbkid bnka~banka FROM t012 INNER JOIN skb1
                               ON t012~bukrs = skb1~bukrs
                               INNER JOIN bnka
                               ON t012~bankl = bnka~bankl
  INTO CORRESPONDING FIELDS OF TABLE gt_test
  WHERE skb1~bukrs = p_bukrs AND
        skb1~saknr LIKE '1002%' AND
        t012~hbkid = skb1~hbkid .
  SELECT hkont dmbtr shkzg FROM bsis
  INTO CORRESPONDING FIELDS OF wa_bsis
  FOR ALL ENTRIES IN gt_test
  WHERE hkont = gt_test-saknr AND
        bukrs = p_bukrs AND
        budat < p_date-low .
    IF wa_bsis-shkzg = 'H'.
      wa_bsis-dmbtr = 0 - wa_bsis-dmbtr.
    ENDIF.
    gt_bsis-hkont = wa_bsis-hkont.
    gt_bsis-dmbtr = wa_bsis-dmbtr.
    COLLECT gt_bsis.
  ENDSELECT.
  SELECT belnr hkont dmbtr shkzg FROM bsis
  INTO CORRESPONDING FIELDS OF TABLE gt_bsis2
  FOR ALL ENTRIES IN gt_test
  WHERE bukrs = p_bukrs AND
        budat >= p_date-low AND
        budat < p_date-high AND
        hkont = gt_test-saknr.
  LOOP AT gt_bsis2 WHERE flag = '' AND shkzg = 'S'.
    IF sy-subrc = 0.
      SELECT SINGLE hkont dmbtr gsber FROM bsis
      INTO CORRESPONDING FIELDS OF gt_temp
      WHERE shkzg = 'H' AND
            belnr = gt_bsis2-belnr.
    ENDIF.
    gt_bsis2-flag = 'X'.
    MODIFY gt_bsis2 INDEX sy-tabix.
    READ TABLE gt_test WITH KEY saknr = gt_bsis2-hkont.
    IF sy-subrc = 0.
      IF gt_temp-hkont = '2101000000'.
        gt_test-d = gt_test-d + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont = '2301010000'.
        gt_test-e = gt_test-e + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '1431'.
        gt_test-f = gt_test-f + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '1441' OR gt_temp-hkont+0(4) = '2213'.
        gt_test-g = gt_test-g + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '1002'.
        gt_test-h = gt_test-h + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '1131' OR gt_temp-hkont+0(4) = '1133'.
        IF gt_temp-gsber = '001'.
          gt_test-i = gt_test-i + gt_temp-dmbtr.
        ELSEIF gt_temp-gsber = '002'.
          gt_test-j = gt_test-j + gt_temp-dmbtr.
        ELSE.
          gt_test-k = gt_test-k + gt_temp-dmbtr.
        ENDIF.
      ELSE.
        gt_test-k = gt_test-k + gt_temp-dmbtr.
      ENDIF.
      MODIFY gt_test INDEX sy-tabix.
    ENDIF.
  ENDLOOP.
  LOOP AT gt_bsis2 WHERE flag = '' AND shkzg = 'H'.
    IF sy-subrc = 0.
      SELECT SINGLE hkont dmbtr gsber FROM bsis
      INTO CORRESPONDING FIELDS OF gt_temp
      WHERE shkzg = 'S' AND
            belnr = gt_bsis2-belnr.
      gt_temp-dmbtr = - gt_temp-dmbtr.
    ENDIF.
    gt_bsis2-flag = 'X'.
    MODIFY gt_bsis2 INDEX sy-tabix.
    READ TABLE gt_test WITH KEY saknr = gt_bsis2-hkont.
    IF sy-subrc = 0.
      IF gt_temp-hkont+0(4) = '2320' OR gt_temp-hkont+0(4) = '2213'.
        gt_test-m = gt_test-m + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '1431'.
        gt_test-n = gt_test-n + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont = '2101000000' OR gt_temp-hkont = '2301010000'.
        gt_test-o = gt_test-o + gt_temp-dmbtr.
*    ELSEIF gt_temp-hkont+0(4) = '1441' OR gt_temp-hkont+0(4) = '2213'.
*      gt_test-g = gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '1002'.
        gt_test-q = gt_test-q + gt_temp-dmbtr.
      ELSEIF gt_temp-hkont+0(4) = '2171'.
        gt_test-r = gt_test-r + gt_temp-dmbtr.
      ELSE.
        gt_test-s = gt_test-s + gt_temp-dmbtr.
      ENDIF.
      MODIFY gt_test INDEX sy-tabix .
    ENDIF.
  ENDLOOP.
  LOOP AT gt_bsis.
    READ TABLE gt_test WITH KEY saknr = gt_bsis-hkont.
    IF sy-subrc = 0.
      gt_test-c = gt_bsis-dmbtr.
    ENDIF.
    MODIFY gt_test INDEX sy-tabix.
  ENDLOOP.
  LOOP AT gt_test.
    gt_test-xh = sy-tabix.
    gt_test-item = gt_test-saknr+4(2).
    MODIFY gt_test.
  ENDLOOP.
*  BREAK-POINT.
ENDFORM.                    " getdata
*&---------------------------------------------------------------------*
*&      Form  fixdata
*&---------------------------------------------------------------------*
FORM fixdata .
  FIELD-SYMBOLS TYPE ANY.
  DATA: n TYPE i.
*指针动态标记相邻行item相同的数据
  LOOP AT gt_test ASSIGNING .
    IF sy-subrc = 0.
      n = sy-tabix + 1.
      READ TABLE gt_test INDEX n.
      IF sy-subrc = 0.
        MOVE-CORRESPONDING TO wa.
        IF wa-item = gt_test-item.
          wa-flag = 'X'.
          gt_test-flag = 'X'.
        ENDIF.
        MOVE-CORRESPONDING wa TO .
        MODIFY gt_test INDEX n.
      ENDIF.
    ENDIF.
    MOVE-CORRESPONDING TO gt_test.
    MODIFY gt_test.
  ENDLOOP.
*在第二个内表中小计
  LOOP AT gt_test.
    MOVE-CORRESPONDING gt_test TO gt_result.
    COLLECT gt_result.
  ENDLOOP.
  LOOP AT gt_result.
    MOVE-CORRESPONDING gt_result TO gt_itab.
    SELECT SINGLE banka FROM ztest999
    INTO gt_itab-banka
    WHERE item = gt_itab-item.
    APPEND gt_itab.
  ENDLOOP.
  CLEAR n.
*将第一个内表中flag = 'X'的行数据插入第二个内表中,同时完成小计在明细之上
  LOOP AT gt_test WHERE flag = 'X'.
    READ TABLE gt_itab WITH KEY item = gt_test-item.
    n = sy-tabix + 1.
    IF sy-subrc = 0.
      MOVE-CORRESPONDING gt_test TO gt_itab.
      INSERT gt_itab INDEX n.
    ENDIF.
  ENDLOOP.
  LOOP AT gt_itab WHERE flag = 'X'.
    gt_itab-xh = ''.
    MODIFY gt_itab.
  ENDLOOP.
  CLEAR n.
  n = 1.
*
  LOOP AT gt_itab WHERE flag = ''.
    gt_itab-xh = n.
    gt_itab-flag2 = 'X'.
    MODIFY gt_itab.
    n = n + 1.
  ENDLOOP.
*如需进行总计,可以通过汇总flag2 = 'X'实现,这里没有具体写出代码
ENDFORM.                    " fixdata
 
 
阅读(2025) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~