DECLARE
   wkarea_irid number;
   wkarea_name varchar2(256);
   cfg_irid    number;
   cfg_ivid    number;  
BEGIN  
  update ck_migration_objects set ci_created = 'N' where ci_stage = 'CKWKAREA';

  wkarea_name := '%s';

  dbms_output.enable(1000000);
  dbms_output.put_line('* Creating Workareas/Configurations' );

  -- If Versioned repos ensure workarea does not exist, may have been previously
  -- created if we aborted
  if jr_sys_privs.is_versioned_repos() then
  
    begin  
      select irid
      into wkarea_irid
      from i$sdd_workareas
      where name = wkarea_name;  
    exception when no_data_found then 
      wkarea_irid := NULL;
    end;
         
    -- Wokrarea already exists do not create it again
    if (wkarea_irid is null) then
    
  -- B982279 - VDESAI - 07/09/99
  -- We need to create a workarea for the complete migration process
  -- at runtime percent s is binded to the WORK AREA NAME for the Migration Process  

  dbms_output.put_line('* Creating Workarea ' || wkarea_name );
  wkarea_irid := NULL;
  wkarea_irid := jr_workarea.create_workarea( user, 
                                              wkarea_name, 
                                              'Created during Migration from Designer/2000 on '||to_char(SYSDATE, 'DD-MON-YYYY, HH24:MM'),
                                              'PRIVATE');

  -- Once the WorkArea created set context to it otherwise an error has occured

  jr_context.set_workarea(wkarea_irid);

 
  -- B935000 - VDESAI - 15/07/99
  -- Create rule to include SYSTEM_FOLDER in workarea
  jr_workarea.define_spec(wkarea_irid, 'INCLUDE_FOLDER(SYSTEM FOLDER{MAIN;LATEST})' ); 


     else
        dbms_output.put_line('* Skipping stage, Workarea ' || wkarea_name || 'already exists' );

     end if;
  end if;

  update ck_migration_objects set ci_created = 'Y' where ci_stage = 'CKWKAREA';

  COMMIT;

  dbms_output.put_line('* Workareas/Configurations Created' );

EXCEPTION 
  when others then 
     dbms_output.put_line (' ** Exception Raised ** ');
     raise;
END;
/


  
