BAPI for Retrieve the last day of a fiscal year

Hello Friends if you are looking for Retrieve the last day of a fiscal year then here you will get the details.

BAPI_CCODE_GET_LASTDAY_FYEAR is a standard SAP BAPI (Business Application Programming Interface) function module used to retrieve the last day of a fiscal year for a given company code in SAP .

Key Details:

  1. Purpose:
    • Returns the last day of the fiscal year for a specified company code (COMP_CODE) and fiscal year (FISC_YEAR).
    • Helps in financial reporting, period closing, and date-based calculations in SAP.
  2. Input Parameters:
    • COMP_CODE (Company Code, e.g., 1000 for a specific entity).
    • FISC_YEAR (Fiscal Year, e.g., 2024).
  3. Output Parameters:
    • LASTDAY_FYEAR (Last day of the fiscal year, e.g., 31.12.2024 for a calendar-based fiscal year).
    • RETURN (Status messages, including errors if any).
  4. Common Use Cases:
    • Automating fiscal year-end processes.
    • Validating financial period closures.
    • Integration with custom reports or external systems.

ABAP Code for –

REPORT z_get_lastday_fyear.

* Data declarations
DATA: lv_company_code TYPE bapi0002_4-comp_code VALUE '1000',  " Example: Company Code
      lv_fiscal_year  TYPE bapi0002_4-fisc_year  VALUE '2024',  " Fiscal Year
      lv_last_day     TYPE bapi0002_4-lastday_fyear,            " Output: Last day of FY
      lt_return       TYPE TABLE OF bapiret2,                   " Return messages
      ls_return       TYPE bapiret2.

* Call BAPI to get the last day of the fiscal year
CALL FUNCTION 'BAPI_CCODE_GET_LASTDAY_FYEAR'
  EXPORTING
    comp_code    = lv_company_code
    fisc_year    = lv_fiscal_year
  IMPORTING
    lastday_fyear = lv_last_day
  TABLES
    return       = lt_return.

* Check for errors
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc = 0.
  WRITE: / 'Error:', ls_return-message.
ELSE.
  WRITE: / 'Company Code:', lv_company_code,
         / 'Fiscal Year:', lv_fiscal_year,
         / 'Last Day of Fiscal Year:', lv_last_day.
ENDIF.

* Optional: Commit if needed (not required for this read-only BAPI)
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

Explanation

  1. Input Parameters:
    • comp_code: Company code (e.g., 1000 for a SAP demo client).
    • fisc_year: Fiscal year (e.g., 2024).
  2. Output:
    • lastday_fyear: Returns the last day of the fiscal year (e.g., 31.12.2024 for a calendar-based fiscal year).
  3. Error Handling:
    • The RETURN table captures messages (e.g., invalid company code/year).
    • Check for TYPE = 'E' (errors) or TYPE = 'S' (success).
  4. Notes:
    • Fiscal Year Variant: The actual last day depends on the company code’s configuration (e.g., OB29 in SAP).
    • Read-Only: No COMMIT is needed (unlike transactional BAPIs).

Leave a Comment