ITPub博客

首页 > Linux操作系统 > Linux操作系统 > ZR_FI_005

ZR_FI_005

原创 Linux操作系统 作者:williamzhou 时间:2019-04-14 10:42:04 0 删除 编辑

*===============================基本信息===============================*
* 标题:记账凭证打印
* 创建日期:2004-12-18       
*===============================定    义===============================*

************************************************************************
* 基本代码
************************************************************************
REPORT ZR_FI_005
NO STANDARD PAGE HEADING
MESSAGE-ID ZFI
LINE-SIZE  120
*LINE-COUNT 80.
LINE-COUNT 90.

************************************************************************
* INCLUDE:包含文件
************************************************************************
INCLUDE OLE2INCL.

************************************************************************
* TABLE: 定义TABLE
************************************************************************
TABLES: BKPF,         "会计核算凭证标题(主表)
        BSEG,         "会计核算凭证段(从表)
        VBKPF,        "预制凭证的凭证抬头
        SKAT,         "总帐科目主记录(科目表:说明)
        CSKT,         "成本中心说明文本
        CSKS,         "成本中心主数据
        KNA1,         "客户主文件的一般数据
        LFA1,         "供应商主数据 (一般地区)
        USER_ADDR,    "
        T003T.        "凭证类型文本
************************************************************************
*INTERNAL TABLES
************************************************************************
*"--记账凭证明细内表--
DATA: BEGIN OF JZPZ OCCURS 0,
           BUKRS LIKE BSEG-BUKRS,  "公司代码
           BELNR LIKE BKPF-BELNR,  "凭证编号

           BLART LIKE BKPF-BLART,  "凭证类型
           BUDAT LIKE BKPF-BUDAT,  "记账日期
           GJAHR LIKE BKPF-GJAHR,  "会计年度
           MONAT LIKE BKPF-MONAT,  "会计期间
           USNAM LIKE BKPF-USNAM,  "过帐审核人
           PPNAM LIKE BKPF-PPNAM,  "预制人
           XBLNR LIKE BKPF-XBLNR,  "付单椐,参考凭证号

           HKONT LIKE BSEG-HKONT,  "科目代码、总帐科目
           ANLN1 LIKE BSEG-ANLN1,  "帐户代码、主资产号
           KUNNR LIKE BSEG-KUNNR,  "帐户代码、购货方编号
           LIFNR LIKE BSEG-LIFNR,  "供应商编号或债权人帐户号
           SGTXT LIKE BSEG-SGTXT,  "摘要
           KOSTL LIKE BSEG-KOSTL,  "成本中心
           PRCTR LIKE BSEG-PRCTR,  "利润中心
           AUFNR LIKE BSEG-AUFNR,  "订单号
           SHKZG LIKE BSEG-SHKZG,  "借/贷标志
           WRBTR LIKE BSEG-WRBTR,  "金额
           DMBTR LIKE BSEG-DMBTR,  "本位币金额
           KOART LIKE BSEG-KOART,  "帐户类型

           SAKNR(10),  "总帐科目编号
           SAKNR_NAME(200), "合并过后的总帐科目名称

           TXT20 LIKE SKAT-TXT20,  "总帐科目名称
           TXT50 LIKE SKAT-TXT50,  "总帐科目详细注释

           WAERS LIKE BKPF-WAERS,    "货币代码
           KURSF LIKE BKPF-KURSF,    "汇率

           ANLHTXT LIKE ANLH-ANLHTXT,"帐户名称、资产主号说明
           KNAME1  LIKE KNA1-NAME1,  "购货方说明
           KNAME2  LIKE KNA1-NAME2,  "购货方说明
           LNAME1  LIKE LFA1-NAME1,  "供应商说明
           LNAME2  LIKE LFA1-NAME2,  "供应商说明
           SORTL   LIKE KNA1-SORTL,  "客户(或供应商)排序字段(或检索词)

           BUTXT LIKE T001-BUTXT,  "单位名称

           SGTXTA(26),  "第一行摘要
           SGTXTB(26),  "第二行摘要
           SGTXTC(26),  "第三行摘要

           TXT50A(100),  "第一行科目名
           TXT50B(100),  "第二行科目名
           TXT50C LIKE SKAT-TXT50,  "第三行科目名(48)

           ANLHTXTA LIKE ANLH-ANLHTXT,"帐户名称、资产主号说明
           ANLHTXTB LIKE ANLH-ANLHTXT,"帐户名称、资产主号说明

           KNAME1A LIKE KNA1-NAME1, "购货方说明
           KNAME1B LIKE KNA1-NAME1, "购货方说明
           LNAME1A LIKE LFA1-NAME1, "供应商说明
           LNAME1B LIKE LFA1-NAME1, "供应商说明

           ZHDM(15),  "最后帐户代码
           ZHMCA(26), "最后帐户名称第一行
           ZHMCB(26), "最后帐户名称第二行
           ZHMCC(26), "最后帐户名称第三行

           WRBTR_D LIKE BSEG-WRBTR,  "贷方金额
           WRBTR_J LIKE BSEG-WRBTR,  "借方金额

           RQ(14),    "日期

           KTEXT LIKE CSKT-KTEXT,    "成本中心名称
           KOSAR LIKE CSKS-KOSAR,    "成本中心类型
           KOSAR_NAME(4),            "成本中心类型名称
           FYLB(8),                  "费用类别

           KTEXTA(12),  "成本中心名称第一行
           KTEXTB(12),  "成本中心名称第二行
           KTEXTC(12),  "成本中心名称第三行

           LRKTEXT LIKE CEPCT-KTEXT, "利润中心
           LRKTEXTA(12),  "利润中心名称第一行
           LRKTEXTB(12),  "利润中心名称第二行
           LRKTEXTC(12),  "利润中心名称第三行

           AFNTXTA(26), "订单文本第一行
           AFNTXTB(26),
           AFNTXTC(26),

           BUZEI LIKE VBSEGA-BUZEI, "预制凭证的项目号
           XNEGP LIKE BSEG-XNEGP,   "反向记账标志

           STBLG LIKE BKPF-STBLG,    "冲销凭证
           STJAH LIKE BKPF-STJAH,    "冲销年度
      END OF JZPZ.

*"--会计凭证标题内表--
DATA: BEGIN OF PZBH OCCURS 0,
       FLAG(4),                  "判断是普通凭证还是预制凭证的标志
       FORFLAG(2),               "判断是打印本位币还是金额的标志
       BELNR(10),                "财务凭证编号
       STBLG LIKE BKPF-STBLG,    "冲销凭证
       STJAH LIKE BKPF-STJAH,    "冲销年度
       BUKRS LIKE BKPF-BUKRS,    "公司代码
       GJAHR LIKE BKPF-GJAHR,    "会计年度
       MONAT LIKE BKPF-MONAT,    "会计期间
       BUDAT LIKE BKPF-BUDAT,    "凭证记帐日期
       USNAM LIKE BKPF-USNAM,    "用户名
       BLART LIKE BKPF-BLART,    "凭证类型
       WAERS LIKE BKPF-WAERS,    "货币代码
       KURSF LIKE BKPF-KURSF,    "汇率
       NAME_LAST(10),
       NAME_FIRST(10),
       XBLNR LIKE BKPF-XBLNR,    "参考凭证号(当作附单据数)
      END OF PZBH.

DATA: IT_PRINT_001 LIKE JZPZ OCCURS 10 WITH HEADER LINE.

*往数据库增加运行日志
  DATA: BEGIN OF IT_ZREPORTLOG OCCURS  0.
    INCLUDE TYPE ZREPORTLOG.
  DATA: END OF IT_ZREPORTLOG.
************************************************************************
* CONSTANTS : 定义常量
************************************************************************

************************************************************************
* TYPE : 定义数据类型
************************************************************************
TYPE-POOLS: SLIS.

************************************************************************
* DATA : 定义变量
************************************************************************
DATA: FLAG TYPE I VALUE 0.     "标记不同类型的帐户代码
DATA: NIAN(4),   "年
      YUE(2),    "月
      RI(2).     "日

DATA:  HJ_JFJE LIKE BSEG-WRBTR, "合计借方金额
       HJ_DFJE LIKE BSEG-WRBTR. "合计贷方金额

DATA: PAGELINE TYPE I VALUE 0.  "一页所打的最多行数。

*单据表格上相关坐标值定义
DATA: A1 TYPE I VALUE 0,
      A2 TYPE I VALUE 0,
      A3 TYPE I VALUE 0,
      A4 TYPE I VALUE 0,
      A5 TYPE I VALUE 0,
      A6 TYPE I VALUE 0,
      A7 TYPE I VALUE 0,
      A8 TYPE I VALUE 0,
      A9 TYPE I VALUE 0.

DATA: B1 TYPE I VALUE 0,
      B2 TYPE I VALUE 0,
      B3 TYPE I VALUE 0,
      B4 TYPE I VALUE 0,
      B5 TYPE I VALUE 0,
      B6 TYPE I VALUE 0,
      B7 TYPE I VALUE 0,
      B8 TYPE I VALUE 0,
      B9 TYPE I VALUE 0.

*
DATA: XBLANK TYPE I VALUE 0.       "空行数目
DATA: ZHS TYPE I VALUE 0.          "总行数
DATA: PAGENUM TYPE I VALUE 0.      "总的页数
DATA: LIMTA TYPE I VALUE 0.
DATA: LIMTB TYPE I VALUE 0.

DATA: YS TYPE I VALUE 0.           "余数
DATA: XHCS TYPE I VALUE 0.         "循环次数
DATA: PZNO TYPE I VALUE 0.         "每个凭证的页序号
DATA: PZS  TYPE I VALUE 0.         "查询到的凭证数

DATA: DS(1)  VALUE 'D',            "判断是否该换页的标志
             NAME_LAST LIKE USER_ADDR-NAME_LAST,
             NAME_FIRST LIKE USER_ADDR-NAME_FIRST,
             NAME(16).

DATA: I TYPE I VALUE 1,
      J TYPE I VALUE 0.

*用于ALV控件双击事件
DATA: G_SELECTED_FIELD_VALUE(80).

*ALV控件构造时需要的参数
DATA: G_ALV_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
      G_ALV_FIELDCAT_LINE LIKE LINE OF G_ALV_FIELDCAT,
      G_ALV_EVENT         TYPE SLIS_T_EVENT.

*ALV控件输出的表头
DATA: G_ALV_LISTHEADER TYPE SLIS_T_LISTHEADER.

*指定ALV控件触发TOP_OF_PAGE事件时调用的子程序
DATA: G_ALV_FORMNAME_TOP_OF_PAGE TYPE SLIS_FORMNAME
             VALUE 'F_ALV_EVENT_TOP_OF_PAGE'.
DATA: G_ALV_FORMNAME_END_OF_LIST TYPE SLIS_FORMNAME
             VALUE 'F_ALV_EVENT_END_OF_LIST'.

*指定ALV控件的显示特征
DATA : G_ALV_LAYOUT TYPE SLIS_LAYOUT_ALV.
************************************************************************
* DEFINE: 定义宏
************************************************************************
DEFINE HCHANGE.
  LEN = STRLEN( JZPZ-&1 ).
  CIS = 0.  BZS = 0.
  ENDFLG = 'N'.
  WHILE ENDFLG <> 'Y'.
    MOVE JZPZ-&1+CIS(1) TO TEST.
    IF TEST < '~' OR TEST = '?'.
      BZS = BZS + 1.
      CIS = CIS + 1.
    ELSE.
      CIS = CIS + 2.
    ENDIF.
    IF CIS >= LEN.
      ENDFLG = 'Y'.
    ENDIF.
  ENDWHILE.
  YUS =  BZS MOD 2 .
END-OF-DEFINITION.
************************************************************************
*  SELECTION SCREEN : 定义报表筛选条件
************************************************************************
SELECTION-SCREEN SKIP.
*确定过滤参数
SELECTION-SCREEN BEGIN OF BLOCK YGF WITH FRAME. TITLE BLK_001.
    PARAMETERS: P_GJAHR LIKE BKPF-GJAHR OBLIGATORY DEFAULT SY-DATUM."会计年度
    PARAMETERS: P_BUKRS LIKE BKPF-BUKRS OBLIGATORY MEMORY ID 051.   "公司代码
SELECTION-SCREEN END OF BLOCK YGF.

SELECTION-SCREEN BEGIN OF BLOCK YANG WITH FRAME. TITLE BLK_002.
    SELECT-OPTIONS P_BLART FOR BKPF-BLART.               "凭证类型
    SELECT-OPTIONS P_BELNR FOR BKPF-BELNR MEMORY ID 052. "财务凭证编号MATCHCODE OBJECT
    SELECT-OPTIONS P_BUDAT FOR BKPF-BUDAT.               "凭证记帐日期
    SELECT-OPTIONS P_PPNAM FOR BKPF-PPNAM.               "预制人
    SELECT-OPTIONS P_USNAM FOR BKPF-USNAM.               "过账审核人


SELECTION-SCREEN END OF BLOCK YANG.

*特殊汇总类型参数
SELECTION-SCREEN BEGIN OF BLOCK BLK_005 WITH FRAME. TITLE BLK_005 .
    PARAMETERS: P_TYPE1 AS CHECKBOX.            "汇总凭证上的GR/IR行项目
    PARAMETERS: P_TYPE2 AS CHECKBOX.            "汇总调整标准成本时的凭证
SELECTION-SCREEN END OF BLOCK BLK_005.

*选择凭证类型
SELECTION-SCREEN BEGIN OF BLOCK BLK_002 WITH FRAME. TITLE BLK_003 .
    PARAMETERS: P_PRINT1 RADIOBUTTON GROUP R1 DEFAULT 'X',
                P_PRINT2 RADIOBUTTON GROUP R1,
                P_PRINT3 RADIOBUTTON GROUP R1.
SELECTION-SCREEN END OF BLOCK BLK_002.

*选择报表类型
SELECTION-SCREEN BEGIN OF BLOCK BLK_003 WITH FRAME. TITLE BLK_004 .
    PARAMETERS: P_REPORT RADIOBUTTON GROUP R2 DEFAULT 'X',
                P_ALV RADIOBUTTON GROUP R2.
SELECTION-SCREEN END OF BLOCK BLK_003.


*===============================事    件===============================*
************************************************************************
* INITIALIZATION.启动程序开始执行
************************************************************************
INITIALIZATION.
  BLK_001 = '必选参数'.
  BLK_002 = '可选参数'.
  BLK_003 = '打印类型'.
  BLK_004 = '报表类型'.
  BLK_005 = '特殊参数处理'.

  PERFORM. F_INI.
************************************************************************
* AT SELECTION SCREEN:
************************************************************************
AT SELECTION-SCREEN.
  PERFORM. F_CHECK_INPUT.          "检查用户输入
************************************************************************
* START OF SELECTION:
************************************************************************
START-OF-SELECTION.
*往数据库增加运行日志
  IT_ZREPORTLOG-MANDT = SY-MANDT.
  IT_ZREPORTLOG-TCODE = SY-TCODE.
  IT_ZREPORTLOG-DATUM = SY-DATUM.
  IT_ZREPORTLOG-UZEIT = SY-UZEIT.
  IT_ZREPORTLOG-UNAME = SY-UNAME.
  IT_ZREPORTLOG-TITLE = SY-TITLE.
  APPEND IT_ZREPORTLOG.
  INSERT INTO ZREPORTLOG VALUES IT_ZREPORTLOG .

  PERFORM. F_READ_DATA.
  IF P_ALV = 'X'.
    PERFORM. F_PRINT_ALV.
  ENDIF.
************************************************************************
* END OF SELECTION
************************************************************************
END-OF-SELECTION.

************************************************************************
* TOP OF PAGE
************************************************************************
TOP-OF-PAGE.
*  PERFORM. F_HEADER.
*  PERFORM. F_LIST.
************************************************************************
* END OF PAGE
************************************************************************
END-OF-PAGE.


*===============================子 例 程===============================*
*&---------------------------------------------------------------------*
*过滤条件有效性检查
*&---------------------------------------------------------------------*
FORM. F_CHECK_INPUT.
  "判断是否存在该凭证记录
  SELECT SINGLE *
    FROM BKPF
    WHERE BUKRS = P_BUKRS AND GJAHR = P_GJAHR
      AND BELNR IN P_BELNR   "会计凭证号码
      AND BUDAT IN P_BUDAT   "凭证中的记帐日期
      AND BLART IN P_BLART   "凭证类型
      AND PPNAM IN P_PPNAM   "预制人
      AND USNAM IN P_USNAM.  "过账审核人

  IF SY-SUBRC <> 0.
    MESSAGE E001.
  ENDIF.
ENDFORM.                    " F_CHECK_INPUT
*&---------------------------------------------------------------------*
*从数据库中读取数据,填充报表输出时所用的内表
*&---------------------------------------------------------------------*
FORM. F_READ_DATA .
  REFRESH PZBH.

*取数到--会计凭证标题内表--
  SELECT BELNR BUKRS GJAHR MONAT BUDAT USNAM BLART WAERS KURSF XBLNR STBLG STJAH
    FROM  BKPF                              "--一般会计凭证标题--
    INTO  CORRESPONDING FIELDS OF TABLE PZBH
    WHERE BUKRS = P_BUKRS AND GJAHR = P_GJAHR
          AND BELNR IN P_BELNR
          AND BUDAT IN P_BUDAT
          AND BLART IN P_BLART
          AND PPNAM IN P_PPNAM  "预制人
          AND USNAM IN P_USNAM  "过账审核人
    ORDER BY BELNR.

*取数到--1.记账凭证明细内表、2.其它--
*开始循环取数
  DESCRIBE TABLE PZBH LINES PZS.
  IF PZS = 0.                              "查询到的凭证数
    MESSAGE I001.
  ELSE.
    LOOP AT PZBH.
      IF PZBH-BELNR <> '' .
        HJ_JFJE = 0.
        HJ_DFJE = 0.
        PERFORM. F_PZOUT.               "取数(一般记账凭证)
        PERFORM. F_FENHANG.             "换行处理
        IF P_REPORT = 'X'.
          PERFORM. F_PRINT_REPORT.      "最终打印显示
        ELSEIF P_ALV = 'X'.
          PERFORM. F_DO_ALV.
        ENDIF.
      ENDIF.

    ENDLOOP.
  ENDIF.

ENDFORM.                    " F_READ_DATA
*&---------------------------------------------------------------------
*&      一般记账凭证取数
*&---------------------------------------------------------------------
FORM. F_PZOUT.
  DATA: L_KOSAR_NAME(4),
        L_FYLB(8).

  DATA : L_TXT1 LIKE SKAT-TXT50,     "
         L_KOSTL LIKE CSKS-KOSTL,    "
         L_KTEXT LIKE CSKT-KTEXT,    "
         L_AUFNR LIKE BSEG-AUFNR,    "内部订单号
         L_KUNNR LIKE BSEG-KUNNR,
         L_LIFNR LIKE BSEG-LIFNR,
         L_SORTL LIKE LFA1-SORTL,
         L_TEMP(100).

  REFRESH JZPZ.
  CLEAR JZPZ.

***取凭证数
  SELECT   BUKRS   "单位名称,代码
           BELNR   "凭证编号
           GJAHR
           HKONT   "总分类帐帐目
           ANLN1   "帐户代码、主资产号
           KUNNR   "帐户代码、购货方编号
           LIFNR   "供应商编号或债权人帐户号
           SGTXT   "摘要
           KOSTL   "成本中心
           PRCTR
           AUFNR   "订单号
           SHKZG   "借/贷标志
           WRBTR   "金额
           DMBTR   "按本位币计的金额
           XNEGP
           KOART   "帐户类型
  FROM BSEG
  INTO CORRESPONDING FIELDS OF JZPZ
  WHERE BUKRS = P_BUKRS AND BELNR = PZBH-BELNR
   AND  GJAHR = P_GJAHR.
    APPEND JZPZ.
    CLEAR JZPZ.
  ENDSELECT.

  SORT JZPZ DESCENDING BY BELNR SHKZG.

  "取会计期间
  LOOP AT JZPZ.
    JZPZ-MONAT = PZBH-MONAT.
    MODIFY JZPZ.
  ENDLOOP.
  "取冲销凭证号及年度
  LOOP AT JZPZ.
    JZPZ-STBLG = PZBH-STBLG.
    JZPZ-STJAH = PZBH-STJAH.
    MODIFY JZPZ.
  ENDLOOP.

*凭证相同项目GI/IR汇总处理
  IF P_TYPE1 = 'X'.
    PERFORM. F_GET_TYPE1.
  ENDIF.
*汇总调整标准成本时的凭证
  IF P_TYPE2 = 'X'.
    PERFORM. F_GET_TYPE2.
  ENDIF.

*取货币名称及汇率
  LOOP AT JZPZ.
    SELECT WAERS     "货币代码
           KURSF     "汇率
      FROM BKPF
      INTO CORRESPONDING FIELDS OF JZPZ
      WHERE BELNR = JZPZ-BELNR AND
            BUKRS = P_BUKRS AND
            GJAHR = P_GJAHR.
      MODIFY JZPZ.
    ENDSELECT.
  ENDLOOP.

*取附单据数XBLNR
  LOOP AT JZPZ.
    LOOP AT PZBH.
     IF PZBH-BELNR = JZPZ-BELNR.
       JZPZ-XBLNR = PZBH-XBLNR.
     ENDIF.
    ENDLOOP.
    MODIFY JZPZ INDEX SY-TABIX.
  ENDLOOP.

*取成本中心名称KTEXT
  LOOP AT JZPZ.
    SELECT KTEXT
      FROM CSKT
      INTO CORRESPONDING FIELDS OF JZPZ
      WHERE SPRAS = '1' AND KOKRS = '1000'
        AND KOSTL = JZPZ-KOSTL.
      MODIFY JZPZ.
    ENDSELECT.
  ENDLOOP.
*取成本中心类型KOSAR_NAME;L_KOSAR_NAME
*取费用类别
  LOOP AT JZPZ.
    IF JZPZ-HKONT+2(4) = '4200'.
      L_KOSAR_NAME = ''.
      L_FYLB = ''.
      SELECT KOSAR
        FROM CSKS
        INTO L_KOSAR_NAME
        WHERE KOKRS = '1000'
          AND KOSTL = JZPZ-KOSTL.
      ENDSELECT.
      IF L_KOSAR_NAME = 'F'.
        L_KOSAR_NAME = '制'.
        L_FYLB = '制造费用'.
      ELSEIF L_KOSAR_NAME = 'L'.
        L_KOSAR_NAME = '管'.
        L_FYLB = '管理费用'.
      ELSEIF L_KOSAR_NAME = 'V'.
        L_KOSAR_NAME = '销'.
        L_FYLB = '销售费用'.
      ENDIF.
      MOVE L_KOSAR_NAME TO JZPZ-KOSAR_NAME.
      MOVE L_FYLB TO JZPZ-FYLB.
      MODIFY JZPZ.
    ENDIF.
  ENDLOOP.

*取客户的简称(检索词)
  LOOP AT JZPZ.
    SELECT SORTL
      FROM KNA1
      INTO CORRESPONDING FIELDS OF JZPZ
      WHERE KUNNR = JZPZ-KUNNR.
      MODIFY JZPZ.
    ENDSELECT.
  ENDLOOP.
*取供应商的简称(检索词)
  LOOP AT JZPZ.
    SELECT SORTL
      FROM LFA1
      INTO CORRESPONDING FIELDS OF JZPZ
      WHERE LIFNR = JZPZ-LIFNR.
      MODIFY JZPZ.
    ENDSELECT.
  ENDLOOP.

*取会计科目
  LOOP AT JZPZ.
    SELECT TXT20                  "总帐科目名称
           TXT50                  "总帐科目详细注释
    FROM SKAT CLIENT SPECIFIED    "总帐科目主记录(科目表:说明)
    INTO CORRESPONDING FIELDS OF JZPZ
    WHERE MANDT = SY-MANDT AND SAKNR = JZPZ-HKONT AND
          KTOPL = '1000' AND SPRAS = '1'.  "会计科目表、语言
      MODIFY JZPZ.
    ENDSELECT.
  ENDLOOP.

*合并会计科目名称
  LOOP AT JZPZ.
    "1:会计科目 = 会计科目代码(HKONT)+成本中心类别(KOSAR_NAME)+成本中心号(KOSTL)
    "            +费用类别(FYLB)+会计科目描述(TXT50)+成本中心名称(KTEXT)
    "2:会议科目 = 会计科目代码(HKONT)+客户号(KUNNR OR LIFNR)
    "            +会计科目描述(TXT50)+客户名称(SORTL)
    L_TXT1 = JZPZ-TXT50.
    CONDENSE L_TXT1.                   "去掉左右空格
    CONCATENATE L_TXT1 '' INTO L_TXT1.
    L_KOSAR_NAME = JZPZ-KOSAR_NAME.
    CONDENSE L_KOSAR_NAME.
    CONCATENATE L_KOSAR_NAME '' INTO L_KOSAR_NAME.
    L_KOSTL = JZPZ-KOSTL.
    CONDENSE L_KOSTL.
    CONCATENATE L_KOSTL '' INTO L_KOSTL.
    L_FYLB = JZPZ-FYLB.
    CONDENSE L_FYLB.
    CONCATENATE L_FYLB '' INTO L_FYLB.
    L_KTEXT = JZPZ-KTEXT.
    CONDENSE L_KTEXT.
    CONCATENATE L_KTEXT '' INTO L_KTEXT.
    L_AUFNR = JZPZ-AUFNR.
    CONDENSE L_AUFNR.
    IF L_AUFNR = ''.
      CONCATENATE L_AUFNR '' INTO L_AUFNR.
    ELSE.
      CONCATENATE '-' L_AUFNR '' INTO L_AUFNR.
    ENDIF.
    L_KUNNR = JZPZ-KUNNR.
    CONDENSE L_KUNNR.
    CONCATENATE L_KUNNR '' INTO L_KUNNR.
    L_LIFNR = JZPZ-LIFNR.
    CONDENSE L_LIFNR.
    CONCATENATE L_LIFNR '' INTO L_LIFNR.
    L_SORTL = JZPZ-SORTL.
    CONDENSE L_SORTL.
    CONCATENATE L_SORTL '' INTO L_SORTL.

    IF JZPZ-KOART = 'D'.
      CONCATENATE JZPZ-HKONT L_KUNNR L_TXT1 '-' L_SORTL INTO L_TEMP.
    ELSEIF JZPZ-KOART = 'K'.
      CONCATENATE JZPZ-HKONT L_LIFNR L_TXT1 '-' L_SORTL INTO L_TEMP.
    ELSE.
      IF JZPZ-HKONT+2(4) = '4200'.
        CONCATENATE JZPZ-HKONT L_KOSAR_NAME L_KOSTL L_FYLB
                    '-' L_TXT1 '-' L_KTEXT L_AUFNR INTO L_TEMP.
      ELSE.
        CONCATENATE JZPZ-HKONT L_TXT1 L_AUFNR INTO L_TEMP.
      ENDIF.
    ENDIF.
    MOVE L_TEMP TO JZPZ-SAKNR_NAME.
    MODIFY JZPZ.
  ENDLOOP.

*取过帐人
  LOOP AT JZPZ.
    SELECT     BLART   "凭证类型
               BUDAT   "记账日期
               USNAM   "过帐审核人
               PPNAM   "预制人
               USNAM   "过账人、用户名
               XBLNR   "付单椐,参照
    FROM BKPF CLIENT SPECIFIED
    INTO CORRESPONDING FIELDS OF JZPZ
    WHERE MANDT = SY-MANDT AND GJAHR = P_GJAHR
          AND BUKRS = JZPZ-BUKRS AND BELNR = JZPZ-BELNR.
      MODIFY JZPZ.
    ENDSELECT.
  ENDLOOP.
ENDFORM.                    " F_PZOUT
*&---------------------------------------------------------------------
*&     为分行而进行的操作
*&---------------------------------------------------------------------
FORM. F_FENHANG.
  DATA: TEST(1).
  DATA: LEN TYPE I VALUE 0,
        CIS TYPE I VALUE 0,
        BZS TYPE I VALUE 0,
        YUS TYPE I VALUE 0,
        WEI TYPE I VALUE 0,
        ZHI TYPE I VALUE 0,
        ENDFLG(1) VALUE 'N',
        V_KTEXT LIKE AUFK-KTEXT,
        AULEN TYPE I VALUE 0.

  LOOP AT JZPZ.
    "摘要处理
    CLEAR JZPZ-SGTXTA.
    CLEAR JZPZ-SGTXTB.
    CLEAR JZPZ-SGTXTC.
    MOVE  JZPZ-SGTXT+0(20)  TO JZPZ-SGTXTA.
    HCHANGE SGTXTA.       "宏运用
    IF YUS <> 0.
      MOVE  JZPZ-SGTXT+0(19) TO JZPZ-SGTXTA.
      WEI = 19.
    ELSE.
      MOVE  JZPZ-SGTXT+0(20) TO JZPZ-SGTXTA.
      WEI = 20.
    ENDIF.
    ZHI = 50 - WEI.
    MOVE  JZPZ-SGTXT+WEI(ZHI) TO JZPZ-SGTXTB.

    "会计科目处理
*    IF P_PRINT2 = 'X'.
    IF JZPZ-WAERS = 'RMB'.
      CLEAR JZPZ-TXT50A.
      CLEAR JZPZ-TXT50B.
      CLEAR JZPZ-TXT50C.
      MOVE  JZPZ-SAKNR_NAME+0(64) TO JZPZ-TXT50A.
      HCHANGE TXT50A.       "宏运用

      IF YUS <> 0.
        MOVE  JZPZ-SAKNR_NAME+0(63)  TO JZPZ-TXT50A.
        WEI = 63.
      ELSE.
        MOVE  JZPZ-SAKNR_NAME+0(64)  TO JZPZ-TXT50A.
        WEI = 64.
      ENDIF.
      ZHI = 100 - WEI.
      MOVE  JZPZ-SAKNR_NAME+WEI(ZHI) TO JZPZ-TXT50B.
      MODIFY JZPZ.
*    ELSEIF P_PRINT3 = 'X'.
    ELSEIF JZPZ-WAERS <> 'RMB'.
      CLEAR JZPZ-TXT50A.
      CLEAR JZPZ-TXT50B.
      CLEAR JZPZ-TXT50C.
      MOVE  JZPZ-SAKNR_NAME+0(34) TO JZPZ-TXT50A.
      HCHANGE TXT50A.       "宏运用

      IF YUS <> 0.
        MOVE  JZPZ-SAKNR_NAME+0(35)  TO JZPZ-TXT50A.
        WEI = 35.
      ELSE.
        MOVE  JZPZ-SAKNR_NAME+0(34)  TO JZPZ-TXT50A.
        WEI = 34.
      ENDIF.
      ZHI = 80 - WEI.
      MOVE  JZPZ-SAKNR_NAME+WEI(ZHI) TO JZPZ-TXT50B.
      MODIFY JZPZ.
    ENDIF.
  ENDLOOP.

ENDFORM.                    " F_FENHANG
*&---------------------------------------------------------------------
*&最终打印显示,处理当前页码
*&---------------------------------------------------------------------
FORM. F_PRINT_REPORT.
  DESCRIBE TABLE JZPZ LINES ZHS.
  YS = ZHS MOD 8 ."5.
  IF YS <> 0.
    XBLANK = 8 - YS."5 - YS.
  ENDIF.
  IF YS = 0 .   "不用打空行的情况
    PAGENUM = ZHS DIV 8 ."5 .
    CLEAR XHCS.
    XHCS = 1.
    DO PAGENUM  TIMES.
      LIMTA = 8 * XHCS - 7."5 * XHCS - 4.
      LIMTB = 8 * XHCS."5 * XHCS.
      J = I MOD 2.

      IF DS = 'D' .
        IF J <> 0 .
          NEW-PAGE.
        ENDIF.
        MOVE 'D' TO DS.
      ELSE.
        SKIP 7.
        PERFORM. F_HEADER.
        PERFORM. F_LIST.
        MOVE 'D' TO DS.
      ENDIF.

      IF J <> 0 .
        NEW-PAGE.
      ENDIF.
      IF J = 0 .
        SKIP 18.
*        SKIP 24.
      ENDIF.
      PERFORM. F_HEADER.
      PERFORM. F_LIST.
      PERFORM. F_BODY USING LIMTA LIMTB .
      IF XHCS = PAGENUM.
        PERFORM. F_BOTTOM USING 'Y'.
      ELSE.
        PERFORM. F_BOTTOM USING 'N'.
      ENDIF.
      I = I + 1.
      XHCS = XHCS + 1.
    ENDDO.
  ELSE.
    PAGENUM = ZHS DIV 8 + 1."5 + 1.

    CLEAR XHCS.
    XHCS = 1.
    DO PAGENUM  TIMES.
      J = I MOD 2.
      IF XHCS = PAGENUM.        "说明是最后一页
        LIMTA = 8 * XHCS - 7."5 * XHCS - 4.
        LIMTB = 8 * ( XHCS - 1 ) + YS ."5 * ( XHCS - 1 ) + YS .

        IF DS = 'D' .
          IF J <> 0 .
            NEW-PAGE.
          ENDIF.
          MOVE 'D' TO DS.
        ELSE.
          SKIP 7.

          PERFORM. F_HEADER.
          PERFORM. F_LIST.
          MOVE 'D' TO DS.
        ENDIF.

        IF J <> 0 .
          NEW-PAGE.
        ENDIF.
        IF J = 0 .
          SKIP 18.
*          SKIP 24.
        ENDIF.
        PERFORM. F_HEADER.
        PERFORM. F_LIST.
        PERFORM. F_BODY USING LIMTA LIMTB .
        PERFORM. F_BLANK USING XBLANK.
        PERFORM. F_BOTTOM USING 'Y'.
      ELSE.
        LIMTA = 8 * XHCS - 7."5 * XHCS - 4.
        LIMTB = 8 * XHCS ."5 * XHCS .

        IF DS = 'D' .
          IF J <> 0 .
            NEW-PAGE.
          ENDIF.
          IF J = 0 .
            SKIP 18.
*            SKIP 24.
          ENDIF.

          PERFORM. F_HEADER.
          PERFORM. F_LIST.
          MOVE 'D' TO DS.
        ELSE.
          SKIP 7.

          PERFORM. F_HEADER.
          PERFORM. F_LIST.
          MOVE 'D' TO DS.
        ENDIF.

        PERFORM. F_BODY USING LIMTA LIMTB .
        PERFORM. F_BOTTOM USING 'N'.
      ENDIF.
      I = I + 1.
      XHCS = XHCS + 1.
    ENDDO.
  ENDIF.

ENDFORM.                    " F_PRINT_REPORT
*&---------------------------------------------------------------------
*&      Form  F_BLANK
*&---------------------------------------------------------------------
FORM. F_BLANK USING NBLANK.
  DO NBLANK TIMES.
*    IF P_PRINT3 = 'X'.
    IF JZPZ-WAERS <> 'RMB'.
      WRITE: AT /A1  SY-VLINE,
             AT  A2  SY-VLINE,
             AT  A3  SY-VLINE,
             AT  A4  SY-VLINE,
             AT  A5  SY-VLINE,
             AT  A7  SY-VLINE,
             AT  A8  SY-VLINE,
             AT  A9  SY-VLINE.
      WRITE: AT /A1  SY-VLINE,
             AT  A2  SY-VLINE,
             AT  A3  SY-VLINE,
             AT  A4  SY-VLINE,
             AT  A5  SY-VLINE,
             AT  A7  SY-VLINE,
             AT  A8  SY-VLINE,
             AT  A9  SY-VLINE.
    ELSE.
      WRITE: AT /A1  SY-VLINE,
             AT  A2  SY-VLINE,
             AT  A7  SY-VLINE,
             AT  A8  SY-VLINE,
             AT  A9  SY-VLINE.
      WRITE: AT /A1  SY-VLINE,
             AT  A2  SY-VLINE,
             AT  A7  SY-VLINE,
             AT  A8  SY-VLINE,
             AT  A9  SY-VLINE.
    ENDIF.

    WRITE: AT /A1   SY-VLINE.
    WRITE: AT  A9   SY-VLINE.
    ULINE  AT  A1(120).
  ENDDO.
ENDFORM.                    " F_BLANK
*&---------------------------------------------------------------------
*&为显示ALV清单而增加内表内容
*&---------------------------------------------------------------------
FORM. F_DO_ALV.

  LOOP AT JZPZ.
    IT_PRINT_001-BUKRS = JZPZ-BUKRS.
    IT_PRINT_001-GJAHR = JZPZ-GJAHR.
    IT_PRINT_001-MONAT = JZPZ-MONAT.
    IT_PRINT_001-BUDAT = JZPZ-BUDAT.
    IT_PRINT_001-BLART = JZPZ-BLART.
    IT_PRINT_001-BELNR = JZPZ-BELNR.
    IT_PRINT_001-SGTXT = JZPZ-SGTXT.
    IT_PRINT_001-HKONT = JZPZ-HKONT.
    JZPZ-TXT50A = JZPZ-TXT50A+10(90).
    CONCATENATE JZPZ-TXT50A JZPZ-TXT50B INTO JZPZ-TXT50A.
    IT_PRINT_001-TXT50A = JZPZ-TXT50A.
    IT_PRINT_001-WAERS = JZPZ-WAERS.
    IT_PRINT_001-KURSF = JZPZ-KURSF.
    IT_PRINT_001-WRBTR = JZPZ-WRBTR.
    IF JZPZ-SHKZG = 'S'.
      IT_PRINT_001-WRBTR_J = JZPZ-DMBTR.
      IT_PRINT_001-WRBTR_D = 0.
    ELSEIF JZPZ-SHKZG = 'H'.
      IT_PRINT_001-WRBTR_D = JZPZ-DMBTR.
      IT_PRINT_001-WRBTR_J = 0.
    ENDIF.
    IT_PRINT_001-PPNAM = JZPZ-PPNAM.
    IT_PRINT_001-USNAM = JZPZ-USNAM.

    APPEND IT_PRINT_001.
 ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------
*&      Form  F_HEADER
*&      单据表头显示
*&---------------------------------------------------------------------
FORM. F_HEADER.
  DATA: STR1(4),
        L_COMP(26),
        L_TYPE(20).              "凭证类型

  SELECT T001~BUTXT
    FROM T001
    INTO L_COMP
    WHERE T001~BUKRS = P_BUKRS.
  ENDSELECT.
*  "取公司名称
*  IF P_BUKRS = '1000'.
*    L_COMP = '厦门市松霖卫浴有限公司'.
*  ELSEIF P_BUKRS = '2000'.
*    L_COMP = '厦门市益周塑胶制造有限公司'.
*  ELSEIF P_BUKRS = '3000'.
*    L_COMP = '厦门市易洁卫浴有限公司'.
*  ELSEIF P_BUKRS = '4000'.
*    L_COMP = '厦门市玩铜制造有限公司'.
*  ELSEIF P_BUKRS = '5000'.
*    L_COMP = '厦门松霖科技有限公司'.
*  ENDIF.
  "取凭证类型
  SELECT LTEXT
    FROM T003T
    INTO L_TYPE
   WHERE BLART = JZPZ-BLART
     AND SPRAS = '1'.
  ENDSELECT.

  MOVE SY-PAGNO TO STR1.
  WRITE: /50 L_COMP.
  SKIP.
  WRITE: /55  '记  帐  凭  证'.
  WRITE: 87  '凭证类型:', JZPZ-BLART, L_TYPE.
  WRITE: / .
ENDFORM.                    " F_HEADER
*&---------------------------------------------------------------------
*&      Form  F_LIST
*&      单据列名显示
*&---------------------------------------------------------------------
FORM. F_LIST.
  DATA: PAGNO(3).
  DATA: STRPAGE(3).

  MOVE JZPZ-BUDAT+0(4) TO NIAN.
  MOVE JZPZ-BUDAT+4(2) TO YUE.
  MOVE JZPZ-BUDAT+6(2) TO RI.

  WRITE: /2 '冲销凭证:', JZPZ-STBLG, '/', JZPZ-STJAH.
  WRITE: 87  '凭证编号:'.
  WRITE: 97  JZPZ-BELNR.

  WRITE: 55  NIAN.
  WRITE: 59  '年'.
  WRITE: 61  YUE.
  WRITE: 63  '月'.
  WRITE: 65   RI.
  WRITE: 67  '日'.

*显示凭证总页数及当前页
  DESCRIBE TABLE JZPZ LINES ZHS.
  YS = ZHS MOD 8."5.
  IF YS = 0 .
    PAGENUM = ZHS DIV 8."5 .
  ELSE.
    PAGENUM = ZHS DIV 8 + 1.
  ENDIF.

  MOVE XHCS TO PAGNO.
  MOVE PAGENUM  TO STRPAGE.
  WRITE: 108 '(', PAGNO, '/' ,STRPAGE , ')'.

  ULINE .
*  IF P_PRINT3 = 'X'.
  IF JZPZ-WAERS <> 'RMB'.
    WRITE: AT /A1 SY-VLINE,
         AT B1  '       摘  要',
         AT A2  SY-VLINE,
         AT B2 '             会计科目',
         AT A3  SY-VLINE,
         AT B3 ' 币别',
         AT A4  SY-VLINE,
         AT B4 '  原币金额',
         AT A5  SY-VLINE,
         AT B5 '  汇率',
         AT A7   SY-VLINE,
         AT B7 '    借方金额',
         AT A8  SY-VLINE,
         AT B8 '   贷方金额',
         AT A9  SY-VLINE.
  ELSE.
    WRITE: AT /A1 SY-VLINE,
         AT B1  '       摘  要',
         AT A2  SY-VLINE,
         AT B2 '             会计科目',
         AT A7   SY-VLINE,
         AT B7 '    借方金额',
         AT A8  SY-VLINE,
         AT B8 '   贷方金额',
         AT A9  SY-VLINE.
  ENDIF.

  WRITE: AT /A1   SY-VLINE.
  WRITE: AT  A9   SY-VLINE.
  ULINE  AT  A1(120).
ENDFORM.                    " F_LIST
*&---------------------------------------------------------------------
*&      单据表身数据显示
*&---------------------------------------------------------------------
FORM. F_BODY USING VAL1 VAL2.
  DATA : L_TXT1(36),
         L_TXT2(36).

  LOOP AT JZPZ FROM VAL1 TO VAL2.
    WRITE: AT /A1   SY-VLINE.
*第一行打印处理
    L_TXT1 = JZPZ-SGTXTA.
    CONDENSE L_TXT1.                   "去掉左右空格
    CONCATENATE L_TXT1 '' INTO L_TXT1.
    WRITE: AT B1 JZPZ-SGTXTA.
    WRITE: AT  A2   SY-VLINE.

    WRITE: AT B2 JZPZ-TXT50A.  "SAKNR_NAME.

*    IF P_PRINT3 = 'X'.
    IF JZPZ-WAERS <> 'RMB'.
      WRITE: AT  A3   SY-VLINE.
      WRITE: AT  B3   JZPZ-WAERS CENTERED.    "货币代码
      WRITE: AT  A4   SY-VLINE.
      WRITE: AT  B4   JZPZ-WRBTR CENTERED.    "金额
      WRITE: AT  A5   SY-VLINE.
      WRITE: AT  B5   JZPZ-KURSF.             "汇率
    ENDIF.
    WRITE: AT  A7   SY-VLINE.

    IF JZPZ-SHKZG = 'H'.
      WRITE: AT B7  ''.
      WRITE: AT A8  SY-VLINE.
      WRITE: AT B8  JZPZ-DMBTR.
      WRITE: AT A9  SY-VLINE.
      HJ_DFJE = HJ_DFJE + JZPZ-DMBTR.
    ELSEIF JZPZ-SHKZG = 'S'.
      WRITE: AT B7 JZPZ-DMBTR.
      WRITE: AT A8  SY-VLINE.
      WRITE: AT B8 ''.
      WRITE: AT A9  SY-VLINE.
      HJ_JFJE = HJ_JFJE + JZPZ-DMBTR.
    ENDIF.
*第一行打印完毕

*第二行打印处理
    WRITE:  AT /A1 SY-VLINE.
    L_TXT2 = JZPZ-SGTXTB.
    CONDENSE L_TXT2.                   "去掉左右空格
    CONCATENATE L_TXT2 '' INTO L_TXT2.
    WRITE: AT  B1 L_TXT2.
    WRITE:  AT  A2 SY-VLINE.

    L_TXT2 = JZPZ-TXT50B.
    CONDENSE L_TXT2.                   "去掉左右空格
    CONCATENATE L_TXT2 '' INTO L_TXT2.
    WRITE: AT  B2 L_TXT2.

*    IF P_PRINT3 = 'X'.
    IF JZPZ-WAERS <> 'RMB'.
      WRITE: AT  A3 SY-VLINE.
      WRITE: AT  A4 SY-VLINE.
      WRITE: AT  A5 SY-VLINE.
    ENDIF.

    WRITE: AT  A7  SY-VLINE.
    WRITE: AT  A8  SY-VLINE.
    WRITE: AT  A9  SY-VLINE.
*第二行打印完毕

    WRITE: AT /A1   SY-VLINE.
    WRITE: AT  A9   SY-VLINE.
    ULINE  AT  A1(120).
  ENDLOOP.

ENDFORM.                    " F_BODY
*&---------------------------------------------------------------------
*&      Form  F_BOTTOM
*&---------------------------------------------------------------------
FORM. F_BOTTOM USING FLGG.
DATA L_TEMP(50).

  L_TEMP = JZPZ-XBLNR.
  IF L_TEMP <> ''.
    CONCATENATE '  附单据' L_TEMP '张' INTO L_TEMP.
  ELSE.
    L_TEMP = '  附单据 0 张'.
  ENDIF.
  L_TEMP = ''.  "暂时去掉

  IF FLGG = 'Y'.
    WRITE: AT /A1  SY-VLINE,
           AT  B1 L_TEMP,
           AT  B5  '   合计',
           AT  B7 HJ_JFJE,        "合计借方金额
           AT  A7  SY-VLINE,
           AT  B8 HJ_DFJE,        "合计贷方金额
           AT  A8  SY-VLINE,
           AT  A9  SY-VLINE.
  ELSE.
    WRITE: AT /A1  SY-VLINE,
           AT  B1 L_TEMP,
           AT  B5  '   合计',
           AT  A7  SY-VLINE,
           AT  A8  SY-VLINE,
           AT  A9  SY-VLINE.
  ENDIF.

  WRITE: AT /A1   SY-VLINE.
  WRITE: AT  A9   SY-VLINE.
  ULINE  AT  A1(120).

  WRITE: AT /70  '审核记帐人:'.
  WRITE: AT 100 '预制人:'.

*取审核记账人USNAM
  CLEAR NAME_LAST.
  CLEAR NAME_FIRST.
  CLEAR NAME.
  SELECT NAME_LAST NAME_FIRST
       FROM USER_ADDR
    INTO (NAME_LAST, NAME_FIRST)
    WHERE BNAME = JZPZ-USNAM.
  ENDSELECT.
  CONCATENATE NAME_LAST(10) NAME_FIRST(8) INTO NAME.
  WRITE: AT 82 NAME LEFT-JUSTIFIED .
*取预制人PPNAM
  CLEAR NAME_LAST.
  CLEAR NAME_FIRST.
  CLEAR NAME.
  SELECT NAME_LAST NAME_FIRST
       FROM USER_ADDR
    INTO (NAME_LAST, NAME_FIRST)
    WHERE BNAME = JZPZ-PPNAM.
  ENDSELECT.
  CONCATENATE NAME_LAST(10) NAME_FIRST(8) INTO NAME.
  WRITE: AT 108 NAME LEFT-JUSTIFIED .
ENDFORM.                    " F_BOTTOM
*&---------------------------------------------------------------------*
*&GR/IR汇总处理
*&---------------------------------------------------------------------*
FORM. F_GET_TYPE1.
  "GR/IR汇总处理
  PERF

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

上一篇: ZR_FI_003
下一篇: ZR_FI_008
请登录后发表评论 登录
全部评论

注册时间:2006-03-01

  • 博文量
    30
  • 访问量
    22340