5/6/2015 - 4:03 PM

Proposed code for automatically generating toolkit service params from RPG D specs

Proposed code for automatically generating toolkit service params from RPG D specs


$toolkit = new ToolkitService();

// Data to be passed to toolkit call
$data = array(
    'testLabel' => 'testValue',

// Build RpgSource object
$rpgSource = RpgSource::fromArray(array('MYLIB','QRPGSRC','MYRPGPGM'));

// Automatically generate params array from source member D specs
$params = $toolkit->GenerateParams($rpgSource, $data);

// Call program passing generated params array
$toolkit->PgmCall('MYRPGPGM', 'MYLIB', $params, null, null);

class RpgSource
    private $library;
    private $file;
    private $member;

    private function __construct(){}

    public static function fromArray(array $data)
        // Construct RpgSource object
        $rpgSource = new RpgSource;
        $rpgSource->library = $data[0];
        $rpgSource->file = $data[1];
        $rpgSource->member = $data[2];

        return $rpgSource;

    public function getLibrary()
        return $this->library;

    public function getSourceFile()
        return $this->file;

    public function getSourceMember()
        return $this->member;

class ToolkitService
    public function GenerateParams(RpgSource $rpgSource, array $data)
        // Use XMLSERVICE to retrieve the source member
        $sourceMember = $this->fetchSourceMember($rpgSource);

        // Parse RPG source file
        $parsedSource = $this->parseSourceMember($sourceMember);

        // Convert RPG D specs to PHP toolkit method calls
        $buildParamsCode = $this->generateParameterArrayFromSource($parsedSource, $data);

        // Initialize array for parameters
        $param = array();

        // Execute string as PHP code

        return $param;

    private function fetchSourceMember(RpgSource $rpgSource)
        // Fetch source member from cache
        $sourceMember = zend_shm_cache_fetch('rpgSource-'.$rpgSource->getLibrary().'-'.$rpgSource->getSourceFile().'-'.$rpgSource->getSourceMember());
        // If source member hasn't been stored in cache, retrieve it
        if (!$sourceMember) {
            // Use XMLSERVICE to retrieve source member
            //   cat mylib.lib/program.file
            // Retrieve library, source file, and source member via RpgSource::get*() methods
            // Store the source member in cache
            zend_shm_cache_store('rpgSource-'.$rpgSource->getLibrary().'-'.$rpgSource->getSourceFile().'-'.$rpgSource->getSourceMember(), $sourceMember, 24*3600);

        return $sourceMember;

    private function parseSourceMember($sourceMember)
        // Imitate parsing logic from D spec tool

        return $parsedSource;

    private function generateParameterArrayFromSource($source, $data)
        // Imitate conversion logic from D spec tool and inject/map values from $data

        return $paramsCode;

    public function pgmCall(){