Total Pageviews

Thursday, 8 June 2023

EBS : PLSQL : How to generate ID based on input date : Oracle Apps

How to generate ID based on input date in PLSQL  

CREATE OR REPLACE FUNCTION generate_estqs_id (p_quote_date IN DATE)

   RETURN NUMBER

IS

   lv_month            NUMBER;

   lv_year             NUMBER;

   lv_year_next        NUMBER;

   lv_max_no           NUMBER;

   lv_from_date        DATE;

   lv_to_date          DATE;

   lv_quote_date       DATE;

   lv_estimtation_id   NUMBER;

BEGIN

   lv_quote_date := p_quote_date;


   SELECT TO_CHAR (lv_quote_date, 'MM')

     INTO lv_month

     FROM DUAL;


   DBMS_OUTPUT.put_line ('lv_month' || '-' || lv_month);


   IF lv_month IN ('01', '02', '03')

   THEN

      SELECT TO_CHAR (lv_quote_date, 'YY') - 1

        INTO lv_year

        FROM DUAL;

   ELSE

      SELECT TO_CHAR (lv_quote_date, 'YY')

        INTO lv_year

        FROM DUAL;

   END IF;


   lv_year_next := lv_year + 1;

   DBMS_OUTPUT.put_line (lv_year || '-' || lv_year_next);


   SELECT TO_CHAR ('01-Apr-' || lv_year), TO_CHAR ('31-Mar-' || lv_year_next)

     INTO lv_from_date, lv_to_date

     FROM DUAL;


   DBMS_OUTPUT.put_line (lv_from_date || '-' || lv_to_date);


   SELECT   NVL (SUBSTR (NVL (MAX (estimation_id), 0),

                         5,

                         LENGTH (MAX (estimation_id))

                        ),

                 0

                )

          + 1

     INTO lv_max_no

     FROM xx_estqs_hdr

    WHERE TRUNC (creation_date) BETWEEN lv_from_date AND lv_to_date;


   DBMS_OUTPUT.put_line ('lv_max_no' || '-' || lv_max_no);

   --lv_ESTIMTATION_id := lv_year || lv_year_next || '0000000' || lv_max_no;

   lv_estimtation_id := lv_year || lv_year_next || LPAD (lv_max_no, 8, 0);

   RETURN lv_estimtation_id;

EXCEPTION

   WHEN OTHERS

   THEN

      RETURN 'Unable to Generate ESTIMTATION Id';

END;

No comments:

Post a Comment

FUSION: Purchasing Query

  1) ---------CPA to PO Amount---------- select poh.segment1, (select sum(nvl(cpol.quantity,1)* cpol.unit_price) from po_headers_all cpoh,po...