Search This Blog

Tuesday, July 10, 2018

Oracle Apps R12 API to Retire Asset in Fixed Assets Module (Asset Retirement)

DECLARE
   Api_Error            Exception;
   /*Test Asset Info */
   L_Asset_Id           Number                            ;
   L_Book_Type_Code     Varchar2 (15)                     := 'xx_book_code';
   L_User_Id            Number                            := 2999;
   L_Cost_Retired       Number                            ;
   L_Proceeds_Of_Sale   Number                            := 0;
   L_Cost_Of_Removal    Number                            := 0;
   V_Request_Id         Number;
                           -- User_Id Must Properly Be Set To Run Calc Gain/Loss
   /* Define Local Record Types */
   L_Trans_Rec          Fa_Api_Types.Trans_Rec_Type;
   L_Dist_Trans_Rec     Fa_Api_Types.Trans_Rec_Type;
   L_Asset_Hdr_Rec      Fa_Api_Types.Asset_Hdr_Rec_Type;
   L_Asset_Retire_Rec   Fa_Api_Types.Asset_Retire_Rec_Type;
   L_Asset_Dist_Tbl     Fa_Api_Types.Asset_Dist_Tbl_Type;
   L_Subcomp_Tbl        Fa_Api_Types.Subcomp_Tbl_Type;
   L_Inv_Tbl            Fa_Api_Types.Inv_Tbl_Type;
   /* Misc Info */
   L_Api_Version        Number                             := 1;
   L_Init_Msg_List      Varchar2 (1)                       := Fnd_Api.G_False;
   L_Commit             Varchar2 (1)                       := Fnd_Api.G_True;
   L_Validation_Level   Number                             := Fnd_Api.G_Valid_Level_Full;
   L_Calling_Fn         Varchar2 (80)                      := 'Retirement Aset wrapper';
   L_Return_Status      Varchar2 (1)                       := Fnd_Api.G_False;
   L_Msg_Count          Number                             := 0;
   L_Msg_Data           Varchar2 (512);
   L_Count              Number;
   L_Request_Id         Number;
   I                    Number                             := 0;
   Temp_Str             Varchar2 (512);
   Mesg_Count           Number;
  
      cursor cur_fa_addition is
   
    select a.asset_number,a.asset_id, b.cost
      from fa_additions_b a, fa_books_v b
     where a.asset_id = b.asset_id
       and a.asset_number in( SELECT C FROM TESTA WHERE asset_number= 'Test1')
       and not exists
     (select 1 from fa_retirements fr where fr.asset_id = a.asset_id);
    
Begin
FOR I IN cur_fa_addition LOOP
l_asset_id := i.asset_id;
L_Cost_Retired := i.cost;
   Dbms_Output.Disable;
   Dbms_Output.Enable (1000000);
   Dbms_Output.Put_Line ('begin');
   Fa_Srvr_Msg.Init_Server_Message;
   Fa_Debug_Pkg.Set_Debug_Flag (Debug_Flag => 'YES');
   -- Get Standard Who Info
   L_Request_Id := Fnd_Global.Conc_Request_Id;
   Fnd_Profile.Get ('LOGIN_ID', L_Trans_Rec.Who_Info.Last_Update_Login);
   Fnd_Profile.Get ('USER_ID', L_Trans_Rec.Who_Info.Last_Updated_By);

   If (L_Trans_Rec.Who_Info.Last_Updated_By Is Null)
   Then
      L_Trans_Rec.Who_Info.Last_Updated_By := -1;
   End If;

   If (L_Trans_Rec.Who_Info.Last_Update_Login Is Null)
   Then
      L_Trans_Rec.Who_Info.Last_Update_Login := -1;
   End If;

   L_Trans_Rec.Who_Info.Last_Update_Date := Sysdate;
   L_Trans_Rec.Who_Info.Creation_Date := L_Trans_Rec.Who_Info.Last_Update_Date;
   L_Trans_Rec.Who_Info.Created_By := L_Trans_Rec.Who_Info.Last_Updated_By;
   L_Trans_Rec.Transaction_Type_Code := Null;
   -- This Will Be Determined Inside Api
   L_Trans_Rec.Transaction_Date_Entered := Null;
   L_Asset_Hdr_Rec.Asset_Id := L_Asset_Id;
   L_Asset_Hdr_Rec.Book_Type_Code := L_Book_Type_Code;
   L_Asset_Hdr_Rec.Period_Of_Addition := Null;
   L_Asset_Retire_Rec.Retirement_Prorate_Convention := Null;
   L_Asset_Retire_Rec.Date_Retired := Null;
   -- Will Be Current Period By Default
   L_Asset_Retire_Rec.Units_Retired := Null;
   L_Asset_Retire_Rec.Cost_Retired := L_Cost_Retired;
   L_Asset_Retire_Rec.Proceeds_Of_Sale := L_Proceeds_Of_Sale;
   L_Asset_Retire_Rec.Cost_Of_Removal := L_Cost_Of_Removal;
   L_Asset_Retire_Rec.Retirement_Type_Code := 'SALE';
   L_Asset_Retire_Rec.Trade_In_Asset_Id := Null;
   L_Asset_Retire_Rec.Calculate_Gain_Loss := Fnd_Api.G_False;
   Fnd_Profile.Put ('USER_ID', L_User_Id);
   L_Asset_Dist_Tbl.Delete;
   Fa_Retirement_Pub.Do_Retirement (P_Api_Version            => L_Api_Version,
                                    P_Init_Msg_List          => L_Init_Msg_List,
                                    P_Commit                 => L_Commit,
                                    P_Validation_Level       => L_Validation_Level,
                                    P_Calling_Fn             => L_Calling_Fn,
                                    X_Return_Status          => L_Return_Status,
                                    X_Msg_Count              => L_Msg_Count,
                                    X_Msg_Data               => L_Msg_Data,
                                    Px_Trans_Rec             => L_Trans_Rec,
                                    Px_Dist_Trans_Rec        => L_Dist_Trans_Rec,
                                    Px_Asset_Hdr_Rec         => L_Asset_Hdr_Rec,
                                    Px_Asset_Retire_Rec      => L_Asset_Retire_Rec,
                                    P_Asset_Dist_Tbl         => L_Asset_Dist_Tbl,
                                    P_Subcomp_Tbl            => L_Subcomp_Tbl,
                                    P_Inv_Tbl                => L_Inv_Tbl
                                   );

   If L_Return_Status = Fnd_Api.G_False
   Then
      Raise Api_Error;
   End If;

   Dbms_Output.Put_Line (   'Asset Retirement Done: Retirement_id: '
                         || L_Asset_Retire_Rec.Retirement_Id
                        );

   --Commit;

   -- Dump Debug Messages When Run In Debug Mode To Log File
   If (Fa_Debug_Pkg.Print_Debug)
   Then
      Fa_Debug_Pkg.Write_Debug_Log;
   End If;

   Fa_Srvr_Msg.Add_Message (Calling_Fn      => L_Calling_Fn,
                            Name            => 'FA_SHARED_END_SUCCESS',
                            Token1          => 'PROGRAM',
                            Value1          => 'RETIREMENT_API'
                           );
   Mesg_Count := Fnd_Msg_Pub.Count_Msg;

   If (Mesg_Count > 0)
   Then
      Temp_Str := Fnd_Msg_Pub.Get (Fnd_Msg_Pub.G_First, Fnd_Api.G_False);
      Dbms_Output.Put_Line ('dump: ' || Temp_Str);

      For I In 1 .. (Mesg_Count - 1)
      Loop
         Temp_Str := Fnd_Msg_Pub.Get (Fnd_Msg_Pub.G_Next, Fnd_Api.G_False);
         Dbms_Output.Put_Line ('dump: ' || Temp_Str);
      End Loop;
   Else
      Dbms_Output.Put_Line ('dump: NO MESSAGE !');
   End If;
 END LOOP; 
Exception
   When Api_Error
   Then
      Rollback Work;
      Fa_Srvr_Msg.Add_Message (Calling_Fn      => L_Calling_Fn,
                               Name            => 'FA_SHARED_PROGRAM_FAILED',
                               Token1          => 'PROGRAM',
                               Value1          => L_Calling_Fn
                              );
      Mesg_Count := Fnd_Msg_Pub.Count_Msg;

      If (Mesg_Count > 0)
      Then
         Temp_Str := Fnd_Msg_Pub.Get (Fnd_Msg_Pub.G_First, Fnd_Api.G_False);
         Dbms_Output.Put_Line ('dump: ' || Temp_Str);

         For I In 1 .. (Mesg_Count - 1)
         Loop
            Temp_Str := Fnd_Msg_Pub.Get (Fnd_Msg_Pub.G_Next, Fnd_Api.G_False);
            Dbms_Output.Put_Line ('dump: ' || Temp_Str);
         End Loop;
      Else
         Dbms_Output.Put_Line ('dump: NO MESSAGE !');
      End If;
  COMMIT;

      Begin
         Fnd_Global.Apps_Initialize (User_Id           => 2999,
                                     Resp_Id           => 55555,
                                     Resp_Appl_Id      => 140
                                    );
         V_Request_Id :=
            Fnd_Request.Submit_Request ('OFA',
                                        'FARET',
                                        Null,
                                        Null,
                                        False,
                                        L_Book_Type_Code
                                       );
         Commit;
         Dbms_Output.Put_Line (V_Request_Id);
      End;

End;
/

--run the Fixed_Assets Manager Resp>Depreciation>Run Depreciation and select the month and Run.

1 comment:

  1. I just want to say I’m new to weblog and certainly savored this page. You actually have outstanding well written articles. Cheers for sharing with us your website.
    Asset Management Software India
    Asset Management Software Chennai
    Asset Management Software
    Asset Management Software Mumbai

    ReplyDelete