c# call as400 program with integer parameters

I'am developing a c# program that need to call as400 program using the cwbx.dll from IBM V7R1. When the program is executing, ocurred an error when set parameter value that in item structure field. This field has to receive integer value N(8,0), converted into an byte array.

For example:

cwbx.Program program = new cwbx.Program();
program.LibraryName = "LIBRABRY";
program.ProgramName = "APINAME";
program.system = system;

ProgramParameters parameters = new ProgramParameters();
parameters.Append("Param", cwbrcParameterTypeEnum.cwbrcInout, 609);

var itemStruc = new cwbx.Structure();
itemStruc.Fields.Append("InputField", 8);

int inputFiled = 4431567;
string inputFieldString = inputFiled.ToString();
var packedConverter = new cwbx.PackedConverter();
packedConverter.DecimalPosition = 0;
packedConverter.Digits = 8;
itemStruc.Fields[parameterName].Value = packedConverter.ToBytes();

The error happens at the last line (bold one) and the message is :

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in TestAS400APIConsoleApp.exe
Additional information: CWB8602 - The property Value is not correct.

Could anyone help me to explain why this error ocurred?

Who is Participating?
Gary PattersonVP Technology / Senior Consultant Commented:
I re-read the initial question.  Even if you fix the C# problem, you're going to have trouble if the IBM i program is expecting an integer.

PackedConverter doesn't create an integer value - it creates a packed decimal value - a completely different numeric format.  If the receiving program on the IBM i really is expecting an integer, then this isn't they way to do it.

In ILE RPG, here are the different Integer types:

byte -  3I 0  (1-byte integer)
short-  5I 0  (2-byte integer)
int  - 10I 0  (4-byte integer)
long - 20I 0  (8-byte integer)

Use cwbx.ShortConverter for short integers, and cwbx.LongConverter for long integers.
MurpheyApplication ConsultantCommented:
What i understand is that you try to call the program with value 4431567, the number of digits id 8, so try to add a leading zero to make the input var also 8 digits.
But I advise, never use numeric parms for as400 parms, make them character...
Gary PattersonVP Technology / Senior Consultant Commented:
Maybe I'm missing something, but I don't see where you assigned a value to packedConverter.  (Also don't see where you assigned a value to parameterName for that matter).
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.