Friday, 27 January 2012

OA Inventory Close API

Spec---------

PROCEDURE inventory_close_api ( Errbuf         OUT          VARCHAR2
                               ,Retcode         OUT          NUMBER
                              , p_company      IN VARCHAR2
                              , p_fiscal_year  IN NUMBER
                              , p_period_num   IN NUMBER)l


Body
---------------------

PROCEDURE inventory_close_api ( Errbuf         OUT          VARCHAR2
                               ,Retcode         OUT          NUMBER
                              , p_company      IN VARCHAR2
                              , p_fiscal_year  IN NUMBER
                              , p_period_num   IN NUMBER)
IS
       
       
  CURSOR ls_period_close( lc_company      VARCHAR2
                        , ln_fiscal_year  NUMBER
                        , ln_period_num   NUMBER) 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_year     = (ln_fiscal_year)
        AND    a.period_num      = ln_period_num
        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_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
        fnd_file.put_line(fnd_file.log,'1st paramaeter - '||p_company||' - 2nd Parameter - '||p_fiscal_year||' - 3rd Parameter - '||p_period_num);
        fnd_file.put_line(fnd_file.output,'WHSE'||'       '||'PERIOD NUM'||'      '||'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_num) 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 ,
                                               p_period_close_date      => Sysdate,
                                               p_schedule_close_date    => ln_period_close.SCHEDULE_CLOSE_DATE,
                                               p_closing_rowid          => p_closing_rowid,
                                               x_wip_failed             => x_wip_failed,
                                               x_close_failed           => x_close_failed,
                                               x_download_failed        => x_download_failed,
                                               x_req_id                 => x_req_id,
                                               x_return_status          => x_return_status);
       FND_FILE.PUT_LINE(fnd_file.output,ln_period_close.ORGANIZATION_CODE||'               '||ln_period_close.period_num||'       '||ln_period_close.period_year);
           IF lc_return_status <> 'S' THEN
              FND_FILE.PUT_LINE(FND_FILE.LOG,'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' );
                  FND_FILE.PUT_LINE(FND_FILE.LOG,'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
        FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory period still open for - '||ln_period_close.organization_code|| 'as there are pending transactions for the month.');
      ELSE
        FND_FILE.PUT_LINE(FND_FILE.LOG,'Inventory period closed for organization - '||ln_period_close.organization_code);
      End If;                                              
        End loop;
    Commit;
      EXCEPTION
       WHEN OTHERS THEN
        FND_FILE.PUT_LINE(FND_FILE.LOG,'Exception - Inventory Close API'||sqlerrm);
  End;


No comments:

Post a Comment