-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
--	Name 		: ckfolmem.sql
--	Description	: This script creates folder members for all PAC 
--			  elements in 212.
--
--	Author		: Sukhy Bassi, Oracle Corporation UK
--	Date		: 8th December 1998
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- Fixed US Bug 910075 Populate OWNERSHIP_FLAG WHERE APPXXX is for a SHARE  

DECLARE

BEGIN


        update ck_migration_objects set ci_created = 'N' where ci_stage = 'CKFOLMEM';

  	dbms_output.enable(1000000);

	dbms_output.put_line('* Creating Folder Members *');

        -- FOLDER_MEMBERS are created for all APPXXX elements in JR_ID_MAPS

	INSERT INTO i$SDD_FOLDER_MEMBERS (IRID,                   
                                          IVID,                   
	                                  PAC_REF,                
	                                  PARENT_IVID,            
	                                  TYPES,                    
	                                  DATE_CREATED,           
	                                  CREATED_BY,             
	                                  DATE_CHANGED,           
	                                  CHANGED_BY,             
	                                  NOTM,                   
	                                  FOLDER_REFERENCE,       
	                                  MEMBER_OBJECT,          
	                                  NAME_IN_CONTEXT,        
	                                  OWNERSHIP_FLAG,         
		                          VISIBILITY )
	 SELECT     		          irid,                                                                                  
 		                          ivid,                                                                                  
 	                                  GET_IRID(owning_app_id, 0),                                                                                 
 	                                  GET_IVID(owning_app_id, 0),                                                                                                                                                                    
	                                  type_id,
	                                  SYSDATE,
	                                  USER,
	                                  SYSDATE,
	                                  USER,
	                                  1,
	                                  GET_IRID(owning_app_id, 0),                                                                                  
	                                  GET_IRID(use_of_id, 0),
	                                  NULL,
	                                  owning_app,
	                                  'PUBLIC'
         FROM JR_ID_MAPS 
         WHERE POP_TAB = 'SDD_STRUCTURE_ELEMENTS'
         AND   ELEMENT_TYPE = 'APPXXX';	 
		 
		 update ck_migration_objects set ci_created = 'Y' where ci_stage = 'CKFOLMEM';
		 
		 COMMIT;
	
EXCEPTION 
  when others then 
     dbms_output.put_line (' ** Exception Raised ** ');
     raise;
END;
/
