【问题标题】:MCH5003, scalar error - ILE RPGMCH5003,标量错误 - ILE RPG
【发布时间】:2017-05-19 19:30:10
【问题描述】:

被调用的程序入口:

dcl-pi PGM1;
  choice uns(3) const;
  returnCode likeds(returnCodeTpl);
  parameterPtr pointer const options(*nopass);
  parameterPtr2 pointer const options(*nopass);
  parameterPtr3 pointer const options(*nopass);
end-pi;

调用程序:

document.field1 = 'EL';
document.field2 = 'T';
document.field3 = 2780;

PGM1(1:returnCode:%addr(document));

document 定义(调用):

dcl-ds document_ qualified based(parameterPtr);
  field1 char(2);
  field2 char(1);
  field3 packed(7:0);
end-ds;

document 定义(在调用者上):

dcl-ds document qualified inz;
  field1 char(2);
  field2 char(1);
  field3 packed(7:0);
end-ds;

被调用的程序然后处理document DS,调用一个导出的过程:

select;
  ...
  when (1 = choice);
    myProc(document_);
  ...
endsl;

myProc 定义:

dcl-proc myProc export;

  dcl-pi *n ind;
    document likeds(document_) const;
  end-pi;

  dcl-s i int(5) inz;

  exec sql                    <--- Error appears there
    select count(field1) into :i from myFile
    where
      field1 = :document.field1 and
      field2 = :document.field2 and
      field3 = :document.field3;

  ...

  return i > 0;

end-proc;

myFile 字段在类型document 字段中相等。

不断出现的错误是MCH5003 - 标量错误。无效标量操作数的长度为 128。exec sql 子句上停止调试。

我真的不知道它是什么!

【问题讨论】:

  • 我并没有真正关注您的代码...但是您为什么要传递指针而不是变量?更不用说你通过引用传递指针......所以你实际上是在传递一个指向指针的指针。
  • 啊@Charles ...问我的老板。这个程序包含多个具有不同参数的程序,所以我不得不想办法处理它们。所以,指针和基于变量。
  • 无论如何,我应该澄清什么?

标签: pointers memory-leaks ibm-midrange rpgle


【解决方案1】:

dcl-ds document_ qualified based(parameterPtr); 与调用者的 PI 相关吗?

我怀疑您应该按值传递指针,而不是 CONST 引用...

dcl-pi PGM1;
  choice uns(3) const;
  returnCode likeds(returnCodeTpl);
  parameterPtr pointer VALUE options(*nopass);
  parameterPtr2 pointer VALUE options(*nopass);
  parameterPtr3 pointer VALUE options(*nopass);
end-pi;

但我仍然认为没有理由搞乱指针..

更新
我认为您不需要 3 个参数...您可以使用同一个指针定义多个 BASED(ptr) 变量。

dcl-pi PGM1;
  choice uns(3) const;
  returnCode likeds(returnCodeTpl);
  parameterPtr pointer VALUE options(*nopass);
end-pi;

dcl-ds doc1 likeds(doc1_t) based(ptr);
dcl-ds doc2 likeds(doc3_t) based(ptr);
dcl-ds doc3 likeds(doc3_t) based(ptr);

  ptr = parameterPtr;
  //all three DS are overlaying the same memory at this point
  // you have to make sure you only access the DS that corresponds to
  // the actual memory layout being used... 
  select;
    when (1 = choice);
      myProc(doc1);
    when (2 = choice);
      myProc2(doc2);
    when (1 = choice);
      myProc3(doc3);
   endsl;

【讨论】:

  • PGM1 包含多个“基于”的变量(一些指向第一个指针,一些指向第二个指针,一些指向第三个指针),并且对于每个“选择”,都可以通过调用特定的过程来使用它们。通过值传递指针,程序不是简单地创建了指针地址的副本吗?
  • 顺便说一句,发现这个话题很有趣。 archive.midrange.com/rpg400-l/200601/msg01022.html 感谢您的洞察力!
  • 问题是我不能将值传递给 RPG 程序。这仅对过程有效,@Charles
  • 是的,这是真的....对不起...没有点击您正在处理 *PGM。
【解决方案2】:

最后是参数传递错误。
在调用 PGM1 之前,对 PGM2 的另一个调用是将八个参数中的第二个作为 char(91) 而不是 char(500) 传递。
我没有看到它,因为它被定义为 likes(),并且 DS 应该是 500 字节长。

谢谢@Charles。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-06
    • 2022-04-20
    相关资源
    最近更新 更多