EDUCAÇÃO E TECNOLOGIA

Implementing Clearing Interface using POSTING_INTERFACE_CLEARING in s4 Hana 1709.

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.

  1. 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,