SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Clearing Customer Documents



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> FI
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Mon Oct 01, 2007 10:42 am    Post subject: Clearing Customer Documents Reply with quote

Code:
FUNCTION Z_CUSTOMER_CLEARING.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  IMPORTING
*"     REFERENCE(I_BKPF) LIKE  BKPF STRUCTURE  BKPF
*"  EXPORTING
*"     REFERENCE(E_MSGID) LIKE  SY-MSGID
*"     REFERENCE(E_MSGNO) LIKE  SY-MSGNO
*"     REFERENCE(E_MSGTY) LIKE  SY-MSGTY
*"     REFERENCE(E_MSGV1) LIKE  SY-MSGV1
*"     REFERENCE(E_MSGV2) LIKE  SY-MSGV2
*"     REFERENCE(E_MSGV3) LIKE  SY-MSGV3
*"     REFERENCE(E_MSGV4) LIKE  SY-MSGV4
*"     REFERENCE(E_SUBRC) LIKE  SY-SUBRC
*"  TABLES
*"      T_BSID STRUCTURE  BSID
*"      T_BLNTAB STRUCTURE  BLNTAB
*"  EXCEPTIONS
*"      CLEARING_PROCEDURE_INVALID
*"      CLEARING_PROCEDURE_MISSING
*"      TABLE_T041A_EMPTY
*"      TRANSACTION_CODE_INVALID
*"      AMOUNT_FORMAT_ERROR
*"      TOO_MANY_LINE_ITEMS
*"      COMPANY_CODE_INVALID
*"      SCREEN_NOT_FOUND
*"      NO_AUTHORIZATION
*"      ERROR
*"----------------------------------------------------------------------

  DATA lt_bseg TYPE bseg.
  DATA anz_mode LIKE RFPDO-ALLGAZMD VALUE 'N'.

  DATA: l_t_blntab  TYPE blntab OCCURS 0 WITH HEADER LINE,
        l_t_ftclear TYPE ftclear OCCURS 0 WITH HEADER LINE,
        l_t_ftpost  TYPE ftpost OCCURS 0 WITH HEADER LINE,
        l_t_fttax   TYPE fttax OCCURS 0 WITH HEADER LINE.

  DATA l_group LIKE apqi-groupid.

  IF t_bsid[] IS INITIAL.
    RAISE TOO_MANY_LINE_ITEMS.
  ENDIF.

  DEFINE rellena_ftpost.
    l_t_ftpost-stype = &1.
    l_t_ftpost-count = &2.
    l_t_ftpost-fnam  = &3.
    l_t_ftpost-fval  = &4.
    append l_t_ftpost.
  END-OF-DEFINITION.

  DEFINE rellena_ftclear.
    select single * INTO lt_bseg
      from bseg
     where belnr = &1
       and bukrs = &2
       and gjahr = &3
       and buzei = &4.
*    select single *
*      from bseg
*     where belnr = BSIK-BELNR
*       and bukrs = BSIK-BUKRS
*       and gjahr = BSIK-GJAHR
*       and buzei = BSIK-BUZEI.
    l_t_ftclear-agkoa = lt_bseg-koart.
    l_t_ftclear-agbuk = lt_bseg-bukrs.
    l_t_ftclear-selfd = 'BELNR'.
    if lt_bseg-umskz is initial.
      l_t_ftclear-xnops = 'X'.
    else.
      l_t_ftclear-agums = lt_bseg-umskz.
    endif.
    concatenate lt_bseg-belnr
                lt_bseg-gjahr
                lt_bseg-buzei
           into l_t_ftclear-selvon.
    append l_t_ftclear.

  END-OF-DEFINITION.

  l_group = sy-tcode.
  anz_mode = 'N'.

*--- Posting interface start
  CALL FUNCTION 'POSTING_INTERFACE_START'
    EXPORTING
*   I_CLIENT                 = SY-MANDT
      i_function               = 'C'    " Using Call Transaction
      i_group                  = l_group
*   I_HOLDDATE               = ' '
*   I_KEEP                   = ' '
      i_mode                   = anz_mode
      i_update                 = 'S'
      i_user                   = sy-uname
      i_xbdcc                  = 'X'
    EXCEPTIONS
      client_incorrect         = 1
      function_invalid         = 2
      group_name_missing       = 3
      mode_invalid             = 4
      update_invalid           = 5
      OTHERS                   = 6
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
           WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

*  LOOP AT i_bsik.
*    rellena_ftclear i_bsik-belnr
*                    i_bsik-bukrs
*                    i_bsik-gjahr
*                    i_bsik-buzei.
*  ENDLOOP.

  DATA l_datum(10).

  rellena_ftpost 'K' 1 'BKPF-BUKRS' i_bkpf-bukrs.
  rellena_ftpost 'K' 1 'BKPF-BLART' i_bkpf-blart.
  WRITE i_bkpf-bldat TO l_datum.
  rellena_ftpost 'K' 1 'BKPF-BLDAT' l_datum.
  WRITE i_bkpf-budat TO l_datum.
  rellena_ftpost 'K' 1 'BKPF-BUDAT' l_datum.
  rellena_ftpost 'K' 1 'BKPF-WAERS' i_bkpf-waers.
  rellena_ftpost 'K' 1 'BKPF-XBLNR' i_bkpf-xblnr.

  DATA l_count TYPE ftpost-count.
  DATA l_sum TYPE bsid-dmbtr.

  LOOP AT t_bsid.
    rellena_ftpost 'P' l_count 'RF05A-NEWBS' t_bsid-bschl.

    rellena_ftclear t_bsid-belnr
                    t_bsid-bukrs
                    t_bsid-gjahr
                    t_bsid-buzei.

    IF t_bsid-shkzg EQ 'S'.
      l_sum = l_sum + t_bsid-dmbtr.
    ELSE.
      l_sum = l_sum - t_bsid-dmbtr.
    ENDIF.

    IF l_sum EQ 0.
      EXIT.
    ENDIF.

  ENDLOOP.

  break-point.
  CALL FUNCTION 'POSTING_INTERFACE_CLEARING'
    EXPORTING
      i_auglv                          = 'EINGZAHL' " Entrada de Pagos
      i_tcode                          = 'FB05'
*     I_SGFUNCT                        = ' '
*     I_NO_AUTH                        = ' '
    IMPORTING
      e_msgid                          = sy-msgid
      e_msgno                          = sy-msgno
      e_msgty                          = sy-msgty
      e_msgv1                          = sy-msgv1
      e_msgv2                          = sy-msgv2
      e_msgv3                          = sy-msgv3
      e_msgv4                          = sy-msgv4
      e_subrc                          = sy-subrc
    TABLES
      t_blntab                         = l_t_blntab
      t_ftclear                        = l_t_ftclear
      t_ftpost                         = l_t_ftpost
      t_fttax                          = l_t_fttax
    EXCEPTIONS
      clearing_procedure_invalid       = 1
      clearing_procedure_missing       = 2
      table_t041a_empty                = 3
      transaction_code_invalid         = 4
      amount_format_error              = 5
      too_many_line_items              = 6
      company_code_invalid             = 7
      screen_not_found                 = 8
      no_authorization                 = 9
      OTHERS                           = 10
            .

  MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
          WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

  CALL FUNCTION 'POSTING_INTERFACE_END'
* EXPORTING
*   I_BDCIMMED                    = ' '
*   I_BDCSTRTDT                   = NO_DATE
*   I_BDCSTRTTM                   = NO_TIME
    EXCEPTIONS
      session_not_processable       = 1
      OTHERS                        = 2
            .
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
            RAISING ERROR.
  ENDIF.


ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> FI All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.