Sie sind auf Seite 1von 28

PeopleCode Basics Writing code is not difficult.

As long as you can read a manual, follow instructions on how to construct a sentence, using the syntax specified, you will be able to write programs. In some case, you do not even have to do this. Wizards and other helpers pop up to generate code automatically. All the user has to do is to answer questions and draw pretty screen designs. This is popular for generating simple applications or sub-routines. It is available in most development environments today. Any major project can be broken down into a set of smaller parts, some of which can be automated. The art of developing great programs is in breaking down a big program into smaller parts and ensuring that each part functions perfectly. At no time however, are the two separate. This is what we will try to show you in the this and the next few chapters. Our goal is to get you to write a one of the largest applications that are there in PeopleSoft. This application. The Virtual Approver, can be broken down into sub-components so that it is easier to understand. In the last chapter, you created your own set of panels that performed some of the same tasks that PeopleSoft's did. You did not see the code behind the panel. This chapter will introduce PeopleCode, practically line by line so that you understand clearly what happens to the code you key in. It looks at the different elements that you need to build the Virtual Approver. If you used other visual development environments, then you most probably have already mastered the art of design. (A topic that we will not do anyway.) We do not concentrate on the code in this chapter either. This chapter is to get you comfortable with the programming environment that PeopleSoft provides. If you already program in some other language, then you may not be too happy with everything PeopleSoft does. C programmers among others will be the ones who get most upset as PeopleSoft puts all programmers on one same level. There is no way except through comments to figure out who wrote a piece of code. Try as hard as you might to format the code and PeopleSoft reformats it to a standard setting in the end. This is just one of the few things about PeopleSoft that you will hate or love. There are others. Programmers at PeopleSoft tried as far as possible not to reinvent the wheel. If there was something else that could do it better, then that something else was used. For example, COBOL is a language of choice when it comes to defining the business rules to be followed. The language has been refined so much that there is little value that PeopleSoft could add to it. Further, rewriting COBOL commands in PeopleCode would simply be a waste of time. So PeopleSoft left it alone. PeopleSoft only looks at managing tables and data through panels. There is nothing more than the panel to get any work done in PeopleSoft. Every command that you require is available. If one needs additional functionality that PeopleSoft missed out, then the facility to call in routines written in other languages like C is always there. This chapter, as with most chapters in this book, takes a different approach. The focus is still the same to teach you how to write great applications using PeopleSoft. And to do this, you will never be swamped with a long program that has lines of code to understand in one go. Rather you will always have small examples that you can try out, test and then put together to get the final result. Another peculiar aspect of this chapter is that none of the examples really do anything sensible. You will find that the names used for objects fields, records, panels, never make any sense. At least, they do not appear to. Remember our purpose here is to teach you to program and not to write 'pretty' code. Tying in long field names, record names, etc., may make sense when writing a full-blown application. But while learning and when you desperately want to see results, writing in long names only wastes time. We could keep discussing the merits and demerits of this as they say "till the cows come home". (If we were in North India, in a state called Bihar, we'd stop just now, for the cows are home and in the Chief Minister's house too.) However, it would serve little purpose. So let's get on to our work. We believe that your confidence will grow and your concepts will be clearer if you take this program byte-by-byte (well, not really that slow.) Before starting on this chapter, you need to be familiar with the Application Designer. This is the tool that does everything. It is assumed that you know how to develop a simple application, i.e. to create fields, records, panels, panels groups and menus. It is also assumed that you are of average intelligence and that you can add 2+2 and get a result of 4. If not, you could enroll for a course in speed mathematics that will be showing on site near you soon! If you do not have any of the previous

skills, DO not go on. Attempting to read more than the next couple of lines of text will cause the green genie who sits in your monitor to breathe fire and destroy your computer. The only concession that can be made is if you can add 1+3 and get a result of 4. You can? Good. Go on. Hello PeopleCode? Tradition has it that the first program that anyone writes in C is "Hello World". It has something to do with the words that Neil Armstrong said when he landed on the moon. He looked down at that mass of blue-green, and said Hello world, I'll be back some day. And I'm gonna be a star. Since C was the language used for programming the rocket that sent him to the moon, all C programmers are now taught to write Hello World in their first C program. Of course, if you did a C course with us, you would start with something different, as if you believed all of the preceding stuff, you'd believe anything. Still, just to keep with a new tradition do remember to key in a quick, "Hello PeopleSoft" when you try out your first program. We will show you how to do it. Quickly revise all that you learned so far. PeopleSoft changes the way one works with databases by changing some of the basic concepts of RDBMS'. Fields are the most basic components of a database now. These have to be defined first. These fields however cannot be used directly, and must be inserted as part of a table, which PeopleSoft calls a record. This record is not to be confused with a row or a set of data that is entered into a table. Only record fields can be used for storing data. Again, in PeopleSoft, this can only be done through a panel. Panels are everything in PeopleSoft. One can use a panel to Add, Update, Display or even correct the data in the table. Building panels is not difficult at all. It is just a question of placing fields on the panel and then selecting the Action to be associated with the panel. There are only five Actions or tasks that can be performed on a panel Add, Update/Display, Update/Display All, Correction and Data Entry. Panels can be used only through menu items, which are linked to panel groups. It is also possible to modify existing panels and change the code associated with them. By copying and moving defined record fields from one panel to another, one can also copy the code that is associated with the field. Program code cannot remain in isolation. It needs to be attached to a field and written in some event of the field. Hence one of the first things to do, is to create a panel with fields to be for writing the code. To ensure that you do not go off alone, try to replicate the same field names and other objects as we do here. Do this so that there is no confusion with what-you-see-and-what-we-get (WYSAWWG, pronounced what-you-see-and-what-we-get). You will find that acronyms like these keep popping up in the computer industry and hence do not get fazed by them. We will add in our fair share and show you how to do the same for free. If by the time you end this book, you cannot talk double-Dutch or your boss still understands you, then we have failed in our duty. Create a two fields FF1 and FF2. Both fields should be of Character type and length 10. Label them FIELD1, FIELD2 and FLD1, FLD2 for the long and short names respectively. Next create a record to place the fields in. Call the record RREC1 and make FF1 the Search key. The record fields now have to be placed on a panel, hence create a panel and name it PPA1. Having done so place the fields on the panel. Now create a panel group to go along with the panel. Name the panel group PPG1 and include panel PPA1 in it. Since there is no other table or panel to be included, save the group. Set RREC1 as the Search record. Also select all the Actions Add, Update/Display, Update/Display All, Correction and Data Entry for the panel group. The last thing to do is to create the menu and to link the panel group to this menu. Save the menu as MMENU, and label the main menu item MMNU1. Under this, place a sub-menu item called LABEL1. Do not forget to link the panel group PPG1 to this sub-menu item. It would be a good idea to save the entire project as the panels and fields will be used over and over again. Call it PPRJ. Test that all this works before going on. Try adding, updating and correcting data

in the table. If you do get an error when trying to do so, it would be because you forgot to build the table before using it. Do this and re-run the program. Test completed? Run PeopleSoft. Click Go | PeopleTools | Application Designer. Open project PPRJ and then display the only panel in it PPA1. You are no ready to enter your first line of code. To do this, right click on FIELD2 as shown in fig.1 to open the pop-up menu.

Fig.1: Right-click a field to enter code You have used this pop up so many times so far, but only selected the last option Panel Field Properties. This time, this is going to change. What you have to select is the second menu item on the list View PeopleCode to add code to one of FIELD2's events. (Actually, the field is FF2, it is labelled FIELD2.) Of course, this is a silly menu item. There is no PeopleCode in the field at all. Edit PeopleCode would have been a more descriptive entry, as it could be used for code that will be placed as well as code that is already placed. But then, with so many things already on the PeopleSoft programmer's mind, this hardly seems like a major issue. Some of the other software companies have got away with worse to a point where customers even paid good money to get conned. If this really bothers you, you can open the XXXX file in a hex editor and change the bytes View to Edit. Do remember by doing this, you will have violated your license agreement and you will no longer have any right to the paid support service that is freely available. Selecting View PeopleCode will cause the display to change. It should look like fig.2. If the window of the right is not an exact fit, maximise it.

Fig.2: The View PeopleCode window There are three parts in the View PeopleCode window that you need to know about. Code is written in the large white space on the right. The field and the event that is currently active decide what appears in this space. A programmer can move quickly from one field to another in a panel and from one event to another in a field. This is done with the help of the two drop-down list boxes that are placed just above the code window. The list box on the left is the field list box. The one on the right is the event list box. While you are already know what a field is, and that when referring to fields on a panel it actually means a record field, an event in computer terms may not be clear. We did tell you at the beginning, that computer people love complicating life. Although everything is simple, there is need to add a bit of mystique. An event is not really something to worry about. It is a happening. Something like your birthday. Like it or not, it occurs every year. (Some women would die just to stop from ageing, literally. After all, when you are dead you age no more. You just get mouldy and rot in some grave. C programmers live on forever!) Another daily event could be breakfast, or the fact that you get up or go to sleep. It could be the first time you and your friend held hands, kissed, made out, that sinking feeling as you went to the altar with a shot gun behind your back, because of the previous event anything at all. Events could be just anything. On the computer too, 'events' are continuously taking place. However, PeopleSoft has selected or predefined few which can be used to place code in. Click on the down arrow of the list box and you will see what events are available. Events determine what happens next in a program. Code is written in the events, and is executed each time the event occurs, is triggered or gets called. This is automatic. For example, a smoker automatically reaches for a cigarette as soon as he gets up. Or if you are a normal human being, the inferiority complexes as you find you know less than us. The list of events recognised by PeopleSoft is rather short but can definitely be used to cover all situations in PeopleSoft. Being predefined by PeopleSoft, the list cannot be changed or added to. At

least, not by you. As to why the list is so short or what else can be added to this list is not really our concern. This is the PeopleSoft collection and should be accepted as such. Fortunately, the events listed in the event drop down box are not cryptic. All of them are simple English words. Since the event can only be a single word, upper and lower case is mixed so that the words make sense. The initial letter of a word is capitalised. For instance, the FieldChange event is displayed with the F and C capitalised. This event is always displayed when the View PeopleCode window is opened.

Fig.3: The event list It is easy to locate events that have code. Coded events show up bold in the list box. Click on any of them to select the event. If there is code associated with the event, it will show up in the code window. Of course, if any of them appear bold at this point, you know that you have done something wrong already since you just created the record and fields placed in it. Select the FieldDefault event as this is the first event in which we will write code. Even a single semicolon is considered code by PeopleSoft. The semi-colon like many other commands that you will see in PeopleSoft appear to be borrowed from C. C programmers will be quick to identify the semi-colon as a full-stop or a sentence terminator. Code does not have to be formatted in any particular order. The semi-colon will let PeopleSoft know when the line is completed. (You will see that whatever you do, your code will be reformatted by PeopleSoft before it is stored.) It is silly, but with each new language that appears, there are new rules to be learned. In fact, there should be some body that defines and standardises the syntax that can be used with a language. The semi-colon is particularly silly as PeopleSoft relies a good bit on COBOL and COBOL uses full-stops to delimit and define the line ending. Hence, adding another line terminator does not make any sense. The COBOL programmers use a full-stop, This semi-colon that you write does not generate any error as there This event is occurs before the field is displayed on the panel. It could be used to initialise the field or perform other tasks that are to be completed before the field is displayed.

Since the event entry was not bold, it does not contain any code. The code window will be blank. Enter the single line of code that you can see in fig.5. This line ff2="hello" ; Initialises the field FF2.

Fig.5: Initialising a field with some value Two things happen when the code is saved. First, if you keyed in the text exactly as shown in the code window, it gets automatically reformatted to FF2 = "hello"; No matter how hard you try or how badly you format the code, it will always return to this. Variables and field names get capitalised. Spaces are inserted before and after the equals sign, and any space before a semi-colon is removed. Later, keywords and functions, when used will also fall in step with PeopleSoft. The other change that takes place is that the event label becomes bold. This can be seen by dropping down the event list box. Now that you saved your application, you can test it by restarting PeopleTools. If you already tested out the application before this, then the application will already be placed on the Go menu. Click Go | Mmenu and start the application. There will be only one new menu option on the main menu bar MMNU. From here, select LABEL1 and Add to make a new entry. A prompt for the Search record will appear, as seen in fig.8. Since the Search key was set to FIELD1, enter a value and proceed. If you get an error at this point, it would be

because you did not create the table after defining the record. Go back to the Application Designer, open the project once more. Click on Build | Project, select Create Tables under Build Options and Execute and build script under Build Execute Options.

Fig.8: Filling in a Search key value for Add As soon as OK is clicked on, the panel appears. However, the fields in the panel are not blank as shown in fig.9.

Fig.9: Both fields get filled with a value In both fields a value appears. In FIELD1, there is 1 which was entered in the Search record. Although the table RREC1 had no values, there was no error flagged. This is because the Action being performed was an Add, which permits one to add values to the table. This value 1 was what was entered in the Search record field and was carried over to the panel. FIELD2 is a different story. If you figured that this value has something to do with the code that was entered in the event FieldDefault, you figured right. However, if you check the lines of code that you entered, you will find that the hello entered was lowercase, while the one that is displayed is uppercase. This is because when the field was created, the Format defined was Uppercase. The properties for a field are carried down to the records which they create. Save this value so that there is some data in the table. Return to the Application Designer to try other functions. Back in the Application Designer, select the field FF2 and the event FieldChange once more. Replace the code that is present there with winmessage ( "FieldDefault",64 ) ;

ff2="hello" ; Once more, the autoformat will take over and reformat the lines of code when you save the project. Space the keywords and the rest out and you will still find that it all comes together once more, as in fig.11.

Fig.11: Code reformatting is automatic The function WinMessage also got capitalised correctly. Therefore since case really does not make a difference other than for formatting purposes, none of the keywords or the functions can be used by the programmer as variables. Close the project and then run the application once more. Again, select Add under the menu LABEL1. Enter 2 at the Search record prompt and click OK.

Fig.13: Application executes with a message box This time before the field appear, a message box appears as in fig.13. Pay attention to what you see on the screen. The message box appears after the panel is displayed by before the fields are placed on it. This is confirmed by the panel tab Ppa1 which is visible on the top left hand corner. The value 64 placed with the WinMessage function displays the information icon. There are other values that you can try out while using WinMessage. More details about this function can be found in Help. Value Meaning 0 One push button: OK. 1 Two push buttons: OK and Cancel. 2 Three pushbuttons: Abort, Retry, and Ignore. 3 Three pushbuttons: Yes, No, and Cancel. 4 Two push buttons: Yes and No. 5 Two push buttons: Retry and Cancel. 0 No icon 16 Stop-sign icon.

32 Question-mark icon. 48 Exclamation-point icon. 64 Lowercase letter "i" in a circle icon. 0 First button is the default. 256 Second button is the default. 512 Third button is the default. (To combine the different buttons with icons and button defaults, add up the values.)

Save this record too. Now there will be two records in the table. Restart the Application Designer, and open the project once more. Now try the following line of code. ^="hello";

Fig.11: PeopleCode has some strange short forms This may seem a truly silly line. However, this is one of the short forms that PeopleCode uses. Since you are encouraged to use as descriptive field and variable names as possible, you may get tired of keying in the field name each time. As soon as you save this line of code, the caret (^) is replaced by the current field name.

Simplification is the name of the game. In actual practice, when referring to any field, one precedes the field name with the table name. The two are separated by a period (.) like RREC1.FF2. Try doing this in the current record and the table name is dropped. For example, try rrec1.ff2="hello" ; This will reformat to FF2 = "hello"; In a way PeopleCode has been optimised as far as the formatting and readability of the program is concerned. All this makes PeopleCode much easier to understand, while leaving a programmer no way in which to leave his own personal mark.

Its time to move on again. Do not waste time trying to figure out why FieldChange is the default event in the event list although FieldDefault is called first when a panel is displayed. The answer is simple and silly. List boxes here are always arranged alphabetically, hence since C comes before D, FieldChange is on the top of the list. If there were more events, then possibly something else may have been displayed. FieldChange is displayed only when there is no code in any of the other events. As soon as code is placed in any of the events, the last event edited is the one that is listed in the event list. Do not delete the code in FieldDefault but move to FieldChange as in fig.19.

Fig.19: Changing events

From now on we will not waste time formatting code incorrectly or even bother you with the change that takes place. So quickly enter the next line in, save and run your application. FF2 = "BYE"; But before you do, pause for just about a minute to try and figure out what the FieldChange event will do and when exactly it will appear. Will it appear when the contents of the field are changed? Or will it appear when you change from field to field? Does it appear before or after a change has been made?

Fig.21: Does BYE appear when entering or leaving the field? Save the changes and rerun the application. Add in another record 3. Click OK and panel Ppa1 will be displayed once more. The highlight will be on FIELD1. As usual, you will find the value that you entered in the Search record is the one that appears in FIELD1. Since the code entered in FieldDefault has not been deleted, FIELD2 displays HELLO. To move the highlight or cursor from FIELD1 to FIELD2, use the mouse or press Tab. Moving into the field does not call the event FieldChange, but click on FIELD1 once more and you will see fig.23.

Fig.23: Moving out of FIELD2 causes BYE to appear Events like this, are the most puzzling ones. From the event name, one would have expected that the event would be called only if there was some change in the contents of the field. However, this did not happen. Change here, meant changing from one field to the next. The easiest way to check when each event gets called is to place a WinMessage in each of them and observe when the event gets triggered. Delete any of the old lines of code as they will not be required anymore. Do all the events in one go. There are not many events as you can see in fig.24. Save the project and run the application again. As usual, Add in another record.

Fig.24: Use WinMessages in events to find out when they are triggered This is a good time to try out all the options that can be used with WinMessage. Place the value as a part of the message string so that you can see the result as you go along. Do not also forget to use the name of the event in the message string so that you know what event causes the WinMessage to appear. For example, the following line of code could be placed in the FieldEdit event WinMessage("FieldEdit 16", 16); This will have the Stop sign appear with the message box when the FieldEdit event is triggered. The purpose of putting in all these lines of code is to learn the sequence of events being triggered. You already know that the first event to be called before anything appears on the panel is the FieldDefault event.

After this event is triggered, the FieldFormula event is the next one called as seen in fig.27.

Fig.27: FieldFormula is the next event after FieldDefault Look at the bottom left of the screen. The message that appears there states what is happening at any given time internally. At this point, the panel is still being loaded or created on the screen. The fields will only appear after another two events get fired FieldDefault and RowInit, which is seen in fig.29.

Fig.29: The last event before the panel is displayed As soon as OK is clicked on this message box, the fields on the panel appear. FIELD1 has a value which was added in the Search record. The second field is blank as there is no code to initialise it anymore. The message boxes that appeared in the last couple of screen shots had Update in the Title. If you thought this was an error or that we pulled a fast one, try it yourself. You will find the screen shots are right. This can be confirmed again by reading the bottom line of the panel. Once the panel is formed completely, the name of the panel Ppa1 and the Action that called it Add, is displayed. You will this true even when using the other Actions.

To continue with the event run, enter HELL in FIELD2. It would be silly if every time one entered a keystroke in a field an event got fired. Hence, it is only once all changes to a field are made and the cursor has left the field, that PeopleSoft recognises that the contents of the field have been modified. Press Tab and the FieldEdit event is triggered. It is triggered just before the FieldChange as the change in contents is recognised first.

Fig.32: FieldEdit is called before FieldChange

Pay attention to the bottom right of the panel once more. You will find that the Field Change is another service that is processed. The FieldFormula event is called again, and this is not the last time that it will be called. It will appear again and again. However, at this point of time, all we are concerned with is getting the sequence of event right. Do not try to figure out too much about the Why? just now. It will become clearer as we go along. At this point, everything comes to a standstill once more, so to keep going on, click on Save and fig.35 will appear on your screen.

Fig.35: As expected SaveEdit is called after a Save Whenever a record is saved, a number of events are called in quick succession. Again, keep watching the bottom left of the panel and you will learn more about the events that are grouped together. The next few events that are triggered belong to the Save Panel service. These are SavePreChg, Workflow and SavePostChg, which is the last event as seen in fig.38.

Fig.38: SavePostChg is the last of the events fired If you followed the sequence of the events fired, you will have noticed that some events like RowSelect, PrePopup, SearchInit never got called. Some also appeared to be called out of order. Rest assured however, there is some method in the madness. And before we go on to explanations and examples that makes all this clear, run through the other Actions in the menu.

Fig.39: Update/Display is the next on the list Run through the menu another time. This time use Update/Display as in fig.39. The sequence that is followed is quite similar to Add that we had used a while ago. FieldFormula is the first event to get called. This is followed by RowInit and RowSelect. At this point, the Search record is being processed. The correct row has therefore to be located from the database. The 4 that was entered in the Search field is matched with the table in the database to select and display the correct row. FIELD2 will correctly display HELL, as this is the value that was stored along with FIELD1 as 4. With the panel now correctly displayed, everything now comes to a halt. The users needs to perform some action before any other trigger is fired. To force an event, delete an L of HELL and leave the field. By doing so, at least two events should be called FieldEdit and FieldChange. And they do. FieldEdit gets called since the contents of the field were modified. FieldChange is called each time the cursor moves out of a field. FieldFormula gets fired again and once more there is a pause. To push things on again, Click Save to record the changes made to the fields, and the following events are triggered SaveEdit, SavePreChg, Workflow and SavePostChg. That there should be a SaveEdit and another three events before the record is committed, seems strange. However, all these events are useful and are made use of by PeopleSoft in its own code/programs. As you work through the examples that follow, the use of each event will be clearer. There is no difference between Update/Display and the Update/Display All Action. The events that both trigger are exactly the same. Use the same record as in the last example by entering 4 in the Search record field. This will call the events FieldFormula and RowInit. The record will be displayed before RowSelect is called. It is now possible to edit the fields, and this time change HEL to HELLO.

Since a change in the field contents has been made, FieldEdit will be triggered. FieldChange follows this as you move out of FIELD2. This is followed by FieldFormula and the display pauses for user input. Again, save the entry and another set of events will be fired. These are SaveEdit, SavePreChg, Workflow and SavePostChg. Do this one last time for the Correction Action. Once more use Search record 4 and observe the events that get called. FieldFormula and RowInit start the ball rolling and are displayed before the field on the panel are displayed. After this, RowSelect is called and one can edit the fields. Change HELLO to BYE and leave FIELD2. FieldEdit and FieldChange get fired. Save the entry and the last sequence of events get triggered SaveEdit, SavePreChg, Workflow and SavePostChg.

Though there are different names to each Action, the sequence which the last three Actions follow, are exactly the same. Add is the only Action that is different. Therefore, Update/Display, Update/Display All and Correction could be used interchangeably. One can enter code in the field events to control input. Since you now know when the events appear, it is time to move on to a bit more code. A field can be filled with data either though the keyboard or by an assignment statement. Defining a default value for a field could be done in any of the events, as it is possible to use code in one field to assign a value to another. It is also possible to assign values to fields through variables. This is helpful when one has to create a value that is a sum of parts. In this case therefore, the resultant value is created on-the-fly. Verify the field-variable assignment by first deleting the code in all events. Now in the FieldChange event, key in the following &A = "good"; FF2 = &A;

You know by now, that you do not have to worry about the formatting. PeopleSoft will take care of this for you as soon as you click Save, as you can see in fig.43.

Fig.43: No matter how bad your alignment is, PeopleCode is always stored neatly When you run the application, nothing will happen until you leave Field2. As soon as you do, BYE will enter in the edit box. In the same manner, FIELD2 could be a composite of two other fields, in which case its contents are not known till the last. A typical example would be a nickname field th at could be formed out of a First name field and the first character of a Surname field. Such initialisations cannot be predefined but must be prepared while the program is in use.

If you look back at all that you have done so far, you will realise that there must have been some code that was executed when you replicated the PeopleSoft panels. There was. The code was not noticed because at no point did we ask you to open the View PeopleCode menu item. Where then is the code hidden? With the record fields. In the last few examples, code was entered under the events that were available for record fields placed on panels. This is visually represented in the project tree as well. Expand every branch of the Records folder and you will find the field FF2 has an entry under it FieldChange. The lightening bolt icon is possibly the programmers way of saying something electrifying happens in the field. Check this out in fig.45.

Fig.45: Events that have code show up in the Project tree This is not the only way in which one can find out if there is code associated with a field. Another way is to change the view of the window on the right. To do this, click View in the main menu and then PeopleCode Display. As seen in fig.47, the Field Name, Type and the events are listed in brief. An event that has code placed in it, has a Yes in the column.

Fig.47: Change the view and see which events have code With the code being attached to the field, any time the field is used, the code is also activated. Hence, if you were scratching your head trying to figure out how you succeeded in getting your application running so well in the last chapter, you know now that it was not all your own doing. All of it was done by PeopleSoft. By using the PeopleSoft fields, you also used the PeopleSoft code that was entered in them. Try copying a field or a record. If there is code in the record, a prompt appears to confirm that the code is also to be copied. For example, select record RREC1. Click File | Save As and enter RREC2 in the dialog box that appears. Fig.50 should appear on your screen.

Fig.50: Copy code? Confirmation box Click Yes and you will find that there is a new record placed in the project tree. The right window did not change at all. The FCh or the FieldChange column still has a Yes in it. Confirm this by rightclicking the field and then selecting View PeopleCode from the pop-up that appears. The event FieldChange will be displayed with the code in it. Do another Save As. This time name the record RREC3 and click No when prompted to copy the code. The display will change once more and you will find that the Yes has disappeared from the FCh column.

Fig.51: It is possible to only copy the field While there are few PeopleCode rules to remember and few events in which one can place PeopleCode in, it is still considered difficult. But this really true only for programmers who are used to old coding practices, where all code is simply placed in one huge file. Applications written in COBOL fall under this category. For a programmer to switch between writing one program to many little ones, that are linked in rather convoluted ways, is not easy. What makes things even worse is the rich set of tools that are available and the ability to call in even more using links with other languages. A programmer could well get swamped. However, if one really breaks an application into its separate parts as PeopleSoft did in defining fields as the basic unit, programming PeopleSoft is much easier and definitely fun. This we will prove in the coming chapter.

Summary
In this chapter you have learned about a few of the PeopleCode commands. WinMessage is the easiest to use when debugging and testing. The code can only be attached to fields under special links called events. These events get called or are fired depending upon the users or the program actions. Since the code is attached to the record field, copying or using the field in another panel or application also copies or allows the code to be used in the other application. This can be prevented if the user wishes to do so.