cancel
Showing results for 
Search instead for 
Did you mean: 

Auto reversal of FBL3N

0 Kudos

FBL3N Transaction : if vendor dosen't Deposit cheque before 90 days autoreversal should happen on 91st day

TYPES : BEGIN OF ty_bsis,

bukrs TYPE bukrs, "Company Code
hkont TYPE hkont, "General Ledger Account
augdt TYPE augdt, "Clearing Date
augbl TYPE augbl, "Document Number of the Clearing Document
zuonr TYPE dzuonr, "Assignment Number
gjahr TYPE gjahr, "Fiscal Year
belnr TYPE belnr_d, "Accounting Document Number
buzei TYPE buzei, "Number of Line Item Within Accounting Document
budat TYPE budat, "Posting Date in the Document
bldat TYPE bldat, "Document date in the document
waers TYPE waers, "currency
xblnr TYPE xblnr1, "reference
blart TYPE blart, "Document type
monat TYPE monat, "period
bschl TYPE bschl, "posting Key
gsber TYPE gsber, "Business Area
dmbtr TYPE dmbtr, "Amount
wrbtr TYPE wrbtr, "Amount in document currency
sgtxt TYPE sgtxt, "Text
aufnr TYPE aufnr_neu, "order
kostl TYPE kostl, "cost center
END OF ty_bsis.

TYPES : BEGIN OF ty_bkpf,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
bktxt TYPE bktxt,
END OF ty_bkpf.
TYPES : BEGIN OF ty_bseg,
bukrs TYPE bukrs,
belnr TYPE belnr_d,
gjahr TYPE gjahr,
buzei TYPE buzei,
lifnr TYPE lifnr,
hkont TYPE hkont,

END OF ty_bseg.


DATA: count TYPE i VALUE 1.
DATA : lt_bsis TYPE TABLE OF ty_bsis,
lt_bkpf TYPE TABLE OF ty_bkpf,
lt_bseg TYPE TABLE OF ty_bseg,
ls_bseg TYPE ty_bseg,
ls_bsis TYPE ty_bsis,
ls_bkpf TYPE ty_bkpf,
lv_date(4) TYPE n.


DATA: w_head TYPE bapiache08,
w_accgl TYPE bapiacgl08,
t_accgl TYPE TABLE OF bapiacgl08,
w_curramt TYPE bapiaccr08,
t_curramt TYPE TABLE OF bapiaccr08,
t_return TYPE TABLE OF bapiret2,
w_return TYPE bapiret2.

DATA lt_REVERSAL TYPE BAPIACREV.


DATA : ld_obj_type TYPE bapiacrev-obj_type ,
ld_obj_key TYPE bapiacrev-obj_key ,
ld_obj_sys TYPE bapiacrev-obj_sys .
*DATA DOCUMENTHEADER TYPE BAPIACHE08.
*DATA OBJ_TYPE TYPE BAPIACHE02-OBJ_TYPE.
*DATA OBJ_KEY TYPE BAPIACHE02-OBJ_KEY.
*DATA OBJ_SYS TYPE BAPIACHE02-OBJ_SYS.
*DATA ACCOUNTGL TYPE STANDARD TABLE OF BAPIACGL08.
*DATA CURRENCYAMOUNT TYPE STANDARD TABLE OF BAPIACCR08.
*DATA RETURN TYPE STANDARD TABLE OF BAPIRET2.
*DATA EXTENSION1 TYPE STANDARD TABLE OF BAPIEXTC.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_hkont FOR bsis-hkont.
SELECTION-SCREEN END OF BLOCK b1.


START-OF-SELECTION.

SELECT
bukrs
hkont
augdt
augbl
zuonr
gjahr
belnr
buzei
budat
bldat
waers
xblnr
blart
monat
bschl
gsber
dmbtr
wrbtr
sgtxt
aufnr
kostl
FROM bsis
INTO TABLE lt_bsis
WHERE hkont IN s_hkont
AND bukrs = 1000.


IF lt_bsis IS NOT INITIAL.
SELECT
bukrs
belnr
gjahr
bktxt

FROM bkpf
INTO TABLE lt_bkpf
FOR ALL ENTRIES IN lt_bsis
WHERE bukrs = lt_bsis-bukrs
AND belnr = lt_bsis-belnr
AND gjahr = lt_bsis-gjahr.


SELECT
bukrs
belnr
gjahr
buzei
lifnr
hkont
FROM bseg
INTO TABLE lt_bseg
FOR ALL ENTRIES IN lt_bsis
WHERE bukrs = lt_bsis-bukrs
AND belnr = lt_bsis-belnr
AND gjahr = lt_bsis-gjahr

AND koart = 'K'.

ENDIF.

LOOP AT lt_bsis INTO ls_bsis.
lv_date = ls_bsis-budat - sy-datum.
SHIFT lv_date LEFT DELETING LEADING '0'.

IF lv_date LE 90.

DELETE TABLE lt_bsis FROM ls_bsis.
ENDIF.
ENDLOOP.

END-OF-SELECTION.

LOOP AT lt_bsis INTO ls_bsis.

CLEAR ls_bseg.
READ TABLE lt_bseg INTO ls_bseg WITH KEY bukrs = ls_bsis-bukrs
belnr = ls_bsis-belnr
gjahr = ls_bsis-gjahr
.

CLEAR ls_bkpf.
READ TABLE lt_bkpf INTO ls_bkpf WITH KEY bukrs = ls_bsis-bukrs
belnr = ls_bsis-belnr
gjahr = ls_bsis-gjahr.


w_head-username = sy-uname.
w_head-comp_code = '1000'.
w_head-doc_type = 'BA'.
w_head-fisc_year = ls_bsis-gjahr.
w_head-fis_period = ls_bsis-monat.
w_head-doc_date = sy-datum.
w_head-pstng_date = sy-datum.
w_head-ref_doc_no = ls_bsis-xblnr.
w_head-header_txt = ls_bkpf-bktxt.



w_accgl-itemno_acc = count. "**********Dount****************"
w_accgl-gl_account = ls_bsis-hkont.
w_accgl-bus_area = ls_bsis-gsber.
w_accgl-orderid = ls_bsis-aufnr.
w_accgl-costcenter = ls_bsis-kostl.
w_accgl-item_text = ls_bsis-sgtxt.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_accgl-gl_account
IMPORTING
output = w_accgl-gl_account.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_accgl-orderid
IMPORTING
output = w_accgl-orderid.

APPEND w_accgl TO t_accgl.

CLEAR w_curramt.
w_curramt-itemno_acc = count. "*********Dount****************"
w_curramt-curr_type = '00'.
w_curramt-currency = ls_bsis-waers.
w_curramt-amt_doccur = ls_bsis-wrbtr.
APPEND w_curramt TO t_curramt.
*
*
CLEAR w_accgl.
w_accgl-itemno_acc = count.
w_accgl-gl_account = ls_bseg-hkont.. "'0007102202'.
w_accgl-AC_DOC_NO = ls_bsis-belnr.
w_accgl-VENDOR_NO = ls_BSEG-LIFNR.. "'0007102202'.
w_accgl-item_text = ls_bsis-sgtxt.
w_accgl-bus_area = ls_bsis-gsber. "'1000'.

IF ls_bsis-aufnr IS NOT INITIAL.
w_accgl-orderid = ls_bsis-aufnr. "'000000900262'.
ENDIF.
IF ls_bsis-kostl IS NOT INITIAL.
w_accgl-costcenter = ls_bsis-kostl. "'HO1090'.
ENDIF.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_accgl-gl_account
IMPORTING
output = w_accgl-gl_account.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = w_accgl-orderid
IMPORTING
output = w_accgl-orderid.

APPEND w_accgl TO t_accgl.

CLEAR w_curramt.
w_curramt-itemno_acc = count. "1.
w_curramt-curr_type = '00'.
w_curramt-currency = ls_bsis-waers.
w_curramt-amt_doccur = ls_bsis-wrbtr. "200.



* APPEND w_curramt TO t_curramt.
*ENDIF.
count = count + 1.



lv_date = ls_bsis-budat - sy-datum.
SHIFT lv_date LEFT DELETING LEADING '0'.

IF lv_date GT 90.


BREAK-POINT.
CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
EXPORTING
documentheader = w_head
IMPORTING
obj_type = ld_obj_type
obj_key = ld_obj_key
obj_sys = ld_obj_sys
TABLES
accountgl = t_accgl
currencyamount = t_curramt
return = t_return
* EXTENSION1 = EXTENSION1
.
ENDIF.

BREAK-POINT.
IF t_return IS NOT INITIAL.
READ TABLE t_return INTO w_return WITH KEY type = 'S'.
IF sy-subrc EQ 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.

WRITE:/ w_return-message.
ELSE.

*DATA RETURN TYPE BAPIRET2.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN = RETURN
.

LOOP AT t_return INTO w_return.
WRITE:/ w_return-message.
ENDLOOP.
ENDIF.
ENDIF.
ENDLOOP.

i wrote this code but iam getting below errors

1 E RW 609 Error in document: BKPFF $ NLDCLNT900

2 E RW 014 FI/CO interface: Line item entered several times

3 E F 5354 Account 2310000 in company code 1000 cannot be directly posted to

Thanks & Regards,

Prashanth Namani

p244500
Active Contributor

When you post the code, plz use "CODE "button to share the code , then it will be clear to all .

did you try to reverse this document manually? using FB08 or the tcode which you used to reves in your company? if its work you need to debug the code and see what are the parameter which you pass .

If you get same error when you do it manually you shold check the GL account which you reverse .

Accepted Solutions (1)

Accepted Solutions (1)

thanga_prakash
Active Contributor
0 Kudos

Hi namani Prashanth

For second message "E RW 014 FI/CO interface: Line item entered several times" it is because of the Item number(itemno_acc) which you are passing to t_accgl.

After passing first item then for the second line itemno_acc has to be incremented, but in your code you are doing increment after appending both the lines so itemno_acc is 1 for both the GL lines.

"F5354 Account 2310000 in company code 1000 cannot be directly posted to" is influenced by SKB1-MITKZ field.

when checking in where used list of this message, in majority of places they have checked NE 'V' and 'A'. check in SKB1 table for 2310000 for MITKZ, this could be the way the account is setup by your FI colleague.

CLEAR w_accgl.
count = count + 1.   <----------------- Add this code--------------
w_accgl-itemno_acc = count.
w_accgl-gl_account = ls_bseg-hkont.. "'0007102202'.
w_accgl-AC_DOC_NO = ls_bsis-belnr.
w_accgl-VENDOR_NO = ls_BSEG-LIFNR.. "'0007102202'.
w_accgl-item_text = ls_bsis-sgtxt.
w_accgl-bus_area = ls_bsis-gsber. "'1000'.
0 Kudos

Tq very much for youi qucik response @Thanga Prakash Thanga Raj.

I will change my code ,

and i will get back to you.

Answers (1)

Answers (1)

former_member1716
Active Contributor
0 Kudos

Hello namani Prashanth,

Firstly Always use CODE option to paste your code, its almost impossible to read your this way.

From your errors below could be the root causes:

--> Same Line items are entered multiple times.

--> Your GL Account mapping/Configuration is wrong.

Check with Valid Data and please paste your code using CODE option.

Regards!

0 Kudos

First of all Tq for your Response Satish Kumar Balasubramanian

As iam new to this Sap Community i did like that ,

Form Next i will do like that.

0 Kudos

Tq for your Response

If you Dont mind May i know how to use Code Option

former_member1716
Active Contributor

Hello namani Prashanth,

You can find the CODE option as highlighted below: