Error Handling With Query Classes

All errors for the query classes, like the other APIs, are logged in the PSMessages collection, instantiated from a session object. In addition, some methods return error codes. See the individual method description to see if it returns anything.

The query classes log errors "interactively", that is, as they happen. For example, suppose you specified an invalid query name. The error would be logged in the PSMessages collection as soon as you executed the GetQuery method.

When to check for errors is application-specific. However, if you check for errors after every assignment, you may see a performance degradation.

PeopleSoft recommends that you check for invalid prompts after using any of the following methods or properties:

  • Save, RunToRowset, or RunToFile Query class methods.

  • SQL, RuntimePrompts, or Prompts Query class properties.

  • Any of the methods or properties in the QueryPrompts collection.

The easiest way to check for errors is to check the number of messages in the PSMessages collection, using the Count property. If the Count is 0, there are no errors.

Local ApiObject &MySession; 
Local ApiObject &ERRORCOL; 
Local ApiObject &Query, &QueryList; 
&MySession = %Session; 
If &MySession Then 
   /* connection is good */ 
   &QueryList = &MySession.SearchPublicQueries(%Query_ListQuery, %Query_FindName, "%", True); 
   For &I = 1 to &QueryList.Count 
      &Query = &QueryList.Item(&I); 
      /* Do processing */ 
      /* Do error checking */ 
      &ERRORCOL = &MySession.PSMessages; 
      If (&ERRORCOL.Count <> 0) Then 
         /* errors occurred - do processing */ 
         /* no errors */ 
   /* do processing for no connection */