Use of "AS" keyword in Visual COBOL R4

[Migrated content. Thread originally posted on 07 June 2011]

Hi - We're currently testing Visual COBL R4 in our project. We are compiling a COBOL program that uses the AS keyword in a .NET C# method. These programs are working in a later version before (R3).

Example:
IF FORMAT-NAME = "FORMATNAME"
INVOKE CSHARP_CLASS::"CSharp_Method" (BY REFERENCE OBJ-COBOL AS CobolClass, BY REFERENCE RECORD)
END-IF


We get an error COBCH0919: An AS expression cannot be used as a receiving item

Any thoughts on this?



Thanks in advance! :)
  • Verified Answer

    I suspect the issue is that you are passing OBJ-COBOL by reference rather than by value. Passing BY REFERENCE means that the CSharpMethod can actually pass back a different object to the caller, making OBJ-COBOL a receiving item.

    Most parameters in the .NET world are passed by value rather than by reference, so unless you need to be able to pass back a different instance to the one being passed in to the method, change everything to BY VALUE and it should work OK.