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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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).
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.