PeopleCode Basics

Embed Size (px)

Citation preview

  • 7/30/2019 PeopleCode Basics

    1/28

    PeopleCode Basics

    Writing code is not difficult. As long as you can read a manual, follow instructions on how to constructa sentence, using the syntax specified, you will be able to write programs. In some case, you do noteven have to do this. Wizards and other helpers pop up to generate code automatically. All the userhas 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. Anymajor project can be broken down into a set of smaller parts, some of which can be automated. Theart of developing great programs is in breaking down a big program into smaller parts and ensuringthat each part functions perfectly. At no time however, are the two separate. This is what we will try toshow you in the this and the next few chapters. Our goal is to get you to write a one of the largestapplications that are there in PeopleSoft. This application. The Virtual Approver, can be broken downinto sub-components so that it is easier to understand. In the last chapter, you created your own set ofpanels that performed some of the same tasks that PeopleSoft's did. You did not see the code behindthe panel. This chapter will introduce PeopleCode, practically line by line so that you understandclearly what happens to the code you key in. It looks at the different elements that you need to buildthe Virtual Approver.If you used other visual development environments, then you most probably have already masteredthe art of design. (A topic that we will not do anyway.) We do not concentrate on the code in thischapter either. This chapter is to get you comfortable with the programming environment thatPeopleSoft provides. If you already program in some other language, then you may not be too happywith everything PeopleSoft does. C programmers among others will be the ones who get most upsetas PeopleSoft puts all programmers on one same level. There is no way except through comments tofigure out who wrote a piece of code. Try as hard as you might to format the code and PeopleSoftreformats 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 somethingelse that could do it better, then that something else was used. For example, COBOL is a language ofchoice 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 inPeopleCode would simply be a waste of time. So PeopleSoft left it alone. PeopleSoft only looks atmanaging tables and data through panels. There is nothing more than the panel to get any work donein PeopleSoft. Every command that you require is available. If one needs additional functionality thatPeopleSoft missed out, then the facility to call in routines written in other languages like C is alwaysthere.

    This chapter, as with most chapters in this book, takes a different approach. The focus is still thesame to teach you how to write great applications using PeopleSoft. And to do this, you will neverbe swamped with a long program that has lines of code to understand in one go. Rather you willalways 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-blownapplication. But while learning and when you desperately want to see results, writing in long namesonly wastes time. We could keep discussing the merits and demerits of this as they say "till the cowscome home". (If we were in North India, in a state called Bihar, we'd stop just now, for the cows arehome and in the Chief Minister's house too.) However, it would serve little purpose. So let's get onto our work. We believe that your confidence will grow and your concepts will be clearer if you takethis 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 toolthat does everything. It is assumed that you know how to develop a simple application, i.e. to createfields, records, panels, panels groups and menus. It is also assumed that you are of averageintelligence and that you can add 2+2 and get a result of 4. If not, you could enroll for a course inspeed mathematics that will be showing on site near you soon! If you do not have any of the previous

  • 7/30/2019 PeopleCode Basics

    2/28

    skills, DO not go on. Attempting to read more than the next couple of lines of text will cause the greengenie who sits in your monitor to breathe fire and destroy your computer. The only concession thatcan 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 dowith the words that Neil Armstrong said when he landed on the moon. He looked down at that mass ofblue-green, and said Hello world, I'll be back some day. And I'm gonna be a star. Since C was thelanguage used for programming the rocket that sent him to the moon, all C programmers are nowtaught to write Hello World in their first C program. Of course, if you did a C course with us, you wouldstart 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 outyour 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 bychanging some of the basic concepts of RDBMS'. Fields are the most basic components of adatabase 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 confusedwith 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 isnot difficult at all. It is just a question of placing fields on the panel and then selecting the Action to beassociated 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 tomodify existing panels and change the code associated with them. By copying and moving definedrecord 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 eventof 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 wedo 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 upin the computer industry and hence do not get fazed by them. We will add in our fair share and showyou how to do the same for free. If by the time you end this book, you cannot talk double-Dutch oryour 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. Labelthem 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. Therecord fields now have to be placed on a panel, hence create a panel and name it PPA1. Having doneso 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 beincluded, 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 asMMENU, 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 overagain. Call it PPRJ. Test that all this works before going on. Try adding, updating and correcting data

  • 7/30/2019 PeopleCode Basics

    3/28

    in the table. If you do get an error when trying to do so, it would be because you forgot to build thetable before using it. Do this and re-run the program.

    Test completed? Run PeopleSoft. Click Go | PeopleTools | Application Designer. Open project PPRJand then display the only panel in it PPA1. You are no ready to enter your first line of code. To dothis, 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 FieldProperties. This time, this is going to change. What you have to select is the second menu item on thelist View PeopleCode to add code to one of FIELD2's events. (Actually, the field is FF2, it is labelledFIELD2.)Of course, this is a silly menu item. There is no PeopleCode in the field at all. Edit PeopleCode wouldhave been a more descriptive entry, as it could be used for code that will be placed as well as codethat 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 withworse 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 doingthis, you will have violated your license agreement and you will no longer have any right to the paidsupport service that is freely available.

    Selecting View PeopleCode will cause the display to change. It should look like fig.2. If the window ofthe right is not an exact fit, maximise it.

  • 7/30/2019 PeopleCode Basics

    4/28

    Fig.2: The View PeopleCode window

    There are three parts in the View PeopleCode window that you need to know about. Code is written inthe large white space on the right. The field and the event that is currently active decide what appearsin this space. A programmer can move quickly from one field to another in a panel and from one eventto another in a field. This is done with the help of the two drop-down list boxes that are placed justabove the code window. The list box on the left is the field list box. The one on the right is the eventlist box.While you are already know what a field is, and that when referring to fields on a panel it actuallymeans 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 bitof mystique. An event is not really something to worry about. It is a happening. Something like yourbirthday. 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 goto sleep. It could be the first time you and your friend held hands, kissed, made out, that sinkingfeeling 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 takingplace. However, PeopleSoft has selected or predefined few which can be used to place code in. Clickon 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 executedeach time the event occurs, is triggered or gets called. This is automatic. For example, a smokerautomatically reaches for a cigarette as soon as he gets up. Or if you are a normal human being, theinferiority 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 allsituations in PeopleSoft. Being predefined by PeopleSoft, the list cannot be changed or added to. At

  • 7/30/2019 PeopleCode Basics

    5/28

    least, not by you. As to why the list is so short or what else can be added to this list is not really ourconcern. 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 simpleEnglish words. Since the event can only be a single word, upper and lower case is mixed so that thewords 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 PeopleCodewindow 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 ofthem 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 wrongalready 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 semi-colon is considered code by PeopleSoft. The semi-colon like many other commands that you will seein PeopleSoft appear to be borrowed from C. C programmers will be quick to identify the semi-colonas 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 youdo, your code will be reformatted by PeopleSoft before it is stored.) It is silly, but with each newlanguage that appears, there are new rules to be learned. In fact, there should be some body thatdefines and standardises the syntax that can be used with a language. The semi-colon is particularlysilly as PeopleSoft relies a good bit on COBOL and COBOL uses full-stops to delimit and define theline ending. Hence, adding another line terminator does not make any sense. The COBOLprogrammers use a full-stop, This semi-colon that you write does not generate any error as there Thisevent is occurs before the field is displayed on the panel. It could be used to initialise the field orperform other tasks that are to be completed before the field is displayed.

  • 7/30/2019 PeopleCode Basics

    6/28

    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 thecode window, it gets automatically reformatted toFF2 = "hello";

    No matter how hard you try or how badly you format the code, it will always return to this. Variablesand field names get capitalised. Spaces are inserted before and after the equals sign, and any spacebefore a semi-colon is removed. Later, keywords and functions, when used will also fall in step withPeopleSoft.

    The other change that takes place is that the event label becomes bold. This can be seen by droppingdown the event list box.

    Now that you saved your application, you can test it by restarting PeopleTools. If you already testedout 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 LABEL1and Add to make a new entry. A prompt for the Search record will appear, as seen in fig.8. Since theSearch key was set to FIELD1, enter a value and proceed. If you get an error at this point, it would be

  • 7/30/2019 PeopleCode Basics

    7/28

    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 andExecute 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 asshown in fig.9.

  • 7/30/2019 PeopleCode Basics

    8/28

    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 Actionbeing performed was an Add, which permits one to add values to the table. This value 1 was whatwas 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 wasentered in the event FieldDefault, you figured right. However, if you check the lines of code that youentered, 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. Theproperties 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 otherfunctions.

    Back in the Application Designer, select the field FF2 and the event FieldChange once more. Replacethe 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.

  • 7/30/2019 PeopleCode Basics

    9/28

    Fig.11: Code reformatting is automatic

    The function WinMessage also got capitalised correctly. Therefore since case really does not make adifference other than for formatting purposes, none of the keywords or the functions can be used bythe 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.

  • 7/30/2019 PeopleCode Basics

    10/28

    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 seeon the screen. The message box appears after the panel is displayed by before the fields are placedon 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 othervalues that you can try out while using WinMessage. More details about this function can be found inHelp.

    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.

  • 7/30/2019 PeopleCode Basics

    11/28

    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. Sinceyou are encouraged to use as descriptive field and variable names as possible, you may get tired ofkeying in the field name each time. As soon as you save this line of code, the caret (^) is replaced by

    the current field name.

  • 7/30/2019 PeopleCode Basics

    12/28

    Simplification is the name of the game. In actual practice, when referring to any field, one precedesthe field name with the table name. The two are separated by a period (.) like RREC1.FF2. Try doingthis 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 isconcerned. All this makes PeopleCode much easier to understand, while leaving a programmer noway 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 eventin 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 mayhave been displayed.

    FieldChange is displayed only when there is no code in any of the other events. As soon as code isplaced in any of the events, the last event edited is the one that is listed in the event list. Do not deletethe code in FieldDefault but move to FieldChange as in fig.19.

    Fig.19: Changing events

  • 7/30/2019 PeopleCode Basics

    13/28

    From now on we will not waste time formatting code incorrectly or even bother you with the changethat 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 itappear 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 willbe displayed once more. The highlight will be on FIELD1. As usual, you will find the value that youentered in the Search record is the one that appears in FIELD1. Since the code entered inFieldDefault 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 thefield does not call the event FieldChange, but click on FIELD1 once more and you will see fig.23.

  • 7/30/2019 PeopleCode Basics

    14/28

    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 theevent would be called only if there was some change in the contents of the field. However, this did nothappen. 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 andobserve when the event gets triggered. Delete any of the old lines of code as they will not be requiredanymore. Do all the events in one go. There are not many events as you can see in fig.24. Save theproject and run the application again. As usual, Add in another record.

  • 7/30/2019 PeopleCode Basics

    15/28

    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 apart of the message string so that you can see the result as you go along. Do not also forget to usethe name of the event in the message string so that you know what event causes the WinMessage toappear. For example, the following line of code could be placed in the FieldEdit eventWinMessage("FieldEdit 16", 16);

    This will have the Stop sign appear with the message box when the FieldEdit event is triggered. Thepurpose of putting in all these lines of code is to learn the sequence of events being triggered. Youalready know that the first event to be called before anything appears on the panel is the FieldDefaultevent.

  • 7/30/2019 PeopleCode Basics

    16/28

    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 atany given time internally. At this point, the panel is still being loaded or created on the screen. Thefields will only appear after another two events get fired FieldDefault and RowInit, which is seen infig.29.

  • 7/30/2019 PeopleCode Basics

    17/28

    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 valuewhich was added in the Search record. The second field is blank as there is no code to initialise itanymore. The message boxes that appeared in the last couple of screen shots had Update in theTitle. If you thought this was an error or that we pulled a fast one, try it yourself. You will find thescreen shots are right. This can be confirmed again by reading the bottom line of the panel. Once thepanel is formed completely, the name of the panel Ppa1 and the Action that called it Add, isdisplayed. You will this true even when using the other Actions.

  • 7/30/2019 PeopleCode Basics

    18/28

    To continue with the event run, enter HELL in FIELD2. It would be silly if every time one entered akeystroke in a field an event got fired. Hence, it is only once all changes to a field are made and thecursor 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 thechange in contents is recognised first.

  • 7/30/2019 PeopleCode Basics

    19/28

    Fig.32: FieldEdit is called before FieldChange

  • 7/30/2019 PeopleCode Basics

    20/28

    Pay attention to the bottom right of the panel once more. You will find that the Field Change is anotherservice that is processed. The FieldFormula event is called again, and this is not the last time that itwill be called. It will appear again and again. However, at this point of time, all we are concerned withis getting the sequence of event right. Do not try to figure out too much about the Why? just now. Itwill become clearer as we go along.

    At this point, everything comes to a standstill once more, so to keep going on, click on Save andfig.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, keepwatching the bottom left of the panel and you will learn more about the events that are groupedtogether. The next few events that are triggered belong to the Save Panel service. These areSavePreChg, Workflow and SavePostChg, which is the last event as seen in fig.38.

  • 7/30/2019 PeopleCode Basics

    21/28

    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 likeRowSelect, 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 explanationsand examples that makes all this clear, run through the other Actions in the menu.

  • 7/30/2019 PeopleCode Basics

    22/28

    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 isfollowed is quite similar to Add that we had used a while ago. FieldFormula is the first event to getcalled. This is followed by RowInit and RowSelect. At this point, the Search record is beingprocessed. The correct row has therefore to be located from the database. The 4 that was entered inthe 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. Withthe panel now correctly displayed, everything now comes to a halt. The users needs to perform someaction 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 becalled FieldEdit and FieldChange. And they do. FieldEdit gets called since the contents of the fieldwere 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 followingevents are triggered SaveEdit, SavePreChg, Workflow and SavePostChg. That there should be aSaveEdit and another three events before the record is committed, seems strange. However, all theseevents are useful and are made use of by PeopleSoft in its own code/programs. As you work throughthe 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 thatboth trigger are exactly the same. Use the same record as in the last example by entering 4 in theSearch record field. This will call the events FieldFormula and RowInit. The record will be displayedbefore RowSelect is called. It is now possible to edit the fields, and this time change HEL to HELLO.

  • 7/30/2019 PeopleCode Basics

    23/28

    Since a change in the field contents has been made, FieldEdit will be triggered. FieldChange followsthis as you move out of FIELD2. This is followed by FieldFormula and the display pauses for userinput. 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 thefield on the panel are displayed. After this, RowSelect is called and one can edit the fields. ChangeHELLO to BYE and leave FIELD2. FieldEdit and FieldChange get fired. Save the entry and the lastsequence 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 fieldevents 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 befilled with data either though the keyboard or by an assignment statement. Defining a default value fora field could be done in any of the events, as it is possible to use code in one field to assign a value toanother. It is also possible to assign values to fields through variables. This is helpful when one has tocreate 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 FieldChangeevent, 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 thisfor you as soon as you click Save, as you can see in fig.43.

  • 7/30/2019 PeopleCode Basics

    24/28

    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 willenter in the edit box. In the same manner, FIELD2 could be a composite of two other fields, in whichcase its contents are not known till the last. A typical example would be a nickname field that couldbe formed out of a First name field and the first character of a Surname field. Such initialisationscannot 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 codethat was executed when you replicated the PeopleSoft panels. There was. The code was not noticedbecause at no point did we ask you to open the View PeopleCode menu item. Where then is the codehidden? With the record fields.

    In the last few examples, code was entered under the events that were available for record fieldsplaced on panels. This is visually represented in the project tree as well. Expand every branch of theRecords folder and you will find the field FF2 has an entry under it FieldChange. The lightening bolticon is possibly the programmers way of saying something electrifying happens in the field. Check thisout in fig.45.

  • 7/30/2019 PeopleCode Basics

    25/28

    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 wayis to change the view of the window on the right. To do this, click View in the main menu and thenPeopleCode Display. As seen in fig.47, the Field Name, Type and the events are listed in brief. Anevent that has code placed in it, has a Yes in the column.

  • 7/30/2019 PeopleCode Basics

    26/28

    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 applicationrunning so well in the last chapter, you know now that it was not all your own doing. All of it was doneby PeopleSoft. By using the PeopleSoft fields, you also used the PeopleSoft code that was entered inthem.Try copying a field or a record. If there is code in the record, a prompt appears to confirm that thecode is also to be copied. For example, select record RREC1. Click File | Save As and enter RREC2in the dialog box that appears. Fig.50 should appear on your screen.

  • 7/30/2019 PeopleCode Basics

    27/28

    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 didnot change at all. The FCh or the FieldChange column still has a Yes in it. Confirm this by right-clicking the field and then selecting View PeopleCode from the pop-up that appears. The eventFieldChange 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 thecode. The display will change once more and you will find that the Yes has disappeared from the FChcolumn.

  • 7/30/2019 PeopleCode Basics

    28/28

    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 placePeopleCode in, it is still considered difficult. But this really true only for programmers who are used toold coding practices, where all code is simply placed in one huge file. Applications written in COBOLfall 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 evenmore using links with other languages. A programmer could well get swamped. However, if one reallybreaks 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 theeasiest to use when debugging and testing. The code can only be attached to fields under speciallinks called events. These events get called or are fired depending upon the users or the programactions. Since the code is attached to the record field, copying or using the field in another panel orapplication also copies or allows the code to be used in the other application. This can be prevented ifthe user wishes to do so.