I have structure as below in C# which is equal to Cobol Copy book structue
Cobol copy book structure:
01 SOS-INPUT-PC50181.
05 CUST-NO-PC50181 PIC X(07).
05 CUST-TYPE-PC50181 PIC X(01).
88 CASH-CUST-PC50181 VALUE "C".
05 END-USE-CODE-PC50181 PIC X(02).
05 EQUIP-MFR-MODEL-PC50181 PIC X(10).
05 ORD-QTY-PC50181 PIC S9(05).
i am converting Csharp struct above byte of arry to pass it to Cobol program
using below code:
after converting above struct to byte array i passing it to cobol program, in cobol program input values are not placeing for each feild ie. customer number has only 6 chars and other values are missing and quantity field is displaying as "illegal value in field".
Please help to map the values to cobol understanding values.
Code:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)]
public class InputStruct
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 7)]
public string CustomerNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
public string CustomerType;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
public string EndUseCode;
[MarshalAs(UnmanagedType.I4, SizeConst = 5)]
public string Quantity;
}
01 SOS-INPUT-PC50181.
05 CUST-NO-PC50181 PIC X(07).
05 CUST-TYPE-PC50181 PIC X(01).
88 CASH-CUST-PC50181 VALUE "C".
05 END-USE-CODE-PC50181 PIC X(02).
05 EQUIP-MFR-MODEL-PC50181 PIC X(10).
05 ORD-QTY-PC50181 PIC S9(05).
i am converting Csharp struct above byte of arry to pass it to Cobol program
using below code:
Code:
public static byte[] StructureToByteArray(object obj)
{
int Length = Marshal.SizeOf(obj);
byte[] bytearray = new byte[Length];
IntPtr ptr = Marshal.AllocHGlobal(Length);
Marshal.StructureToPtr(obj, ptr, true);
Marshal.Copy(ptr, bytearray, 0, Length);
Marshal.FreeHGlobal(ptr);
return bytearray;
}
Please help to map the values to cobol understanding values.
Comment