Friday, October 29, 2010

Embedding MaxL in a here document

I am fortunate to be using Essbase in a UNIX/Linux environment.  I say this because I consider shell scripting, whether it be bash or korn, to be vastly superior to Windows DOS/batch files.  I've written hundreds of scripts in both environments and the bash/korn shell scripts are invariably easier to write, faster, and more maintainable.  The availability of here documents is just one reason why.  Let me explain.

UNIX/Linux shell scripts basically allow you to embed a string in a command.  In other words, you can call a command (essmsh in the example below) and pass a multi-line string to it.  Well, you may say, I can just have multiple calls to essmsh and achieve the same thing in my handy-dandy bat file.  Maybe, but it won't be as clean as using a here document.  Let me give a sample shell script to illustrate.

The below would reside in a shell script.  We'll call it 'sample.sh'.

#begin sample.sh

APPLICATION=Sample
DATABASE=Basic
DATA_FILE=dims.txt
RULES_FILE=dims
ERROR_FILE=dim_errors.txt

essmsh <<END
import database $APPLICATION.$DATABASE dimensions
from server text data_file $DATA_FILE
using server rules_file $RULES_FILE
on error append to $ERROR_FILE;
END

#end sample.sh


So you see, there's no need for passing parameters from a bat/cmd file to a mxl file.  You can set the variables at the beginning of your shell script and use them in the here document's string while passing them directly to the essmsh command.  You don't have to refer to another file with the MaxL to see what's going on (and maintain two files).  In addition, you don't have to contend with all the crazy double quotes versus single quotes nonsense in MaxL files.  Also, if you are making multiple calls to essmsh in your bat file, each instance is separate.  In other words, if you set a variable in your first essmsh call, it will not be available in subsequent calls.  Here documents neatly sidestep this problem, as you're only making one essmsh call.

To recap, a here document allows you to put both your variables and MaxL in a single file, making maintenance a breeze.  You'll also avoid most double quotes / single quotes issues in MaxL files.

What's not to like?

No comments:

Post a Comment