Skip to content

Instantly share code, notes, and snippets.

@kfeoktistoff
Created February 24, 2016 16:33
Show Gist options
  • Save kfeoktistoff/5b3aa19f1aa1feb0607d to your computer and use it in GitHub Desktop.
Save kfeoktistoff/5b3aa19f1aa1feb0607d to your computer and use it in GitHub Desktop.
Parsing SAP BO (blx) file, saving folders, dimensions and measures in csv file. To get bxl file, add .zip to the end of business layer file and extract blx file inside the archive. This extraction path should be used as an inputFile.
import xml.etree.ElementTree as ET
inputFile=open('C:/tmp/input.blx', 'r')
outputFile=open('C:/tmp/output.csv', 'w+')
separator = ','
def isDir(elem):
return elem.attrib.get('xsi:type') == 'business:Folder'
def isDimension(elem):
return elem.attrib.get('xsi:type') == 'business:Dimension'
def isMeasure(elem):
return elem.attrib.get('xsi:type') == 'business:Measure'
def isDimensionOrMeasure(elem):
return isDimension(elem) or isMeasure(elem)
def printFolderCsv(directory, path):
currentPath = list(path)
currentPath.append(directory.attrib.get('businessName'))
writeOutput('F', currentPath)
for child in directory:
if isDir(child):
print(child.attrib.get('businessName'))
childPath = list(currentPath)
printFolderCsv(child, childPath)
elif isDimensionOrMeasure(child):
childPath = list(currentPath)
childPath.append(child.attrib.get('businessName'))
writeDimOrMes(child, childPath)
return
def writeOutput(type, path):
str = '"' + type + '"'
for i in reversed(path):
str += separator + '"' + i + '"'
outputFile.write(str + '\n')
def writeDimOrMes(child, path):
if (isDimension(child)):
writeOutput('D', path)
else:
writeOutput('M', path)
root = ET.parse(inputFile)
result = ''
for elem in root.findall('./*/businessItems'):
if isDir(elem):
printFolderCsv(elem, [])
elif isDimensionOrMeasure(elem):
writeDimOrMes(elem, [])
@kfeoktistoff
Copy link
Author

Hello,

You're right, the parser works with older version of SAP BO. Since 4.1 the format is binary and the script doesn't work any more

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment