Re: Passing an as400structure in a ServiceProgramCall

David Gibbs via JAVA400-L <[email protected]> Sat, 2 Apr 2022 17:16:55 -0500
Newsgroups gmane.comp.lang.as400.java
Message-ID <CAEStNX=nyh9QfMSfgfg_nopi+HpfAd5Y-ej50niaD22Q3_4jYA@mail.gmail.com>
Use pcml. It handles memory allocation and is much easier to use.

On Sat, Apr 2, 2022 at 4:49 PM Pete Helgren <[email protected]> wrote:

> Tried and failed at this last fall but I am making another stab at it.
> I am calling a DCM API from Java
> ("/QSYS.LIB/QICSS.LIB/QYCDRNWC.SRVPGM")  The format is RNW0300. The part
> that I am struggling with is that one of the parameters is a structure.
> Like so (from docs):
>
> Required Parameter Group:
> 1    Certificate request data    Input    Char(*)
>
> 2    Length of certificate request data    Input    Binary(4)
>
> 3    Format name    Input    Char(8)
>
> 4    Error Code    I/O    Char(*)
>
> That first parameter is a structure (Format RNW0300). It looks like this:
>
> Offset
> Dec  Hex    Type               Field
> 0        0       Binary (4)      Offset to certificate path and file name
> 4        4       Binary (4)       Length of certificate path and file name
> Char (*)     Certificate path and file name
>
> I coded it in Java like so:
>
>    AS400DataType[] format = {
>    // 0 0 Binary (4) Offset to certificate path and file name
>         new AS400Bin4(),
>    // 4 4 Binary (4) Length of certificate path and file name
>         new AS400Bin4(),
>    // Char (*) Certificate path and file name
>         new AS400Text(certificate_path.length())
>    };
>
>    AS400Structure rnw0300 = new AS400Structure(format);
>
> Then I set the parameter like this:
>
>   // Set up the parms
>      ProgramParameter[] parameterList = new ProgramParameter[4];
>   // 1 Certificate request data Input Char(*) the structure for format
> RNW0300
>      parameterList[0] = new ProgramParameter(rnw0300.toBytes(new Object[]
> { 8, certificate_path.length(), certificate_path }));
>   // 2 Length of certificate request data Input Binary(4)
>      parameterList[1] = new ProgramParameter(new
> AS400Bin4().toBytes(rnw0300.getByteLength()));
>   // 3 Format name Input Char(8)
>      parameterList[2] = new ProgramParameter(new
> AS400Text(8).toBytes(apiFormat));
>   // 4 Error Code I/O Char(*)
>      ErrorCodeParameter ec = new ErrorCodeParameter(true, true);
>      parameterList[3] = ec;
>
> When calling the service program I get this error returned:
>
> AS400Message (ID: CPF9872 text: Program or service program QYCDRNWC in
> library QICSS ended. Reason code
> 2.):com.ibm.as400.access.AS400Message@b7566fbf
>
> The message description says this:
>
> Message ID . . . . . . . . . :   CPF9872
>
> Message file . . . . . . . . :   QCPFMSG
>
>    Library  . . . . . . . . . :     QSYS
>
>
>
> Message . . . . :   Program or service program &1 in library &2 ended.
> Reason
>
>    code &3.
>
> Cause . . . . . :   The specified program or service program was ended due
> to
>
>    one of the following:
>
>      1 -- A pointer was used that is not available for use while running
> in the
>
>    current program state.
>
>      2 -- A pointer was used, either directly or as a basing pointer, that
> has
>
>    not been set to an address.
>
>
> So it seems to indicate that a pointer isn't properly set.  Not sure
> which parameter it is complaining about but my guess is that it is the
> structure reference.
>
> Bit of a noob at this but it seems pretty simple.  Do you see anything
> that is radically wrong?  I couldn't find a good example of passing a
> AS400Structure as an input parameter....(perhaps my assumption that that
> is the issue is wrong)
>
> --
> Pete Helgren
> www.petesworkshop.com
> GIAC Secure Software Programmer-Java
> AWS Certified Cloud Practitioner
> Microsoft Certified: Azure Fundamentals
> Twitter - Sys_i_Geek  IBM_i_Geek
> --
> This is the Java Programming on and around the IBM i (JAVA400-L) mailing
> list
> To post a message email: [email protected]
> To subscribe, unsubscribe, or change list options,
> visit: https://lists.midrange.com/mailman/listinfo/java400-l
> or email: JAVA400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
> Before posting, please take a moment to review the archives
> at https://archive.midrange.com/java400-l.
>
> Help support midrange.com by shopping at amazon.com with our affiliate
> link: https://amazon.midrange.com
>
-- 
IBM i on Power Systems: For when you can't afford to be out of business!

I'm riding in the American Diabetes Association's Tour de Cure to raise
money for diabetes research, education, advocacy, and awareness.  You can
make a tax-deductible donation to my ride by visiting
https://mideml.diabetessucks.net.

You can see where my donations come from by visiting my interactive
donation map ... https://mideml.diabetessucks.net/map (it's a geeky thing).

I may have diabetes, but diabetes doesn't have me!
-- 
This is the Java Programming on and around the IBM i (JAVA400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/java400-l
or email: JAVA400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
Before posting, please take a moment to review the archives
at https://archive.midrange.com/java400-l.

Help support midrange.com by shopping at amazon.com with our affiliate
link: https://amazon.midrange.com