简体   繁体   English

如何从RPG程序创建新的文件成员?

[英]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. 我需要为我的RPG程序中的现有物理文件创建一个新成员。 I know of two ways, and I must say, that I like neither: 我知道有两种方式,我必须说,我不喜欢:

  1. use QCMDEXC to make a call to ADDPFM 使用QCMDEXC来调用ADDPFM
  2. write an CL-program, that calls ADDPFM and call that from RPG 编写一个CL程序,调用ADDPFM并从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. 第一个涉及将一个必须由QCMDEXC解析的命令拼凑在一起,这听起来并不高效(我知道,这里的扩展部分不是通话,而是成员的创建) - 但真正困扰我的是什么关于它,是我不觉得它直截了当,但相反难以遵循,而不是很审美。

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. 此外,它在您的RPG代码中看起来并不可怕,因为它只是一个正常的过程调用。 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. 但我必须创建一个额外的外部程序,需要转移到我的RPG程序将被使用的所有系统。 It also kind of conflicts with my sense of aesthetics, creating an extra source and binary just to do one api call. 它也与我的美学感相冲突,创造了一个额外的源和二进制只是为了做一个api调用。

Is there a way to call the api directly, without QCMDEXC ? 有没有办法直接调用api,没有QCMDEXC Or maybe another RPGish way of creating a new member to a PF? 或者也许是另一种为PF创建新成员的RPGish方式? Google was no help to me at all.. 谷歌对我毫无帮助..

Thanks 谢谢

There is no way to directly create a physical file member from within RPG. 无法从RPG中直接创建物理文件成员。

The options you listed are good. 您列出的选项很好。 Another is the system() API. 另一个是system()API。 If this is a new app, try to avoid multiple members; 如果这是一个新的应用程序,请尽量避免多个成员; they are not friends with SQL. 他们不是SQL的朋友。 Traditional multi-member apps use a wrapper CL to handle the ADDPFM and OVRDBF before calling the RPG: 在调用RPG之前,传统的多成员应用程序使用包装器CL来处理ADDPFM和OVRDBF:

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. 显然,对于更新版本的RPG,我们可以在F规范中进行覆盖。 But there is still no way to manipulate file members directly from within RPG. 但是仍然没有办法直接在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. 我倾向于为system()或QCMDEXC编写过程包装器并将其放在服务程序中,这样我就可以在我的RPG程序中进行操作系统级别的工作。 If you prefer, write a specific ADDPFM procedure and call that 'API'. 如果您愿意,请编写特定的ADDPFM程序并调用该“API”。

To give some example of the QCMDEXC solution. 举一些QCMDEXC解决方案的例子。 If you just need some way within an RPG-program to create a member, and you don't want to add any additional (CL-)programs, this is a simple solution that does the job: 如果你只是需要在RPG程序中创建一个成员,并且你不想添加任何其他(CL-)程序,这是一个简单的解决方案,可以完成这项工作:

You can create a procedure crt_mbr like this: 您可以像这样创建一个crt_mbr过程:

 Pcrt_mbr          B
 D                 PI
 D lib                           10A   value
 D file                          10A   value
 D mbr                           10A   value
 Dqcmdexc          PR                  extpgm('QCMDEXC')
 D str                          200a   options(*varsize) const
 D len                           15P 5 const
 Dcmd              S            200A
 Dlen              S             15P 5
  /free
   cmd = 'ADDPFM FILE('+%trimr(lib)+'/'+%trimr(file)+') ' +
         'MBR(' + %trimr(mbr) +')';
   len = %len(%trimr(cmd));
   qcmdexc(cmd: len);
  /end-free
 Pcrt_mbr          E

It can look like this in v7: 它在v7中看起来像这样:

dcl-proc crt_mbr;
  dcl-pi *n;
    lib    char(10) value;
    file   char(10) value;
    mbr    char(10) value;
  end-pi;

  dcl-pr qcmdexc  extpgm('QCMDEXC');
    str    char(200) options(*varsize) const;
    len    packed(15:5) const;
  end-pr;

  dcl-s cmd    char(200) inz('');
  dcl-s len    packed(15:5) inz(0);

  cmd = 'ADDPFM FILE(' + %trimr(lib) + '/' + %trimr(file) + ')' +
        ' MBR(' + %trimr(mbr) + ')';
  qcmdexc(cmd: %len(%trimr(cmd)));
end-proc;

You might need to add the prototype at the beginning of your program (depending on your release): 您可能需要在程序开头添加原型(取决于您的版本):

 Dcrt_mbr          PR
 D lib                           10A   value
 D file                          10A   value
 D mbr                           10A   value

Know in your program you can just call: 在你的程序中知道你可以打电话:

/free
 ...
 crt_mbr('MY_LIB': 'MY_FILE': 'NEW_MEMBER');
 ...
/end-free

Please notice, that this has no error handling at all. 请注意,这根本没有错误处理。 So if eg the file allready contains a member of that name, your program will dump. 因此,如果文件allready包含该名称的成员,则您的程序将转储。 Add monitoring or different error handling as needed. 根据需要添加监视或不同的错误处理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM