/******************************************************************************
*
* Filename         -  $Workfile: mws_rename_uld.sql  $
*
*                     Name         Date       Version     CR Number
* Author              Chris Penny  22/12/2003		
*
* Project Name     -  Ultratrak Database
*
* Source Code
* Identifier       -  FAS/FALCP
*
* Description      -  Live Schema Stored Procedure
*
* Language         -  Oracle PL/SQL
*
* File History     -  For development history run Show History report in PVCS
*
* Copyright Ultra Electronics Airport Systems Limited, 2003
*
*******************************************************************************/

PROMPT CREATE OR REPLACE PROCEDURE mws_rename_uld 

CREATE OR REPLACE PROCEDURE mws_rename_uld (
    p_flight_id     IN  ulds.flight_id%TYPE
  , p_from_uld_no   IN  ulds.uld_no%TYPE
  , p_to_uld_no     IN  ulds.uld_no%TYPE
  , p_uld_id_code   IN  ulds.uld_id_code%TYPE
  , p_user_id       IN  tagtrak_users.user_id%TYPE
  , p_location      IN  location.location_code%TYPE
  , p_retcode       OUT INTEGER
) 
AS 

   error_invalid_uld EXCEPTION;

BEGIN

   /* First we need to validate the new ULD NO entered by the MWS user */
   IF NOT uld_cards.validate_uldno (p_to_uld_no) THEN
      RAISE error_invalid_uld; -- validation fails for new ULD
   END IF;

   rename_uld (
                  NULL -- scanner_id
                , p_flight_id
                , p_from_uld_no
                , p_to_uld_no
                , p_uld_id_code
                , p_user_id
                , p_location
                , p_retcode
              );

EXCEPTION

   WHEN error_invalid_uld THEN
      p_retcode := pkg_constants.error_uld_invalid;

   WHEN OTHERS THEN
      p_retcode := pkg_constants.error_failed_to_rename_uld;

END mws_rename_uld;
/
sho err
