Read spool files from iseries in C#

I am trying to read spool files from iseries in C# with the cwbx library, to that avail i have read the api and called the QUSCRTUS API in order to create an user space and then QUSLSPL to fill the user space with my user's spool data.

So far so good, i can see the user space being filled with the info i need:

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   Ø0100SPLF0100QUSLSPL   1151007110852C   h   {   Y   ¢   ø   
    Ç       ì                                                    FLEON     QGPL      SPLF0100*CURRENT  *ALL                *ALL
      *ALL                                                                                                                     
                                           xxxxxxxxFLEON     *ALL                FLEON     QGPL                                
*ALL    *ALL                        FLEON     PRTCAJOD20QGPL      *STD      FLEON      i   ?» pà'e ®ø  G W   µià'wÇô}       FLE
ON     PRTCONT01 QUSRSYS   *STD      SIPD93     i   "ë q @ lÚ   èM´    ié@ÑÆ/-       FLEON     PRTINF01  QUSRSYS   *STD      HJ
PD05     i   ø  qÀ¦ü¶³}  D Õ   àiÀ¥] É\       FLEON     PRTVILLA05QUSRSYS   CHEQUES   FLEON      i   r  pø_ ½ ø   Õ'   ãiø_ j \
       FLEON     RGI462    QUSRSYS   *STD      CLPD741    i   h  ºmi)oNø  åÕ    ÏimýS Aµ       FLEON     PRTCON0206QUSRSYS   *S
TD      HJPD27     i   +¿ rk:ôá{{         ik:T  °       FLEON     PRTPACO   QUSRSYS   *STD      SIPD93     i   "ë q @ lÚ   Ñã· 
   i<º3 ê\       xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Open in new window


My problem is that i don't know how to call the QUSRTVUS API in order to read the user space. I don't want to call any service program or code something in the iseries, i want everything to be done in my C# application. When i call the api i only see some x's instead of the list entries i need to then call the final API to read the contents.

Here's the call i am doing:

                programPointer.LibraryName = "QSYS";
                programPointer.ProgramName = "QUSRTVUS";
                programPointer.system = system;

                ProgramParameters parametersPointer = new ProgramParameters();
                //nombre userspace creado anteriormente
                parametersPointer.Append("usrspcnam", cwbrcParameterTypeEnum.cwbrcInout, 20);
                stringConverterUsrspcnam.Length = 20;
                parametersPointer["usrspcnam"].Value = stringConverterUsrspcnam.ToBytes("FLEON     QGPL      ");
                //posicion
                parametersPointer.Append("posicion", cwbrcParameterTypeEnum.cwbrcInout, 4);     
                LongConverter packedCovertedPosicion = new cwbx.LongConverterClass();
                parametersPointer["posicion"].Value = packedCovertedPosicion.ToBytes(1);
                //longitud
                parametersPointer.Append("longitud", cwbrcParameterTypeEnum.cwbrcInout, 4);
                LongConverterClass packedConverterLongitud = new cwbx.LongConverterClass();
                parametersPointer["longitud"].Value = packedConverterLongitud.ToBytes(140);
                //receptor
                parametersPointer.Append("receptor", cwbrcParameterTypeEnum.cwbrcOutput, 4);
                programPointer.Call(parametersPointer);

                Structure sc = new Structure();
                sc.Fields.Append("userarea", 64);
                sc.Fields.Append("sizeheader", 4);
                sc.Fields.Append("structurelevel", 4);
                sc.Fields.Append("formatname", 8);
                sc.Fields.Append("apiused", 10);
                sc.Fields.Append("datecreated", 13);
                sc.Fields.Append("infostatus", 1);
                sc.Fields.Append("usersize", 4);
                sc.Fields.Append("offsetinput", 4);
                sc.Fields.Append("sizeinput", 4);
                sc.Fields.Append("offsetheader", 4);
                sc.Fields.Append("sizeheader", 4);
                sc.Fields.Append("offsetlist", 4);
                sc.Fields.Append("sizelist", 4);
                sc.Fields.Append("numberlist", 4);
                sc.Fields.Append("sizeentry", 4);
                sc.Bytes = parametersPointer["receptor"].Value;
                StringConverter datos = new cwbx.StringConverterClass();
                string dat = datos.FromBytes(sc.Fields["apiused"].Value);
                dat = datos.FromBytes(sc.Fields["datecreated"].Value);

Open in new window


I am using the SPLF0100 format. My problem could be that the API is expecting binary variables instead of char or integers, so i may not know how to properly convert the data in the parameters. I tried to use a structure as shown above but i don't know if the length of each field can be declared literally from the api, which shows each field type and size.

For reference, the api documentation is in http://www-01.ibm.com/support/knowledgecenter/ssw_i5_54/apis/qusrtvus.htm
Francisco LeonAsked:
Who is Participating?
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.

Francisco LeonAuthor Commented:
I can read from the receptor variable all variables that can be mapped to chars, such as "datecreated". I am just having trouble with the variables that are supposed to be binary, such as "numberlist"
0
tliottaCommented:
'Starting position' and 'Length of data' are both 4-byte (32-bit) binary integers.

Of more concern, though, might be that the content of the user space is going to be EBCDIC and including various printer controls, along with various binary integer values for lengths, offsets, etc. That means that you need to ensure that no EBCDIC/ASCII conversion happens when a buffer comes across the connection and that you process buffer data bytes accordingly.
0
Francisco LeonAuthor Commented:
Bah, i was able to fix it by myself. I had to use LongConverter in order to read the 4-byte values from the receptor. I don't know why, because int is 32 bits (4 bytes) and should be enough, but there isn't a "IntConverter" in the cwbx library. If you try ShortConverter or any other converter you wouldn't get any errors, just 0 in the variable. Also i set the receiving variable to size 140 to be able to hold most of the SPLF0100 format.

For reference, here is the code:

                ProgramParameters parametersPointer = new ProgramParameters();
                //nombre userspace creado anteriormente
                parametersPointer.Append("usrspcnam", cwbrcParameterTypeEnum.cwbrcInout, 20);
                stringConverterUsrspcnam.Length = 20;
                parametersPointer["usrspcnam"].Value = stringConverterUsrspcnam.ToBytes("FLEON     QGPL      ");
                //posicion
                parametersPointer.Append("posicion", cwbrcParameterTypeEnum.cwbrcInout, 4);     
                LongConverter packedCovertedPosicion = new cwbx.LongConverterClass();
                parametersPointer["posicion"].Value = packedCovertedPosicion.ToBytes(1);
                //longitud
                parametersPointer.Append("longitud", cwbrcParameterTypeEnum.cwbrcInout, 4);
                LongConverterClass packedConverterLongitud = new cwbx.LongConverterClass();
                parametersPointer["longitud"].Value = packedConverterLongitud.ToBytes(140);
                //receptor
                parametersPointer.Append("receptor", cwbrcParameterTypeEnum.cwbrcOutput, 140);
                StringConverter stringConverterReceptor = new cwbx.StringConverterClass();
                programPointer.Call(parametersPointer);

                Structure sc = new Structure();
                sc.Fields.Append("userarea", 64);
                sc.Fields.Append("sizeheader", 4);
                sc.Fields.Append("structurelevel", 4);
                sc.Fields.Append("formatname", 8);
                sc.Fields.Append("apiused", 10);
                sc.Fields.Append("datecreated", 13);
                sc.Fields.Append("infostatus", 1);
                sc.Fields.Append("usersize", 4);
                sc.Fields.Append("offsetinput", 4);
                sc.Fields.Append("sizeinput", 4);
                sc.Fields.Append("offsetheader", 4);
                sc.Fields.Append("sizeheader", 4);
                sc.Fields.Append("offsetlist", 4);
                sc.Fields.Append("sizelist", 4);
                sc.Fields.Append("numberlist", 4);
                sc.Fields.Append("sizeentry", 4);
                sc.Bytes = parametersPointer["receptor"].Value;
                
                //read two values, for example:
                StringConverter datos = new cwbx.StringConverterClass();
                string dat = datos.FromBytes(sc.Fields["userarea"].Value);
                LongConverter sco = new cwbx.LongConverter();
                long sco2 = sco.FromBytes(sc.Fields["sizeheader"].Value);

Open in new window


Perhaps LongConverter doesn't have a good name...
0

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
Francisco LeonAuthor Commented:
i fixed it myself
0
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
IBM System i

From novice to tech pro — start learning today.

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.