BAPI to clear posting

FB05 through FM, POSTING_INTERFACE_CLEARING

6350,204

Posting Clearing document through function module POSTING_INTERFACE_CLEARING

*** Header and line item diffrentiation:

LCF_STYPE_K            TYPE  STYPE_PI           VALUE ‘K’, ” HEADER Line

LCF_STYPE_P            TYPE  STYPE_PI           VALUE ‘P’, ” Line Item

*** Populate and map FTCLEAR  to POSTING_INTERFACE_CLEARING

LDS_FTCLEAR–AGKOA  = ‘K’ or ‘D’ ( based on account type, Vendor or Customer for Out Going / Incoming Payments.

LDS_FTCLEAR–AGBUK  =  <company_code>.

LDS_FTCLEAR–XNOPS  = ‘X’.

LDS_FTCLEAR–SELFD  = <referece_document_number>

LDS_FTCLEAR–SELVON = <reference_field> ” SELFD is value of the filed assigned here.

APPEND LDS_FTCLEAR TO P_LDT_FTCLEAR.

*** FTPOST sample filling data

LDS_FTPOST–STYPE = P_LCF_STYPE.

LDS_FTPOST–COUNT = P_LDF_COUNT.

LDS_FTPOST–FNAM = P_LCF_FNAM.

LDS_FTPOST–FVAL = P_FVAL.

APPEND LDS_FTPOST TO P_LDT_FTPOST.

Call the below function modules in following order.

POSTING_INTERFACE_START

POSTING_INTERFACE_CLEARING

POSTING_INTERFACE_END

POSTING_INTERFACE_START :

CALL FUNCTION ‘POSTING_INTERFACE_START’

EXPORTING

I_CLIENT           = SY–MANDT

I_FUNCTION         = ‘C’ ( Function: BDC, Call Trans. Using, internal interface)

I_MODE             = MODE ( N – no screen, A – all screen, E – Error –> Mode we use in Call transaction)

I_USER             = SY–UNAME

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.

POSTING_INTERFACE_CLEARING:

CALL FUNCTION ‘POSTING_INTERFACE_CLEARING’

EXPORTING

I_AUGLV      =      ‘AUSGZAHL’ ” Follow below mentioned table

I_TCODE      =     ‘FB05’

I_SGFUNCT      =      ‘C’

IMPORTING

E_MSGID         =      LDS_RETURN–ID

E_MSGNO         =      LDS_RETURN–NUMBER

E_MSGTY         =      LDS_RETURN–TYPE

E_MSGV1         =      LDS_RETURN–MESSAGE_V1

E_MSGV2         =      LDS_RETURN–MESSAGE_V2

E_MSGV3         =      LDS_RETURN–MESSAGE_V3

E_MSGV4         =      LDS_RETURN–MESSAGE_V4

*             E_SUBRC        =      SY-SUBRC

TABLES

T_BLNTAB     =      LDT_BLNTAB

T_FTCLEAR    =      LDT_FTCLEAR

T_FTPOST     =      LDT_FTPOST

T_FTTAX      =      LDT_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.

Note the following :

The data is marked with a record type (header, code = K; item, code = P) and counter. –  LCF_STYPE_K  and  LCF_STYPE_S

Up to 950 line items can be transferred.

The data is transferred with the field name and field value.

The data must be transferred in the following sequence:

Document header data ( K 1)

Document item 1 ( P 1)

Document item 2 ( P 2)  etc.

The field names are the same as those used on the entry screen (e.g. ‘BKPF-WAERS’, ‘BSEG-WRBTR’, ‘COBL-GSBER’…).

Suppose if it Cost Center / Profit Center – its COBL-KOSTL and COBL-PRCTR

The footer data can be transferred using the following fields:

Posting key:        RF05A-NEWBS or BSEG-BSCHL

Account number:     RF05A-NEWKO or BSEG-KONTO                      or BSEG-KUNNR (for customer accounts)                      or BSEG-LIFNR (for vendor accounts)                      or BSEG-HKONT (for G/L accounts)

Special G/L indicator: RF05A-NEWUM or BSEG-UMSKZ

Company code (for intercompany posting):                      RF05A-NEWBK or BSEG-BUKRS.

The field names are analyzed by the function module so that the data can be assigned to the right screens. Field names for one-time data or data for an alternative payer must start with ‘BSEC-‘, for example (see screen SAPLFCPD 0100).

Processing with ‘Call Transaction … Using ‘

If processing takes place with ‘Call Transaction .. Using’, the initiator can see whether processing was successful by looking at the export parameter’SUBRC’.

SUBRC = 0 means that the document was posted. The document number is stored in table T_BLNTAB. For intercompany documents, several document numbers are stored here.

SUBRC <> 0 means that the document could not be posted. Information concerning the error which has arisen is returned via the message fields MSGID, MSGNO, etc.

Support of transaction ‘FBB1’

If you want to access transaction FBB1, you should note the following:

Enter the foreign currency key in field BKPF-WAERS.

In this transaction you should enter the local currency amount in field BSEG-WRBTR for each document item.

POSTING_INTERFACE_END:

CALL FUNCTION ‘POSTING_INTERFACE_END’

EXPORTING

I_BDCIMMED              = ‘X’

EXCEPTIONS

SESSION_NOT_PROCESSABLE = 1

OTHERS                  = 2.

FollowLikeRSS Feed

Alert Moderator

Assigned Tags

FIN (Finance)

clearing

code

document

fb05

payment

posting interface

View more...

Similar Blog Posts

How to activate Invoice Receipt Date in document header for any company

By Marek TurczynskiJun 16, 2020

Change financial document using function module FI_DOCUMENT_CHANGE

By Jonathan EemansJan 27, 2020

Extending BKPF Table by adding custom or ZZ Fields in SAP

By Divya MunnuruJun 18, 2018

Related Questions

Can FM POSTING_INTERFACE_CLEARING be used just for clearing?

By Likitha GopalApr 21, 2022

clear vendor down payment

By madjid khanevadegiDec 11, 2018

error F8 006 Transaction code FB1K is invalid in BAPI POSTING_INTERFACE_CLEARING

By KAPIL MEHTAFeb 14, 2018

6 Comments

You must be Logged on to comment or reply to a post.

Former Member

June 20, 2013 at 5:12 pm

Notes are very helpful.

Like 0

Share

Former Member

July 30, 2013 at 9:16 pm

Hello Ramkrishna,

This is very helpful. I am in the process of writing one such program where I am posting a few entries and clearing some open items at the same time. But, the requirement here is a little unique where the clearing is not based on just one field but based on two fields (BELNR and XREF3 ) with an AND condition between them. Is this even possible to do ?

If yes, can you please suggest me a way to do this ?

Thank you once again for the information you have posted here.

Like 0

Share

Former Member

Blog Post Author

July 31, 2013 at 2:23 am

Hi Santosh,

Don't think this is possible through FB05. The reason am saying this is we can have only one additional selection (its radio button).

Just to give a try, do the following:

Alternatively, please use Assignment field. But before that your assignment filed should hold both BELNR + XREF3 values then you can use the field for selection. This is just an alternative, you can think of it.

And, Try to add two values to FTCLEAR internal table in FM and see whats happening. May you can simulate as sample code and try.

*** Populate and map FTCLEAR  to POSTING_INTERFACE_CLEARING

LDS_FTCLEAR-AGKOA  = 'K' or 'D'

LDS_FTCLEAR-AGBUK  =  <company_code>.

LDS_FTCLEAR-XNOPS  = 'X'.

LDS_FTCLEAR-SELFD  = 'BELNR'

LDS_FTCLEAR-SELVON = 'BELNR' value

APPEND LDS_FTCLEAR TO P_LDT_FTCLEAR.

LDS_FTCLEAR-AGKOA  = 'K' or 'D'

LDS_FTCLEAR-AGBUK  =  <company_code>.

LDS_FTCLEAR-XNOPS  = 'X'.

LDS_FTCLEAR-SELFD  = 'XREF3' " you may not have this filed in selection, use OTHERS.

LDS_FTCLEAR-SELVON = 'XREF3' value

APPEND LDS_FTCLEAR TO P_LDT_FTCLEAR.

Once you try this, leave the results here. It may be helpful for others; even me.

Thanks

Like 0

Share

Former Member

September 20, 2016 at 8:36 pm

There is an error.

I wonder why noone didn't catch it yet.

SELFD = Field Name from the Document Index

SELVON = Input Field for Search Criterion for Selecting Open Items.

Just need to swap these two values.

Like 0

Share

Himmel P

September 26, 2016 at 7:04 am

Hi All,

Using these FMs i am able to successfully post/clear the document against each open document. ( one clear document generated for one open document )

But my requirement is to create only one clear document against all open documents of the same customer .

Would some one help me in this case how to fill these FTPOST and FTCLEAR tables.

Appreciate your valuable inputs .

Thank you.

Like 0

Share

chedva Ankava

July 31, 2022 at 6:52 am

Hi, I would like to use the POSTING_INTERFACE_CLEARING FM for  large amount of items to be cleared (over 950)

Is there a solution to this? (besides split the posting and create multiple documents )

Thank you for your help, Chedvi

Atif Mukhtar

April 21, 2020 14 minute read

Implementing Clearing Interface using POSTING_INTERFACE_CLEARING in s4 Hana 1709.

027,208

SAP has provided a clearing process using tcode FB05 which is not very user friendly in order to perform clearing a new module is created in SAP using provided interface for the convenience of users.

Create a screen using below interface:

2.Upon save event call below subroutines in sequence.

3. Source code provided below:

*&---------------------------------------------------------------------*

*& Include LZFIBRF01

*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*

* INCLUDE TABLECONTROL_FORMS *

*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*

*& Form USER_OK_TC *

*&---------------------------------------------------------------------*

FORM USER_OK_TC USING P_TC_NAME TYPE DYNFNAM

P_TABLE_NAME

P_MARK_NAME

CHANGING P_OK LIKE SY-UCOMM.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*

DATA: L_OK TYPE SY-UCOMM,

L_OFFSET TYPE I.

*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

*&SPWIZARD: Table control specific operations *

*&SPWIZARD: evaluate TC name and operations *

SEARCH P_OK FOR P_TC_NAME.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

L_OFFSET = STRLEN( P_TC_NAME ) + 1.

L_OK = P_OK+L_OFFSET.

*&SPWIZARD: execute general and TC specific operations *

CASE L_OK.

WHEN 'INSR'. "insert row

PERFORM FCODE_INSERT_ROW USING P_TC_NAME

P_TABLE_NAME.

CLEAR P_OK.

WHEN 'DELE'. "delete row

PERFORM FCODE_DELETE_ROW USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME.

CLEAR P_OK.

WHEN 'P--' OR "top of list

'P-' OR "previous page

'P+' OR "next page

'P++'. "bottom of list

PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME

L_OK.

CLEAR P_OK.

* WHEN 'L--'. "total left

* PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.

*

* WHEN 'L-'. "column left

* PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.

*

* WHEN 'R+'. "column right

* PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.

*

* WHEN 'R++'. "total right

* PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.

*

WHEN 'MARK'. "mark all filled lines

PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

CLEAR P_OK.

WHEN 'DMRK'. "demark all filled lines

PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

CLEAR P_OK.

* WHEN 'SASCEND' OR

* 'SDESCEND'. "sort column

* PERFORM FCODE_SORT_TC USING P_TC_NAME

* l_ok.

ENDCASE.

ENDFORM. " USER_OK_TC

*&---------------------------------------------------------------------*

*& Form FCODE_INSERT_ROW *

*&---------------------------------------------------------------------*

FORM fcode_insert_row

USING P_TC_NAME TYPE DYNFNAM

P_TABLE_NAME .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*

DATA L_LINES_NAME LIKE FELD-NAME.

DATA L_SELLINE LIKE SY-STEPL.

DATA L_LASTLINE TYPE I.

DATA L_LINE TYPE I.

DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <LINES> TYPE I.

*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.

ASSIGN (L_LINES_NAME) TO <LINES>.

*&SPWIZARD: get current line *

GET CURSOR LINE L_SELLINE.

IF SY-SUBRC <> 0. " append line to table

L_SELLINE = <TC>-LINES + 1.

*&SPWIZARD: set top line *

IF L_SELLINE > <LINES>.

<TC>-TOP_LINE = L_SELLINE - <LINES> + 1 .

ELSE.

<TC>-TOP_LINE = 1.

ENDIF.

ELSE. " insert line into table

L_SELLINE = <TC>-TOP_LINE + L_SELLINE - 1.

L_LASTLINE = <TC>-TOP_LINE + <LINES> - 1.

ENDIF.

*&SPWIZARD: set new cursor line *

L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.

*&SPWIZARD: insert initial line *

INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.

<TC>-LINES = <TC>-LINES + 1.

*&SPWIZARD: set cursor *

SET CURSOR LINE L_LINE.

ENDFORM. " FCODE_INSERT_ROW

*&---------------------------------------------------------------------*

*& Form FCODE_DELETE_ROW *

*&---------------------------------------------------------------------*

FORM fcode_delete_row

USING P_TC_NAME TYPE DYNFNAM

P_TABLE_NAME

P_MARK_NAME .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*

DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: delete marked lines *

DESCRIBE TABLE <TABLE> LINES <TC>-LINES.

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

IF <MARK_FIELD> = 'X'.

DELETE <TABLE> INDEX SYST-TABIX.

IF SY-SUBRC = 0.

<TC>-LINES = <TC>-LINES - 1.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " FCODE_DELETE_ROW

*&---------------------------------------------------------------------*

*& Form COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*

* text

*----------------------------------------------------------------------*

* -->P_TC_NAME name of tablecontrol

* -->P_OK ok code

*----------------------------------------------------------------------*

FORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME

P_OK.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*

DATA L_TC_NEW_TOP_LINE TYPE I.

DATA L_TC_NAME LIKE FELD-NAME.

DATA L_TC_LINES_NAME LIKE FELD-NAME.

DATA L_TC_FIELD_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <LINES> TYPE I.

*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.

ASSIGN (L_TC_LINES_NAME) TO <LINES>.

*&SPWIZARD: is no line filled? *

IF <TC>-LINES = 0.

*&SPWIZARD: yes, ... *

L_TC_NEW_TOP_LINE = 1.

ELSE.

*&SPWIZARD: no, ... *

CALL FUNCTION 'SCROLLING_IN_TABLE'

EXPORTING

ENTRY_ACT = <TC>-TOP_LINE

ENTRY_FROM = 1

ENTRY_TO = <TC>-LINES

LAST_PAGE_FULL = 'X'

LOOPS = <LINES>

OK_CODE = P_OK

OVERLAPPING = 'X'

IMPORTING

ENTRY_NEW = L_TC_NEW_TOP_LINE

EXCEPTIONS

* NO_ENTRY_OR_PAGE_ACT = 01

* NO_ENTRY_TO = 02

* NO_OK_CODE_OR_PAGE_GO = 03

OTHERS = 0.

ENDIF.

*&SPWIZARD: get actual tc and column *

GET CURSOR FIELD L_TC_FIELD_NAME

AREA L_TC_NAME.

IF SYST-SUBRC = 0.

IF L_TC_NAME = P_TC_NAME.

*&SPWIZARD: et actual column *

SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.

ENDIF.

ENDIF.

*&SPWIZARD: set the new top line *

<TC>-TOP_LINE = L_TC_NEW_TOP_LINE.

ENDFORM. " COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*

*& Form FCODE_TC_MARK_LINES

*&---------------------------------------------------------------------*

* marks all TableControl lines

*----------------------------------------------------------------------*

* -->P_TC_NAME name of tablecontrol

*----------------------------------------------------------------------*

FORM FCODE_TC_MARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME.

*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------*

DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: mark all filled lines *

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

<MARK_FIELD> = 'X'.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

*&---------------------------------------------------------------------*

*& Form FCODE_TC_DEMARK_LINES

*&---------------------------------------------------------------------*

* demarks all TableControl lines

*----------------------------------------------------------------------*

* -->P_TC_NAME name of tablecontrol

*----------------------------------------------------------------------*

FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*

DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE cxtab_control.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: demark all filled lines *

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

<MARK_FIELD> = SPACE.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

*&---------------------------------------------------------------------*

*& Form FETCH_DATA

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM FETCH_DATA .

clear: mgl,

igl,

ogl.

select single hkont into mgl

from t012k

where bukrs in s_bukrs

and hbkid in s_hbkid

and hktid in s_hktid.

concatenate mgl+0(9) '1' into igl.

concatenate mgl+0(9) '2' into ogl.

clear i_oitems[].

if pinp = 'X'.

select k~blart s~zuonr k~budat s~valut s~dmbtr s~belnr s~gjahr s~shkzg

s~bschl s~buzei

into corresponding fields of table i_oitems

from bkpf as k

inner join bsis as s

on k~belnr = s~belnr

and k~gjahr = s~gjahr

and k~bukrs = s~bukrs

where k~bukrs in s_bukrs

and k~budat in s_budat

and s~hkont = igl.

* and k~blart in ('DZ','KZ').

else.

select k~blart s~zuonr k~budat s~valut s~dmbtr s~belnr s~gjahr s~shkzg

s~bschl s~buzei

into corresponding fields of table i_oitems

from bkpf as k

inner join bsis as s

on k~belnr = s~belnr

and k~gjahr = s~gjahr

and k~bukrs = s~bukrs

where k~bukrs in s_bukrs

and k~budat in s_budat

and s~hkont = ogl.

* and k~blart in ('DZ','KZ').

endif.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form POST_CLEAR_DOCS

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM POST_CLEAR_DOCS .

* perform post_acct_transaction.

perform calculate_total.

perform fill_post_data.

perform fill_clear_data.

perform post_with_clearing.

perform fetch_data.

Perform clear_data.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form FILL_POST_DATA

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM FILL_POST_DATA .

CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

EXPORTING

I_DATE = s_augdt-low

* I_MONMIT = 00

I_PERIV = 'Z1'

IMPORTING

E_BUPER = cdoc_period

E_GJAHR = cdoc_year

EXCEPTIONS

INPUT_FALSE = 1

T009_NOTFOUND = 2

T009B_NOTFOUND = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.

CALL FUNCTION 'FI_PERIOD_CHECK'

EXPORTING

I_BUKRS = s_bukrs-low

I_OPVAR = ' '

I_GJAHR = cdoc_year

I_KOART = 'S'

* I_KONTO = ' '

I_MONAT = cdoc_period

** I_SPERI =

* I_RLDNR =

I_GLVOR = 'RFBU'

* I_LDGRP =

IMPORTING

E_OPER = eperiod_chk

EXCEPTIONS

ERROR_PERIOD = 1

ERROR_PERIOD_ACC = 2

INVALID_INPUT = 3

OTHERS = 4

.

IF SY-SUBRC <> 0.

message e020(zfi_am) with s_bukrs-low cdoc_year cdoc_period.

ENDIF.

clear ftpost.

ftpost-stype = 'K'.

ftpost-count = '001'.

ftpost-fnam = 'BKPF-BLDAT '.

ftpost-fval = s_augdt-low+6(2) && s_augdt-low+4(2) && s_augdt-low+0(4) .

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-BLART '.

ftpost-fval = 'SA'.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-BUKRS '.

ftpost-fval = s_bukrs-low.

append ftpost.

ftpost-fnam = 'BKPF-BUDAT '.

ftpost-fval = s_augdt-low+6(2) && s_augdt-low+4(2) && s_augdt-low+0(4) .

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-MONAT '.

ftpost-fval = cdoc_period+1(2) .

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-WAERS '.

ftpost-fval = s_waers-low .

append ftpost.

clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-KURSF '.

*

*ftpost-fval = 1. "exchange rate

*

*append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'FS006-DOCID'.

ftpost-fval = '*' .

append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-BELNR'.

*

*ftpost-fval = zobj_type+0(10) .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-WWERT '.

*

*ftpost-fval = bbkpf-wwert .

*

*append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-XBLNR '.

ftpost-fval = 'Reference' .

append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-BVORG '.

*

*ftpost-fval = bbkpf-bvorg .

*

*append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-BKTXT '.

ftpost-fval = 'Document Header Text' .

append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'RF05A-PARGB '.

*

*ftpost-fval = bbkpf-pargb .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-VBUND '.

*

*ftpost-fval = bbkpf-vbund .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-XMWST '.

*

*ftpost-fval = bbkpf-xmwst .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'FS006-DOCID '.

*

*ftpost-fval = bbkpf-docid .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'FS006-BARCD '.

*

*ftpost-fval = bbkpf-barcd .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-STODT '.

*

*ftpost-fval = bbkpf-stodt .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-BRNCH '.

*

*ftpost-fval = bbkpf-brnch .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-NUMPG '.

*

*ftpost-fval = bbkpf-numpg .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-STGRD '.

*

*ftpost-fval = bbkpf-stgrd .

*

*append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-KURSF_M '.

*

*ftpost-fval = bbkpf-kursf_m .

*

*append ftpost.

*

*nro_asiento = nro_asiento + 1.

*

*aux_sistema = zsist.

*

*aux_lote = zlote.

*

*concatenate aux_sistema '-' aux_lote '-' nro_asiento into aux_awkey.

*

*Agregado de los campos clave

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BKPF-AWTYP '.

ftpost-fval = 'BKPF' .

append ftpost.

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-AWKEY '.

*

*ftpost-fval = 'Assignment' .

*

*append ftpost.

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BKPF-AWSYS '.

*

*ftpost-fval = 'SAD_220' .

*

*append ftpost.

ftpost-stype = 'P'.

ftpost-count = '001'.

if pinp = 'X'.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-HKONT'.

ftpost-fval = mgl .

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-BSCHL'.

ftpost-fval = '40'.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-WRBTR'.

ftpost-fval = acct_amount.

condense ftpost-fval.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-ZUONR'.

ftpost-fval = 'Assignment'.

append ftpost.

*

*ftpost-stype = 'P'.

*

*ftpost-count = '002'.

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BSEG-BSCHL'.

*

*ftpost-fval = '50'.

*

*append ftpost.

*

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BSEG-HKONT'.

*

*ftpost-fval = igl .

*

*append ftpost.

*

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BSEG-ZUONR'.

*

*ftpost-fval = 'Assignment'.

*

*append ftpost.

else.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-HKONT'.

ftpost-fval = mgl .

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-BSCHL'.

ftpost-fval = '50'.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-ZUONR'.

ftpost-fval = 'Assignment'.

append ftpost.

*ftpost-stype = 'P'.

*

*ftpost-count = '002'.

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BSEG-BSCHL'.

*

*ftpost-fval = '40'.

*

*append ftpost.

*

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BSEG-HKONT'.

*

*ftpost-fval = ogl .

*

*append ftpost.

*

*

*clear: ftpost-fnam, ftpost-fval.

*

*ftpost-fnam = 'BSEG-ZUONR'.

*

*ftpost-fval = 'Assignment'.

*

*append ftpost.

endif.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BDC_OKCODE'.

ftpost-fval = '/00'.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BSEG-WRBTR'.

ftpost-fval = acct_amount.

condense ftpost-fval.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BDC_OKCODE'.

ftpost-fval = '=AB'.

append ftpost.

clear: ftpost-fnam, ftpost-fval.

ftpost-fnam = 'BDC_OKCODE'.

ftpost-fval = '=BU'.

append ftpost.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form FILL_CLEAR_DATA

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM FILL_CLEAR_DATA .

loop at i_oitems where mark = 'X'.

S_FTCLEAR-agkoa = 'S'.

S_FTCLEAR-agbuk = s_bukrs-low.

S_FTCLEAR-XNOPS = 'X'.

if pinp = 'X'.

S_FTCLEAR-AGKON = igl.

else.

S_FTCLEAR-AGKON = ogl.

endif.

S_FTCLEAR-SELFD = 'BELNR'.

S_FTCLEAR-selvon = i_oitems-belnr.

APPEND S_FTCLEAR to FTCLEAR.

endloop.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form POST_ACCT_TRANSACTION

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM POST_ACCT_TRANSACTION .

* Fill Document Header

zdoc_head-bus_act = 'RFBU'.

zdoc_head-obj_type = 'BKPFF'.

*doc_header-obj_key = 'AAAABBBB'.

*doc_header-obj_sys = 'NLD220'.

zdoc_head-username = sy-uname.

zdoc_head-header_txt = 'Clearing doc header text'.

zdoc_head-comp_code = s_bukrs-low.

zdoc_head-ref_doc_no = 'Reference Doc'.

zdoc_head-doc_date = s_augdt-low.

zdoc_head-pstng_date = s_augdt-low.

zdoc_head-doc_type = 'SA'.

* Fill Line 1 of Document Item

zagl-itemno_acc = '1'.

zagl-gl_account = mgl.

*zagl-gl_account = '0028001061'.

*zagl-pstng_date = sy-datum.

zagl-pstng_date = s_augdt-low.

zagl-item_text = 'ITem Text'.

zagl-alloc_nmbr = 'Assignment'.

APPEND zagl.

CLEAR zagl.

* Fill Line 1 of Document Item

zagl-itemno_acc = '2'.

if pinp = 'X'.

zagl-gl_account = igl.

else.

zagl-gl_account = ogl.

endif.

*zagl-gl_account = '0028001061'.

*zagl-pstng_date = sy-datum.

zagl-pstng_date = s_augdt-low.

zagl-item_text = 'ITem Text'.

zagl-alloc_nmbr = 'Assignment'.

APPEND zagl.

CLEAR zagl.

if pinp = 'X'.

* Fill Line 1 of Document Value.

zcurr-itemno_acc = '1'.

zcurr-currency_iso = 'PKR'.

zcurr-amt_doccur = acct_amount.

APPEND zcurr.

CLEAR zcurr.

* Fill Line 2 of Document Value

zcurr-itemno_acc = '2'.

zcurr-currency_iso = 'PKR'.

zcurr-amt_doccur = acct_amount * -1.

APPEND zcurr.

CLEAR zcurr.

else.

* Fill Line 1 of Document Value.

zcurr-itemno_acc = '1'.

zcurr-currency_iso = 'PKR'.

zcurr-amt_doccur = acct_amount * -1.

APPEND zcurr.

CLEAR zcurr.

* Fill Line 2 of Document Value

zcurr-itemno_acc = '2'.

zcurr-currency_iso = 'PKR'.

zcurr-amt_doccur = acct_amount.

APPEND zcurr.

CLEAR zcurr.

endif.

* Add tax code in extension1 table.

zext-field1 = 'BAPI CALL'.

APPEND zEXT.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'

EXPORTING

DOCUMENTHEADER = zdoc_head

* CUSTOMERCPD =

* CONTRACTHEADER =

TABLES

ACCOUNTGL = zagl

ACCOUNTRECEIVABLE = zcust

* ACCOUNTPAYABLE =

* ACCOUNTTAX =

CURRENCYAMOUNT = zcurr

* CRITERIA =

* VALUEFIELD =

EXTENSION1 = zext

RETURN = zret

* PAYMENTCARD =

* CONTRACTITEM =

* EXTENSION2 =

* REALESTATE =

* ACCOUNTWT =

.

read table zret with key type = 'E'.

* number = '506'.

if sy-subrc = 0.

message e021(zfi_am).

call screen '9001'.

endif.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

DOCUMENTHEADER = zdoc_head

* CUSTOMERCPD =

* CONTRACTHEADER =

IMPORTING

OBJ_TYPE = zobj_type

OBJ_KEY = zobj_key

OBJ_SYS = zobj_sys

TABLES

ACCOUNTGL = zAGL

ACCOUNTRECEIVABLE = zcust

* ACCOUNTPAYABLE =

* ACCOUNTTAX =

CURRENCYAMOUNT = zcurr

* CRITERIA = zcrt

* VALUEFIELD =

EXTENSION1 = zext

RETURN = zret

* PAYMENTCARD =

* CONTRACTITEM =

* EXTENSION2 =

* REALESTATE =

* ACCOUNTWT =

.

loop at zret where type = 'S'.

message s022(zfi_am) with zret-message zobj_type

zobj_key zobj_sys.

endloop.

*

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

IMPORTING

RETURN = zret.

leave to transaction 'ZFIBR'.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form POST_WITH_CLEARING

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM POST_WITH_CLEARING .

CALL FUNCTION 'POSTING_INTERFACE_START'

EXPORTING

I_CLIENT = SY-MANDT

I_FUNCTION = 'C'

* I_GROUP = ' '

* I_HOLDDATE = ' '

* I_KEEP = ' '

I_MODE = 'E'

I_UPDATE = 'S'

I_USER = sy-uname

* I_XBDCC = ' '

EXCEPTIONS

CLIENT_INCORRECT = 1

FUNCTION_INVALID = 2

GROUP_NAME_MISSING = 3

MODE_INVALID = 4

UPDATE_INVALID = 5

USER_INVALID = 6

OTHERS = 7

.

IF SY-SUBRC <> 0.

* Implement suitable error handling here

message e022(zfi_am).

ENDIF.

if pinp = 'X'.

CALL FUNCTION 'POSTING_INTERFACE_CLEARING'

EXPORTING

I_AUGLV = 'EINGZAHL'

I_TCODE = 'FB05'

I_SGFUNCT = 'C'

* I_NO_AUTH = ' '

* I_XSIMU = ' '

IMPORTING

E_MSGID = msg_id

E_MSGNO = msg_no

E_MSGTY = msg_typ

E_MSGV1 = msg_V1

E_MSGV2 = msg_V2

E_MSGV3 = msg_V3

E_MSGV4 = msg_V4

E_SUBRC = e_stat

TABLES

T_BLNTAB = LDT_BLNTAB

T_FTCLEAR = FTCLEAR

T_FTPOST = FTPOST

T_FTTAX = LDT_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

.

IF SY-SUBRC <> 0.

message e023(zfi_am).

* Implement suitable error handling here

ENDIF.

else.

CALL FUNCTION 'POSTING_INTERFACE_CLEARING'

EXPORTING

I_AUGLV = 'AUSGZAHL'

I_TCODE = 'FB05'

I_SGFUNCT = 'C'

* I_NO_AUTH = ' '

* I_XSIMU = ' '

IMPORTING

E_MSGID = msg_id

E_MSGNO = msg_no

E_MSGTY = msg_typ

E_MSGV1 = msg_V1

E_MSGV2 = msg_V2

E_MSGV3 = msg_V3

E_MSGV4 = msg_V4

E_SUBRC = e_stat

TABLES

T_BLNTAB = LDT_BLNTAB

T_FTCLEAR = FTCLEAR

T_FTPOST = FTPOST

T_FTTAX = LDT_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

.

IF SY-SUBRC <> 0.

message e023(zfi_am).

* Implement suitable error handling here

ENDIF.

endif.

CALL FUNCTION 'POSTING_INTERFACE_END'

EXPORTING

I_BDCIMMED = 'X'

* I_BDCSTRTDT = NO_DATE

* I_BDCSTRTTM = NO_TIME

EXCEPTIONS

SESSION_NOT_PROCESSABLE = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

message e024(zfi_am).

ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form CALCULATE_TOTAL

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM CALCULATE_TOTAL .

clear acct_amount.

loop at i_oitems where mark = 'X'.

acct_amount = acct_amount + i_oitems-dmbtr.

endloop.

ENDFORM.

*&---------------------------------------------------------------------*

*& Form CLEAR_DATA

*&---------------------------------------------------------------------*

*& text

*&---------------------------------------------------------------------*

*& --> p1 text

*& <-- p2 text

*&---------------------------------------------------------------------*

FORM CLEAR_DATA .

clear: FTPOST[],

FTCLEAR[].

ENDFORM.

4. On saving a clearing document will be posted in system.

5. Details of the clearing document:

6. List of the clearing documents:

Thanks and Regards,

FollowLikeRSS Feed

Alert Moderator

AUGLV Purpose
AUSGZAHL Outgoing payment
EINGZAHL Incoming payment
GUTSCHRI Credit memo
UMBUCHNG Transfer posting with clearing
返回ABAP参考资料列表