Announcement

Collapse
No announcement yet.

What is the equivallent of a *Entry PLIST in /Free?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is the equivallent of a *Entry PLIST in /Free?

    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?

  • #2
    Re: What is the equivallent of a *Entry PLIST in /Free?

    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

    Comment


    • #3
      Re: What is the equivallent of a *Entry PLIST in /Free?

      Originally posted by Mike Lemon
      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?
      Like Jamie said, pr and pi. Here's an example program (names of files and whatnot changed to protect the innocent):
      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
      to call this in free, you'd specify in the calling program:
      Code:
       /free
           mysqltst1(var1:var2);
       /end-free
      Hope that helps.

      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 7, 2012, 01:21 PM. Reason: the usual... read it and facepalmed then fixed it to make more sense.

      Comment


      • #4
        Re: What is the equivallent of a *Entry PLIST in /Free?

        More specifically, create a PR & PI, with the name MAIN

        If your program name is RPG123, you should code it as follows:
        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 
        Add parameters as needed - and use like instead of defining length whenever possible.

        Comment


        • #5
          Re: What is the equivallent of a *Entry PLIST in /Free?

          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

          Comment


          • #6
            Re: What is the equivallent of a *Entry PLIST in /Free?

            More specifically, create a PR & PI, with the name MAIN
            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:

            PHP Code:
            D RPG123               pr                  extpgm('RPG123')
            D  blah                               2 

            Comment


            • #7
              Re: What is the equivallent of a *Entry PLIST in /Free?

              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).

              Comment


              • #8
                Re: What is the equivallent of a *Entry PLIST in /Free?

                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.

                Comment


                • #9
                  Re: What is the equivallent of a *Entry PLIST in /Free?

                  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.
                  Code:
                  D                 pi
                  D   name                        10a   const
                   /free
                        dsply ('Hello ' + name);
                        return;
                  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.

                  Comment


                  • #10
                    Re: What is the equivallent of a *Entry PLIST in /Free?

                    @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

                    Comment


                    • #11
                      Re: What is the equivallent of a *Entry PLIST in /Free?

                      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.

                      Comment


                      • #12
                        Re: What is the equivallent of a *Entry PLIST in /Free?

                        Originally posted by jamief View Post
                        @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?
                        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:
                        1. Those who understand the purpose of prototypes and who use /COPY files appropriately
                        2. Those who don't understand the purpose of prototypes so they code the same prototype in several modules
                        3. 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.

                        Comment


                        • #13
                          Re: What is the equivallent of a *Entry PLIST in /Free?

                          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.

                          Comment


                          • #14
                            Re: What is the equivallent of a *Entry PLIST in /Free?

                            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.

                            Comment


                            • #15
                              Re: What is the equivallent of a *Entry PLIST in /Free?

                              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?

                              Comment

                              Working...
                              X