Search code examples
c#apiibm-midrange

How to pass an array(*) of binary(4) parameter to IBM iSeries api in C#?


I am trying to retrieve the spool files in C# and i was successful on displaying most of the info in WRKSPLF in my program using the cwbx.dll.

However, turns out format SPLF0100 and SPLF0300 that i used are useless because the first one doesn't return some fields i need like dates, and the other one doesn't return the internal job and spool file identifier i need to use the QSPOPNSP API to actually read the file. So i need to use SPLF0200.

The problem is, that format requires you to pass an array(*) of binary(4) with the keys of the fields you want returned, and i don't know how to do that on C#. I saw a RPG example that uses a data structure like this:

IKEYARA      DS     (7)
I I            201                   B   1   40KEY1
I I            216                   B   5   80KEY2
I I            211                   B   9  120KEY3   
C                     CALL 'QUSLSPL'     (3)
C                     PARM           SPCNAM
C                     PARM 'SPLF0200'FORMAT  8   (4)
C                     PARM '*CURRENT'USRNAM 10
C                     PARM '*ALL'    OUTQ   20
C                     PARM '*ALL'    FRMTYP 10
C                     PARM '*ALL'    USRDTA 10
C                     PARM           QUSBN
C                     PARM           JOBNAM 26
C                     PARM           KEYARA      
C                     PARM 3         KEY#

So i tried to use cwbx.Structure to do the same:

Program programSpool = new Program();
programSpool.LibraryName = "QSYS";
programSpool.ProgramName = "QUSLSPL";
programSpool.system = system;

ProgramParameters parametersQuslpl = new ProgramParameters();

//nombre userspace creado anteriormente
parametersQuslpl.Append("usrspcnam", cwbrcParameterTypeEnum.cwbrcInout, 20);
StringConverter stringConverterUsrspcnam = new cwbx.StringConverterClass();
stringConverterUsrspcnam.Length = 20;
parametersQuslpl["usrspcnam"].Value = stringConverterUsrspcnam.ToBytes("FLEON     QGPL      ");
//tipo de formato a leer del spool
parametersQuslpl.Append("frmname", cwbrcParameterTypeEnum.cwbrcInout, 8);
StringConverter stringConverterFrmname = new cwbx.StringConverterClass();
stringConverterFrmname.Length = 8;
parametersQuslpl["frmname"].Value = stringConverterFrmname.ToBytes("SPLF0200");
//nombre de usuario del spool a bajar
parametersQuslpl.Append("usrnam", cwbrcParameterTypeEnum.cwbrcInout, 10);
StringConverter stringConverterUsrnam = new cwbx.StringConverterClass();
stringConverterUsrnam.Length = 10;
parametersQuslpl["usrnam"].Value = stringConverterUsrnam.ToBytes("*CURRENT");
//nombre de cola de salida
parametersQuslpl.Append("cola", cwbrcParameterTypeEnum.cwbrcInout, 20);
StringConverter stringConverterCola = new cwbx.StringConverterClass();
stringConverterCola.Length = 20;
parametersQuslpl["cola"].Value = stringConverterCola.ToBytes("*ALL");
//tipo de formulario
parametersQuslpl.Append("frmtyp", cwbrcParameterTypeEnum.cwbrcInout, 10);
StringConverter stringConverterFrmtyp = new cwbx.StringConverterClass();
stringConverterFrmtyp.Length = 10;
parametersQuslpl["frmtyp"].Value = stringConverterFrmtyp.ToBytes("*ALL");
//data de usuario
parametersQuslpl.Append("usrdta", cwbrcParameterTypeEnum.cwbrcInout, 10);
StringConverter stringConverterUsrdta = new cwbx.StringConverterClass();
stringConverterUsrdta.Length = 10;
parametersQuslpl["usrdta"].Value = stringConverterUsrdta.ToBytes("*ALL");
//error?
parametersQuslpl.Append("error", cwbrcParameterTypeEnum.cwbrcInout, 116);     
StructureClass sc2 = new StructureClass();
sc2.Fields.Append("bytesprov", 4);
sc2.Fields.Append("bytesavail", 4);
sc2.Fields.Append("messageid", 7);
sc2.Fields.Append("err", 1);
sc2.Fields.Append("messagedta", 100);     
parametersQuslpl["error"].Value = sc2.Bytes;
//nombre trabajo
parametersQuslpl.Append("nombretrabajo", cwbrcParameterTypeEnum.cwbrcInput, 26);
stringConverterUsrdta.Length = 26;
parametersQuslpl["nombretrabajo"].Value = stringConverterUsrdta.ToBytes("*                         ");
//keys
parametersQuslpl.Append("keys", cwbrcParameterTypeEnum.cwbrcInput, 103);

StructureClass keys = new StructureClass();
keys.Fields.Append("nombrearchivo", 10); //char10 201
keys.Fields.Append("usuario", 10); //char10 203
keys.Fields.Append("nombrecola", 10); //206
keys.Fields.Append("datosusuario", 10); //209
keys.Fields.Append("estado", 10); //210
keys.Fields.Append("paginas", 4); //bin 211
keys.Fields.Append("copias", 4); //bin 213
keys.Fields.Append("fecha", 7); //216
keys.Fields.Append("hora", 6); //217
keys.Fields.Append("idtrabajo", 16); //218
keys.Fields.Append("idarchivo", 16); //219*/
parametersQuslpl["keys"].Value = keys.Bytes;
//cantidad keys a devolver
parametersQuslpl.Append("cantidadkeys", cwbrcParameterTypeEnum.cwbrcInput, 4);
LongConverterClass LongConverterKeys = new cwbx.LongConverterClass();
        parametersQuslpl["cantidadkeys"].Value = LongConverterKeys.ToBytes(11);

However, i get the following error:

"CPF34C2 - Too many selection criteria specified."

Anyone has an idea on how to proceed?


Solution

  • If you take a look at the message detail using DSPMSGD...

    Cause . . . . . : When the qualified job name is specified as a selection
    criteria, the user name, form type, user specified data, and output queue
    name selection criteria must be blank.