You are on page 1of 7

/Free Tutorial 1

Shirey Consulting Services

Tutorial 1 Getting Started with /Free

So you want to learn /Free, do you? Well, no problem. Its easy and its fun. Well, at least easy. So lets get right into it.

Disclaimer These tutorials are not designed to teach you everything you ever wanted to know about /Free. They are designed as a fun, simple way to get started in the topic and not feel like a total idiot. And if you learn everything here you will have learned a lot. But for more information on /Free (and you should look for more info once you finish this), please see Jim Martins excellent (and not too long or expensive) book Free Format RPG IV. In fact, I would order a copy now and use it as an adjunct to these tutorials. Good reference.

Anti-Disclaimer If a disclaimer is something you use to hedge your bets about the topic you are talking about, then I guess this would be an anti-disclaimer. /Free is not something that you will use intermittently in your program or only in certain situations. /Free is something that you can use instead of the old column based RPG. I have been using it exclusively for quite some time now and have never run into a situation, even though I have done a number of tricky, dickey programs. /Free is all you need and its good to get used to it now because the train has left the station and we are never going back to column based coding. In fact, the word on the street is that RPG V, which is in the works and will be released sometime in the next few OS releases, will be strictly /Free. And that is a good thing that helps RPG position itself as a legitimate language with people who didnt break in on RPG III.

Get a Program to Work With OK, enough posturing, lets start by creating a stub program. You can start from scratch or take a simple one and copy it but either way, get a small program that you can work with. To begin with, delete off all C-specs. Yes, all of them. And that includes any *ENTRY lines. To begin with this will be a program that has no input parms. When you are done there shouldnt be a C line anywhere in the program (not even a C*). For the moment, comment out the F-specs and either comment out or delete your D-specs. This will make it easier and prevent compiler mistakes. You wont have much left but thats fine.

Page 1

/Free Tutorial 1

Shirey Consulting Services

You can do programs that are part fixed format and part /Free, in which case the free stuff will be mixed in with the traditional C-specs, but thats for wimps. Just do /Free and forget about all that fixed format stuff. I know, when I first started using /Free I thought there were some things you just had to do with regular C-specs, but thats soooooo totally bogus. /Free is all you need.

F-specs, D-Specs, I-Specs, and O-Specs The first thing you need to know is that /Free makes no changes to the F, D, I, and O specs. You will code them up just like you do when you are doing a normal, outmoded, fixed format program. The truth is that /Free works only on your C-specs, and if you want the full truth, /Free replaces your C-specs. Thats right, Tex, if your program is totally /Free you will have no C-specs what so ever. I know, its outrageous. I love it.

/Free Syntax The syntax rules for /Free are so simple that its almost like there are none. Almost. First, you MUST tell the compiler that what you are about to do is in /Free. And you do that by coding the verbiage /Free, starting in column 7 of the first line in your procedure division (thats the column you would put an * in if you were coding C* for comments in fixed). You will do that right at the top of the area where the C specs would normally start. Once you put in your /Free, then no C specs can be coded below that until you have a /End-Free, which also begins in column 7. After the /End-Free you can have C-specs and you can even have multiple /Free - /End-Free code segments with normal C-specs in between. But like I said, thats for wimps. If you have your whole procedure division coded in /Free then you dont need the /End-Free at the end of the program. The compiler can figure out that the program is over. If you do feel the need to code an /end-free then it goes at the very end of the program (after any subroutines, not after the LR indicator which you need to include just like with fixed format RPG). Its also important to mention that, like RPG, /Free is case independent. You can code /free, /Free, /FrEe, /FREE, whatever you want and the system could care less. And the same is true for all /Free commands and parms. I generally put my code in UPPER CASE and my comments in lower case but a lot of folks do the reverse. You are limited only by your sense of style and propriety. OK, so far we have our F-specs, our D-specs, and no C-specs, but we do have /Free and /EndFree coded up with nothing in column 6. You with me, sport?

Page 2

/Free Tutorial 1

Shirey Consulting Services

Fig 1 - /Free Program Start. Remember, the /end-free at the end is optional and the *INLR is required.

Page 3

/Free Tutorial 1 /Free Syntax 2 Now we are ready to code some /Free stuff.

Shirey Consulting Services

Unlike fixed format where you have a C in column 6 and can put an * in column 7, you can never put anything in columns six or seven for /Free. And that includes the markers for comments when we get to that point. So, just keep it in mind nothing ever goes in columns 6 or 7 (except for the /Free and /End-Free junk). So, lets start by putting in an EVAL statement. Remember, there is no MOVE support in /Free (take a couple of deep breaths now, bend at the waist, youll get past it) and so you have to use the EVAL. Create a D-spec field, say dave with a 10 alpha picture (because the other thing you cant do in /Free is to define fields on the fly, but thats OK because that was bogus too). Now lets enter the EVAL statement EVAL DAVE = Nice Guy; Lets start it in column 8 because that is the left most column we can use so just type it in. You can really start this in any column 8 or higher but I like to start as far left as I can so I can indent. Notice that there are no extra spaces in this statement, no positional requirements. Of course, there could be extra spaces, like if you had a series of EVALs and you wanted the equal sign to line up. No positional requirements. You can also write it without the EVAL. No, Im totally serious, dude, the compiler is that smart. And you dont have to capitalize DAVE either. I just like emphasizing it. DaVe = Nice Guy; The last thing you need to do then is put a semicolon after the statement. Every single statement in /Free has a semicolon at the end, even ELSE and things like that. In the beginning it will be hard but pretty soon youll get used to it and then youll say things like Im going to the store, semicolon when you talk. You want to try to avoid that. Finally, we better put on the LR indicator and I will tell you straight up that the old SETON with the LR in the HI column doesnt work in /Free. Instead, just use a simple EVAL (EVAL LR = *ON;) or even (LR = *ON;). Now at this point I want you to go ahead and compile this program. Yeah, I know its one line but that just means it wont take too long. If you get errors then boy you are really stup . . . er, I mean I bet the problem is you have something in column 6 or 7 somewhere. Or you forgot the semicolon. Or something really dorky like that. Get a clean compile and then well continue. Im going to fix myself a highball.

Page 4

/Free Tutorial 1

Shirey Consulting Services

Fig 2 - /Free Syntax

Page 5

/Free Tutorial 1 Comments

Shirey Consulting Services

Now that we have a line of code, lets enter some comments. After all, some people may want a bit of an explanation for anything that equates Dave with Nice Guy. Comments are always preceded by two slashes; //. You can start them anywhere on the line (after columns six and seven, of course) and so you can either put your comments above or to the right of the code. // Initializing fields. Eval dave = Nice Guy;

Eval dave = Nice Guy;

// An obvious blatant lie.

You can do it either way. It doesnt matter to me. I mean why should I care? No, live and let live, thats my motto. I dont interfere. Its just that I think, based on my own personal preferences and certain divine truths that have been revealed only to me, that its much better to put the comments above. One of the beauties of /Free is that it makes the code so much more readable, theres more white space. Putting comments to the right of it makes it harder to read. Plus the comment lines are so short. But it really doesnt matter to me. Do what you damn well please. You will anyway.

Fig 3 - /Free with some comments

Page 6

/Free Tutorial 1 The End

Shirey Consulting Services

At this point I think you should recompile. God help us if you get errors putting in a comment (although Ive done it on a couple of occasions but I like to think of myself as an extraordinary exception). Done? Congratulations, you are now a /Free programmer. Add it to your resume, ask your boss for a raise. What? The IF statement? Oh yeah, youre right, that might be helpful. OK, if you insist, always good to know a few advanced /Free functions like the If and the Else and all that. The next tutorial will look at program logic statements.

Questions or Comments?

For more information on how/Free can help you, contact Shirey Consulting Services at 616-452-6398 or support@shireyllc.com.

Page 7

You might also like