PgmCall passing file DS with packed numerics as input

PgmCall passing file DS with packed numerics as input

Postby kenberg on Tue Jan 22, 2013 10:26 pm

We have a lot of programs that use a externally defined file as a DS when calling programs. These files can of course have numeric values that are packed. I have no idea how to make this work.

The file I am currently working with looks like
Code: Select all

Field                           
Name     Type Length  Dec  Loc   
GENNMWP    A     10          1   
ACC#WP     P      9    0    11   
ONEWONWP   P      4    0    16   
ONEPRZ#WP  P      3    0    19   
ONEPCTWP   P      2    0    21   
TWOWONWP   P      4    0    23   
TWOPRZ#WP  P      3    0    26   
TWOPCTWP   P      2    0    28   
THRWONWP   P      4    0    30   
THRPRZ#WP  P      3    0    33   
THRPCTWP   P      2    0    35   


The called program receives the values as a 46 byte string OK but when it tries to move to the DS get a decimal data error. This is no big surprise since when I looked at the incoming values the numerics were not packed.

I know I can use the AddParameterPackDec process for a normal parameter into a program but I am only passing one parameter so this does not sound like the correct way to handle.

I could create a wrapper but hoping to not have to.
kenberg
 
Posts: 10
Joined: Sun Jan 03, 2010 8:12 pm

Re: PgmCall passing file DS with packed numerics as input

Postby aseiden on Wed Jan 23, 2013 12:57 am

Hi, Ken,

Yes, with PHP toolkit version 1.4.0+ this task is easy to do.
If you don't already have this, you can install Zend's Toolkit update 12-12 from the Zend Server for IBM i download page.

Here's a sample script that should work for you. Just update the connection values, param values, and the pgmname and library.
Code: Select all
<?php
require_once('ToolkitService.php');

// connection options (may vary)
$conn = ToolkitService::getInstance('*LOCAL', 'myuser', 'mypass');

// stateless mode is easiest connection type when getting started
$conn->setOptions(array('stateless'=>true));

// ensure data structure hierarchy, naming, etc.
$conn->setOptions(array('dataStructureIntegrity' => true));

// create PHP array containing data structure elements
$ds[] = $conn->addParameterChar('both', 10, 'comment for GENNMWP', 'GENNMWP',  'mycharabcd');
$ds[] = $conn->addParameterPackDec('both', 9, 0, 'comment for ACC#WP', 'ACC#WP',  123456789);
$ds[] = $conn->addParameterPackDec('both', 4, 0, 'comment for ONEWONWP', 'ONEWONWP',  1234);
$ds[] = $conn->addParameterPackDec('both', 3, 0, 'comment for ONEPRZ#WP', 'ONEPRZ#WP',  123);
$ds[] = $conn->addParameterPackDec('both', 2, 0, 'comment for ONEPCTWP', 'ONEPCTWP',  12);
$ds[] = $conn->addParameterPackDec('both', 4, 0, 'comment for TWOWONWP', 'TWOWONWP',  1234);
$ds[] = $conn->addParameterPackDec('both', 3, 0, 'comment for TWOPRZ#WP', 'TWOPRZ#WP',  123);
$ds[] = $conn->addParameterPackDec('both', 2, 0, 'comment for TWOPCTWP', 'TWOPCTWP',  12);
$ds[] = $conn->addParameterPackDec('both', 4, 0, 'comment for THRWONWP', 'THRWONWP',  1234);
$ds[] = $conn->addParameterPackDec('both', 3, 0, 'comment for THRPRZ#WP', 'THRPRZ#WP',  123);

// add data structure as a parameter
$params[] = $conn->addDataStruct($ds, 'myPackDs');

// call program with params. Receive array of output params back.
$result = $conn->PgmCall('MYPGM', 'MYLIB', $params);

if ($result) {
    // output parameters after program call
    echo '<PRE>' . print_r($result['io_param'], true) . '</PRE>';
} else {
    echo 'Error calling program: ' . $conn->getErrorCode() . ' ' . $conn->getErrorMsg();
}

The output will resemble:
Code: Select all
Array
(
    [myPackDs] => Array
        (
            [GENNMWP] => mycharabcd
            [ACC#WP] => 123456789
            [ONEWONWP] => 1234
            [ONEPRZ#WP] => 123
            [ONEPCTWP] => 12
            [TWOWONWP] => 1234
            [TWOPRZ#WP] => 123
            [TWOPCTWP] => 12
            [THRWONWP] => 1234
            [THRPRZ#WP] => 123
        )

)
Ken, try and let us know if that does it.

--Alan Seiden
aseiden
 
Posts: 819
Joined: Thu Apr 09, 2009 5:45 pm

Re: PgmCall passing file DS with packed numerics as input

Postby kenberg on Wed Jan 23, 2013 10:53 pm

Alan you rock.

Worked well once I figured out a couple of syntax issues on my part. Your example worked without a flaw. Thank you....
kenberg
 
Posts: 10
Joined: Sun Jan 03, 2010 8:12 pm


Return to New Toolkit

Who is online

Users browsing this forum: longnoz and 2 guests