Tuesday, 17 February 2015

Inventory Period Close for All Organization through API

/*create or replace PROCEDURE inventory_close_api (
  
   p_company       IN       VARCHAR2,
 
   p_period_date    IN       date
)
AS*/

DEClare
  p_company         VARCHAR2(100) := 'JGC_July_June';
  p_period_date     date     := TO_DATE('06/01/2014','MM/DD/014');
  
   CURSOR ls_period_close (
      lc_company       VARCHAR2,
    
      ln_period_date    Date
   )
   IS
      SELECT b.organization_code, b.organization_name, a.*
        FROM org_acct_periods a, org_organization_definitions b
       WHERE a.period_set_name = lc_company
        
         AND a.period_start_date =  ln_period_date
         AND a.open_flag = 'Y'
         AND a.organization_id = b.organization_id;

   lc_return_status    VARCHAR2 (1);
   lc_msg_data         VARCHAR2 (2000);
   lc_errbuf           VARCHAR2 (2000);
   ln_msg_count        NUMBER;
   p_closing_rowid     VARCHAR2 (100);
   x_wip_failed        BOOLEAN;
   x_close_failed      BOOLEAN;
   x_download_failed   BOOLEAN;
   x_rec_rpt_launch_failed BOOLEAN;
   x_req_id            NUMBER;
   x_return_status     VARCHAR2 (100);
   ln_user_id          NUMBER;
   ln_org_id           NUMBER;
   ln_resp_id          NUMBER;
   ln_resp_app_id      NUMBER;
BEGIN
   dbms_output.put_line ('1st paramaeter - '
                      || p_company
                      || ' - 3rd Parameter - '
                      || p_period_date
                     );
   dbms_output.put_line ('WHSE'|| '       '|| 'PERIOD YR');
  
   ln_user_id := 1738;                  --:=APPS.FND_PROFILE.VALUE('USER_ID');
   ln_resp_id := apps.fnd_profile.VALUE ('RESP_ID');
   ln_resp_app_id := apps.fnd_profile.VALUE ('RESP_APPL_ID');
   ln_org_id := apps.fnd_profile.VALUE ('ORG_ID');

   BEGIN
      fnd_client_info.set_org_context (ln_org_id);
   END;

   BEGIN
      fnd_global.apps_initialize (1738, ln_resp_id, ln_resp_app_id);
   END;

   FOR ln_period_close IN ls_period_close (p_company,
                                           --p_fiscal_year,
                                           p_period_date
                                          )
   LOOP
      EXIT WHEN ls_period_close%NOTFOUND;
       cst_accountingperiod_pub.close_period
               (
               p_api_version                 => 1.0,
                p_org_id                      => ln_period_close.organization_id,
                p_user_id                     => ln_period_close.created_by,
                p_login_id                    => ln_period_close.last_update_login,
                p_closing_acct_period_id      => ln_period_close.acct_period_id,
                x_wip_failed                  => x_wip_failed,
                x_close_failed                => x_close_failed,
                x_req_id                      => x_req_id,
                x_unprocessed_txns            => x_download_failed,
                x_rec_rpt_launch_failed       =>   x_rec_rpt_launch_failed,             
                x_return_status               => x_return_status
               );
      dbms_output.put_line (ln_period_close.organization_code
                         || '               '
                         || ln_period_close.period_start_date
                        );

      IF lc_return_status <> 'S'
      THEN
         dbms_output.put_line ('STATUS : ' || lc_return_status);
         COMMIT;

         IF ln_msg_count <= 1
         THEN
            lc_errbuf := lc_errbuf || lc_msg_data;
         ELSE
            FOR ln_i IN 1 .. ln_msg_count
            LOOP
               lc_errbuf := lc_errbuf || ' ' || fnd_msg_pub.get (ln_i, 'F');
               dbms_output.put_line ( 'STATUS : ' || lc_errbuf);
            END LOOP;
         END IF;
      END IF;

      IF     ln_period_close.period_close_date IS NOT NULL
         AND ln_period_close.open_flag = 'Y'
      THEN
         dbms_output.put_line
                          ('Inventory period still open for - '
                           || ln_period_close.organization_code
                           || 'as there are pending transactions for the month.'
                          );
      ELSE
         dbms_output.put_line ('Inventory period closed for organization - '
                            || ln_period_close.organization_code
                           );
      END IF;
   END LOOP;

   COMMIT;
EXCEPTION
   WHEN OTHERS
   THEN
      dbms_output.put_line ('Exception - Inventory Close API' || SQLERRM
                        );
END;

No comments:

Post a Comment

Query to Find Receipt Class and its GL Combinition Query

SELECT ARC.NAME ReceiptClass,        ARC.CREATION_METHOD_CODE Creation_Mehthod,        DECODE (ARC.REMIT_METHOD_CODE,             ...