Calling MV routines from COS routines

3 views
Skip to first unread message

Patrick

unread,
Jun 4, 2013, 1:46:29 PM6/4/13
to InterSy...@googlegroups.com
Hi, I was wondering if it is possible to call MV subroutines from within a Cache ObjectScript routine. e.g. .int
Thank you,
Patrick

Michael Cohen

unread,
Jun 4, 2013, 2:06:30 PM6/4/13
to InterSy...@googlegroups.com

Sure you can.  The syntax is:  DO ^routinename   or  DO ^routinename(args…)

 

MVBasic programs are compiled into Caché routines.  If you don’t specify the name, the system generates one.  An easy way to find the generated name is to CATALOG the program and look at the VOC entry.

 

Here is a sample TCL session.

MV:ED BP MYSUB

MYSUB

New record.

----:I

0001= SUBROUTINE MYSUB(ARG)

0002= CRT "IN MYSUB"

0003= CRT "ARG IS: ":ARG

0004= RETURN

0005=

Bottom at line 4.

----:FIBC

"MYSUB" filed in file "BP".

MYSUB

[B0] Compilation completed.

[243] 'MYSUB' Cataloged Local.

MV:CT VOC MYSUB

     MYSUB

0001 V

0002 MVB.15ýMV

0003 B

0004

0005

0006

0007 L

0008 MYSUB

0009 BP

0010 MV

MV:

MV:[D ^MVB.15("RED")

IN MYSUB

ARG IS: RED

MV:

 

Life i

 

Life is simpler if you use #PRAGMA to specify your routine name.

MV:ED BP MYSUB

MYSUB

4 lines long.

----:I #PRAGMA ROUTINENAME=MYSUB

0001: #PRAGMA ROUTINENAME=MYSUB

----:FIBC

"MYSUB" filed in file "BP".

MYSUB

[B0] Compilation completed.

[243] 'MYSUB' Cataloged Local.

MV:CT VOC MYSUB

     MYSUB

0001 V

0002 MYSUBýMV

0003 B

0004

0005

0006

0007 L

0008 MYSUB

0009 BP

0010 MV

MV:

MV:[D ^MYSUB("GREEN")

IN MYSUB

ARG IS: GREEN

MV:

 

Note that the program need not be CATALOGed in order for COS to execute it.

 

/Michael

--

Edward Clark

unread,
Jun 4, 2013, 2:06:42 PM6/4/13
to InterSy...@googlegroups.com
yep. mvbasic subroutines *are* Caché routines, and can be used in the same way that you use any other routine. The trick is knowing the name to use to call the routine.
 
The simplest way to call the routine is to use the MVCALL object script command. If you have an cataloged mvbasic program MYPROGNAME or subroutine MYSUBNAME, you just use the cataloged name:
  MVCALL MYSUBNAME(parm1,parm2)
  MVCALL MYPROGNAME
 
When you compile an mvbasic program, by default a generated name is used for the routine. This is done because generally, the names of mvbasic programs are often not valid routine names. You can see the generated name by looking at the VOC catalog entry. For a program MYPROG:
 
USER:CT VOC MYPROG
     MYPROG
0001 V
0002 MVB.2ýUSER

0003 B
0004
0005
0006
0007 L
0008 MYPROG
0009 BP
0010 USER
 
The routine name is MVB.2 in the USER namespace. The next routine compiled will become MVB.3. you could use this directly in objectscript:
  do ^MVB.2
or
  do ^|"USER"|MVB.2
but that wouldn't be a good idea because the name is generated. However, you can name the routine. In the mvbasic source, add:
  #PRAGMA ROUTINENAME=MYPROG
and the name MYPROG will be used in place of MVB.whatever. Then you can just
  do ^MYPROG.
 
Another way to call mvbasic from objectscript is to put the code into a class. Methods in classes can be written in mvbasic and then called just like any other method.
 


From: InterSy...@googlegroups.com [mailto:InterSy...@googlegroups.com] On Behalf Of Patrick
Sent: Tuesday, June 04, 2013 1:47 PM
To: InterSy...@googlegroups.com
Subject: [InterSystems-MV] Calling MV routines from COS routines

Hi, I was wondering if it is possible to call MV subroutines from within a Cache ObjectScript routine. e.g. .int
Thank you,
Patrick

--
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
To post to this group, send email to Cac...@googlegroups.com
To unsubscribe from this group, send email to CacheMV-u...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CacheMV?hl=en
---
You received this message because you are subscribed to the Google Groups "InterSystems: MV Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to InterSystems-...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages