MCH5003,标量错误 - ILE RPG

MCH5003, scalar error - ILE RPG

调用的程序入口:

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 子句上停止。

我真的想不通这是什么!

与调用方的 PI 相关的 dcl-ds document_ qualified based(parameterPtr); 在哪里?

我怀疑您应该按值传递指针,而不是 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 之前,另一个调用 PGM2 将八个参数中的第二个作为 char(91) 而不是 char(500) 传递。
没看到是因为它被定义为likeds(),那个DS应该是500字节长的。

谢谢@Charles。