将大型机副本书转换为csv时,小数位置不会添加

时间:2016-04-30 13:03:09

标签: python mainframe

我正在尝试将大型机字帖转换为csv(仅限所有数据类型的长度),但小数位不添加。例如,假设$_r = FALSE * TRUE; // (0 * 1) if ($_r) ? print 'TRUE' : print 'FALSE'; // prints FALSE $_r = FALSE / TRUE; // (0 / 1) if ($_r) ? print 'TRUE' : print 'FALSE'; // prints FALSE $_r = TRUE / FALSE; // (1 / 0) if ($_r) ? print 'TRUE' : print 'FALSE'; // prints Warning: **Division by zero** col1。它将转换为总大小13,但预期输出应为13 + 7 = 20

S9(13)v9(7)

1 个答案:

答案 0 :(得分:1)

如果你可以使用python以外的语言, 其他几个选项包括

  1. JRecord有一个Cobol2Csv计划
  2. 查看Stingray Project。这是一个用于阅读Mainframe cobol数据的python项目
  3. 如果是Mainframe Cobol,请使用Cb2xml将Cobol-Copybook转换为Xml。 Cb2xml会为你解析Cobol,它会计算字段位置/长度/比例等。很容易将Cb2xml-Xml加载到python(或Ruby或JavScript等)中。您仍需要检查它是否为假定的小数(V图片)或实际的小数点(。)。
  4. 如果您准备使用Jython,则允许直接访问Java程序。
  5. e.g。在python中加载由cb2xml生成的xml

    tree = ET.parse('cbl2xml_Test110.cbl.xml')
    

    以下程序将打印Cobol copybok属性变为:

    ## Get an attribute if it exist otherwise return ''
    def getAttr(d, key):
        r=''
        if key in d.attrib:
            r = d.attrib[key]
        return r
    
    # Get attribute if it exists
    def getAttrId(d, key):
        r=''
        if key in d.attrib:
            r = key + '=' + d.attrib[key]
        return r
    
    ##########################################################################
    # Purpose: Print one item
    ##########################################################################
    def printItem(indent, item):
        n = indent + item.attrib['level'] + " " + item.attrib['name'] + "                                                                                    "
        n = n[:50]
    
        print n, '\t', item.attrib['position'], '\t', item.attrib['storage-length'], '\t', getAttr(item, 'display-length'), getAttr(item, 'picture'), getAttrId(item, 'usage'), getAttrId(item, 'numeric'), getAttrId(item, 'signed')
        for child in item.findall('item'):
        printItem(indent + "    ", child)
    
    #########################################################################
    
    tree = ET.parse('cbl2xml_Test110.cbl.xml')
    root = tree.getroot()
    
    print ">> ", root.tag, root.attrib['filename']
    
    for child in root.findall('item'):
        printItem("  ", child)
    

    使用过其他语言的cb2xml的人的一些例子

    注意:我写过JRecord并维护cb2xml