Friday, December 11, 2009

PSMessages to capture the messages while using CI


While working with CI, it's a critical part to understand the errors that happen during execution. Several ways are there to capture this error/warning messages. PSMessages is one way to accomplish this requirement.

What we need to do is to loop through the PSMessages object to capture and display all the messages (errors/warnings), which will be easier for the developer to debug the system.

See the image above for a simple example for the same


Use the PSMessages collection to return all of the messages that occur during the session. The following example finds all the messages listed in the PSMessages collections when the Component Interface Save methods fails. The example assumes that &CI is the Component Interface object reference.

If Not &CI.Save() Then

/* save didn’t complete */

&COLL = &MYSESSION.PSMessages;

     For &I = 1 to &COLL.Count

&ERROR = &COLL.Item(&I);

&TEXT = &ERROR.Text;


 

/* do message processing */


 

End-For;

&COLL.DeleteAll(); /* Delete all messages in queue */

End-if;

As you evaluate each message, delete it from the PSMessages collection. Or, delete all the messages in the queue at once using DeleteAll.

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

Considerations for Declaring Collections

You must declare all collections for C/C++ and COM as objects, or else you receive errors at runtime.

0 comments:

Post a Comment

Total Pageviews

Copyright © Tech & Management Notes