Function Module Name for Retrieving Closing Balance
FUNCTION zgl_bal.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(COMP) TYPE BKPF-BUKRS
*" REFERENCE(DATE) TYPE BKPF-BUDAT
*" REFERENCE(ACCT) TYPE BSEG-HKONT
*" EXPORTING
*" REFERENCE(BALANCE) TYPE BSEG-DMBTR
*"----------------------------------------------------------------------
DATA : companycodeid LIKE bapi0002_2-comp_code,
posting_date LIKE bapi0002_4-posting_date,
fiscal_year LIKE bapi0002_4-fiscal_year,
fiscal_period LIKE bapi0002_4-fiscal_period.
DATA : account_balances TYPE TABLE OF bapi3006_4 WITH HEADER LINE.
DATA : bal TYPE bseg-dmbtr.
DATA : iv_date TYPE d,
ev_month_begin_date TYPE d,
ev_month_end_date TYPE d.
DATA : companycode LIKE bapi3006_0-comp_code,
glacct LIKE bapi3006_0-gl_account,
fiscalyear LIKE bapi3006_4-fisc_year,
currencytype LIKE bapi3006_5-curr_type VALUE 10.
DATA : it_bkpf TYPE TABLE OF bkpf WITH HEADER LINE.
DATA : BEGIN OF it_bseg OCCURS 0,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
shkzg TYPE bseg-shkzg,
dmbtr TYPE bseg-dmbtr,
END OF it_bseg.
companycodeid = comp.
posting_date = date.
iv_date = date.
CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
EXPORTING
iv_date = iv_date
IMPORTING
ev_month_begin_date = ev_month_begin_date
ev_month_end_date = ev_month_end_date.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
companycodeid = companycodeid
posting_date = posting_date
IMPORTING
fiscal_year = fiscal_year
fiscal_period = fiscal_period.
IF ev_month_end_date NE date.
IF fiscal_period = 1.
fiscal_period = 12 .
fiscal_year = fiscal_year - 1 .
ELSE.
fiscal_period = fiscal_period - 1.
ENDIF.
ENDIF.
companycode = comp.
glacct = acct.
fiscalyear = fiscal_year.
CALL FUNCTION 'BAPI_GL_ACC_GETPERIODBALANCES'
EXPORTING
companycode = companycode
glacct = glacct
fiscalyear = fiscalyear
currencytype = currencytype
TABLES
account_balances = account_balances.
READ TABLE account_balances WITH KEY fisc_year = fiscalyear fis_period = fiscal_period.
IF sy-subrc = 0.
balance = account_balances-balance.
ENDIF.
IF ev_month_end_date NE date.
SELECT * FROM bkpf INTO TABLE it_bkpf WHERE bukrs = comp AND budat >= ev_month_begin_date
AND budat <= date.
IF it_bkpf[] IS NOT INITIAL.
SELECT belnr gjahr shkzg dmbtr
FROM bseg INTO CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE belnr = it_bkpf-belnr AND gjahr = it_bkpf-gjahr AND hkont = acct AND bukrs = comp.
ENDIF.
LOOP AT it_bseg.
IF it_bseg-shkzg = 'H'.
bal = bal - it_bseg-dmbtr.
ELSEIF it_bseg-shkzg = 'S'.
bal = bal + it_bseg-dmbtr.
ENDIF.
ENDLOOP.
balance = balance + bal.
ENDIF.
ENDFUNCTION.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(COMP) TYPE BKPF-BUKRS
*" REFERENCE(DATE) TYPE BKPF-BUDAT
*" REFERENCE(ACCT) TYPE BSEG-HKONT
*" EXPORTING
*" REFERENCE(BALANCE) TYPE BSEG-DMBTR
*"----------------------------------------------------------------------
DATA : companycodeid LIKE bapi0002_2-comp_code,
posting_date LIKE bapi0002_4-posting_date,
fiscal_year LIKE bapi0002_4-fiscal_year,
fiscal_period LIKE bapi0002_4-fiscal_period.
DATA : account_balances TYPE TABLE OF bapi3006_4 WITH HEADER LINE.
DATA : bal TYPE bseg-dmbtr.
DATA : iv_date TYPE d,
ev_month_begin_date TYPE d,
ev_month_end_date TYPE d.
DATA : companycode LIKE bapi3006_0-comp_code,
glacct LIKE bapi3006_0-gl_account,
fiscalyear LIKE bapi3006_4-fisc_year,
currencytype LIKE bapi3006_5-curr_type VALUE 10.
DATA : it_bkpf TYPE TABLE OF bkpf WITH HEADER LINE.
DATA : BEGIN OF it_bseg OCCURS 0,
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
shkzg TYPE bseg-shkzg,
dmbtr TYPE bseg-dmbtr,
END OF it_bseg.
companycodeid = comp.
posting_date = date.
iv_date = date.
CALL FUNCTION 'HR_JP_MONTH_BEGIN_END_DATE'
EXPORTING
iv_date = iv_date
IMPORTING
ev_month_begin_date = ev_month_begin_date
ev_month_end_date = ev_month_end_date.
CALL FUNCTION 'BAPI_COMPANYCODE_GET_PERIOD'
EXPORTING
companycodeid = companycodeid
posting_date = posting_date
IMPORTING
fiscal_year = fiscal_year
fiscal_period = fiscal_period.
IF ev_month_end_date NE date.
IF fiscal_period = 1.
fiscal_period = 12 .
fiscal_year = fiscal_year - 1 .
ELSE.
fiscal_period = fiscal_period - 1.
ENDIF.
ENDIF.
companycode = comp.
glacct = acct.
fiscalyear = fiscal_year.
CALL FUNCTION 'BAPI_GL_ACC_GETPERIODBALANCES'
EXPORTING
companycode = companycode
glacct = glacct
fiscalyear = fiscalyear
currencytype = currencytype
TABLES
account_balances = account_balances.
READ TABLE account_balances WITH KEY fisc_year = fiscalyear fis_period = fiscal_period.
IF sy-subrc = 0.
balance = account_balances-balance.
ENDIF.
IF ev_month_end_date NE date.
SELECT * FROM bkpf INTO TABLE it_bkpf WHERE bukrs = comp AND budat >= ev_month_begin_date
AND budat <= date.
IF it_bkpf[] IS NOT INITIAL.
SELECT belnr gjahr shkzg dmbtr
FROM bseg INTO CORRESPONDING FIELDS OF TABLE it_bseg
FOR ALL ENTRIES IN it_bkpf
WHERE belnr = it_bkpf-belnr AND gjahr = it_bkpf-gjahr AND hkont = acct AND bukrs = comp.
ENDIF.
LOOP AT it_bseg.
IF it_bseg-shkzg = 'H'.
bal = bal - it_bseg-dmbtr.
ELSEIF it_bseg-shkzg = 'S'.
bal = bal + it_bseg-dmbtr.
ENDIF.
ENDLOOP.
balance = balance + bal.
ENDIF.
ENDFUNCTION.
Comments
Post a Comment