Chinaunix首页 | 论坛 | 博客
  • 博客访问: 97121
  • 博文数量: 55
  • 博客积分: 530
  • 博客等级: 中士
  • 技术积分: 460
  • 用 户 组: 普通用户
  • 注册时间: 2010-11-02 11:21
个人简介

大龄ABAP自由顾问

文章分类

全部博文(55)

文章存档

2016年(1)

2015年(4)

2014年(14)

2013年(2)

2012年(3)

2011年(31)

我的朋友

分类: Windows平台

2016-01-25 15:46:19

SPAN { font-family: "隶书"; font-size: 11pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; } function z_int_fi_68.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     VALUE(EAI_INPUT) TYPE  ZEAI_INPUT OPTIONAL
*"  EXPORTING
*"     VALUE(EAI_OUTPUT) TYPE  ZEAI_OUTPUT
*"  TABLES
*"      LT_IN STRUCTURE  ZFI_TCS_IN OPTIONAL
*"      LT_OUT STRUCTURE  ZFI_TCS_OUT OPTIONAL
*"----------------------------------------------------------------------
  tables :zfi_bank,zfi_zfdy,zfi_ar_code.

  tables:zfi_fgs.

  data:
    begin of it_code occurs 0,
      code like zfi_tcs_in-code,
    end of it_code.
  data:lt_zfi_chlj_log like table of zfi_chlj_log with header line.
  data:ls_zfi_chlj_log like line of lt_zfi_chlj_log.
  data:
    lt_in1               like zfi_tcsbank occurs with header line,
    lt_in1_time          like zfi_tcsbank occurs with header line,
    gt_del               like zfi_tcsbank occurs with header line,
    it_accountreceivable like table of bapiacar09 with header line,
    it_accountgl         like table of bapiacgl09 with header line,
    it_accounttax        like table of bapiactx09 with header line,
    it_currencyamount    like table of bapiaccr09 with header line,
    it_return            like table of bapiret2   with header line,
    it_accountpayable    like table of bapiacap09 with header line,
    it_add               like table of zfi_cus29g with header line,
    gd_documentheader    like bapiache09,
    gd_documentheader2    like bapiache09,
    gd_documentheader3    like bapiache09,
    gd_customercpd       like bapiacpa09,
    gd_customercpd2       like bapiacpa09,
    gd_customercpd3      like bapiacpa09.

  data:
      it_accountreceivable2 like table of bapiacar09 with header line,
      it_accountgl2         like table of bapiacgl09 with header line,
      it_accounttax2       like table of bapiactx09 with header line,
      it_currencyamount2    like table of bapiaccr09 with header line,
      it_return2            like table of bapiret2   with header line,
      it_accountpayable2    like table of bapiacap09 with header line,
      it_add2               like table of zfi_cus29g with header line.

  data:
      it_accountreceivable3 like table of bapiacar09 with header line,
      it_accountgl3        like table of bapiacgl09 with header line,
      it_accounttax3     like table of bapiactx09 with header line,
      it_currencyamount3   like table of bapiaccr09 with header line,
      it_return3          like table of bapiret2   with header line,
      it_accountpayable3  like table of bapiacap09 with header line,
      it_add3              like table of zfi_cus29g with header line.

  data:lv_lifnr like lfa1-lifnr.
  data:
    n type i,
    lv_time1(15type c,
    lv_time2(15type c,
    lv_start like tzonref-tstamps,
    lv_end   like tzonref-tstamps,
    lv_hours like sretgstruc-hour1,
    message  type char200,
    message1 type char10.

  clear eai_output.
  refresh lt_out.

  loop at  lt_in.
    call function 'ENQUEUE_EZFI_54_LOCK'
      exporting
        code           lt_in-code
      exceptions
        foreign_lock   1
        system_failure 2
        others         3.
    if sy-subrc <> 0.
      lt_out-code lt_in-code.
      lt_out-message '数据重复/或错误数据重复传入时间间隔太短'.
      append lt_out.
      delete lt_in where code lt_in-code.
    else.
      it_code-code lt_in-code.
      append it_code.
    endif.
  endloop.
  if not lt_in[] is initial.
    select *
          into table gt_del from zfi_tcsbank
          for all entries in lt_in
          where code lt_in-code.
  endif.

  sort gt_del by code.
  loop at lt_in.
    clear lt_in1.
    read table gt_del with key code lt_in-code binary search.
    if sy-subrc <> 0.
      lt_in1-code lt_in-code.
      lt_in1-cpudt  sy-datum.
      lt_in1-cputm  sy-uzeit.
      append lt_in1.
    endif.
  endloop.
  modify zfi_tcsbank from table lt_in1.
  commit work and wait.

  loop at  gt_del.
    if gt_del-cpudt is initial.
      gt_del-cpudt sy-datum 1.
      gt_del-cputm sy-uzeit.
      update zfi_tcsbank set cpudt gt_del-cpudt
                             cputm gt_del-cputm
                       where code gt_del-code.
      commit work and wait.
    endif.

    concatenate sy-datum sy-uzeit
           into lv_time1.
    concatenate gt_del-cpudt gt_del-cputm
           into lv_time2.
    lv_start lv_time2.
    lv_end   lv_time1.
    call function 'SRET_TIME_DIFF_GET'
      exporting
        utc_start lv_start
        utc_end   lv_end
      importing
        hours     lv_hours.
    if sy-subrc eq 0.
      if gt_del-belnr ne ''.
        delete lt_in where code gt_del-code.
      elseif gt_del-belnr eq '' and  lv_hours le 1.
        delete lt_in where code gt_del-code.
      elseif gt_del-belnr eq '' and  lv_hours gt 1.
        delete gt_del.
      endif.
    endif.
  endloop.
  clear lt_in1[].

  if lt_in[] is not initial.

    clear:it_return[],it_return2[],it_return3[].
    loop at  lt_in.

      select single *
        into zfi_bank
        from zfi_bank
       where bukrs lt_in-bukrs.

*1.分公司奖励记账凭证:
*
*     借:其他应付款-暂收款
*   贷:应收帐款-客户(按客户付款方记帐)

      move-corresponding lt_in to lt_in1.
      gd_documentheader-doc_date   sy-datum.
      gd_documentheader-pstng_date sy-datum.
      gd_documentheader-username   sy-uname.
      gd_documentheader-fisc_year  sy-datum(4).
      gd_documentheader-fis_period sy-datum+4(2).
      gd_documentheader-bus_act    'RFBU'.
      gd_documentheader-ref_doc_no lt_in-xblnr.
      gd_documentheader-header_txt lt_in-bktxt.
      gd_documentheader-comp_code  lt_in-bukrs.
      gd_documentheader-doc_type   'DA'.

      if lt_in-ywlx 'FF'.
        n n + 1.
        it_currencyamount-itemno_acc n.
        it_currencyamount-currency   'CNY'.
        it_currencyamount-amt_doccur lt_in-dmbtr.
        append it_currencyamount.
        clear  it_currencyamount.
        it_accountreceivable-itemno_acc n.
        it_accountreceivable-gl_account '2241050000'."kemu
        it_accountreceivable-customer   space.
        it_accountreceivable-comp_code  lt_in-bukrs.
        it_accountreceivable-alloc_nmbr lt_in-zuonr."
        it_accountreceivable-item_text  lt_in-sgtxt.
        append it_accountreceivable.
        clear  it_accountreceivable.
        it_add-itemno_acc n.
        it_add-bschl      '40'.
*        IT_ADD-RSTGR      = '112'.
*        IT_ADD-IDXSP      = '01'.                           "结算方式01写死
        append it_add.
        clear  it_add.

        n n + 1.
        it_currencyamount-itemno_acc n.
        it_currencyamount-currency   'CNY'.
        it_currencyamount-amt_doccur -* lt_in-dmbtr ."jin e
        append it_currencyamount.
        clear  it_currencyamount.
        it_accountreceivable-itemno_acc n.
        it_accountreceivable-gl_account space.
        it_accountreceivable-customer   lt_in-kunnr."ke mu
        it_accountreceivable-comp_code  lt_in-bukrs."gong si
        it_accountreceivable-alloc_nmbr lt_in-zuonr."FEN PEI HAO
        it_accountreceivable-item_text  lt_in-sgtxt"HANG XIANG MU WEN BEN
        append it_accountreceivable.
        clear  it_accountreceivable.
        it_add-itemno_acc n.
        it_add-bschl      '11'.   "记帐代码
*      IT_ADD-RSTGR      = '110'.  "付款原因代码
        it_add-idxsp      '38'.  "结算方式
        append it_add.
        clear  it_add.
        lt_out-bukrs lt_in-bukrs.
      endif.


      call function 'Z_BAPI_ACC_DOCUMENT_CHECK'
        exporting
          documentheader    gd_documentheader
          customercpd       gd_customercpd
        tables
          accountgl         it_accountgl
          accountreceivable it_accountreceivable
          accountpayable    it_accountpayable
          currencyamount    it_currencyamount
          accounttax        it_accounttax
          gt_add            it_add
          return            it_return.

      loop at it_return
        where type 'E'
           or type 'A'.
        concatenate it_return-message message
               into message.

      endloop.

      if sy-subrc 0.
        lt_out-code  ''.
        lt_out-bukrs lt_in-bukrs.
*    lt_out-belnr = gt_del-belnr.
        lt_out-budat sy-datum.
        lt_out-message message.
        append lt_out.

        ls_zfi_chlj_log-bukrs lt_in-bukrs.
        ls_zfi_chlj_log-code lt_in-code.
        ls_zfi_chlj_log-budat sy-datum..
        ls_zfi_chlj_log-mesge message.
        ls_zfi_chlj_log-ywlx lt_in-ywlx.
       append ls_zfi_chlj_log to lt_zfi_chlj_log.

clear ls_zfi_chlj_log.

        continue.
      endif.

* 2.分公司挂总公司记账凭证:
*    贷:其它应付款-暂收款 50
*    借:应收帐款-总公司(9109000197):(客户号)

      gd_documentheader2-doc_date   sy-datum.
      gd_documentheader2-pstng_date sy-datum.
      gd_documentheader2-username   sy-uname.
      gd_documentheader2-fisc_year  sy-datum(4).
      gd_documentheader2-fis_period sy-datum+4(2).
      gd_documentheader2-bus_act    'RFBU'.
      gd_documentheader2-ref_doc_no lt_in-xblnr.
      gd_documentheader2-header_txt lt_in-bktxt.
      gd_documentheader2-comp_code  lt_in-bukrs.
      gd_documentheader2-doc_type   'SA'.

      clear n.
      n n + 2.
*      READ TABLE IT_CURRENCYAMOUNT INTO IT_CURRENCYAMOUNT2 INDEX N.
*      IT_CURRENCYAMOUNT2-AMT_DOCCUR = IT_CURRENCYAMOUNT2-AMT_DOCCUR.
      it_currencyamount2 =  it_currencyamount.
      it_currencyamount2-itemno_acc n.
      it_currencyamount2-currency   'CNY'.
      it_currencyamount2-amt_doccur lt_in-dmbtr.
      append it_currencyamount2.
      clear  it_currencyamount2.

*      READ TABLE IT_ACCOUNTRECEIVABLE INTO IT_ACCOUNTRECEIVABLE2 INDEX N.
      it_accountreceivable2-gl_account '2241050000'.
      it_accountreceivable2-itemno_acc n.
      it_accountreceivable2-customer   space.
      it_accountreceivable2-comp_code  lt_in-bukrs.
      it_accountreceivable2-alloc_nmbr lt_in-zuonr."
      it_accountreceivable2-item_text  lt_in-sgtxt.
      append it_accountreceivable2.
      clear  it_accountreceivable2.
      it_add2-itemno_acc n.
      it_add2-bschl      '50'.
*      IT_ADD2-IDXSP      = '38'.  "结算方式
      append it_add2.
      clear  it_add2.


      n 1.
*      READ TABLE IT_CURRENCYAMOUNT INTO IT_CURRENCYAMOUNT2 INDEX N.
*      IT_CURRENCYAMOUNT2-AMT_DOCCUR = - IT_CURRENCYAMOUNT2-AMT_DOCCUR.
      it_currencyamount2-itemno_acc n.
      it_currencyamount2-currency   'CNY'.
      it_currencyamount2-amt_doccur lt_in-dmbtr ."jin e
      append it_currencyamount2.
      clear  it_currencyamount2.

*      READ TABLE IT_ACCOUNTRECEIVABLE INTO IT_ACCOUNTRECEIVABLE2 INDEX N.

      it_accountreceivable2-itemno_acc n.
      it_accountreceivable2-gl_account space.
      it_accountreceivable2-customer   =  '9109000197'."ke mu
      it_accountreceivable2-comp_code  lt_in-bukrs."gong si
      it_accountreceivable2-alloc_nmbr lt_in-zuonr."FEN PEI HAO
      it_accountreceivable2-item_text  lt_in-sgtxt"HANG XIANG MU WEN BEN
      append it_accountreceivable2.
      clear  it_accountreceivable2.
      it_add2-itemno_acc n.
      it_add2-bschl      '01'.   "记帐代码

      append it_add2.
      clear  it_add2.


      call function 'Z_BAPI_ACC_DOCUMENT_CHECK'
        exporting
          documentheader    gd_documentheader2
          customercpd       gd_customercpd2
        tables
          accountgl         it_accountgl2
          accountreceivable it_accountreceivable2
          accountpayable    it_accountpayable2
          currencyamount    it_currencyamount2
          accounttax        it_accounttax2
          gt_add            it_add2
          return            it_return2.

      loop at it_return2
        where type 'E'
           or type 'A'.
        concatenate it_return2-message message
               into message.
      endloop.

      if sy-subrc 0.
        lt_out-code  ''.
        lt_out-bukrs lt_in-bukrs.
*    lt_out-belnr = gt_del-belnr.
        lt_out-budat sy-datum.
        lt_out-message message.
        append lt_out.

        ls_zfi_chlj_log-bukrs lt_in-bukrs.
        ls_zfi_chlj_log-code lt_in-code.
        ls_zfi_chlj_log-budat sy-datum..
        ls_zfi_chlj_log-mesge message.
        ls_zfi_chlj_log-ywlx lt_in-ywlx.
 append ls_zfi_chlj_log to lt_zfi_chlj_log.
clear ls_zfi_chlj_log.

        continue.
      endif.

* 3.总公司挂分公司记账凭证:
*
*    借:其他应付款-暂收款
*贷:应付帐款-分公司(对应42分公司的V码)
      gd_documentheader3-doc_date   sy-datum.
      gd_documentheader3-pstng_date sy-datum.
      gd_documentheader3-username   sy-uname.
      gd_documentheader3-fisc_year  sy-datum(4).
      gd_documentheader3-fis_period sy-datum+4(2).
      gd_documentheader3-bus_act    'RFBU'.
      gd_documentheader3-ref_doc_no lt_in-xblnr.
      gd_documentheader3-header_txt lt_in-bktxt.
      gd_documentheader3-comp_code  '2000'.
      gd_documentheader3-doc_type   'SA'.

      clear n.
      n n + 1.
*      READ TABLE IT_CURRENCYAMOUNT INTO IT_CURRENCYAMOUNT3 INDEX N.
      it_currencyamount3-itemno_acc n.
      it_currencyamount3-currency   'CNY'.
      it_currencyamount3-amt_doccur lt_in-dmbtr.
      append it_currencyamount3.
      clear  it_currencyamount3.

*      READ TABLE IT_ACCOUNTRECEIVABLE INTO IT_ACCOUNTRECEIVABLE3 INDEX N.
      it_accountreceivable3-itemno_acc n.

      it_accountreceivable3-gl_account '2241050000'."kemu
      it_accountreceivable3-customer   space.
      it_accountreceivable3-comp_code  =  '2000'.
      it_accountreceivable3-alloc_nmbr lt_in-zuonr."
      it_accountreceivable3-item_text  lt_in-sgtxt.
      append it_accountreceivable3.
      clear  it_accountreceivable3.
      it_add3-itemno_acc n.
      it_add3-bschl      '40'.
      append it_add3.
      clear  it_add3.

      n n + 1.
*      READ TABLE IT_CURRENCYAMOUNT INTO IT_CURRENCYAMOUNT3 INDEX N.
      it_currencyamount3-itemno_acc n.
      it_currencyamount3-currency   'CNY'.
      it_currencyamount3-amt_doccur -* lt_in-dmbtr ."jin e
      append it_currencyamount3.
      clear  it_currencyamount3
      .
      it_accountpayable3-itemno_acc n.
      it_accountpayable3-gl_account space.
      select single lifnr into lv_lifnr from zfi_fgs
        where bukrs lt_in-bukrs.
      it_accountpayable3-vendor_no lv_lifnr."ke mu
      it_accountpayable3-comp_code  '2000'."gong si
      it_accountpayable3-alloc_nmbr lt_in-zuonr."FEN PEI HAO
      it_accountpayable3-item_text  lt_in-sgtxt"HANG XIANG MU WEN BEN
      append it_accountpayable3.
      clear  it_accountpayable3.
      it_add3-itemno_acc n.
      it_add3-bschl      '31'.   "记帐代码
*      IT_ADD-RSTGR      = '110'.  "付款原因代码
      it_add3-idxsp      '38'.  "结算方式
      append it_add3.
      clear  it_add3.


      call function 'Z_BAPI_ACC_DOCUMENT_CHECK'
        exporting
          documentheader    gd_documentheader3
          customercpd       gd_customercpd3
        tables
          accountgl         it_accountgl3
          accountreceivable it_accountreceivable3
          accountpayable    it_accountpayable3
          currencyamount    it_currencyamount3
          accounttax        it_accounttax3
          gt_add            it_add3
          return            it_return3.

      loop at it_return3
        where type 'E'
           or type 'A'.
        concatenate it_return3-message message
               into message.
      endloop.


      if sy-subrc <> 0.
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait 'X'.
*        LOOP AT IT_RETURN WHERE TYPE = 'S'.
*          MOVE IT_RETURN-MESSAGE_V2+0(10) TO MESSAGE1.
*        ENDLOOP.
      else.
        rollback work.

        lt_out-code  ''.
        lt_out-bukrs lt_in-bukrs.
*    lt_out-belnr = gt_del-belnr.
        lt_out-budat sy-datum.
        lt_out-message message.
        append lt_out.

        ls_zfi_chlj_log-bukrs lt_in-bukrs.
        ls_zfi_chlj_log-code lt_in-code.
        ls_zfi_chlj_log-budat sy-datum..
        ls_zfi_chlj_log-mesge message.
        ls_zfi_chlj_log-ywlx lt_in-ywlx.
 append ls_zfi_chlj_log to lt_zfi_chlj_log.
clear ls_zfi_chlj_log.
        continue.
      endif.

**同时提交三个Bapi
      clear:it_return[],it_return2[],it_return3[].

      call function 'Z_BAPI_ACC_DOCUMENT_POST_29'
        exporting
          documentheader    gd_documentheader
          customercpd       gd_customercpd
        tables
          accountgl         it_accountgl
          accountreceivable it_accountreceivable
          accountpayable    it_accountpayable
          currencyamount    it_currencyamount
          accounttax        it_accounttax
          gt_add            it_add
          return            it_return.

      call function 'Z_BAPI_ACC_DOCUMENT_POST_29'
        exporting
          documentheader    gd_documentheader2
          customercpd       gd_customercpd2
        tables
          accountgl         it_accountgl2
          accountreceivable it_accountreceivable2
          accountpayable    it_accountpayable2
          currencyamount    it_currencyamount2
          accounttax        it_accounttax2
          gt_add            it_add2
          return            it_return2.

      call function 'Z_BAPI_ACC_DOCUMENT_POST_29'
        exporting
          documentheader    gd_documentheader3
          customercpd       gd_customercpd3
        tables
          accountgl         it_accountgl3
          accountreceivable it_accountreceivable3
          accountpayable    it_accountpayable3
          currencyamount    it_currencyamount3
          accounttax        it_accounttax3
          gt_add            it_add3
          return            it_return3.

      loop at it_return
        where type 'E'
           or type 'A'.
        concatenate it_return-message message
               into message.
      endloop.

      loop at it_return2
          where type 'E'
             or type 'A'.
        concatenate it_return2-message message
               into message.
      endloop.

      loop at it_return3
        where type 'E'
           or type 'A'.
        concatenate it_return3-message message
               into message.
      endloop.

      if message ''.
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait 'X'.
        loop at it_return where type 'S'.
          move it_return-message_v2+0(10to message1.
        endloop.
        loop at it_return2 where type 'S'.
          concatenate message1 ' ' it_return2-message_v2+0(10into message1.
*          MOVE IT_RETURN2-MESSAGE_V2+0(10) TO MESSAGE1.
        endloop.
        loop at it_return3 where type 'S'.
          concatenate message1 ' ' it_return3-message_v2+0(10into message1.
        endloop.

        ls_zfi_chlj_log-bukrs lt_in-bukrs.
        ls_zfi_chlj_log-code lt_in-code.
        ls_zfi_chlj_log-budat sy-datum..
        ls_zfi_chlj_log-belnr it_return-message_v2+0(10).
        ls_zfi_chlj_log-belnr2 it_return2-message_v2+0(10.
        ls_zfi_chlj_log-belnr3 it_return3-message_v2+0(10).
        ls_zfi_chlj_log-ywlx lt_in-ywlx.
        append ls_zfi_chlj_log to lt_zfi_chlj_log.
        clear ls_zfi_chlj_log.

      else.

        rollback work.

        continue.

      endif.



      lt_out-code    lt_in-code.
      lt_out-belnr   message1.
      lt_out-budat   sy-datum.
      lt_out-message message.
      lt_out-ywlx    lt_in-ywlx.

      lt_in1-belnr   message1.
      lt_in1-budat   lt_out-budat.
      lt_in1-message message.
      lt_in1-ywlx    lt_in-ywlx.

      append lt_out.
      append lt_in1.
      clear  lt_in.

      clear:
        gd_documentheader,gd_customercpd.
      clear:
        gd_documentheader2,gd_customercpd2.
      clear:
        gd_documentheader3,gd_customercpd3.

      refresh:
        it_accountgl,it_accountgl2,it_accountgl3,
        it_accountreceivable,it_accountreceivable2,it_accountreceivable3,
        it_accountpayable,it_accountpayable2,it_accountpayable3,
        it_currencyamount,it_currencyamount2,it_currencyamount3,
        it_accounttax,it_accounttax2,it_accounttax3,
        it_add,it_add2,it_add3,
        it_return,it_return2,it_return3.

    endloop.

  modify zfi_chlj_log from table lt_zfi_chlj_log.

    if not lt_in1[] is initial.
      select code cpudt cputm
        into corresponding fields of table lt_in1_time
        from zfi_tcsbank
         for all entries in lt_in1
       where code lt_in1-code.
    endif.

    sort lt_in1_time by code.
    loop at lt_in1.
      clear lt_in1_time.
      read table lt_in1_time with key code lt_in1-code
                             binary search.
      lt_in1-cpudt lt_in1_time-cpudt.
      lt_in1-cputm lt_in1_time-cputm.
      modify lt_in1.
    endloop.

    modify zfi_tcsbank from table lt_in1.
    commit work and wait.
  endif.

  loop at gt_del.
    lt_out-code  gt_del-code.
    lt_out-bukrs gt_del-bukrs.
    lt_out-belnr gt_del-belnr.
*        LT_OUT-BUDAT = SY-DATUM.
    lt_out-message '数据重复/或错误数据重复传入时间间隔太短'.
    append lt_out.
  endloop.

  loop at  it_code.
    call function 'DEQUEUE_EZFI_54_LOCK'
      exporting
        code it_code-code.
  endloop.

* 处理EAI公用信息
  move-corresponding eai_input to eai_output.
  describe table lt_out lines eai_output-main_cnt.
  if eai_output-main_cnt > 0.
    eai_output-msg_code 'S'.
    concatenate '共读出' eai_output-main_cnt '条记录.'
           into eai_output-msg_detail.
  else.
    eai_output-msg_code   'W'.
    eai_output-msg_detail '无相关记录!'.
  endif.

endfunction.
阅读(1358) | 评论(0) | 转发(0) |
0

上一篇:关于调用其他程序返回表

下一篇:没有了

给主人留下些什么吧!~~