I am going to assume that you know what Procedures and Subprocedures are. Below I am going to give the three most common ways I use Procedures and Subprocedures. I prefer the simpler looking code I gave in the first example as, in my opinion, it is easier to understand. In this next example I am using a Subprocedure like a subroutine, to validate a date. The old way would look like below.
Below is the equivalent with free definitions. In this example I am going to execute a procedure, ValLineNbr, to validate that the alphanumeric line number is numeric and if the field is numeric return the line number as a number. And below is the free format version.ILE Concepts in RPG - Part 1 - Sub Procedures and Modules - yusy4code
This is what it looks like in fixed format:. For more details about how to define a data structure see here. And now for the Procedure itself.
The fixed format version has the starting Procedure specification P-specline 5, and ending P-spec, line The Procedure interface is coded on lines 6 and 7. As I said before there are many other ways to code and use Procedures. If you have a method you would like to share please do not post it in the comments, as the formatting in that section will make it look strange.
Contact me through the Contact Formon the right, and I will send you an email with my address. If you send me your example in an email I will include it method in a new post. I mostly use procedures instead of subroutines now. Some of the real power of this method is to use it in conjunction with RPG modules.
Modules allow you to create multiple use objects similar to copybooks without the overhead. I think this great that IBM finally made free form for the "D" specs. Although, I don't know when I will be able to experiment with the code as I have been out of work for a long time I am in the Chicago area where the companies existbut work is scarce.
Just as it is in CL. The code here is not particularly inviting, and I think that is because it is not arranged at all. It is actually much prettier and easier to read when the field descriptions line up, and I don't think this is due to strangeness. I get the same reaction from users on screens; they look better lined up.Midware Ltd. Sign-up for e-mail notifications.
Take our weekly poll. Service programs are a very powerful component of the ILE environment. A service program allows a program to reference a module dynamically rather that statically. One or more modules are used to create a service program. In our example, we're going to create a service program using our one procedure module.
We'll give the service program the same name as the module which has the same name as the source member. A service program can kind of be thought as a collection of modules, which in turn has a collection of procedures.
Now, we're going to create the program using the mainline module and the service program. The entry module defaults to the first and only module. The program will be created with a reference to the service program, rather than an actual copy of it. Sometimes this is called bind by reference vs.
Because of the bind by reference, the program object is smaller than if it were bind by copy. Each time the program is called, all references to service programs will be resolved and the current version of the service program, modules and procedures will be copied into memory. Obviously, the main advantage this provides is that when the modules need to be changed and re-compiled, only the service program needs to be changed.
The next time the program object runs, the new version of the service program will be retrieved. In this sense, a service program is very similar to an externally called program, while retaining the benefits of ILE procedures.
The only significant disadvantage dynamic binding has over static binding, is that service programs do take some extra resources to resolve references at run time vs. This extra overhead should be irrelevant however compared to the maintenance benefits provided.
The only exception to this is if a program that uses a service program is called several hundred times online of thousands of times in batch. If this is the case however, you could make a strong case for moving PGM2 to a procedure and including it in a service program as well. It is up to your discretion whether you use bind-by-reference or bind-by-copy. However, my opinion is that bind-by-reference should always be used.
When a program is bound to a service program, it is bound to the signature as well. If new procedures are added to the service program, or exports are re-arranged, a different signature will be generated.Someone said to me that the reason that they will not use totally free RPG is they cannot call programs using it.
RPG example: Talk to a Webservice and store reply XML or JSON in IFS
In the earlier flavors of free format RPG they could just switch from free format to fixed to do the call, and return to free format afterwards. Therefore, the approach used above is not possible. For some time there has been alternative method to call programs using, what I call, external program procedure calls. This method even predates free format definitions. But I am just going to discuss how to do this in totally free format.
In the declare procedure prototype definition, DCL-PRthere is a keyword I can use to indicate that this procedure is really an external program. This allows me to call the external program just like any procedure. Let me get straight to the code:. Line 2: My standard control options I use in every program. Lines 3 — 7: This is the procedure prototype definition for my external program.
Sample Service Program - IBM - RPG
I will show an example of the program and procedure names being different later. Lines 4 — 6: These are the three parameters that will be passed and returned to and from the external program. In this example I have given them names, which I normally don't do as I cannot use these as variable names later in the program.
Lines 8 — These are the definitions of the variables I will be using to pass and return from the procedure. Line The external program can change the values in the parameter variables, that I can then use. One advantage of using subprocedures is that I can define a procedure within it that remains "local", i. If I am only going to call an external program from within a subprocedure I can define the procedure prototype with the subprocedure, rather than at the top of the program.
Line 2: I am going to call the same program as before, but this time I am giving it a procedure name, OtherPgm1Returnsthat is different from the program name. Lines 3 — 5: This time I am not going to give the parameters names. If the program I am calling does not require parameters to be passed I can define a procedure prototype without any parameters, and call the procedure with no parameters. In these examples the parameters in the procedure prototype definition have extra keywords on them.
Why would I want that? As the examples shown on lines 7 — 11 I don't have to use a variable to pass a value to the external program. I can just pass the value. I tend to do this for two reasons:.
A Practical Way to Add Exports to a Service Program
It just a case of personal preference, I prefer to do it this way. If you don't then you don't have to. But I can use a variable in the EXTPGM keyword, which allows me to call multiple different programs using one procedure prototype definition. Which is the same as using a variable name in the CALL operation code.
Line 6: When I call the procedure it calls the program's name that is in the variable PgmName. I hope that this post, and the examples contained within, will convince the person I mentioned in the first paragraph, and anyone else who has used the same excuse, that it is possible to call a program in totally free RPG.
Now there is no reason why they should not start coding using totally free format. This article was written for IBM i 7. It brought advanced features to handle many aspects of business logic and the ability to connect with many other languages. Unfortunately, one of my previous supervisors continuously discouraged me from and relentlessly harassed me for using the advanced features of this beautiful language simply because he could neither comprehend nor adapt to the evolving nature of ILE-RPG and the advanced features of embedded SQL.The following figure combines all the specifications used in this program.
This is what you should enter into the source file for this program.
Accessing Externally Attached Devices. Example Of An Interactive Application. Ibm - Rpg Interview Questions. Ibm - Rpg Practice Tests. IT Skills. Management Skills. Communication Skills. Business Skills. Digital Marketing Skills. Human Resources Skills. Health Care Skills. Finance Skills. All Courses. All Practice Tests. Ibm - Rpg Tutorial. Job Recommendation Latest.
Jobs in Meghalaya Jobs in Shillong. View All Locations. How to design your resume? Have you ever lie on your resume? Read This Tips for writing resume in slowdown What do employers look for in a resume?
Interview Tips 5 ways to be authentic in an interview Tips to help you face your job interview Top 10 commonly asked BPO Interview questions 5 things you should never talk in any job interview Best job interview tips for job seekers 7 Tips to recruit the right candidates in 5 Important interview questions techies fumble most What are avoidable questions in an Interview? Top 10 facts why you need a cover letter? Username Password.Most debates about binder language center around how signatures should be generated.
After hashing things out in the debate, most people settle on a single method: hard-coded signatures. This article explains why. When you create ILE modules, you have the option to declare subprocedures as exported or not exported.
This means only that a procedure is exported from the module. It does not mean that a procedure is exported from a service program built from this module. Binder language is coded in a separate source member from the rest of the service program. In this example, my service program will have three different procedures exported from it. If there are any other procedures with the EXPORT keyword specified, they will be available to other modules in the service program but not callable from the outside of the service program.
This is important because, under the covers, programs that are bound to my service program will always call the routines by number. For example:. A program that calls the startSomething procedure will do that by calling export 1.
Likewise, a program that calls the finishSomething procedure will call 3. Service program signatures are designed to protect you from mistakes in calling the wrong routine. Now you decide to add a new procedure named doSomethingMore. The ILE Concepts manual here are links to the 6. The idea is that the service program will now have two signatures; both of them will be generated by the system.
With this method, your service program will have two signatures, and both will be considered legal. The theory is that this protects you from mistakes as described in the previous section. Indeed, I find that this accomplishes nothing. As long as you know this and do it consistently, this will give you backward compatibility.
That was driving me crazy. It was deterring me from adding more subprocedures. My existing callers will work. Complete backward compatibility.ILE encourages modular programming. One might get overwhelmed with the key words, procedure, module, service program, binding etc. I will break down all those pieces and show the high level steps to stitch all together to create a single program.
When multiple programs are involved in a process, there are two ways you can call the other part of the process. C- Control — Program control. Control the flow.
It does validations and call the required business logic. Business logic is the place where we keep our business logics such as credit, pricing or item validation etc. In a regular OPM approach, every process, order entry, billing will have the credit logic incorporated in that program separately. One might miss one process, holding the old logic. Here the ILE concept helps to keep the business logic in one place and used by many other programs.
So when the logic changes, IT has to change it in only one place. Let me break it down and keep it simple. You can not use a subroutine out of a program. Whereas, we can place many subprocedures under one module and it can be called from any other programs. All prototype and PI interfaces can be placed in a single module with NOMAINand ever procedure can be accessed from outside program from multiple places.
Step 1- Create a module- place PR and PI or any other business logic as well if needed and create a service program. Next, when we have lot of service programs or module, it may be tough to remember all to include during the compile time. You can handle it in two way. Use option 5 or 9 to work with the directory where you can add any module or service programs.
You are commenting using your WordPress. You are commenting using your Google account. You are commenting using your Twitter account.
You are commenting using your Facebook account. Notify me of new comments via email. Notify me of new posts via email. How to utilize the ILE concept?Service program is one of the important concepts in RPGLE and if you understand it completely, then you can leverage its modularity to write reusable components at ease. Let us see that in this article. Please go to the article, Service Programs and its importance in RPGLE — Part 2 to understand technically about a service program or to get answers for the below questions.
What is a service program? A Service program is a collection of procedures, modules, binding directories, and other service programs. These objects can be reused by binding the service program in whatever application that needs them. That is, for easy understanding, you can assume the service program as an improved version of the regular program object. In the regular program, we will be writing subroutines which will be used only within that program.
But the difference is, you cant call a service program directly. You can only invoke the export procedures in it. Instead of writing independent procedures, you can also write independent programs and can reuse it.
So, why you need to go for service programs? Because the service program is bound by reference, the object size when compared to any ILE program is very small. We can have a separate service program for each and every application.
For example, if you are going to write a new finance application, then you can write all reusable calculations in procedures in a utility module and can bind that to a service program and use them anywhere in any program. The advantage of this is, for example, say we are having 10 procedures. Out of which, procedure1 and procedure2 are used in program1 and procedure 4 and procedure5 are used in program2.
If you are updating procedure1, then you have to update the service program and compile just the program1. You need not recompile the program2. This example just involves 2 programs. But the real-time scenario deals with a lot more programs and this will really be helpful in maintenance. It is easy to invoke any procedure exported in a service program just by binding the service program to any program.
You can ask that, we can create standalone programs for each and every reusable component so that it will be reusable and also easy to maintain. The answer to that is, it will be very difficult to maintain and organize all of them. There are many ways to address a single problem. You can choose whichever suits you the best. When you have to go for a service program? Whenever you are going to write a new application or whenever you are going to write a bunch of reusable utilities, you can go for a service program.
To leverage the benefits of the service program, you need to use the binder language. Else, you will miss the real power of it during maintenance.
If you are going to invoke any program multiple times, then you can write the program as a module and bind it in a service program. If you are going to write a program which is going to be used very rarely, then spending time on creating a service program, binder languages are unnecessary.
You can simply write a regular standalone ILE program. Binder source and its use in the service program Binder source, Binder language, Binding source are all same and used for version controlling of the service program. You can still create a service program without binder language. But eventually, you will be losing the power of easy maintenance.
Whenever you update the service program, a new signature will be auto-generated and will be stacked in the service program object for reference by any of the ILE program that uses the service program.
You can compare this with the common level check error. But in the service program, all the signatures will be maintained and if the signature present in the ILE program is not found in the available list in service program, then we get signature violation error.
How to create a service program?