RM/COBOL -- Passing Data to Cobol Program

HI - 

I have file that contains 1 record but the length of data can be from 2 chars to 700,000 chars.  I want to access such file in RM/COBOL program, ran via shell.

Neither FD section approach nor sending via LINKAGE section is working. Using XML  IMPORT FUNCTION. Is there any other oway to pass the data. Something like reading file in shell, pass address of data to cobol program, and   Cobol access via address if possible. [Looking for utilityC CRG or DARG].

  

  • 0

    Dear Swapnil,

    Is there any structure to the data?   You mention XML...does the data have XML markup?

    Or is this just a BLOB (binary large object)?

  • 0 in reply to 

    It is json document  .. with Multiple occurrences

  • Suggested Answer

    0 in reply to 

    I use a fairly simple PHP script to translate JSON to XML.  Here it is...

    <?php
    $file = 'php://stdin';
    $file = file_get_contents($file);
    $array = json_decode($file, true);
    // print_r($array);
    
    $dom = new DOMDocument('1.0', 'utf-8');
    $dom->preserveWhiteSpace = false;
    $dom->formatOutput = false;
    $root = $dom->createElement('root');
    $dom->appendChild($root);
    
    array2xml($array, $root, $dom);
    
    echo $dom->saveXML();
    
    function array2xml($array, $node, &$dom, $defaultName = 'rootItem')
    {
        foreach($array as $key => $value)
            {
            if(preg_match("/^[0-9]/", $key))
                // $key = "node-{$key}";
                $key = $defaultName;
            $key = strtolower(preg_replace("/[^a-z0-9_\-]+/i", '', $key));
            
            if($key==='')
                $key = '_';
    
            $a = $dom->createElement($key);
            $node->appendChild($a);
    
            if(!is_array($value))
                $a->appendChild($dom->createTextNode($value));
            else {
                $newDefault = (substr($key,-1) == 's') ? substr($key,0,-1) : ($key .  'Item');
                array2xml($value, $a, $dom, $newDefault);
                }
            }
    }
    ?>
    

    We had a major vendor shift from XML to JSON.  Documents were complicated.  This script works.

    Then, you create XSLT to import the output from the script.

    Good luck!

    Tom

  • 0 in reply to 

    thnxs Tom