CALL external .NET DLL
It is possible to use external .NET library files (DLLs) in your AMT-COBOL application. These external library files should be placed in the call directory specified in your Basepaths. When using external libraries, it is advised to also define an External Interface definition.
By default the library will be called by the same .NET version which runs AMT. To call the library with an older .NET version, the library must be added to either the Sys.ini parameter 'AMTCALLDLLNET48' or 'AMTCALLDLL'. See Configuring Sys.ini.
AMT-COBOL
To call .NET library files, you can write a CALL instruction in your COBOL code using the following syntax:
CALL '<Library File>.<Class>.<Method>' [USING <Parameter list> [RETURNING <Return Code Identifier>]]
Parameter | Description |
<Library File> |
The file name of the .NET DLL. |
<Class> |
The class name of the .NET Method. |
<Method> |
The method name of the .NET Method. |
<Parameter list> |
Parameters can be identifiers or literals separated by commas, specified in correspondence with
the parameter list that applies to the methode that is called. |
<Return Code Identifier> |
Optionally you can specify a Numeric Identifier to receive the Return code of the call. Instead of RETURNING, GIVING can also be used. |
Example:
working-storage section.
01 call-parameters.
02 call-param1 PIC 9(4).
02 call-param2 PIC 9(4).
02 call-returncode PIC
9(9).
procedure division.
001-start.
move 64 to call-param1.
move 42 to call-param2.
call 'CallTest.MathExample.Multiply' using call-param1, call-param2, by
value 3 returning call-returncode.
if call-returncode is zeroes
display call-param1
else
display 'Error:
' call-returncode
end-if.
stop run.
C# (.NET)
When writing the .NET Library there are a few things to keep in mind.
Besides defining the parameters specified in the AMT-COBOL CALL instruction, an Object must
be defined as first parameter. This object will be filled with information
about the AMT-COBOL application upon being called.
To return data to the AMT-COBOL program you can declare parameters by reference.
CallTest.dll Example:
using System;
namespace CallTest {
public class MathExample {
public void Multiply (Object parentCaller, ref int param1, int param2, int param3) {
param1 = param1 * param2 * param3;
} // Multiply
} // Class MathExample
} // Namespace CallTest