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

7 comments:

  1. ; 7th line from last. But nice post and a good warning to those like me who make this very assumption.

    ReplyDelete
  2. I thought I had deleted that one. Have updated the PeopleCode snippet to take that ; out. And it still validates and saves.

    ReplyDelete
  3. Yes, nice post indeed. I am one of those people who tend to use a PeopleCode file created by searching for ;

    The Find In features within application designer are improved upon within change impact analyzer, but unfortunately not everyone has access to this tool.

    ReplyDelete
    Replies
    1. That's great to know about Change Impact Analyzer. I've never had a chance to use it. Will maybe look at that.

      Delete
  4. A friend has been in touch and said that a SQL script is another option for doing a Find In PeopleCode. You can use the PCTEXT field on PSPCMTXT.

    ReplyDelete
  5. Have you looked at Decode Peoplecode
    http://sourceforge.net/projects/decodepcode/files/

    ReplyDelete
    Replies
    1. Yes, I have seen that in the past. But I have not looked at it recently.

      Delete