jhargett
6th February 2006, 17:34
I have had some success with this, so I thought I would pass it along. Especially since I got a lot of ideas from this board. This is a method I have used to integrate with Baan IVc4 without using OpenWorld or other (expensive) packages. You can actually write a Baan AFS script that can be called from the unix command line and pass data to it.
Here is the general flow of the process:
Create a simple ASCII file containing the data to modify Baan. I use a simple format that can be parsed easily by a Baan function. For instance, for sales order data, something like this:
HEAD|017605|5XA|2/01/2006
LINE|1|1001783|10
LINE|2|1001821|20
Each line can be parsed in Baan using the string.scan function.
At the Unix command line, you can now call a Baan AFS script that you have created. I wrote a small shell script to do this. What this code does is, call a Baan script with 2 arguments. The first is the path to the data file that you created in step 1, and the second is a path to a new file that Baan can use to write data to.
#/usr/bin/sh
# all BAAN and ORACLE env variables are set here
. /baan/bse/bin/baan.env
PATH=$BSE/bin:$PATH
export PATH
BASE_DIR=/apps/integration/so_integration
DATA_FILES=${BASE_DIR}/data_files
COMM_FILE=/tmp/soint_${$}.txt
echo ${COMM_FILE}
APP=$1
FILE=$2
CONO=$3
INPUT_FILE=${DATA_FILES}/${APP}/${FILE}
echo "Input file:${INPUT_FILE}"
echo "Executing Baan session"
echo "bshell6.1 -nodebug -server -set BSE_COMPNR=$CONO otdzls0201 $INPUT_FILE $COMM_FILE"
bshell6.1 -nodebug -server -set BSE_COMPNR=$CONO otdzls0201 $INPUT_FILE $COMM_FILE
echo "Baan session executed. Reading results..."
{ while read myline;do
echo $myline
done } < $COMM_FILE
rm $COMM_FILE
mv $INPUT_FILE ${DATA_FILES}/${APP}/processed/
The Baan script that is called is a 3GL program script in Baan with no form. This can be done in session ttaad2130m000 - Maintain Program Scripts. This script can contain normal AFS function calls. Make sure you create a function called main, this is the entry point for the script.
Here is a big piece of the puzzle, this main function can have arguments! Inside the main function, do this
// Baan 3GL code
string input_file(128)
string output_file(128)
| command line arguements
input_file = argv$(1)
output_file = argv$(2)
input_file is the ASCII file that you created in step 1. output_file will be a way for this script to communicate with the calling unix script.
In the this Baan script, parse the input file that you created and use AFS to insert the data in to Baan. Any data that you want to pass back to the calling unix script, you write to the output file using seq.puts()
That's it in a nutshell. More info on creating AFS scripts can be found all over this forum and there is also some info on calling Baan objects from the command line using the bshell. Really the only thing that I discovered (which may also have been published somewhere, so I probably can't even take credit for) is that you can pass arguments to the Baan script from the command line. This is the key to passing data to the function and returning what it did. Granted, it is not the easiest method in the world, but it is cheap!
Hope it helps,
Jon
Here is the general flow of the process:
Create a simple ASCII file containing the data to modify Baan. I use a simple format that can be parsed easily by a Baan function. For instance, for sales order data, something like this:
HEAD|017605|5XA|2/01/2006
LINE|1|1001783|10
LINE|2|1001821|20
Each line can be parsed in Baan using the string.scan function.
At the Unix command line, you can now call a Baan AFS script that you have created. I wrote a small shell script to do this. What this code does is, call a Baan script with 2 arguments. The first is the path to the data file that you created in step 1, and the second is a path to a new file that Baan can use to write data to.
#/usr/bin/sh
# all BAAN and ORACLE env variables are set here
. /baan/bse/bin/baan.env
PATH=$BSE/bin:$PATH
export PATH
BASE_DIR=/apps/integration/so_integration
DATA_FILES=${BASE_DIR}/data_files
COMM_FILE=/tmp/soint_${$}.txt
echo ${COMM_FILE}
APP=$1
FILE=$2
CONO=$3
INPUT_FILE=${DATA_FILES}/${APP}/${FILE}
echo "Input file:${INPUT_FILE}"
echo "Executing Baan session"
echo "bshell6.1 -nodebug -server -set BSE_COMPNR=$CONO otdzls0201 $INPUT_FILE $COMM_FILE"
bshell6.1 -nodebug -server -set BSE_COMPNR=$CONO otdzls0201 $INPUT_FILE $COMM_FILE
echo "Baan session executed. Reading results..."
{ while read myline;do
echo $myline
done } < $COMM_FILE
rm $COMM_FILE
mv $INPUT_FILE ${DATA_FILES}/${APP}/processed/
The Baan script that is called is a 3GL program script in Baan with no form. This can be done in session ttaad2130m000 - Maintain Program Scripts. This script can contain normal AFS function calls. Make sure you create a function called main, this is the entry point for the script.
Here is a big piece of the puzzle, this main function can have arguments! Inside the main function, do this
// Baan 3GL code
string input_file(128)
string output_file(128)
| command line arguements
input_file = argv$(1)
output_file = argv$(2)
input_file is the ASCII file that you created in step 1. output_file will be a way for this script to communicate with the calling unix script.
In the this Baan script, parse the input file that you created and use AFS to insert the data in to Baan. Any data that you want to pass back to the calling unix script, you write to the output file using seq.puts()
That's it in a nutshell. More info on creating AFS scripts can be found all over this forum and there is also some info on calling Baan objects from the command line using the bshell. Really the only thing that I discovered (which may also have been published somewhere, so I probably can't even take credit for) is that you can pass arguments to the Baan script from the command line. This is the key to passing data to the function and returning what it did. Granted, it is not the easiest method in the world, but it is cheap!
Hope it helps,
Jon