Skip to Content
0

Document was wrongly cleared with itself

Nov 28, 2017 at 01:42 PM

66

avatar image
Former Member

Dear Experts!

I have very urgent question. We did report in FI module and it was created final invoice it was automatically cleared namely it created clearing document even line items is not zero in FBL5N it has cleared positions. But it should not be, and If I want to reverse document from FBRA it gives errro as "Line items is not zero"

Dear experts is there any FM / Bapi or standart Tcode to change status of this wrongly cleared document to open

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
avatar image
Former Member Dec 04, 2017 at 07:03 AM
0

Good morning everyone.

I found the reason of problem and solution.

Problem: in our development, when down payment is created or final invoice is created they were automatically clared without any clering documents. This was really strange situation that led to error " Line items is not zero ". The reason was FM which is called as 'CLEAR_DOCUMENTS' was used incorrectly.

Solution: Thanks to some FM we were able to reset documents in order to clear them correctly. I am posting code on purpose it will be usefull for others in future.

" Processing resetting documents
form resetting_document using ls_rf05r type rf05r
                              l_bukrs type bseg-bukrs.
  " Postab initialization
  data:    begin of postab occurs 50,
           xauth(1)      type c,
           xhell(1)      type c.
          include structure rfpos.
          include rfeposc9.
  data:    xbkpf(1)      type c,
           xbseg(1)      type c,
           xbsec(1)      type c,
           xbsed(1)      type c,
           xpayr(1)      type c,
           xbsegc(1)     type c,
           xbsbv(1)      type c,
           xmod(1)       type c,
           end of postab.
  " Form variables initialization
  data:
    xerlk type rfpdo1-f140xdel,
    stodt type bkpf-budat,
    xragl1 type table of ragl1,
    ls_xragl1 type ragl1,
    xragl2 type table of ragl2,
    ls_xragl2 type ragl2,
    xragl3 type table of ragl3,
    ls_xragl3 type ragl3,
    xbkorm type table of bkorm,
    ls_bkpf type bkpf,
    ls_bseg type bseg,
    xkdf(1) type c,
    xskv(1) type c.

  " Read data from BKPF table
  call function 'READ_DOCUMENT_HEADER'
    exporting
      belnr     = ls_rf05r-augbl
      bstat     = space
      bukrs     = ls_rf05r-bukrs
      gjahr     = ls_rf05r-gjahr
      xarch     = space          "keine Suche im Archiv
    importing
      e_bkpf    = ls_bkpf
    exceptions
      exit      = 4
      not_found = 8.

  " Get cleared items
  refresh: postab, xragl1, xragl2, xragl3.
  call function 'GET_CLEARED_ITEMS'
    exporting
      i_bvorg   = ls_bkpf-bvorg
      i_bukrs   = ls_rf05r-bukrs
      i_belnr   = ls_rf05r-augbl
      i_gjahr   = ls_rf05r-gjahr
    importing
      e_xkdf    = xkdf
      e_xskv    = xskv
    tables
      t_items   = postab
    exceptions
      not_found = 1
      others    = 2.

  " Filling out tables
  loop at postab.
    move-corresponding postab to ls_xragl1.
    append ls_xragl1 to xragl1.
  endloop.

  " Filling second table
  select * from bseg into corresponding fields of ls_bseg where bukrs eq ls_rf05r-bukrs and
   belnr eq ls_rf05r-augbl and gjahr eq ls_rf05r-gjahr.
    if ls_bseg-augbl eq ls_rf05r-augbl and ( ls_bseg-fdgrp eq space or ls_bseg-fdlev eq space ).
      move-corresponding ls_bseg to ls_xragl2.
      append ls_xragl2 to xragl2.
    endif.
  endselect.

  " Reverse clearing
  call function 'REVERSE_CLEARING' in update task
    exporting
      i_augbu = ls_rf05r-bukrs
      i_augbl = ls_rf05r-augbl
      i_auggj = ls_rf05r-gjahr
      i_xerlk = xerlk
      i_stodt = stodt
    tables
      t_ragl1 = xragl1
      t_ragl2 = xragl2
      t_ragl3 = xragl3
      t_bkorm = xbkorm.

  " extended withholding tax
  call function 'FI_CHECK_EXTENDED_WT'
    exporting
      i_bukrs              = l_bukrs
    exceptions
      component_not_active = 1
      not_found            = 2
      others               = 3.

  " Reset documents FI
  call function 'FI_WT_RESET_CLEARING' in update task
    exporting
      i_augbu = ls_rf05r-bukrs
      i_augbl = ls_rf05r-augbl
      i_auggj = ls_rf05r-gjahr
    tables
      t_ragl1 = xragl1.

  " Open FI
  call function 'OPEN_FI_PERFORM_00001040_E'
    exporting
      i_xvbup = 'X'
      i_rf05r = ls_rf05r
    tables
      t_xragl = xragl1.

  " If everyting is ok show message and write to table
  if ls_rf05r-bvorg is initial.
    " Append to intenal table that will display logs
    ls_tickets-name = icon_led_green.
    ls_tickets-matnr = ls_ticketnumber-ticketnumber.
    ls_tickets-text = 'Successfully generated'.
    append ls_tickets to lt_tickets.
    " Apply changes to Database
    commit work.
  endif.
endform.
Share
10 |10000 characters needed characters left characters exceeded
Eli Klovski
Nov 28, 2017 at 01:45 PM
0

Hi,

It is a strange situation you are describing. Can you post the screenshot of the document, including its clearing information?

Regards,

Eli

Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi Eli

As you can see in picture two final invoice documents which status is open in FBL5N

But I f I check those documents numbers from table BSEG it has already cleared document number which should not be. Thus If I want to clear documents it gives an error

снимок.png (5.5 kB)
0
Eli Klovski
Nov 29, 2017 at 12:34 PM
0

Clearing document could be there, but did you check the clearing date? If the date is in the future and you run FBL5N report with date of today, then it would still show you that the items are open. Sometimes, people who do the clearing make a typo and if the period is not closed, clearing date could be wrong.

Share
10 |10000 characters needed characters left characters exceeded