Search code examples
apiibm-midrangerpgle

How to create a new file member from an RPG-program?


I need to create a new member for an existing physical file in my RPG-program. I know of two ways, and I must say, that I like neither:

  1. use QCMDEXC to make a call to ADDPFM
  2. write an CL-program, that calls ADDPFM and call that from RPG

The first one involves cat'ing together a command that has to be parsed by QCMDEXC which does not sound to performant (I know, the expansive part here is not the call, but the creation of the member) -- but what bothers me really about it, is that I don't find it straightforward, but on the contrary hard to follow and not very aesthetic.

The second one uses a compiled program, so there is no concating and parsing involved. Also, it does not look that horrible in your RPG-code, because it is only one normal procedure call. But I'll have to create an extra external program, that need's to be transfered to all systems my RPG-program will be used on. It also kind of conflicts with my sense of aesthetics, creating an extra source and binary just to do one api call.

Is there a way to call the api directly, without QCMDEXC? Or maybe another RPGish way of creating a new member to a PF? Google was no help to me at all..

Thanks


Solution

  • There is no way to directly create a physical file member from within RPG.

    The options you listed are good. Another is the system() API. If this is a new app, try to avoid multiple members; they are not friends with SQL. Traditional multi-member apps use a wrapper CL to handle the ADDPFM and OVRDBF before calling the RPG:

    PGM &month
    DCL &month *char 3
    DCL &mbr *char 10
    chgvar &mbr ('SALES' *cat &month)
    addpfm sales &mbr
    monmsg...
    ovrdbf sales mbr(&mbr)
    call RPG_PGM
    endpgm
    

    Obviously, with more recent versions of RPG, we can do the overrides in the F specs. But there is still no way to manipulate file members directly from within RPG. I tend to write procedure wrappers for system() or QCMDEXC and put that in a service program so I can do OS-level work from within my RPG programs. If you prefer, write a specific ADDPFM procedure and call that 'API'.