you must use PR & PI
Please post your current *Entry plist
Hi all,
How do we get around coding a *ENTRY PList and use /free instead? Is there a way to do this with a prototype?
you must use PR & PI
Please post your current *Entry plist
All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Like Jamie said, pr and pi. Here's an example program (names of files and whatnot changed to protect the innocent):
to call this in free, you'd specify in the calling program:Code:hoption(*srcstmt:*nodebugio) hdftactgrp(*no) actgrp('mysqltst1') hthread(*serialize) hdatfmt(*iso) hbnddir('QC2LE':'JDBC') fsometbl uf a e k disk d conn s like(Connection) d rs s like(ResultSet) d MYSQLTST1 pr extpgm('MYSQLTST1') d usrid 15a const d pword 15a const d MYSQLTST1 pi d usrid 15a const d pword 15a const /copy inclib/qrpglesrc,jni /copy inclib/qrpglesrc,jdbc_h /free exec sql set option commit = *none; conn = jdbc_Connect( 'com.mysql.jdbc.Driver' : 'JDBC:MySQL://smtp.server.com/web_webserver' : %trim(usrid) : %trim(pword) ); if (conn = *null); return; endif; rs = jdbc_ExecQry(conn: 'Select * from stuff'); dow (jdbc_nextRow(rs)); stufid = (jdbc_GetCol(rs:1)); stuftitle = (jdbc_GetCol(rs:2)); stufstatus = (jdbc_GetCol(rs:3)); write sometblr; enddo; jdbc_freeResult(rs); jdbc_close(conn); *inlr = *on; /end-free
Hope that helps.Code:/free mysqltst1(var1:var2); /end-free
Andy
Edit:
For clarity, it should be noted that Var1 and Var2 on the call should match the usrid and pword of the called program.
Last edited by ARobb73; August 7th, 2012 at 02:21 PM. Reason: the usual... read it and facepalmed then fixed it to make more sense.
More specifically, create a PR & PI, with the name MAIN
If your program name is RPG123, you should code it as follows:
Add parameters as needed - and use like instead of defining length whenever possible.PHP Code:* Prototype for incoming parms - eliminates need for *ENTRY plist
D Main pr extpgm('RPG123')
D blah 2
* Prototype interface for incoming parms - eliminates need for *ENTRY plist
D Main pi
D blah 2
the name for the PR & PI don't really matter...what the PR & PI references is the value in the EXTPGM in this case. as long as the EXTPGM name is correct you can name the PR & PI BYTEME is you wish and it will be valid. but i suspect that with this thread being months old that the OP has been able to determine how to use prototyping for their purposes based on previous replies...
I'm not anti-social, I just don't like people -Tommy Holden
Can't remember when/where, but at some point in the past I remember reading that using MAIN as the name is not a good idea due to possible name collision or something as I recall. Ever since then, I've named it the same as the program name, so like this:More specifically, create a PR & PI, with the name MAIN
PHP Code:D RPG123 pr extpgm('RPG123')
D blah 2
I don't think 'MAIN' is a reserved word. NOMAIN you'd want to stay away from, but MAIN would be fine. It's generally easier to make it something more meaningful though (like Tom's example of BYTEME ... which I had to read about 3 times before it registered).
Ha! BYTEME... I didn't catch that at first either.
Anyway, sorry I didn't mean that MAIN is a reserved word. But if you always use MAIN as the prototype name for every program, it may at some point collide with another one... I think that's what I read. I always use the program name and it seems to work well, but maybe MAIN or BYTEME is ok too.
If it's reasonable that you might someday want to call the program from another RPG program, then you should put the prototype in a /copy file so callers call make a prototyped call. In that case, for sure you'd want to give it a unique and meaningful name.
If you know you'd never want to call the program from another RPG program, then starting in 7.1 you don't even need a prototype, and you can code the PI without a name. (Unless you use the MAIN keyword, in which case you do need a name for the main procedure, but you still don't need a prototype.)
Here's a complete working 7.1 program.
Prior to 7.1, you do need a prototype and you have to give the same name to the PI. But in that case, even when the prototype is internal, using the name MAIN just sets up a bad pattern that someone else might follow. Better to give even internal main prototypes a meaningful name.Code:D pi D name 10a const /free dsply ('Hello ' + name); return;
@Barbara,
Okay I'll bite: I agree not properly naming a prototype is a BAD idea.
So what would be the reason(s) the IBM development team would spent time to allow just that thing for 7.1?
All my answers were extracted from the "Big Dummy's Guide to the As400"
and I take no responsibility for any of them.
www.code400.com
Thanks to all who replied.
Yes, I realize this isn't a brand new thread, and that the OP may have already have figured it out - but because of the replies (from lots of familiar faces), I learned some new stuff.
For example - it never dawned on me to put each program that uses a PI instead of *entry PLIST in a /copy member - I've always just prototyped it within the program, and any programs that called it.
(Like many here), I do not have the "luxury" of bouncing ideas off of other programmers at my shop - I'm it. And when you're "it", sometimes it is hard to keep up with current syntax, trends, etc.
Once again, thank you - I just hope that I can give back to a community from which I've learned so much.
The intent of the 7.1 change was to make it easier to create local subprocedures by not requiring a prototype. Also to make it easier to create programs that are never called from RPG.
We realized that making prototypes optional could be misused. Naive programmers might code a procedure without a prototype in one module and then code the prototype in another module when they want to call it.
But naive programmers were already doing something similar. They were coding a procedure with a prototype in one module, and then copying the prototype into another module.
Our thinking was that forcing prototypes for all procedures, including non-exported procedures, wasn't particularly helping the naive (or sloppy) programmers who weren't using prototypes correctly. So we decided that it would be better to ease the coding experience for all the other programmers who do understand.
Basically, we can divide RPG programmers into three groups:
- Those who understand the purpose of prototypes and who use /COPY files appropriately
- Those who don't understand the purpose of prototypes so they code the same prototype in several modules
- Those who understand the purpose of prototypes but who code the prototype in several modules anyway
Not requiring prototypes for local procedures helps those in the first group who would rather not code prototypes for local procedures, or for programs that will never be called by another RPG module. And it doesn't hinder those in the first group who think it's a good idea to have prototypes anyway.
Not requiring prototypes doesn't particularly hinder the second group because they are already doing it wrong.
It's only the third group that's really affected. Not requiring prototypes in the module that defines the procedure makes it a bit easier for them to continue their sloppy ways. But a) we hope this group is vanishingly small and b) it's hard to care much about them anyway.
Dan, I read your post after I posted mine. Congratulations on moving from the second group to the first group!
If I'd read your post first, I might have been a bit more gentle on the second group that I call "naive". I hope everyone understands that I only mean "naive" in terms of using prototypes, not anything about their programming in general.
I didn't consider myself to be in the second group - I generally use /copy books for prototypes, have service programs, etc. But I guess for the case of converting from *entry to PI for entry parameters, I've been shown the error of my ways, and will correct accordingly.
![]()
Wow...interesting info in this thread.
First, let me state that I'm a COBOL'er and not very proficient in RPG, let alone the /FREE style. However, we have a few programs where the programmer jumps in and out of "/FREE" to define the parameter list used when the program is called from CL.
My Question: Are the PI/PR prototype methods shown above applicable for CL calls too?
to call them from RPG...yes. any program call can be prototyped
I'm not anti-social, I just don't like people -Tommy Holden
Sorry...maybe I didn't state it properly or don't understand your reply. I was referring to the calling of an RPG /FREE program from a CL program:
Based on the example above, would it look like this:Code:DCL VAR(&BRANCH) TYPE(*CHAR) LEN(12) CALL PGM(OE287E1) PARM(&BRANCH)
Code:D Main pr extpgm('OE287E1') D Branch 12
If your RPG program has a pi to match the pr you posted above, then yes you can call it from a CL just like that.
Thanks! Great to know...next time I'm doing maintenance there will be some changes made![]()
Given Terry's CL example, I would expect the 7.1 code to be as simple as:
In older releases you'd have to code:Code:D pi D Branch 12
Remember the idea here is to replace *ENTRY, he's not going CALL OE287E1, the call is comng from CL. That's why I campaigned IBM to release the PR restriction -- it's just duplicated and unnecessary code for stuff like this.Code:D Main pr extpgm('OE287E1') D Branch 12 D Main pi D Branch 12
Bookmarks