CREATE NEW TREE

来源:互联网 发布:小郡主芊芊 知乎 编辑:程序博客网 时间:2024/05/06 10:05

Tree Classes Implementation

   1.

      Get a session object.

      Before you can get a tree, you have to get a session object. The session controls access to the tree, provides error tracing, enables you to set the runtime environment, and so on. Use the %Session system variable to return a reference to the current PeopleSoft session.

      &Session = %Session;

   2.

      Get a tree object.

      Use the GetTree method specifying a null value (" ") to return a closed tree object.

      &MyTree = &Session.GetTˋree();

   3.

      Create the Tree.

      The Create method creates a new tree with the name PERSONAL_DATA2. To ensure that you have a valid tree, use the All built-in function. Description is a required property (if you don’t specify something for Description you cannot save the tree.)

      &TreeReturn = &MyTree.Create("", "", "PERSONAL_DATA2", "1999-06-01", "PERSONAL_DATA"); &MyTree.description = "test tree";

   4.

      Add a level.

      To add a level, you have to instantiate a level collection. Although there aren’t any levels in the tree, you can still access this collection. Use the Add method with the level collection to add a new level. Remember, the level name must be 8 characters or less. Description is a required property (if you don’t specify something for Description you cannot save the tree.)

      &LvlColl = &MyTree.levels; &Level = &LvlColl.add("FIRST LVL"); &Level.description = "First Level";

   5.

      Add the root node.

      Because this is a new tree, you must first add the root node.

      &RootNode = &MyTree.insertroot("00001");

   6.

      Add a leaf.

      To add a new leaf, you must have a reference to the parent node object. Using the All built-in function ensures that there is a root node before you try to insert the leaf with the InsertChildLeaf method.

      If ALL(&RootNode) Then &NewLeaf = &RootNode.InsertChildLeaf("8000", "8999"); end-if;

   7.

      Save the tree.

      When you execute the Save method, the new tree is saved to the database.

      &RSLT = &MyTree.Save();

      Note. If you’re running the tree API from an Application Engine program, the data won’t actually be committed to the database until the Application Engine program performs a COMMIT.   8.

      Check for errors.

      You can check if there were any errors using the PSMessages property on the session object.

      If All (&RSLT) Then /* errors occurred = do error checking */ &ERRORCOL = &Session.PSMessages; For &I = 1 To &ERRORCOL.count /* do error processing */ End-For; Else /* no errors - saved correctly - do other processing */ End-If;

      If there are multiple errors, all errors are logged to the PSMessages collection, not just the first occurrence of an error.

Note. If you’ve called the Tree API from an Application Engine program, all errors are also logged in the application engine error log tables.

 

Create(SetID, UserKeyValue, TreeName, EffDt, StructureName)

Example

&MYTREE.Create("","","PERSONAL_NEW", "05-05-1997", "PERSONAL_DATA");

原创粉丝点击