HP 3000 Manuals

ANYPARM Calls From HP Business BASIC/XL [ HP Business BASIC/XL Reference Manual ] MPE/iX 5.0 Documentation


HP Business BASIC/XL Reference Manual

ANYPARM Calls From HP Business BASIC/XL 

There are two methods of calling external procedures written to be called
by the ANYPARM method.  The first utilizes HP Business BASIC/XL's
EXTERNAL and CALL statements.  The second implements the underscore (_)
to call the external.  In both calling methods, the programmer has the
responsibility for ensuring that the external being called is compatible
with the formal parameter interface used by HP Business BASIC/XL's
ANYPARM calling feature.

The external procedure can be included in any executable library.  The
order for resolving external procedure references for HP Business
BASIC/XL programs executing in the interpreter is the same as that
specified in the LIB = or XL = parameter when the interpreter is invoked.
If the program is a compiled program, then the search order is the same
as when the compiled program is starts executing.

Using ANYPARM EXTERNAL and CALL 

The ANYPARM EXTERNAL statement is used to explicitly declare procedures
that are to be called using the ANYPARM call feature.  The CALL statement
described in this section is used to transfer execution control to
externals declared in an ANYPARM EXTERNAL statement.

Explicit declaration of procedures to be called by the ANYPARM method
allows you to specify additional options concerning the scope and name of
the external.  External procedures can be declared in the main subunit of
the program to be GLOBAL to the entire program.  Otherwise, the external
declaration is local to the subunit in which it is declared.  A valid HP
Business BASIC/XL identifier can be aliased to the names of externals
which are not valid HP Business BASIC/XL identifiers, that is, procedure
names which begin with an underscore.

The formal parameter list is not included in the ANYPARM EXTERNAL
declaration since both the number and type of the formal parameters are
not restricted.

Syntax 

[GLOBAL] ANYPARM [EXTERNAL] ap_name_clause_list 

Parameters 

ap_name_clause_     A list composed of ap_name_clause elements with the
list                syntax:

                                   [{,}               ]
                    ap_name_clause [{;} ap_name_clause]

ap_name_clause      The identifier used to call the external from HP
                    Business BASIC/XL together with an option that allows
                    the name to be aliased to the actual name of the
                    external.  The syntax of ap_name_clause is:

                             ap_external_name [ ALIAS "alias_name" ]

ap_external_ name   The meaning is dependent on the presence or absence
                    of the ALIAS option.

                       1.  The ALIAS option is not present.
                           ap_external_name is a valid HP Business
                           BASIC/XL identifier in lower case that is the
                           name of the external procedure in the
                           executable library to be called from HP
                           Business BASIC/XL. The maximum length of the
                           name of the external is 60 characters.

                       2.  The ALIAS option is present.  ap_external_name 
                           is a valid HP Business BASIC/XL identifier
                           used in the CALL statement in the HP Business
                           BASIC/XL program to reference the alias_name 
                           external procedure in the executable library.
                           The alias_name will be treated as the
                           case-sensitive name of the procedure in the
                           executable library.

                    In both cases, the ap_external_name is the identifier
                    to be used with the CALL statement.

alias_name          The name of the external procedure.  The alias_name 
                    is case-sensitive.  The maximum length of the name of
                    the external is 60 characters.

GLOBAL              Use of the GLOBAL option is restricted to the main
                    program subunit.  Use of the option specifies that
                    the ANYPARM EXTERNAL declaration is accessible to all
                    of the HP Business BASIC/XL procedures and functions
                    in the program.  This allows external calls to be
                    made from the subunits without an additional ANYPARM
                    EXTERNAL declaration.

The CALL Statement to Externals Declared Using ANYPARM EXTERNAL 

The CALL statement for an ANYPARM EXTERNAL procedure is similar to that
of other EXTERNALS.

Syntax 

CALL ap_external_name [( actual_param_list )]

Parameters 

ap_external_     An HP Business BASIC/XL identifier declared in an
name             ANYPARM EXTERNAL or GLOBAL ANYPARM EXTERNAL declaration.

act_param_list   The list of actual parameters to be passed to the
                 external procedure.  When more than two actual
                 parameters are present in the list, each is separated
                 from the next by a comma.  Two consecutive commas are
                 not valid.  Each of the actual parameters can be a
                 numeric or string identifier representing an HP Business
                 BASIC/XL variable, or a literal, function, or expression
                 that is evaluated prior to calling the external.  Actual
                 parameters that are HP Business BASIC/XL variables are
                 passed by reference.  To pass HP Business BASIC/XL
                 variables by value, enclose the relevant identifier in a
                 set of parentheses.  All other actual parameters are
                 evaluated, if required, and passed by value.  Entire
                 arrays passed as parameters must include the parentheses
                 for the dimension information.  An asterisk replaces
                 each of the numbers that are required to reference an
                 individual element of the array.

Examples 

The following example shows the use of ANYPARM to call the externals
ANYPARM_SUM and fileprint.  Notice that the calls here are similar to
calling any other external.

     100 GLOBAL ANYPARM EXTERNAL Fileprint
     110 ANYPARM EXTERNAL Sum ALIAS "ANYPARM_SUM"
     120 INTEGER Int1,Int2,Int3,Int4,Total
     130 Int1=1;Int2=2;Int3=3;Int4=4;Total=0
     140 CALL Fileprint("Beginning of Program.","Total is:",Total)
     150 CALL Sum(Total,Int1,Int2)
     160 CALL Sum(Total,Total,Int3,Int4)
     170 CALL Sum   ! No parameters are required for the call
     180 CALL Fileprint("New total is:",Total)
     190 CALL Suba(Total,10.50)
     200 CALL Fileprint("End of Program")
     210 END
     220 !
     230 SUB Suba(=INTEGER Substotal,REAL Price)
     235 REM Fileprint was declared as GLOBAL
     240    CALL Fileprint("Total Price is:",Substotal*Price)
     250 SUBEXIT

Using the Underscore to Call an ANYPARM External 

The underscore is used to call external procedures in an executable
library following an implicit local external declaration.  By implicit,
it is meant that no previous ANYPARM EXTERNAL statement in the HP
Business BASIC/XL program is required to declare the external procedure
name.  The external to be called must be present in the executable
library or program.  Implicit declaration does not allow aliasing.  Use
of the underscore in a program subunit results in an implicit local
external declaration.  If the underscore is used in the main subunit, the
implicit declaration is local to the main subunit.  Refer to the
following section, "Resolving Name Conflicts in Calls to ANYPARM
Externals," for a description of HP Business BASIC/XL's method of
determining which procedure is called when externals with the same names
are declared both explicitly and implicitly within a program.

Syntax 

     _ap_external_name [  act_param_list  ]

Parameters 

ap_external_     A valid HP Business BASIC/XL identifier that is the name
name             of the external procedure in the executable library to
                 be called.  The maximum length of the name of the
                 external is 60 characters.  The entry point name is
                 ap_external_name in lower case unless the external is
                 explicitly declared with an ALIAS clause.

act_param_list   Same as the actual parameter list, act_param_list, in
                 the CALL ap_external_name statement.  Note that
                 parentheses do not enclose the actual parameters when
                 using the underscore to make a call to an external.

Examples 

The following example shows the use of the underscore in a call to an
ANYPARM External.

     100 INTEGER Int1,Int2,Int3,Total
     110 Int1=1;Int2=2;Int3=3;Total=0
     120 _FILEPRINT "Beginning of Program","Total is:",Total
     130 _ANYPARM_SUM Total,Int1,Int2
     140 _ANYPARM_SUM Total,Int3,Int4
     150 _ANYPARM_SUM  ! No actual parameters need be associated with a call
     160 _FILEPRINT "New total is:",Total
     170 CALL Suba(Total,10.50)
     180 _FILEPRINT "End of Program."
     190 END
     200 !
     210 SUB Suba(INTEGER Substotal,REAL Price)
     220    _FILEPRINT "Total Price is:",Substotal * Price
     230 SUBEND

Resolving Name Conflicts in Calls to ANYPARM Externals 

When any of the GLOBAL explicitly, local explicitly, or local implicitly
declared ANYPARM external procedures have the same name, HP Business
BASIC/XL uses a hierarchy for determining which declaration is relevant
to a specific call from within the program.  The declarations are
searched in the following order:

   1.  Local explicit ANYPARM declarations.
   2.  Local implicit ANYPARM declarations.
   3.  GLOBAL explicit ANYPARM declarations.

Since the names of all externals in the executable library must be
unique, it is wise to give unique names to each of the externals
referenced within your HP Business BASIC/XL program.  Unique names for
each external will avoid the mistake of calling non-ANYPARM externals
when using the underscore.  It will also ensure that you are calling the
external that you intend to call.

The following examples are designed to clarify the actual external
procedures called when conflicts arise between the various forms of
ANYPARM external declarations.  The ALIAS option has been used to allow
distinction between calls to three ANYPARM EXTERNAL procedures, Test1,
Test2, and Test3.  In each example, "Call" (in the comments) refers to
the procedure actually called.

Examples 

The first example demonstrates the effect of aliasing the external
procedure named Test1 to the HP Business BASIC/XL identifier, Test2.

     10 ANYPARM EXTERNAL Test2 ALIAS "Test1"  ! Explicit local declaration
     20 CALL Test2                            ! Call is made to Test1

In the following example, the explicit local declaration takes precedence
over the implicit local declaration.

     10 ANYPARM EXTERNAL Test2 ALIAS "Test1"  ! Explicit local declaration
     20 CALL Test2                            ! Call is made to Test1
     30 _Test2    ! Implicit local declaration  Call is made to Test1

In the following example, the explicit local declaration takes precedence
over the explicit global declaration.

     10 GLOBAL ANYPARM EXTERNAL Test2 ALIAS "Test3"  ! Explicit global declaration
     20 ANYPARM EXTERNAL Test2 ALIAS "Test1"         ! Explicit local declaration
     30 CALL Test2                                   ! Call is made to Test1

In the following example, the implicit local declaration takes precedence
over the explicit global declaration in the main subunit.  However, in
the Suba subunit, the explicit global declaration is used to determine
which external to call.

     10 GLOBAL ANYPARM EXTERNAL Test2 ALIAS "Test1"  ! Explicit global declaration
     30 _Test2           ! Implicit local declaration  Call is made to Test2
     40 CALL Suba
     50 END
     60 SUB Suba
     70    CALL Test2    ! Call is made to Test1 as specified in GLOBAL declaration
     80 SUBEND

An explicit local external declaration also takes precedence over
implicit local ANYPARM declarations.  In the following example, a call is
made to the Pascal external, Test4, using the ANYPARM underscore.  Avoid
calls to non-ANYPARM externals using the ANYPARM underscore.

     10 EXTERNAL PASCAL Test4  ! Explicit local external Pascal declaration
     20 _Test4                 ! Call is made to the external Pascal procedure Test4



MPE/iX 5.0 Documentation