12/08/2015

Save PeopleCode to File

I've worked with a few people who perform a search for a semi-colon character ( ; ) in PeopleCode in the Find In dialog box and use the Save PeopleCode to File option. They do this so all PeopleCode can be saved to a file. And then whenever they want to perform a search they will search the file instead of using the Find In dialog box again. Using a text editor to search the file is usually MUCH quicker than using the Find In dialog box.

I think people use semi-colon for their search because they think every piece of PeopleCode must have one. This in fact is wrong. Here is a 30 line piece of Record FieldChange PeopleCode that will save and compile using PeopleTools 8.54.13. (Granted - it is non-sensical. But I'm just proving the point that not all PeopleCode must have a semi-colon.)

This PeopleCode program makes use of a wide variety of built-in functions and language constructs, such as:
  • If, Else, End-If
  • Evaluate, When, When-Other, End-Evaluate
  • Upper, Lower, String
  • Abs, Max, AccruableDays
  • %Date
  • For, End-For, Exit
  • Try, Throw, Catch, End-Try
  • CreateJavaObject, CreateException
  • Error, MsgGet
  • RECORD.FIELD notation
The moral of this story is: keep in mind that not all PeopleCode has a to have a semi-colon. And if you use the Find In PeopleCode, semi-colon ( ; ), Save PeopleCode to File option, realise that you may not have all your PeopleCode saved to your file. Even though it can be slow, I use the Find In dialog box. I just time other things around it, like writing a blog post.

/* Comment of course */
Evaluate PSOPRDEFN.OPRID
When = "VP1"
   If PSOPRDEFN.OPRID = Upper("cc") And
         "y" <> "z" Then
      If ("a" = "B") Then
         While 1 = 1
            PSOPRDEFN.OPRID = Lower("AA")
         End-While
      End-If
   End-If
   <* Comments too *>
When = "PS"
   If Abs(1.0) = Max(AccruableDays(%Date, %Date, 0)) Then
      Return
   End-If
When-Other
   For &intCounter = 1 To PSOPRDEFN.FAILEDLOGINS
      try
         If &intCounter = Round(100.12912, 0) Or
               String(&intCounter) = CreateJavaObject("String", "Hello").concat(" World") Then
            Exit
         Else
            throw CreateException(2, 160, "'%1' doesn't support property or method '%2'", "SomeClass", "SomeMethod")
         End-If
      catch Exception &exc
         Error MsgGet(0, 0, "hello world!")
      end-try
   End-For
End-Evaluate