Can I use /free without an /end-free in rpgleref source?

871 Views Asked by At

I am writing a set of programs that create, write and compile a set of SQLRPGLE programs. A lot of the code at the beginning of my program is repeated in every program I have, so it makes sense for me to put this into a reference source ... it is roughly of the form

    H some h specs
    D a load of d specs

    /free
       my nice free formatted code that I use everywhere

Then my metaprogram comes along and adds lots of code. At this point my program looks like this

    /copy *libl/qrpgleref,myRefPgm

      lots of nice rpg and sql

    /end-free

When I compile this it doesn't work - I think this is because the program can't match up the /free and /end-free properly ... is that right? Or am I missing something more subtle here?

Cheers

3

There are 3 best solutions below

0
On

I think the reason your program isn't compiling, based only on the samples provided in your question, is because you have H and D specs mixed in with your free format calc specs. Order is important with RPG and you can't mess with that. If your copied code requires D and H specs, then you have two options:

  • Create a separate /copy source member for the H, D, and C (free format) specs. Then /copy them into your RPG program in the right places.
  • Create a *MODULE or *SRVPGM and then copy only the D specs for the prototype into your RPG program. Based only on what you posed in your question, I think the best solution is to create a service program. To make it easier to bind a service program to an RPG program, I like to create a binding directory and then place an H spec in my RPG program: H BNDDIR(library/bnddir). That way, I can still compile with a normal 14 in PDM.
1
On

I think you can, but why not add the /free and /end-free anyway just in case there is confusion or problems in the future?

0
On

Per the IBM ILE RPGLE Language Reference (SC09-2508-08)

Any statements that are included by a /COPY or /INCLUDE directive are considered fixed syntax calculations. Any free-form statements in a /COPY member must be delimited by the /FREE and /END-FREE directives.

Also note:

The free-form calculation block ends when you specify /END-FREE.

My recommendation is avoid /copybooks as much as possible.