justout
20th March 2003, 14:48
Hello,

I need to return a value from a 3GL call. I believe that

function main()
{
...
}

cannot return a value. Is this correct? Is there a way to return a value from a 3GL?

Secondly, if I have to pass a value to function main how do I do it?

Here is the code:

|***************************************************
|* whinh9999 0 VRC B50C c tst
|* Test
|* Script Type: 123
|***************************************************

function main(string temp(100))
{
mess(temp)
}

How do I invoke the object:

Just,

owhinh9999

does not work

Thanks a lot,
JO

zardoz
20th March 2003, 15:35
Why not use a DLL instead?

If you want to use a 3GL, you can also declare some external variables in both the calling and the called program and do import and export vars.

justout
21st March 2003, 06:03
Hi zardoz,

Thanks. I have to use a 3GL!

The requirement is that I invoke the 3GL from a shell script. The shell script will pass some values to the function main(string temp(100))

In that case, how do I do it?

Thanks,
JO

zardoz
21st March 2003, 10:54
Try this:

in the 3GL program:

extern string temp(100)
.....
function main()
{
.....
import("temp", temp)
mess("temp")
}
......

in the calling program:

extern string temp(100)
.....
export("temp", temp)
....


NB.: if you have to use only 50 chars, you can use the predefined variable free$, and you haven't to export or import it.

justout
21st March 2003, 11:28
Hi,

I got you but .. how can I invoke my 3GL from a shell script?

Thanks,
JO

zardoz
21st March 2003, 11:44
You can make a session (without forms and reports) which use the 3GL script and call the session with zoom.to function.
(I don't know in B50 if there is other solutions).

justout
21st March 2003, 11:46
Ok ... Thanks!

NPRao
22nd March 2003, 02:09
Hi JustOut/JO/Derek,

Please fill up profile with BaaN/OS/Database info.

Here is the solution-


|* First program script - zmadmtest
extern long ret.val
function main()
{
long procid
procid = activate("ozmadmnp", "Hello", "World", "Testing")
message("Procid=%d", procid)
import("ret.val", ret.val)
message("Return value=%d", ret.val)
exit(0)
}


|* Second program script - zmadmnp
extern long ret.val
function main()
{
long i
message("No. of args=%d", argc()-1)
for i = 1 to (argc() - 1)
message("Argument(%d)=%s", i, argv$(i))
endfor
ret.val = 2003
export("ret.val", ret.val)
}


This example shows how you can pass arguments to a 3-GL script and also get the return values.

I hope it helps you out.

justout
22nd March 2003, 05:45
Hi NPRao,

I need to invoke "ozmadmnp" from a shell script ... not another Baan program!
How should I do it?

Thanks and Regards,
Derek!

NPRao
22nd March 2003, 07:57
Derek,

Refer to the links on the board here -

Running session in background (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=8872&highlight=bshell6.2+server)

Running a Baan script from UNIX command line; ba6.1 runtime options (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=6850&highlight=bshell6.2+server)

ba6.1 max users reached on init (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=5951&highlight=bshell6.2+server)

rc.startjob doesn't work (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=5882&highlight=bshell6.2+server)

Run Baan function from script (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=5794&highlight=bshell6.2+server)

Running a Baan script from UNIX command line; ba6.1 runtime options (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=6850&highlight=ba6.2)

ba6.2 and bshell6.2 (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=537&highlight=ba6.2)

ba6.1 from a unix script (http://www.baanboard.com/baanboard/showthread.php?s=&threadid=403&highlight=ba6.1)

I need to invoke "ozmadmnp" from a shell script ... not another Baan program!

The big issue here is that you cannot send back any string or long return values to the ba6.2 or bshell6.2 executables. They do not seem to be handling that. In that case you have to use a file based error handling like generating a error file name as <script-code>.err

justout
22nd March 2003, 09:54
Hello NP,

I am still going through all the links. Thanks. But I had a question upfront.

What your are trying to saying is that I cannot return the value directly to the shell script from the Baan 3GL. Instead the 3GL has to store it to a "Result File" so to say and then get the shell script to read the file and interpret the value?

Can I at least pass the "Result File" name from the shell script to the Baan3GL. Then it is sure that the 3GL will create a file that the shell script knows? (The reason I want this is that there could be multipe parallel invocations so the "Result File" should be unique using some Timestamp or something.)

Am I making sense?

JO!

lbencic
24th March 2003, 17:59
I've had this problem before. You can create the return file inside your Baan script, giving it a unique name, then pass the name out when you call your shell script. Have the shell script use that for the output result.

justout
25th March 2003, 04:19
Hello lbencic,

Thank you for your reply. But actually I am going the other way. My process is:

Step 1
Invokes Invokes
Job Scheduler -----------------> Shell Script --------------> Baan3GL

Step 2

Baan3GL does processing and decides a result (Success/Failure). Since the Baan3GL cannot return a value, maybe the Baan3GL stores result in a file.

Step 3
Returns Creates
Job Scheduler <---------------- Shell Script <-------------- Baan3GL
Notification (Reads Result file
Result file
created by
Baan 3GL)

What I need is that the file created by the Baan3GL(child process) be unique and known to the particular instance of the shell script(parent process) that invoked it.

I am thinking on the lines of using PIDs. What do you guys think?

Regards,
JO!

justout
25th March 2003, 04:29
Ooops .. the previous post got garbled!

Hello lbencic,

Thank you for your reply. But actually I am going the other way. My process is:

Step 1

###########Invokes############Invokes########
Job Scheduler -----------------> Shell Script --------------> Baan3GL

Step 2

Baan3GL does processing and decides a result (Success/Failure). Since the Baan3GL cannot return a value, maybe the Baan3GL stores result in a file.

Step 3
#########ReturnsNotification########Creates Result file
Job Scheduler <---------------- Shell Script <-------------- Baan3GL
###################(Reads
###################Result file
###################created by
###################Baan 3GL)

What I need is that the file created by the Baan3GL(child process) be unique and known to the particular instance of the shell script(parent process) that invoked it.

I am thinking on the lines of using PIDs. What do you guys think?

Regards,
JO!

NPRao
25th March 2003, 04:39
JO,

You are very much on track. Refer to the $BSE/etc/rc.startjob and $BSE/etc/rc.startjobdm scripts and modify them for your requirements.

Other ideas to pass a file name from Unix shell script to BaaN 3-GL is to use Environment variables and read from the 3-GL the value of that environment variable by using - getenv$() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_system_and_user_information_getenv)

Typical shell scripts which generate the random files use the $$ for the process id or you can add the time stamping to the file name using the command - `date +%Y%m%d%H%M%S` so that you can get a unique file name as well as time-based sort-able file name.

the PID options which you can use in Unix are -

$$ - PID of current shell
$! - PID of the last background process

Good Luck!