Download as pdf or txt
Download as pdf or txt
You are on page 1of 196

Sage MAS 90 and 200 ERP

Object Interface

CERTIFIED STUDENT CURRICULUM


SAGE LEARNING SERVICES

Curriculum Version 2.0 TCSW9OI


NOTICE
This document and the Sage Software product may be used only in accordance with the accompanying Sage Software
End User License Agreement. You may not use, copy, modify, or transfer the Sage Software product or this
documentation except as expressly provided in the license agreement.
Visit our Web site at www.sagesoftwareuniversity.com, or call 1-800-944-4299 to learn about training classes that are
added throughout the year.
Information in this document is intended solely as general information with respect to common business issues and is
not to be construed as professional advice. It is always best to consult a tax or accounting professional for all tax and
account related questions. THE INFORMATION HEREIN IS PROVIDED “AS IS” AND ALL WARRANTIES ARE
EXPRESSLY DISCLAIMED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY: OF
MERCHANTABILITY; OF FITNESS FOR ANY PARTICULAR PURPOSE; OF NON-INFRINGEMENT OF ANY
PROPRIETARY RIGHT OF ANY THIRD PARTY IN ANY COUNTRY; OTHERWISE ARISING OUT OF ANY
PRODUCT, PROPOSAL, SPECIFICATION OR SAMPLE; AND ANY WARRANTY THAT THE DOCUMENT IS
ERROR FREE. No license, express, implied, by estoppel or otherwise, to any intellectual property right is granted by
this document. Sage Software may make changes to the information in this document at any time, without notice.
Recipient is solely responsible for assessing the suitability of the information and assumes all risk of use.
© 2008 Sage Software, Inc. All rights reserved. Sage Software, Sage Software logos, and the Sage Software product and
service names mentioned herein are registered trademarks or trademarks of Sage Software, Inc., or its affiliated entities.
All other trademarks or registered trademarks are the property of their respective owners.
04/15/2008
Sage MAS 90 and 200 Object Interface

Contents
Welcome and Introduction..................................................... 1
Prerequisites, Available Resources, and Lab Exercises ........ 2
Support for the Object Interface ............................................ 3
Example Programs................................................................. 4
The ProvideX OLE Server ..................................................... 5
ProvideX OLE Server Methods and Properties..................... 6
ProvideX OLE Server Requirements .................................. 12
Lab - Exercise 1................................................................... 13
The Session Object ................................................................ 14
LastErrorNum and LastErrorMsg Properties ...................... 15
General Properties for Session Information ........................ 16
Path Properties..................................................................... 18
Session Properties for Business Objects.............................. 20
Properties for Instantiated Objects ...................................... 22
Instantiating and Dropping a Session Object ...................... 23
Setting the User ................................................................... 25
Setting the Company ........................................................... 27
Setting the Date ................................................................... 28
Setting the Module .............................................................. 29
Lab - Exercise 2................................................................... 32
Security Overview ................................................................. 34
Instantiating a Security Object ............................................ 35
Properties of the SY_Security Object.................................. 36
Methods of the SY_Security Object.................................... 37
Lab - Exercise 3................................................................... 39
Foundation Class Overview ................................................. 41
User Interface Class Level (UI)........................................... 42
Service Class Level (SVC).................................................. 43
Business Class Level (BUS)................................................ 44
Report Classes (RPT) .......................................................... 45

Certified Student Course Curriculum - Version 2.0 Page iii


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Update Classes (UPD)......................................................... 47


Lab - Exercise 4................................................................... 50
Standards Overview.............................................................. 53
Program Naming Standards................................................. 54
Table Naming Standards ..................................................... 56
Example Programs................................................................ 57
Transaction Entry ............................................................... 58
General Journal Entry.......................................................... 59
General Ledger Budget from Excel..................................... 62
Sales Order Entry ................................................................ 64
Visual Basic .NET Example Programs ............................... 65
Appendix A - Example Program Listings
and Documentation ............................................................... 85
Appendix B - UDF / UDT Setup for Example
Programs.............................................................................. 176
Appendix C - Message Library Reference ....................... 188
Appendix D - Sage MAS 90 Security Events
and Module Options............................................................ 189
Appendix E - Running PVXCOM on a Remote
Machine................................................................................ 192

Page iv Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 1
Welcome and Introduction
0
1

Welcome to the Object Interface training class. This class is designed to introduce
programmers to the ProvideX OLE server (ProvideX COM) and Sage MAS 90
and 200 Object Interface. This is accomplished by using examples created in both
VBScript and VB.NET, where we show you how to use the Object Interface to
interact with the Sage MAS 90 and 200 database.
This class is intended to meet the following objectives:
• Provide an understanding of the ProvideX OLE server
• Learn about the methods and properties of the Session object
• Learn about the Sage MAS 90 and 200 Security object
• Learn about the properties and methods of the Sage MAS 90 Base Classes
• Provide an overview of the Sage MAS 90 and 200 standards where they apply to
the Object Interface
• Provide example programs
Note: Information in this curriculum pertains to Sage MAS 90 and 200. Although
these programs have a common architecture, some of the features vary depending on
the product implemented. This training curriculum focuses on the features available
in Sage MAS 90.

Certified Student Course Curriculum - Version 2.0 Page 1


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Prerequisites, Available Resources, and Lab Exercises


0

Prerequisites
An understanding of the following is required in working with the curriculum:
• Sage MAS 90 Data File Structure
• Sage MAS 90 Core Modules
• Object Orientated Programming
• Automation (Interfacing with Applications through COM)

Available Resources
0

The following is a list of available resources.


• File Layouts and Program Information: Contains the Sage MAS 90 Table and
File Layouts. Located on the Resources Web page in the Sage MAS 90 Desktop.
• Object Reference: (ObjectReference.chm) Contains base object references.

Lab Exercises
The lab exercises in this curriculum are presented in VBScript. You can use any text
editor and Internet Explorer version 5 or higher to complete these exercises. This
makes the exercises independent of any one development environment. If you are
using your own development tool and programming language to work through the
exercises, the logic is the same but you must make any necessary syntax changes for
your development environment.
The solutions to the lab exercises are also provided with the course materials in
VisualBasic.net.

Page 2 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Support for the Object Interface


0

Sage Software supports the Sage MAS 90 Foundation Classes, the Sage MAS 90
Business Objects, and the Sage MAS 90 Object Interface.
• ProvideX programming support is available through Sage Software for Master
Developers who are creating modifications to Sage MAS 90 programs only.
• Sage Software cannot support, troubleshoot, debug code, or assist with the design
of programs written in any other programming language.
• The examples provided or demonstrated in this class are provided as is and
without support or warranty.

Certified Student Course Curriculum - Version 2.0 Page 3


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Example Programs
0

The example programs are created using VBScript and Visual Basic.
• Visual Studio 2003 or higher is required to open the Visual Basic example project
in Visual Studio.
• .Net Framework version 1.1 or higher is required to run the Visual Basic
examples.
The Visual Basic project used with this class is made up of several small programs,
each of which has a specific function.
• For example, one of the programs only initializes the Sage MAS 90 Session,
while another just logs into Sage MAS 90, and still another program sets the Sage
MAS 90 module date.
• This was done to make it easier to focus on key concepts as they are covered in
this class.
• This is not necessarily the design approach used in the real world.
• An application like the examples provided are typically coded in a single
program.
• We cannot suggest how you should design your programs because we are not
familiar with each set of unique business requirements.

Page 4 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 2
The ProvideX OLE Server
0
2

The ProvideX.Script OLE server allows external applications to directly invoke and
interact with ProvideX and ProvideX objects. You can use the ProvideX.Script OLE
server with virtually any COM compliant application or programming language such
as VB, Delphi, VBScript, and VBA.
The topics in this lesson include:
• ProvideX OLE Server Methods and Properties
• ProvideX OLE Server Requirements

Certified Student Course Curriculum - Version 2.0 Page 5


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Methods and Properties


0

Methods of the ProvideX.Script Class


The OLE server itself has six methods. These methods are:
• Init(path) - Called before accessing any other method in the script engine to set
the working directory for the server and perform binding to the ProvideX DLL
layer. You should set the path to the \MAS90\Home directory. If the path is left
blank, the current directory is used.
• Execute(statement) - Invoked to execute any ProvideX command.
• Evaluate(expression) - Evaluates and returns the ProvideX expression provided
and returns its value as a variant (you can use it as either numeric or string).
• Run(program) - Runs the specified ProvideX program. This method does not
return until the program ends.
• Reset( ) - Closes all local files and clears variables (it executes a BEGIN).
• NewObject(ClassName, Params …) - Creates a new object of the specified
name and returns an object reference. ClassName is the name of the ProvideX
class, must be the first argument, and is required. Params are optional; however,
when creating a new Business object, a handle to the Session object is a required
parameter and must be the second argument.

Properties of the ProvideX.Script Class


There are three properties associated with the script interface. They are as follows:
Instance - Returns a unique string to identify the server during its lifetime.
State - Returns the state of the server. 0 (zero) is returned for un-initialized and 1
(one) is returned for initialized.
Parameter - Read/write property used to access the specified ProvideX parameter.

Page 6 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Methods and Properties (continued)


0

Properties and Methods of the ProvideX.Dispatch Class


To create an object within the OLE server, the method NewObject is used. It returns
an object identifier to the ProvideX object created. Along with the ProvideX defined
properties and methods, the OLE server adds the following method and properties:
• Instance - Property, Read-Only, String. Returns a unique identifier of the
ProvideX.Script object used to create the automation object. This is important
because you cannot pass the automation object to another ProvideX.Script server.
• ScriptObject - Property, Read-Only, Object. Returns the parent ProvideX.Script
object.
• CmdHandle - Property, Read-Only, Long. Returns the ProvideX handle the
automation object is tied to.
• DropObject( ) - Method. Used to implicitly release the ProvideX based object
and its resources. This is important when using Garbage Collecter languages
(.NET) which sometimes do not release a COM object as you expect.

Late Binding
The methods and properties of the MAS 90 objects are accessed with COM using
pure IDispatch interfaces that require the use of late binding.
• VB Script always uses late binding to interface with COM objects.
• Visual Basic can use late binding by insuring that Option Strict Off is set and the
CreateObject function is used.
• C# developers can take advantage of functionality build into the .NET Framework
that enables .NET programmers to perform late binding. A C# example is
included with the example programs to illustrate this.

Data Types
It is important you understand that COM is generally data-type insensitive. You can
access a numeric value as either a string or a number. This causes a problem when
dealing with the ProvideX OLE server because in ProvideX, you can have Cust_no$
and Cust_no as two unique data variables.
• To avoid this problem, the OLE server mandates all property references indicate
the data type in the first character of the property name. This means:
- All references to string properties must have an 's' followed by the property
name
- All numeric properties must have an 'n' followed by the property name
- All integer properties must have an 'i' followed by the property name
- If a property is an object identifier, the property name must have an 'o' prefix
Certified Student Course Curriculum - Version 2.0 Page 7
Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Methods and Properties (continued)


0

When referencing the methods of ProvideX programs, the first character of the
method name must match the data type returned. For example:
returnValue = object.sReturnsStringValue()
returnValue = object.nReturnsNumericValue()
• These data type prefixes are only for use by programs using the OLE server; not
by the ProvideX application itself. This means the property Cust_no$ in ProvideX
is sCust_no when referenced by the OLE server and the property Cust_no in
ProvideX is nCust_no from the OLE server.
• The type prefix is not required for variables passed to and from ProvideX methods
as parameters; however, variables must have their data type implicitly set before
passing them on the parameter list of a ProvideX method. Using Visual Basic for
this example where the ProvideX method accepts one parameter and returns a
string value in that parameter:
Dim myParam As String'Type not known to ProvideX OLE Server
retVal = object.nMethod(myParam)'This will cause an Error 548

Figure 1

• An error similar to one of the above examples occurs because even though
myParam is declared as type String, the ProvideX OLE server is not aware of its
type. This is corrected by making sure the variable is first assigned a String value
before passing as a parameter as follows:
Dim myParam As String = ""
retVal = object.nMethod(myParam)
- Do not use the prefix type in the parameter list of a method call.
- Use of the 'o' prefix allows the specification of properties and/or methods
within ProvideX objects to declare themselves as objects.

Page 8 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Methods and Properties (continued)


0

Example – Handling of ProvideX data types through COM


ProvideX Class definition
100 DEF CLASS "MYCLASS"

200 ! Public Properties


205 PROPERTY StrVar$
210 PROPERTY IntVar%
215 PROPERTY NumVar
220 PROPERTY ObjPtr

300 ! Public Methods


305 FUNCTION ReturnString$()
310 FUNCTION ReturnInteger%()
315 FUNCTION ReturnNumber()
320 FUNCTION ReturnObjPtr()

400 !Accepts a string parameter, return type is numeric


405 FUNCTION SetString(SetValue$)

410 ! Returns string parameter, return type is numeric


415 FUNCTION GetString(GetValue$)

999 END DEF

Certified Student Course Curriculum - Version 2.0 Page 9


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Methods and Properties (continued)


0

VB Implementation of this ProvideX Class


Public Class Form1

Dim PvxScript As Object


Dim myPVXObject As Object

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

PvxScript = CreateObject("ProvideX.Script")
PvxScript.Init(MAS90HomePath)

myPVXObject = PvxScript.NewObject("MyClass")

Dim StrVar As String


Dim IntVar As Integer
Dim NumVar As Double
Dim ObjPtr As Object

' Prefix Property mame to indicate data type


StrVar = myPVXObject.sStrVar
IntVar = myPVXObject.iIntVar
NumVar = myPVXObject.nNumVar
ObjPtr = myPVXObject.oObjPtr

' Prefix the method name to indicate return type


StrVar = myPVXObject.sReturnString()
IntVar = myPVXObject.iReturnInteger()
NumVar = myPVXObject.nReturnNumber()
ObjPtr = myPVXObject.oObjPtr

Page 10 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Methods and Properties (continued)


0

' Type prefix is not used in parameter lists


' Parameters must be set to a value, not just declared
Dim GetParam As String = ""
IntVar = myPVXObject.nGetString(GetParam)

Dim myParam As String = "Some String value"


IntVar = myPVXObject.nSetString(myParam)
IntVar = myPVXObject.nSetString("ABCDEFG")

' Cleanup - DropObject()


myPVXObject.DropObject()
myPVXObject = Nothing
PvxScript = Nothing

End Sub

End Class

Certified Student Course Curriculum - Version 2.0 Page 11


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

ProvideX OLE Server Requirements


0

• The ProvideX OLE server must be registered. Running or double-clicking


Pvxcom.exe file self-registers the ProvideX OLE server.
• You must initialize the ProvideX OLE server using the Init() method. The Init()
method must be the first method invoked after creating the ProvideX.Script
object. This method accepts the path to the MAS90\HOME directory as a
parameter.
• The Sage MAS 90 and 200 Object Interface license must be present on the system
or the Init() method will fail with the message "Failed to initialize the ProvideX
Library". This license is included with some Sage MAS 90 and 200 versions or it
is available from Sage Software.

Figure 2

Page 12 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 1
0

The purpose of this lab is to review the information learned in the previous topics and
to provide experience creating and initializing a ProvideX COM object. Complete all
steps in this exercise and accept all defaults unless otherwise instructed.
In this exercise, enter the following VBScript to a .VBS file to create a ProvideX
Script object, initialize the object with a known MAS90\Home directory, and invoke
the NewObject method to create a new Sage MAS 90 Session object. After the Sage
MAS 90 Session object is created, a message box displays the value of one of the
Session object’s properties.
1. Create the ProvideX COM object.
Set oScript = CreateObject("ProvideX.Script")
2. Call the Init method. This requires the path to the MAS90 home directory.
oScript.Init("C:\Program Files\Sage Software\
MAS 90\Version4\MAS90\Home")
3. Create a new Sage MAS 90 Session object using the NewObject method and
return the objects handle in oSS.
Set oSS = oScript.NewObject("SY_Session")
4. Display the value of one of the Sage MAS 90 Session object's properties.
MsgBox(oSS.sPathSystem)
5. Call the CleanUp and DropObject methods to destroy the Session object and
release any ProvideX resources.
oSS.nCleanUp()
oSS.DropObject()
Set oSS = Nothing
Set oScript = Nothing

Certified Student Course Curriculum - Version 2.0 Page 13


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 3
The Session Object
0
3

The SY_Session object is the core of the Sage MAS 90 system. It provides methods
and properties all other Sage MAS 90 objects can use. You must create a Session
object before any other Sage MAS 90 Business object is created; a handle to the
Session object is a required parameter when creating any other object. The Session
object also provides access to the Sage MAS 90 Security object, which is also
required before accessing the Sage MAS 90 Business objects.
The topics in this lesson include:
• LastErrorNum and LastErrorMsg Properties
• General Properties for Session Information
• Path Properties
• Session Properties for Business Objects
• Properties for Instantiated Objects
• Instantiating and Dropping a Session Object
• Setting the User
• Setting the Company
• Setting the Module
• Setting the Date
Note: Refer to the Object Reference for the Session object documentation.

Page 14 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

LastErrorNum and LastErrorMsg Properties


0

Although errors may occur, the user does not get notified of the error directly by the
Sage MAS 90 Session object. Instead, the methods used return a non-zero value
(retSUCCESS) or a zero (retFAILURE). In the event of a retFAILURE, the
LastErrorNum and LastErrorMsg properties of the Session object are set and the user
interface level can use it to display an appropriate error message. Some common error
messages are listed in Appendix C.
Note: All Sage MAS 90 Objects have their own LastErrorNum and LastErrorMsg
properties defined.
..

Property Name Data Type Description


LastErrorNum String This property contains the number or error
code of the last error.
LastErrorMsg String This property contains the text of the last error
message.

Certified Student Course Curriculum - Version 2.0 Page 15


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Properties for Session Information


0

At the core of the SY_Session object, there are key properties the object maintains.
Most of these properties store information specific about the session started,
including whether the session is running in the Sage MAS 200 environment or from a
Terminal server.
The table below lists the key properties:

Property Name Data Type Description


Initialized Numeric 1 or This property indicates the SY_Session
zero object is properly initialized and is ready to
use. Any other object or program depending
on the SY_Session object to instantiate
should perform an EVN on this property (an
error condition indicates the object is not
instantiated).
CS Numeric 1 or This property indicates Sage MAS 200 is
zero running in a Client-Server environment
(utilizing the WindX programs from
ProvideX). This property replaces the
%SYS_WDX global variable.
Wdx String This property contains the [wdx] prefix used
to access applications or data files on the
workstation when running in the Sage
MAS 200 environment. It replaces the
%SYS_WDX$ global variable and is only
set when the CS flag is set.
TerminalServer Numeric 1 or This flag indicates whether the user is
zero currently operating in the Terminal Services
environment.
WorkstationName String The user’s workstation name is maintained
in this property. Workstation information is
maintained specifically for printing because
printer settings change when a user moves
from workstation to workstation. The
workstation name is also used to keep track
of session information.

Page 16 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Properties for Session Information (continued)


0

LegacyTerm String This property contains the legacy TERM$


variable if created. An application program
must first run the BuildTerm method in the
SY_Session object before a TERM$
variable is stored in this property (its
primarily so applications do not have to run
the BuildTerm method every time the
TERM$ variable is needed).
CurrentPID Numeric The current Windows PID for the ProvideX
session is stored in this variable. It is used to
track session information and to know when
a specific process has ended.
LauncherHwnd Numeric The handle to the Desktop. Not used with
the Object Interface.
Updating Numeric 1 or This property is used by the modules when
zero in the middle of an update.
RegisteredName String This is the name of the registered user of the
product. It is primarily used on the startup
splash screen.

Certified Student Course Curriculum - Version 2.0 Page 17


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Path Properties
0

There are properties used to determine path and file names. When the company or
user logon states are changed, the path properties of the SY_Session object are
automatically updated.
The table below lists the path properties:

Property Name Data Type Description


PathCompany String Fully-qualified path to the current company
directory. All data files except for Payroll
must be located within this path that has the
format of MAS_xxx, where xxx is the
company code. Within this directory, each of
the modules has their own data directory for
their company under the familiar format of
yyxxx, where yy is the two-character
application code and xxx is the company
code.
PathUser String Fully-qualified path to the users home
directory.
PathSystem String Fully-qualified path to the MAS_SYSTEM
directory. This is where all the common
system data files are maintained.
PathHome String Fully-qualified path to the HOME directory.
This directory contains the ProvideX
interpreter and utilities.
PathBase String Fully-qualified path to the root MAS90
directory. Note the root directory does not
need to be called MAS90.
PathCSRoot String UNC path to the Sage MAS 200 server. This
property is blank if the user is running a
Sage MAS 90 system.
PathHelp String Fully-qualified path to the HELP directory.
In Sage MAS 200, Help files are located on
the local workstation. In Sage MAS 90,
Help files are located on the server.

Page 18 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Path Properties (continued)


0

PathDictionary String Fully-qualified path to the dictionary data


files (PROVIDEX.DDE, PROVIDEX.DDF,
PROVIDEX.DCL, and PROVIDEX.PRM).
PathPayroll String Fully-qualified path to the Payroll data files.
This path is usually the same as
PathCompany$; however, users have the
option to move Payroll data files to a
different directory for security purposes.
The format of the directory structure is
identical to that described for
PathCompany$.
PathReport String Fully-qualified path to the REPORTS
directory. This directory contains the Crystal
report files.
RootPrefix String To ultimately support multiple installations
using the same SQL server, the RootPrefix$
property contains the prefix to append to all
the company and system data files. This is
hard-coded to MAS_. When accessing data
files directly, use the RootPrefix$ property.
FileSuffix String All 4.x-standard data files now have a file
extension of .M4T while previous data files
maintain the .SOA extension.

Certified Student Course Curriculum - Version 2.0 Page 19


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Session Properties for Business Objects


0

There are properties used by the Business objects to communicate company, user, and
module information between the Desktop and the Business object. Many of these
properties were previously a part of SY0CTL.SOA as the TERM$ record.
The table below lists the properties for the Business object:

Property Name Data Type Description


CompanyKey String The current company key is stored in this
property. The company key is a surrogate key,
which is a numeric value with a range from 1
through 9,999,999,999. Although the key is
numeric, it is stored as a string in both the
data file and as a property in the Session
object.
CompanyCode String The current company’s three-character
company code.
CompanyName String The current company’s name is stored in this
property and used primarily for display in the
Desktop; however, other applications can
access this property to display the full
company name in their application programs.
UserKey String The current user’s surrogate key is stored in
this property. Similar to the CompanyKey$
property, the user key is a surrogate key with
a range from 1 to 9,999,999,999. If no user
security is configured or the user is logging
on to the system as an Administrator, the
UserKey$ property is set to zero.
UserCode String The current users three-character code is
stored in the UserCode$ property. This is
primarily for backwards compatibility and
you should generally not use the three-
character user code. All logon logic now uses
a full user logon rather than three-character
initials.

Page 20 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Session Properties for Business Objects (continued)


0

UserName String This property represents the current users


logon name. This is how users access the
system after security is enabled. If no user
security is configured, this property is set to
Default User. If the user is logged on as
Administrator, the UserName$ property is set
to Administrator.
ModuleName String The current module the user is accessing is
stored in this property. By default, this
property is set to Library Master.
ModuleCode String The three-character module code is stored in
this property as defined in the SY_Module
table. Module codes are always upper-case
and are generally two characters separated by
a forward slash. Only special modules should
have three-character module codes.
ModuleLevel Numeric This is the level of the programs for the
current module as specified in the
SY_Module table. Note this is not the level of
the data files accessed (which are the same,
except when converting data from previous
levels).
ModuleEverest Numeric 1 This property indicates whether the current
or zero module is a 4.x-standard module as defined in
the SY_Module table.
ModuleDate String The current modules date is stored in this
property. The module date is stored in the
SY_ModuleDate table and is indexed by the
user key, company key, and module code.
SystemDate String The system date is the date the system was
started. It is set by default during startup and
you cannot change it.

Certified Student Course Curriculum - Version 2.0 Page 21


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Properties for Instantiated Objects


0

In addition to the properties from the previous topic listing data-related items, a
number of additional properties are defined to maintain objects the SY_Session object
instantiates. Although the SY_Session object may instantiate many other objects,
only the objects listed below are accessible from outside the SY_Session object.
These objects are specifically exposed because they provide additional functionality
to both the SY_Session object and to other application objects that create a
SY_Session object.
The table below lists the properties for instantiated objects:

Property Name Data Type Description


UI Numeric The SY_UI object contains a number of
user interface methods including progress
meter and message box routines. It also
contains a number of Desktop-specific
routines and essentially provides a user
interface into the SY_Session object. The
SY_Session object should not display any
UI (see below).
Security Numeric When a new program is launched, a
SY_Security object is created for the
current session’s user. This security object
contains the security access information
needed to see if the user can access the
program in the first place, and subsequently
in 4.x-enabled modules, what types of
permissions the user has.
FileObj Numeric The SY_File object contains methods
needed to open data files. It essentially
replaces the SYPATH public program and
provides a single repository for all path
resolving methods.
WinAPI Numeric The *OBJ/WinAPI object is a ProvideX
object containing a number of Windows
API calls such as registry access and INI
file reads; however, the use of this object
should be limited to only functions that can
run on the Sage MAS 200 server as the
object does not run on a local workstation.
Module code needing to run on a local
workstation should continue to use the
SYZDLL and SYZFIL programs.

Page 22 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Instantiating and Dropping a Session Object


0

Instantiating a Session Object


Virtually every Sage MAS 90 object requires a SY_Session object created and passed
into it. This is due to each of the Sage MAS 90 objects requiring core system and
session information that only the SY_Session object provides. Like any ProvideX
object, the SY_Session object is instantiated through COM using the
ProvideX.Script.NewObject() method. The SY_Session object does not take any
arguments; therefore, instantiating a new SY_Session object always looks as follows:
oSS = oPvxScript.NewObject("SY_Session")
where oPvxScript is the handle given to the ProvideX.Script object by the
programmer and oSS has the handle to the Session object assigned to it.
Note: You can only instantiate one SY_Session object for a given session. Attempts
to create a second SY_Session object returns an error 200.
When the SY_Session object is instantiated, the following functions are performed:
• The error handler is set so all error messages flow through the same error
processing routines.
• Define the ProvideX parameters consistently for all programs.
• The key path variables are then defined and directories created if they do not
currently exist. Although the Company and User paths are not set until a
SetCompany and SetUser, respectively, are made, the remaining path variables
are set (such as the Home and System) and the prefix for the system.
• The Message Library is established to the SY_Message.M4T table in the
MAS_SYSTEM directory.
• The SY_File and *obj\WinAPI objects are instantiated. The SY_Session object
uses these two objects but also makes them available directly to any other
Business object as public properties.
• If the user is running in the Client/Server environment, the CS variables are set.
ODBC entries are read from the workstation and the Sage MAS 200-specific path
variables are set.
• The SY_System.M4T table is opened and read. This table contains core system
preferences and parameters for the installation.
Note: The SY_System file is not opened again. You must reinitialize the
SY_Session object when system parameters change.
• The SY_Company.M4T, SY_User.M4T and SY_Module.M4T tables are opened
and the channels are maintained in private variables of the SY_Session object.

Certified Student Course Curriculum - Version 2.0 Page 23


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Instantiating and Dropping a Session Object (continued)


0

• The ODBC path and registry information is written out.


• The workstation name is resolved. If the user is running in a Terminal Server
environment, the workstation is resolved by first identifying the client name
(WTSClientName) and then the user name (WTSUserName). If neither exist, the
server’s name is used.
At this point, the SY_Session object is initialized. Basic operations like file access,
password encryption/decryption, and other methods not requiring company or user
information are available.

Dropping the Session Object


The cleanup method must be called before dropping the Session object because of the
recursive dependencies of the Session object in other objects it creates.
oSS.nCleanup()
oSS.DropObject

Page 24 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the User


0

There are several ways to establish the user logon in the SY_Session object
depending on the circumstances in which the object is started. How the user is
accessing the system determines which method is used to set the user.
The Logon method is used to set the user. This method is always called when the
Desktop is starting up and handles default situations such as no security being
configured or using the Windows logon.
• The Logon method first checks the UseWindowsLogon and RequirePasswords
flags.
- If the UseWindowsLogon and RequirePasswords flag sare set, the Logon
method fails as the user is required to enter a password before logging on. If
the RequirePasswords flag is not set, the user’s ID is obtained from the
operating system and the Logon method calls the SetUser method and returns
success.
- If the UseWindowsLogon flag is not set and security is not enabled, the Logon
method calls SetUser to log on as the DefaultUser and returns success.
• In the event the Logon method fails, the originating program needs to obtain a
user logon and password from the user and pass them to the SetUser method
before proceeding.
- Because UI is not handled within the SY_Session object, only a retSUCCESS
or a retFAILURE is passed back from this method. You can use the
LastErrorNum and LastErrorMsg properties to get the reason for the failure.
Note: Developers writing external applications integrating to Sage MAS 90 or Sage
MAS 200 without the Desktop must provide their own mechanism to obtain a user
logon and password.

Certified Student Course Curriculum - Version 2.0 Page 25


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the User (continued)


0

Third-Party Method
Third-party applications logging on to Sage MAS 90 or Sage MAS 200 should make
the following method calls in order to log on:
retVAL = oSS.nLogon()
While retVAL = 0
'
' Logic to get username and password goes here
'
retVAL = oSS.nSetUser(username, password)
Wend
This method ensures the DefaultUser logon (or Windows logon) is used for logon
purposes if no security is configured, (or if Use Windows Logon is specified in
System Configuration).
• If the DefaultUser or Administrator user logons are not used, the SetUser method
then decrypts the password passed into it and compares it with what is stored in
the SY_User.M4T table.
- If the password is invalid, the method returns a retFAILURE and sets the
property LastErrorNum$ to SY_InvalidPassword. The calling program can
display the message that an invalid password was used or return the user back
to the logon prompt.
• Logon attempts are logged and if the password fails, a wait of approximately 3
seconds occurs preventing brute force logon attempts.
• If the logon is successful, the various user variables including paths, user logon,
and user code are set as properties in the SY_Session object. The Library Master
date is set to the system date automatically.
- If the user previously logged on to the system, the last company they accessed
is set using the SetCompany method. Finally, the SessionID$ variable is
defined. This is a somewhat unique variable used for defining temporary and
Crystal Reports work tables.

Page 26 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the Company


0

To access a company using the Business Object Interface, you must configured the
company to allow external access. You can find this setting in Company Maintenance
on the Preferences tab. The default for this setting is turned off.
Setting the company code is relatively straight-forward and is primarily designed to
set company-specific public and private properties of the SY_Session object. After
the company code is read in, the CompanyCode, CompanyKey, and CompanyName
properties are set and the two data paths, PathCompany and PathPayroll, are defined
based on the directory information stored in the company record.
• The SetCompany method takes a required three-character company code and an
optional noChange argument. See examples below.
• The SetCompany method will fail if the company is not configured to allow
external access.

Example 1
In this example, the SetCompany method is called to set the company to the ABC
company and sets the last company field for the user as ABC. If the method fails, it
returns 0 (zero) and the message box displays the Session object’s LastErrorMsg
property for the reason it failed.
retVAL = oSS.nSetCompany("ABC")
If retVAL = 0 Then
MsgBox("Unable to set company ABC" & oSS.sLastErrorMsg)
End If

Example 2
This example sets the noChange parameter which instructs the method not to change
the last company field for the user and also displays the LastErrorMsg on failure.
retVAL = oSS.nSetCompany("ABC", 1)
If retVAL = 0 Then
MsgBox("Unable to set company ABC" & oSS.sLastErrorMsg)
End If

Certified Student Course Curriculum - Version 2.0 Page 27


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the Date


0

If a date does not exist for the user key, company key, and module code, the
SetModule and SetProgram methods will fail and an error SY_NoDate is returned.
The calling program must set the date for the user, company, and module with the
SetDate method before calling the SetModule method.
• Before calling the SetDate method, you must set up the user and company.
• The SetDate method accepts two arguments, module code and date.
- You can have the module code in the format of XX, X/X, or XXX for three-
character module codes.
- You must have the date in the format of YYYYMMDD and passed as a string.
- The SetDate method name is prefixed with an n because this method returns
an integer value, 1 on success, 0 on failure:
retVAL = oSS.nSetDate("G/L","20050331")

Page 28 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the Module


0

The last method to call before the SY_Session object is fully functional is the
SetModule method. Usually, this method is called as part of the SetProgram method
or within the SY_Launcher/SY_UI objects, so it is not always explicitly called. This
method is probably one of the most complicated as it does a number of checks to
ensure the module accessed is configured properly and returns a number of error
statuses that need checking and handling appropriately.
• The first check performed makes sure the User and Company properties are set in
the SY_Session object. If these properties are not set, the method returns a
SY_NoUserSet or SY_NoCompanySet error, respectively.
• Check registration by creating a SY_Registration object, if it does not already
exist for this session. Registration information is passed into this object for
validation even though the actual data is stored in the SY_System.M4T and
SY_Module.M4T tables. Users can access unregistered modules for 45 days from
the first time they are accessed. There are three possible outcomes to the
registration check.
- Success - The module is registered and all checks come back clean.
- Trial Mode - The module is not registered and is in trial mode. This returns
back a SY_NoRegistration error condition. In this case, the calling program
should display the Trial Mode dialog indicating the module is not registered
and will expire on a given date. To successfully set the module after such a
message, recall the SetModule method with an exclamation point after the
three character module code (for example: A/P!).
- Failure - The module trial period is expired or the record is tampered with. In
this case, the SY_RegExpired error message is returned to the calling
program.
• If the calling program is attempting to change into the same module, return back a
retSUCCESS but set the error number to SY_CurrentModule. The calling
program may want to display a message, but typically, it just ignores this.
• Check activation to ensure the module is activated for the company the user is
currently logged on to. If the module is not activated (data files are created for it),
return a SY_NotActivated error message.
• Get the module date for the module switched to from the SY_ModuleDate.M4T
table. If a date does not exist for this user key, company key, and module code, set
it to today’s date if the AutoSetDate flag is set or return an error SY_NoDate. The
calling program must set the date for the user, company, and module before
proceeding (use the SetDate method for this).
• Check for General Ledger. If General Ledger is not configured, return an error
code SY_NoGeneralLedger.

Certified Student Course Curriculum - Version 2.0 Page 29


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the Module (continued)


0

• Check for a new system or conversion by opening the _Options or 0 table of the
module being accessed. If this is a new system (either the New System flag is not
set or set to Y), set the error code to SY_NewSystem. Because the options record
is opened at this time, also check to see if module conversion is required (v record
in old 0 table). If a conversion is required, set the error code to
SY_NeedToConvert.
• Set the module-specific properties in the SY_Session object.

VBScript Example
The SetModule method accepts a three-character module code as its only argument
(“X/X” for two character module codes, or “XXX” for three character module codes).
In this VBScript example, if the SetModule method fails the Session object’s
LastErrorMsg property displays as the reason for the failure.
retVAL = oSS.nSetModule("G/L")
If retVAL = 0 Then
MsgBox("Unable to set module G/L" & oSS.sLastErrorMsg)
End If
For easy reference, the following table lists all the error codes returned from the
SetModule method.

Error Code Description


SY_NoUserSet The SetUser method is not called to set a user for this
session.
SY_NoCompanySet The SetCompany method is not called to set a company.
SY_NoModule The module code passed does not exist in
SY_Module.M4T.
SY_RegExpired This module is in trial mode (45 days free access).
SY_NoRegistration This module’s registration is expired or the registration
information is corrupted.
SY_NotActivated The module accessed is not activated for this company.
SY_NewSystem This module is not accessed for this company and needs
configuration (run through all the setup options or the
new Setup Wizard).
SY_NeedToConvert This module needs conversion. Run conversion from
Company Maintenance before proceeding.

Page 30 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Setting the Module (continued)


0

SY_NoDate A date record does not exist for this module, company,
and user.
SY_NoGeneralLedger The General Ledger module is not activated or
configured for this company.

Certified Student Course Curriculum - Version 2.0 Page 31


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 2
0

The purpose of this lab is to review the information learned in the previous topics and
to provide experience creating and initializing a Sage MAS 90 Session object.
Complete all steps in this exercise and accept all defaults unless otherwise instructed.
In Exercise 1, your VBScript created and initialized a ProvideX Script object, then
invoked the NewObject method to create a new Sage MAS 90 Session object. In this
exercise, add the necessary method calls to initialize the Session object and put it in a
fully functional state, (SetCompany, SetDate, and SetModule). Enter and save the
following VBScript to a .VBS file.
1. Working with the VBScript you created to complete the previous exercise, delete
the following code from steps 4 and 5 of the previous exercise.
MsgBox (oss.sPathSystem)
oSS.nCleanUp()
oSS.DropObject()
Set oSS = Nothing
Set oScript = Nothing
2. Continue by entering the following code at the end of the script. The Logon
method returns 1 if Sage MAS 90 Security is not enabled or if Sage MAS 90 is
configured to use Windows security.
retVAL = oss.nlogon()
3. If the Logon method fails, obtain a user name and password then use the SetUser
method to allow access. In this step, the user is allowed only one attempt to supply
a valid user name and password.
If retVAL = 0 Then
User = Trim(InputBox("Enter User Name"))
Password = Trim(InputBox("Enter Password"))
retVAL = oSS.nSetUser(User,Password)
End If
4. If SetUser fails, display LastErrorMsg for the reason and quit.
If retVAL = 0 Then
MsgBox(oSS.sLastErrorMsg)
oSS.DropObject()
Set oSS = Nothing
WScript.Quit
End If
5. Set the company using the SetCompany() method. This will fail if the company is
not configured to allow external access.
Company = Trim(InputBox("Enter CompanyCode",,_
oSS.sCompany Code))
retVAL = oSS.nSetCompany(Company)

Page 32 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 2 (continued)


0

6. If SetCompany fails, display LastErrorMsg for reason and quit.


If retVAL = 0 Then
MsgBox(oSS.sLastErrorMsg)
oSS.DropObject()
Set oSS = Nothing
WScript.Quit
End If
7. Set the module date for General Ledger. Call the SetDate method before the
SetModule method. The format for the date passed to SetDate must be
YYYYMMDD.
retVAL = oSS.nSetDate("G/L","20050315")
If retVAL = 0 Then
MsgBox("SetDate Failed - " & oSS.sLastErrorMsg)
Else
8. Set the module to General Ledger.
retVAL = oSS.nSetModule("G/L")
9. Check retVAL in case the module is not activated and take appropriate action.
If retVAL = 0 Then
MsgBox("SetModule Failed - " & oSS.sLastErrorMsg)
Else
10. The Session object is fully initialized. Display some of the Session properties in a
message box to verify it is working and then quit.
MsgBox("Current Company: " & oSS.sCompanyName & vbCRLF &_
"Company Data Path: " & oSS.sPathCompany & vbCRLF & _
"Current Module: " & oSS.sModuleName & vbCRLF & _
"Module Date: " & oSS.sModuleDate)
End If
End If
11. Destroy the Session object using the DropObject method.
oSS.nCleanUp()
oSS.DropObject()
Set oSS = Nothing
Set oScript = Nothing

Certified Student Course Curriculum - Version 2.0 Page 33


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 4
Security Overview
0
4

All Business objects must have a Security object attached to the Session object or an
error 200 occurs when creating the Business object. When a program is run from Sage
MAS 90, it automatically has this Security object created; however, developers
writing their own interface to Sage MAS 90 Business objects must create a Security
object before instantiating the Business object itself.
The topics in this lesson include:
• Instantiating a Security Object
• Properties of the SY_Security Object
• Methods of the SY_Security Object

Page 34 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Instantiating a Security Object


0

The Security object is created by the Session object using the SetProgram method.
SetProgram accepts one numeric argument, a task ID (required), and a second string
argument (optional) in which the name of the program referenced by the task ID is
returned. The task ID is always for the User Interface (UI) object corresponding to the
Business object to run. For example, if your program uses the General Ledger
Account business object (GL_Account_bus), then you must first call the SetProgram
method with the task ID of the General Ledger Account UI object (GL_Account_ui)
before creating a GL_Account_bus object. Note the handle to the Session object must
pass as the second argument to the NewObject method when creating a new Sage
MAS 90 Business object.
retVAL = oSS.nSetProgram(20000001)
BusObj = oScript.NewObject("GL_Account_bus", oSS)
• Sage MAS 90 program and class names all follow this same schema. For
example: GL_Budget_bus and GL_Budget_ui are the General Ledger Budget
Business and User Interface objects.
Note: This is covered later in the Sage MAS 90 Program Naming Standards topic.
You can obtain the task ID for a program using a Session method called LookupTask.
The LookupTask method takes a program name argument and returns the task ID of
that program.
TaskID = oSS.nLookupTask("GL_Account_ui")
You can then pass the returned value of the LookupTask method to SetProgram:
retVAL = oSS.nSetProgram(TaskID)
You can also do this in one step as follows:
retVAL = oSS.nSetProgram(oSS.nLookupTask("GL_Account_ui"))
• If the SetProgram method was successful, it returns a handle to the Security
object, if not it returns 0 (zero). You can access the Security object by using the
Security property of the Session object as displayed in the example below. Note
the Security property is prefixed with a lower case o because it is a property of a
ProvideX class and its data type is Object.
retVAL = oSS.nSetProgram(oSS.nLookupTask("GL_Account_ui"))
If oSS.oSecurity.nCreateAccess = 1 Then ...
• The CreateAccess property returns 1 (one) if the user has create access in the
General Ledger Account Maintenance program and 0 (zero) if the user does not.
The Security object's properties and methods are listed in the following topics.
Note: Refer to the Standard and Utilities Online Reference for the Security object
documentation.

Certified Student Course Curriculum - Version 2.0 Page 35


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Properties of the SY_Security Object


0

Property Name Data Type Description


CreateAccess Numeric 1 The user has the ability to create new records
or zero in a maintenance program. Create access
assumes the user also has modify access.
DeleteAccess Numeric 1 The user is able to remove records in the
or zero maintenance program.
ModifyAccess Numeric 1 The user is able to modify existing records in
or zero a maintenance program but may not
necessarily be able to create new records or
delete existing ones.
ReadAccess Numeric 1 The user has basic read-only access to the
or zero program. If this flag is not set, no other flags
can or are set. The object, however, gets
created so errors do not occur in some
common programs even though the user has
no access to this program.
SecurityAccess Numeric This property is set as follows:
Read Access only = 0, CreateAccess = 1,
CreateAccess and ModifyAccess = 3,
Full Access (CreateAccess and
ModifyAccess and DeleteAccess) = 7
Print Access Numeric 1 Applies to Report and Update objects only.
or zero This flag is equivalent to the read-only access
flag except with update programs the user is
only able to print reports from an update but
not actually perform the update.
UpdateAccess Numeric 1 Applies to Update objects only. The user is
or zero able to both print and update reports from an
update program. This flag requires that the
print flag is also set.
RoleList String The list of roles assigned to the current user.
The items in the list are delimited with
CHR(138).
TaskName String The name of the program security is validated
against is stored in this property. It is typically
a UI object.

Page 36 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Methods of the SY_Security Object


0

CheckSecurityEvent(event$) / CheckSecurityEvent(event$, user$)


Check whether a user has rights to perform a security event or module option. The
names of the security events in Sage MAS 90 can be referenced by Module using
Role Maintenance.

Syntax obj.nCheckSecurityEvent(event)
obj.nCheckSecurityEvent(event, user)

Parameters event - String (required) - Name of the event to be checked


user – String (optional) - Key to the override user (if nul, then
currently logged on user is checked).
Returns On success: Returns 1
On failure: Returns 0
Example result=oSS.oSecurity.nCheckSecurityEvent
"SE_GLPRIVATEBATCHES")
result= oSS.oSecurity.nCheckSecurityEvent
("SE_GLPRIVATEBATCHES",overrideUserKey)

Notes A return value of 1 indicates the user (either the current user or
the specified override user) has the right to perform the specified
security event or module option.

Certified Student Course Curriculum - Version 2.0 Page 37


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Methods of the SY_Security Object (continued)


0

CheckOverrideOptPassword(user$, password$)
Validate the override password/user combination entered into the Allow Future
Postings override dialog. If a valid user/password was entered, then see if the user has
the rights to perform this security event.

Syntax obj.nCheckOverrideOptPassword(user, password)

Parameters user – String (required) - User name to be validated


password – String (required) - User password to be validated
(may be nul).
Returns On success: Returns 1
On failure: Returns 0
Example result=oSS.oSecurity.nCheckOverridePassword
(ovrdUser, ovrdPass)

Notes A return value of 1 indicates this is a valid user and this user has
rights to perform this security event.
A return value of 0 indicates either the user is invalid, or the user
lacks the right to this security event. In this event,
coSession'LastErrorNum$ and coSession'LastErrorMsg$ is set
for display by the calling program.
This function will be expanded in a future release.

SetToReadOnly( )
Overrides the permissions for the current task to 0 (zero) or Read-Only. This method
is commonly used in inquiry programs to force the maintenance task into a read-only
task. Note this method is irreversable - the task cannot revert back to the original
security setting.

Syntax obj.nSetToReadOnly()

Parameters (none)
Returns Numeric (no value)
Example oSS.oSecurity.nSetToReadOnly()

Notes Sets the rights for the current task to Read-Only. This sets the
following public properties to 0:
CreateAccess, ModifyAccess, DeleteAccess, and UpdateAccess.
The ReadAccess property is set to 1.

Page 38 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 3
0

The purpose of this lab is to review the information learned in the previous topics and
to provide experience using the Security object’s methods and properties. Complete
all steps in this exercise and accept all defaults unless otherwise instructed.
In this exercise, create a new Security object to check a security event for the user.
Use the SetProgram method to get a Security object for the GL_Account_ui program
so you can access a GL_Account_bus Business object. The users SecurityAccess
properties are then displayed in a message box. Some of the detail from the previous
examples is omitted only so the new functionality is emphasized. Enter and save the
following VBScript to a VBS file.
1. Working with the VBScript you created to complete the previous exercise, delete
the following code from steps 10 and 11 of the previous exercise.
MsgBox("Current Company: " & oSS.sCompanyName & vbCRLF &
"Company Data Path: " & oSS.sPathCompany & vbCRLF &
"Current Module: " & oSS.sModuleName & vbCRLF & "Module
Date: " & oSS.sModuleDate)
End If
End If
oSS.nCleanUp()
oSS.DropObject()
Set oSS = Nothing
Set oScript = Nothing
2. Continue by entering the code below at the end of the script. Create a new
Security object and use the CheckSecurityEvent method to check if the user has
rights to access private batches.
Set mySecur = oScript.NewObject("SY_Security", oSS, 0)
PrivateBatches = _
mySecur.nCheckSecurityEvent("SE_GLPRIVATEBATCHES")
If PrivateBatches = 1 Then
MsgBox ("Allow this user access to private batches")
End If
3. Use the SetProgram method to create the Security object for the Business object
to run. The LookupTask method returns the TaskID of the program
GL_Account_ui.
retVAL = oSS.nSetProgram(oSS.nLookupTask("GL_Account_ui"))

Certified Student Course Curriculum - Version 2.0 Page 39


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 3 (continued)


0

4. If SetProgram did not fail (the user has access to the Program), create a new
Business object; otherwise, display the LastErrorMsg. The Session object handle
is required when creating a new Business object.
If retVAL = 0 Then
Set oGLAccount = oScript.NewObject("GL_Account_bus", oSS)
Else
MsgBox(oSS.sLastErrorMsg)
End If
5. Display the user’s security access to the Business object.
MsgBox("Read Access:"& CStr(oSS.oSecurity.nReadAccess)& vbCRLF &_
"Create Access:" & CStr(oSS.oSecurity.nCreateAccess)& vbCRLF & _
"Modify Access:" & CStr(oSS.oSecurity.nModifyAccess)& vbCRLF & _
"Delete Access:" & CStr(oSS.oSecurity.nDeleteAccess))
6. Set the user’s security access to Read Only using the SetToReadOnly method.
Display the change in the Security Access properties.
oSS.oSecurity.nSetToReadOnly()
MsgBox("Read Access:"& CStr(oSS.oSecurity.nReadAccess)& vbCRLF &_
"Create Access:" & CStr(oSS.oSecurity.nCreateAccess)& vbCRLF & _
"Modify Access:" & CStr(oSS.oSecurity.nModifyAccess)& vbCRLF & _
"Delete Access:" & CStr(oSS.oSecurity.nDeleteAccess))

End If
End If
mySecur.DropObject()-
oGLAccount.DropObject()-
oSS.DropObject()------

Set mySecur = Nothing


Set oGLAccount = Nothing
Set oSS = Nothing
Set oScript = Nothing

Page 40 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 5
Foundation Class Overview
0
5

The foundation classes are the building blocks for all the objects in Sage MAS 90 and
200 Version 4.x. These are often referred to as base classes. Most object-based
applications have a foundation class library so common functionality and user
interface standards are adhered to throughout the product. The Sage MAS 90
foundation library consists of classes of these types: Business objects, Service
objects, Report objects, Update objects, and User Interface objects. In this lesson, we
look at the properties and methods of these base classes which are inherited by the
Sage MAS 90 objects accessed through the COM interface.
The topics in this lesson include:
• User Interface Class Level (UI)
• Service Class Level (SVC)
• Business Class Level (BUS)
• Report Classes (RPT)
• Update Classes (UPD)
Note: Refer to the Object Reference for the Foundation Class documentation.

Certified Student Course Curriculum - Version 2.0 Page 41


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

User Interface Class Level (UI)


0

You can access the Sage MAS 90 UI objects through the COM interface using the
Process method. UI objects are instantiated in the same way as a Business object, then
the Process method is invoked which runs the program just as it would run from
within Sage MAS 90. The Process method does not return until the program is closed.
Below is an example of invoking a UI object through COM:
securityOBJ = oSS.nSetProgram(oSS.nLookupTask("GL_Account_ui"))
Set oUIOBJ = oScript.NewObject("GL_Account_ui", oSS)
retVAL = oUIOBJ.nProcess()

Page 42 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Service Class Level (SVC)


Service classes are used primarily for validations but can also have additional logic
added to them to handle any read-only functions required by other applications. The
service class, at its core, is a lighter-weight version of the business class, containing
only methods necessary for reading data out of the data file. Service objects can be
used by your application instead of Business objects when there is no requirement to
modify the data. The properties and methods of the base Service class, which are
inherited by all other Service objects and Business objects, are documented in the
Object Reference (see SY_Service).

Certified Student Course Curriculum - Version 2.0 Page 43


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Business Class Level (BUS)


The Business Class inherits all functionality from the Service Class level and adds the
ability to modify records. The Business object also encapsulates the business rules
necessary to maintain referential integrity within the object and the Sage MAS 90
database. The following list defines what types of actions or rules might be coded into
a business object.
• Default values for new records that are created - Default values are usually
defined in the ProvideX data dictionary and are assigned using the SetDefaults
method when a new record is created.
• Validations for each column in the main table - Some values in the columns
may be restricted as to what range of values are allowed.
• Rules for when records are removed - Some records may be factory defaults
and cannot be removed or other fields or tables may need to be updated when
records are removed.
• Rules for writing data -In particular, other fields or tables that need to be
updated when the main table is updated.
• Security - Specifically security events and module options specific to a particular
application. Task level security is handled by the foundation classes.
There is no user interface embedded in the business class level (message boxes and
prompts); therefore, any application accessing a Business object through the COM
interface needs to provide any desired user-interface. The user is not notified of any
errors occuring directly by the Business object. Instead, the methods used returns a 0
(zero) value (retFAILURE) in the event of an error or failure and the LastErrorNum$
and LastErrorMsg$ properties of the business object are set and used by the user
interface level to display an appropriate error message. The properties and methods of
the base Business class, which are inherited by all other Business objects are
documented in the Object Reference (see SY_Maint and SY_MaintSet).

Page 44 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Report Classes (RPT)


0

The Report object is created by either a module-specific report object (for example,
GL_Report) or the report object itself (for example, SY_RoleReport_rpt) to launch a
Crystal report from a report setting. This object contains methods and properties
needed to launch a Crystal report from a report setting.

Properties of a Report Object


Property Name Data Type Description
LastErrorNum String This property contains the number or
error code of the last error.
LastErrorMsg String This property contains the text of the last
error message.

Methods of a Report Object


ProcessReport(destination)
Prepares report information for passing to Crystal Reports.
Syntax Result = coBusiness.nProcessReport(destination)

Parameters Destination – String (required) Where the report is to be processed


to
Valid Desktionations - "PREVIEW", "PRINT", "DEFERRED",
"EXPORT", and "EXPORTDATA"
Returns On success: retSUCCESS (1)
On warning: retWARNING (-1)
On failure: retFAILURE (0)
Example result=coBusiness.nProcessReport("DEFERRED")

Notes Valid destinations without Sage MAS 90 UI are PRINT and


DEFERRED only

Certified Student Course Curriculum - Version 2.0 Page 45


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Report Classes (RPT) (continued)


0

SetDeferredOptions(prt$, copies, purge$, secure$, collate$)


Stores the values entered on the Deferred Print Options dialog.

Syntax object.nSetDeferredOptions(prt, copies, purge,


secure, collate)

Parameters prt - String (required) - Selected printer


copies – Numeric (required) - Selected number of copies
purge – String (required) - Purge after printing (Y = Yes,
N = No)
secure – String (required) - Limit access to deferred output
collate – String (required) - Collate output (Y = Yes, N = No)
Returns On success: retSUCCESS (1)
On failure: retFAILURE (0)
Example tmp = coReport.nSetDeferredOptions (defPrinter,
defCopies, defPurge, defSecure, defCollate)

Page 46 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Update Classes (UPD)


This object manages the primary processes of an update including register and journal
generation, validation routines for posting periods and years, security events, error
log creation, and update interruption restarts.

Properties of an Update Object


Property Name Data Type Description
CurrentPeriod String Stores the current General Ledger
period from GL_Options.
PeriodEndingDate String Stores the General Ledger period
ending date.
PeriodStartingDate String Stores the General Ledger period
starting date.
LastErrorNum String Contains the number or error code of
the last error.
LastErrorMsg String Contains the text of the last error
message.

Methods of an Update Object


SetPostingDate(postingDate$)
Validates posting date and sets local cPostingDate$ variable.

Syntax objectHandle.nSetPostingDate(postingDate)

Parameters PostingDate – String "YYYYMMDD"


Returns On success: reSUCCESS (1)
On failure: retFAILURE (0)
On warning: retWARNING (-1)
Example RetVAL=obj.nSetPostingDate(postingDate)

SetPrintComment(value$)
Sets the local cPrintFullComment variable for use during the populate register work
table routine.

Syntax objectHandle.nSetPrintComment(checkBoxValue)

Parameters PrintComment – String – "Y" or "N"


Returns On success: retSUCCESS (1)
Example RetVAL=_obj.nSetPrintComment("Y")

Certified Student Course Curriculum - Version 2.0 Page 47


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Update Classes (UPD) (continued)


0

Update( )
Starts the update process. Calls a common program to create future fiscal years and
update beginning balances as necessary. Calls update routines in the register and
update business object: UpdateInit, UpdateMain, and UpdateCleanup.

Syntax objectHandle.nUpdate()

Parameters (none)
Returns On success: retSUCCESS (1)
On failure: retFAILURE (0)
Example retVAL = oPostObject.nUpdate()

ProcessReport(destination$)
Calls the CheckForRestart() method in the register and updates the Business object.
Calls the ProcessReport() method in SY_ReportCommon. Calls the
SetPostingDate(postingDate$) method if necessary.

Syntax objectHandle.nProcessReport(destination)

Parameters destination – String – PRINT, DEFERRED, PREVIEW,


EXPORT, EXPORTDATA
Returns On success: retSUCCESS (1)
On failure: retFAILURE (0)
On warning: retWARNING (-1)
Example retVAL = oGLPost.nProcessReport("DEFERRED")

Notes Valid destinations without Sage MAS 90 UI are PRINT and


DEFERRED only

Page 48 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Update Classes (UPD) (continued)


0

PrintErrorLog( )
Instantiates error log UI object. Processes print dialogue. Called from SY_UpdateUI
if errors exist.

Syntax objectHandle.nPrintErrorLog()

Parameters (none)
Returns On success: retSUCCESS (1)
On failure: retFAILURE (0)
Example retVAL = oUpdateObj.nPrintErrorLog()

Notes

Certified Student Course Curriculum - Version 2.0 Page 49


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 4
0

The purpose of this lab is to review the information learned in the previous topics and
to provide experience creating a new general ledger account with a subaccount.
Complete all steps in this exercise and accept all defaults unless otherwise instructed.
In this exercise, create a new general ledger account and subaccount using the
GL_SubAccount_bus and GL_Account_bus objects. Enter and save the following
VBScript to a VBS file.
1. Working with the VBScript you created to complete the previous exercise, delete
the following code from steps 5 and 6 of the previous exercise.
MsgBox("Read Access:"& CStr(oSS.oSecurity.nReadAccess) & vbCRLF &
"Create Access:" & CStr(oSS.oSecurity.nCreateAccess) & vbCRLF &
"Modify Access:" & CStr(oSS.oSecurity.nModifyAccess) & vbCRLF &
"Delete Access:" & CStr(oSS.oSecurity.nDeleteAccess))
oSS.oSecurity.nSetToReadOnly()
MsgBox("Read Access:"& CStr(oSS.oSecurity.nReadAccess) & vbCRLF &
"Create Access:" & CStr(oSS.oSecurity.nCreateAccess) & vbCRLF &
"Modify Access:" & CStr(oSS.oSecurity.nModifyAccess) & vbCRLF &
"Delete Access:" & CStr(oSS.oSecurity.nDeleteAccess))

End If
End If
mySecur.DropObject()-
oBUSOBJ.DropObject()-
oSS.DropObject()------

Set mySecur = Nothing


Set oGLAccount = Nothing
Set oSS = Nothing
Set oScript = Nothing
2. Continue by entering the code below at the end of the script. Create a new general
ledger subaccount Business object.
Set oGLSubAccount = oScript.NewObject("GL_SubAccount_bus", oSS)
3. Create a new subaccount using the SetKeyValue method from the GL
SubAccount Business object to set the value for the key columns SegmentNo$
and SubAccountCode$.
retVAL = oGLSubAccount.nSetKeyValue("SegmentNo$","03")
retVAL = oGLSubAccount.nSetKeyValue("SubAccountCode$","05")
4. Use the SetKey method from the GL SubAccount Business object to set the Key
for the new subaccount created. SetKey returns a 1 if the key already exists and a
2 if the key is new.
retVAL = oGLSubAccount.nSetKey()

Page 50 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 4 (continued)


0

5. Use the SetValue method from the SubAccount Business object to set the values
for the remaining columns SubAccountDesc$, SubAccountShortDesc$, and
Status$.
retVAL = oGLSubAccount.nSetValue("SubAccountDesc$",_
"West Warehouse")
retVAL = oGLSubAccount.nSetValue("SubAccountShortDesc$",_
"WST WRHSE")
retVAL = oGLSubAccount.nSetValue("Status$","A")
6. Use the Write method to write the record to disk.
retVAL = oGLSubAccount.nWrite()
7. If the Write method failed, display the last error message from the GL
SubAccount Business object and quit.
If retVAL = 0 Then
MsgBox (oGLSubAccount.sLastErrorMsg)
oGLSubAccount.DropObject()
oSS.DropObject()
Set oGLSubAccount = Nothing
Set oSS = Nothing
Set oScript = Nothing
WScript.Quit

Else
MsgBox ("Sub Account Write complete ")
End If
8. Use the SetKey method from the GL Account Business object to set the key for
the new general ledger account created.
retVAL = oGLAccount.nSetKey("100-60-05")
9. Use the SetValue method from the GL Account Business object to set the values
for the remaining general ledger account columns.
retVAL = oGLAccount.nSetValue("Account$","100-60-05")
retVAL = oGLAccount.nSetValue("AccountDesc$",_
"Cash - West Warehouse")
retVAL = oGLAccount.nSetValue("RawAccount$","1006005")
retVAL = oGLAccount.nSetValue("MainAccountCode$","100")
retVAL = oGLAccount.nSetValue("Status$","A")
retVAL = oGLAccount.nSetValue("ClearBalance$","N")
retVAL = oGLAccount.nSetValue("AccountType$","01")
retVAL = oGLAccount.nSetValue("CashFlowsType$","C")
retVAL = oGLAccount.nSetValue("AccountGroup$","000")
retVAL = oGLAccount.nSetValue("AccountCategory$","A")
10. Use the Write method to write the record to disk.
retVAL = oGLAccount.nWrite()
Certified Student Course Curriculum - Version 2.0 Page 51
Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lab - Exercise 4 (continued)


0

11. If the GL Account Write failed, display the last error message from the GL
Account Business object.
If retVAL = 0 Then
MsgBox (oGlAccount.sLastErrorMsg)
Else
MsgBox ("Gl Account Write complete - Script Complete")
End If
12. Destroy the Sage MAS 90 Objects using the DropObject method from
ProvideX.Script.
End If
End If
oGLSubAccount.DropObject()
oGlAccount.DropObject()
oSS.nCleanUp()
oSS.DropObject()
13. Clear the object handles.
Set oGLSubAccount = Nothing
Set oGlAccount = Nothing
Set oss = Nothing
Set oScript = Nothing

Page 52 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 6
Standards Overview
The directory structure, naming standards, and program and file naming standards are
6

covered in detail in the Data File Structures course; however, for reference, a brief
overview is included in this lesson.
The topics in this lesson include:
• Program Naming Standards
• Table Naming Standards

Certified Student Course Curriculum - Version 2.0 Page 53


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Program Naming Standards


0

In general, the program names match the primary data file name whenever possible.
The structure of a program name is as follows:
• Module Identifier - The two-character module identifier is used to prefix all
application programs and objects. Programs and objects are placed in their
respective two-character module identifier directory.
• Master Developer Identifier - If the program is maintained by a Master
Developer, following the two-character module identifier, the developer should
insert their three-character Master Developer identifier following the module
identifier. An underscore does not need to preface the Master Developer
identifier.
• Underscore - The underscore follows the module identifier or the Master
Developer identifier, if it exists, but not both.
• Descriptive Name - The descriptive part of the program name is generally the
name of the primary data table.
• Program Type - Objects have a type code indicating what type of object is
created. The following type names are used by Sage MAS 90 objects. Some
objects may combine one or more of these suffixes.
- _bus - Indicates the object is a primary maintenance (business) object
- _svc - Indicates the object is a service object
- _val - Indicates the object is a validation object
- _ui - Indicates the object is a UI object
- _upd - Indicates the object is an updating object
- _rpt - Indicates the object is a reporting object

Program File Extensions


Sage MAS 90 Classes must have a .PVC extension in order to be recognized as a
Class by ProvideX.
• .M4P - Sage MAS 90 programs not defined as Classes
• No Extension - Sage MAS 90 legacy programs do not have any extension

Page 54 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Program Naming Standards (continued)


0

Program Name Examples


Program Name Description
GL_Account_svc.pvc General Ledger Account Service object
GL_Account_bus.pvc General Ledger Account Business
object
GL_Account_ui.pvc General Ledger Account User Interface
object
GL_Account_val.pvc General Ledger Account Validation
object
GL042_Account_bus.pvc Master Developer (042) modified
Business object
GL_Common.M4P General Ledger common routines
PRWMAA Payroll Employee Maintenance
Note: Not available through the Object
Interface
SO_SalesOrder_bus.pvc Sales Order Entry header Business
object
SO_SalesOrderDetail_bus.pvc Sales Order Entry detail Business
object

Certified Student Course Curriculum - Version 2.0 Page 55


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Table Naming Standards


0

Sage MAS 90 tables for 4.x programs follow a similar naming standard as used by
Sage MAS 90 programs. The file names consist of the two-character module
identifier, the Master Developer identifier if any, and a descriptive name. The only
distinction between the program name and data file name is the file extension. Sage
MAS 90 data files have an extension of .M4T, while Sage MAS 90 legacy data files
have an extension of .SOA. Data files are stored in a central location (under the
MAS_xxx directory where xxx is the company code).

Examples of Sage MAS 90 Table Names


Table Name Description
GL_AccountHistory.M4T General Ledger Account History Table
SO_SalesOrderHeader.M4T Sales Order Header Table
SO_SalesOrderDetail.M4T Sales Order Line/Detail Table
PR1ABC.SOA Payroll Employee Master File

Page 56 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Lesson 7
Example Programs
0
7

In this lesson, review the example programs provided with this curriculum and point
out some things which might require special consideration when developing your
applications.
The topics in this lesson include:
• Transaction Entry
• General Journal Entry
• General Ledger Budget from Excel
• Sales Order Entry
• Visual Basic .NET Example Programs
The Visual Basic examples include the following, which are launched from a
common window displayed after the Sage MAS 90 Session object is fully initiated:
• Sales Order Entry
• Add General Ledger Accounts with UDFs
• General Journal Entry and posting with UDFs
• Printing the General Journal using the RPT object
• Update the General Journal using the UPD object
• Invoking a Sage MAS 90 UI Object (Source Journal Maintenance)
Note: For documentation purposes, the code examples have numbered lines
referencing the text description of the code. These line numbers are not needed and
are not used in live programs.

Certified Student Course Curriculum - Version 2.0 Page 57


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Transaction Entry
0

Transaction entry programs having a header and a line/detail panel such as General
Journal Entry or Sales Order Entry, utilize two Business objects. A header Business
object which maintains the header table and a detail Business object which maintains
the detail table.
• The Header object is instantiated and used much the same way as other Business
objects with a couple of key differences.
- When the Header object is instantiated, it instantiates its corresponding detail
object. So it is not necessary to implicitly instantiate the detail object.
- The Header object has a property named Lines which is an object handle to its
Detail object and is used to access the methods and properties of the Detail
object.

Page 58 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Journal Entry


0

Assume both the ProvideX.Script and Sage MAS 90 Session objects are instantiated
and initialized as oScript and oSS respectively, and the user, company and module are
all set. Then we instantiate a General Ledger General Journal Entry Header Business
object (header) and access the General Journal Detail Business object using the
Header object's Lines property.
1. retVAL = oSS.nSetProgram(oSS.nLookupTask("GL_GeneralJournal_ui"))
2. Set oGLJournalEntry = oScript.NewObject("GL_GeneralJournal
_bus",oSS)
3. retVAL = oGLJournalEntry.MoveFirst()
4. retVAL = oGLJournalEntry.oLines.MoveFirst()
5. Set oJrnlLines = oGLJournalEntry.oLines
6. retVAL = oJrnlLines.MoveLast()

1 You must obtain a Security object by calling the SetProgram method with
the Task ID of the UI object before accessing the Business object.
2 The header Business object is instantiated in the same way as other Business
objects, using the NewObject method, passing in the class name of the
Header object, and a reference to the Session object.
3 The Header object's MoveFirst() method is invoked first to set the Header
Key.
4 Invoke the Detail object's MoveFirst() method which sets the pointer to the
first key of the records in the detail table and match the Header Key and
reads the record.
5 Assign the Detail object handle to a variable of type Object.
6 Access the Detail object with that variable. On this line, the Detail object's
MoveLast() method sets the pointer in the detail table to the last key of the
records matching the Header Key.

Certified Student Course Curriculum - Version 2.0 Page 59


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Journal Entry (continued)


0

Maintaining or creating header and detail records


The first step to maintaining or creating new transactions is setting the Header Key.
This is done by invoking the SetKey() method after using the SetKeyValue() method
to set the value of each of the key segments. For example, the key of the General
Journal header table consists of two segments: SourceJournal$ and EntryNo$. The
following lines set the header key for the General Journal Business object:
1. retVAL = oGLJournalEntry.nSetKeyValue("SourceJournal$", "AP")
2. retVAL = oGLJournalEntry.nGetNextEntryNo("AP", strEntryNo)
3. retVAL = oGLJournalEntry.nSetKeyValue("Entryno$", strEntryNo)
4. retVAL = oGLJournalEntry.nSetKey()

1 The first key segment, SourceJournal$, is set to Accounts Payable.


2 The GetNextEntryNo() method returns the next available entry number for
a Source Journal.
3 The second key segment, EntryNo$, is set to the entry number returned by
GetNextEntryNo().
4 The Header object's SetKey() method is invoked which sets the file pointer
of the Header table to AP000005. If the key does not exist, then a new
record is created.

After SetKey is performed, the HeaderKy$ property of the Detail object is set and any
matching detail records are loaded into a memory file. You can then change, delete, or
create the detail records in the memory file using the detail Business object. The
Detail object only maintains this memory file, any changes are not written to disk
until the Write() method of the Header object is invoked.
The detail records are accessed just like the records of any Business object. You can
browse records using MoveFirst() and MoveNext(). You can also access individual
detail records using the Find() method as follows:
retVAL = oJrnlLines.nMoveNext()
retVAL = oJrnlLines.nFind(keyValue)

Page 60 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Journal Entry (continued)


0

Below are the method calls to the General Journal Detail Business object to create a
new detail record for the Header Key set on the previous page and write it to the
Detail Object's memory file.
1. retVAL = oJrnlLines.nAddLine()
2. retVAL = oJrnlLines.nSetValue("AccountKey$","100-00-00",
"kACCOUNT")
3. retVAL = oJrnlLines.nSetValue("PostingComment$","Debit Amount")
4. retVAL = oJrnlLines.nSetValue("DebitAmount", 200)
5. retVAL = oJrnlLines.nWrite()

1 The AddLine() method is used to create a new detail line.


2 SetValue() sets the value of the AccountKey$ column to 100-00-00 using
an alternate index kACCOUNT when the account number is validated.
kACCOUNT is necessary here because the primary key of GL_Account is
not formatted ("100000000") and we are passing in 100-00-00.
3 SetValue() sets the PostingComment$ column to Debit Amount.
4 SetValue() sets the DebitAmount column to 200.
5 The Detail object's Write() method writes the new detail record to the
memory file.

Similar logic is repeated for each of the new detail lines to create. To write the header
and any new or changed detail records to disk, the Write() method of the Header
object is invoked as follows:
retVAL = oGLJournalEntry.nWrite()
Note: Refer to Appendix A for a complete documented listing of the General Journal
Entry example.

Certified Student Course Curriculum - Version 2.0 Page 61


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Ledger Budget from Excel


0

The GL Period Budget Detail Business object is used in this example to retrieve
original and revised budget data from an Excel spreadsheet using the Excel COM
object. The account number and fiscal year information for the budget data is also
retrieved from Excel. This information is used by the GL Period Budget Detail
Business object to enter the period budget debit and credit amounts into the
GL_PeriodBudgetDetail.M4T table.
Note: Refer to Appendix A for a complete documented listing of this example.
Listed below are unique key points to using the Sage MAS 90 Business objects in this
example. The requirements are:
• The ABC company demo data which has original budget data for the fiscal year
2010.
• The GLbudgetreport.xls Excel spread sheet is available with the class downloads.
• The GLbudgetreport.xls file must be in this location on the workstation running
the example: C:\Temp\GLbudgetreport.xls.
The first issue encountered was the required Business object does not have a like-
named corresponding UI object to reference in the SetProgram() call. In these cases,
SetProgram needs to reference another or similar UI object from the same module for
which security is set appropriately to enable the Business object to perform the
required tasks. In this program and as shown below, we passed the task ID for
GL_BudgetMaintenance_ui then instantiated the GL_PeriodBudgetDetail_bus
Business object.
retVAL = oSS.nSetProgram(oSS.nLookupTask("GL_BudgetMaintenance
_ui"))
Set oGLBudget = oScript.NewObject("GL_PeriodBudgetDetail_bus",
oSS)
The next consideration was the general ledger account numbers supplied by the
source data are fully formatted account numbers. This is an issue because the
AccountKey$ column in the budget detail records requires the nonformatted account
number.

Page 62 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

General Ledger Budget from Excel (continued)


0

To solve this, we used the GL_Account service object to access the GL_Account
record by the supplied formatted account number (Account$ column), then we can
retrieve the nonformatted account number (AccountKey$ column) to use with the
budget SetKeyValue() method.
1. Set oGLService = oScript.NewObject("GL_Account_svc", oSS)
2. retVAL = oGLService.nSetIndex("kACCOUNT")
3. retVAL = oGlService.nFind(fmtAccount)
4. Dim Record As String = ""
5. Dim IOList As String = ""
6. retVAL = oGLService.nGetRecord(Record,IOList)
7. Dim Columns() As String
8. Columns = Split(Record,Chr(138))
9. AccountKey = Columns(0)

10. retVAL = oGLBudget.nSetKeyValue("AccountKey$", Accountkey)

1 Instantiate a GL_Account Service object and set the object handle in the
variable oGLService.
2 Set the current index of the service object to kACCOUNT. By default the
index is kPRIMARY, which is not the formatted account number.
3 Find the GL_Account using the formatted account key from the source
data.
4 Declare variable as string and assign its value so it passes as a parameter.
5 Same as line 4.
6 The GetRecord() method returns the data of the current record set on line 3.
The data is returned in the first parameter and the columns are separated by
Chr(138), which is the default ProvideX field separator. The record's IO
List is returned in the second parameter.
7 Declare a String array to contain the current record's columns.
8 Use the VB Split function to store the individual column values into
elements of an array. Specify Chr(138) as the delimiter.
9 The nonformatted AccountKey$ is the first column accessed from the first
element of the array.
10 The key value can now be set for the AccountKey$ with the value of the
first column returned by the GetRecord() method.

Certified Student Course Curriculum - Version 2.0 Page 63


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Sales Order Entry


0

The following is an example of the same basic logic used to create a new sales order
using the Sales Order Business object:
1. oSS.nSetProgram(oSS.nLookupTask("SO_SalesOrder_ui"))
2. oSOOrder = oScript.NewObject("SO_SalesOrder_bus", oSS)
3. oSOOrder.nGetNextSalesOrderNo(NextOrderNo)
4. oSOOrder.nSetKeyValue("SalesOrderNo$", NextOrderNo)
5. oSOOrder.nSetKey()
6. oSOOrder.nSetValue("ARDivisionNo$", "02")
7. oSOOrder.nSetValue("CustomerNo$", "ORANGE")
8. oSOOrder.oLines.nAddLine()
9. oSOOrder.oLines.nSetValue("ItemCode$", "D2000")
10. oSOOrder.oLines.nSetValue("QuantityOrdered", 2)
11. oSOOrder.oLines.nWrite()
12. oSOOrder.nWrite()

1 SetProgram with the Task ID of the UI object before accessing the Business
object.
2 Create a new SO_SalesOrder_bus object oSOOrder as the object handle.
3 GetNextSalesOrderNo() returns the next automatic sales order number.
4 The header key is set to the number returned by GetNextSalesOrderNo().
5 Set the file pointer of the Header table. The key does not exist so a new
record is created.
6 Set the value of ARDivisionNo$ to 02.
7 Set the value of CustomerNo$ to ORANGE.
8 Create a new detail line for this header.
9 Set the value of the detail line ItemCode field to D2000.
10 Set the value of the detail line QuantityOrdered field to 2.
11 The Detail Object's Write() method writes the new detail record to the
memory file.
12 The Header Object's Write() method writes the header and any new or
changed detail records to disk.

Page 64 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs


0

The Visual Basic example programs were developed in Visual Studio .Net, using
Visual Basic 2003. Version 1.1 of the .Net Framework is required to run the example.
The following is an example of the required code in VB needed to instantiate a
Sage MAS 90 Session object:
Public Class Form1
Inherits System.Windows.Forms.Form

+ Windows Form Designer generated code

1. Dim oScript As Object


2. Dim oSS As Object

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e _


As System.EventArgs) Handles MyBase.Load

3. oScript = CreateObject("ProvideX.Script")
4. oScript.Init("C:\Program Files\Sage\MAS90\HOME")
5. oSS = oScript.NewObject("SY_Session")

End Sub

End Class

Certified Student Course Curriculum - Version 2.0 Page 65


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

1 Declare an object handle for the ProvideX.Script class.


2 Declare an object handle for the Sage MAS 90 Session object.
3 Create new ProvideX.Script object.
4 Initialize the ProvideX.Script object with the ..\MAS90\Home path.
5 Creates a new Sage MAS 90 Session object.

The MAS90_VB2 Project Design


One of the goals when designing the Visual Basic example project included with this
course was to keep the VB code as simple as possible to better highlight the logic
specific to PVXCOM and Sage MAS 90. The result is that separate programs were
created to illustrate one, maybe two key concepts each. If you are new to interfacing
with COM objects in your programs, we wanted to make it clear there is no
requirement or benefit to this design approach. In fact, if this was a real world
application, it would have been easier to code it up in a single program.
References added to the MAS90_VB2 Project
To enable the Excel COM objects used in the BudgetFromExcel.vb example, a
reference to the Microsoft Excel Object Library was added. This requires Microsoft
Office is installed on the workstation where you are running Visual Studio.
The StartUpModule.vb Program
When the MAS90_VB2 application executes, the first program running is
StartUpModule.vb. This program's main function is to create and initialize a Sage
MAS 90 Session. To do this, the program creates a ProvideX Script object, creates a
Sage MAS 90 Session object, logs on to Sage MAS 90, and then sets the company,
the module, and the module date.
The PVXCOM and Session objects created are defined as Public because they are
used by all of the other programs in the project. Also, declared as Public in the start up
program are handles to the common dialog programs used to prompt for company,
user/password, and module date.
After the Sage MAS 90 Session is ready to use, StartUpModule.vb runs the
MAS90_Examples.vb program. When MAS90_Examples.vb terminates,
StartUpModule.vb picks up where it left of to clean up, drop the Session object, and
then terminates.

Page 66 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

The following is a listing of the StartUpModule.vb program with the key statements
numbered. The numbered statements are documented in the table after the listing.
Imports System.Text

Module StartUpModule

1. Public oScript
2. Public oSS
3. Public CompanyDLG As New MAS90_Company()
4. Public LogonDLG As New MAS90_Logon()
5. Public DateDLG As New MAS90_Date()
6. Public retVAL As Integer

Sub Main()

'Fetch MAS90 path from SOTAMAS90 registry key


Dim SOTAMAS90Key = Microsoft.Win32.Registry.CurrentUser.
OpenSubKey ("Software\ODBC\ODBC.INI\SOTAMAS90")
Dim InitPath = SOTAMAS90Key.GetValue("Directory") & "\Home"

'Instantiate the ProvideX Script Object that will be used


'by all programs. Init() must be the first method called
7. oScript = CreateObject("ProvideX.Script")
8. oScript.Init(InitPath)
'Instantiate the MAS90 Session Object to be used by all programs
'The Session object must be available to all MAS90 objects
9. oSS = oScript.NewObject("SY_SESSION")

'If MAS90 Security is enabled or not using Integrated Logon,


'then the Logon() method will return 0

Certified Student Course Curriculum - Version 2.0 Page 67


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

10. If Not (CBool(oSS.nLogon())) Then

Do
11. LogonDLG.ShowDialog()
12. If LogonDLG.DialogResult=DialogResult.Cancel Then GoTo CLEANUP
13. Loop Until CBool(oSS.nSetUser(LogonDLG.UserName.Text,
LogonDLG.Password.Text))
End If

'Set the Session date, module and company


14. oSS.nSetModule("SYS")
'Company must be configured to allow external access
15. CompanyDLG.ShowDialog()
16. If Not (CBool(oSS.nSetCompany(Left(CompanyDLG.Company.Text,
3)))) Then
MessageBox.Show(oSS.sLastErrorMsg)
GoTo CLEANUP
End If

'Run the MAS90 Business Framework Interface program


17. System.Windows.Forms.Application.Run(New MAS90_Examples())

CLEANUP:
18. oSS.nCleanUp()
19. oSS.DropObject()
oSS = Nothing
oScript = Nothing

End Sub
End Module

Page 68 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

1 Define a public object handle to the ProvideX.Script object.


2 Define a public object handle to the Sage MAS 90 Session object.
3 Define public handle to the Select Company dialog (MAS90_Company.vb).
4 Define public handle to the Logon/Change User dialog(MAS90_Logon.vb).
5 Define public handle to the Change Date dialog (MAS90_Date.vb).
6 Define public Integer variable for Success/Failure return values.
7 Create ProvideX.Script object and assign the object handle to oScript.
8 Initialize the ProvideX.Script object using the path to MAS90\Home.
9 Instantiate the Session object and assign the object handle to oSS.
10 If the Logon method fails, then use SetUser() to logon to Sage MAS 90.
11 Display the Logon dialog (MAS90_Logon.vb) to obtain user/password.
12 If the Logon Dialog is canceled, then clean up and quit.
13 Loop until the SetUser method returns success.
14 Set the module to Library Master.
15 Display the Select Company dialog (MAS90_Company.vb).
16 Set the company to the company code selected in the Company dialog.
17 Run MAS90_Examples.vb (all other examples are run from this form).
18 Calls the Session Cleanup method.
19 Destroys the Session object.

Certified Student Course Curriculum - Version 2.0 Page 69


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


The MAS90_Examples.vb Program
After the StartUpModule.vb program successfully logs on to Sage MAS 90 and sets
the company and module, it runs the MAS90_Examples.vb program. The
MAS90_Examples.vb program opens the window displayed below.

Figure 3

• The function of this program is to launch the various VB example programs when
the user clicks the buttons. When one of the buttons is clicked, the SetSession()
function is called to set up the Session to run the example program.
• The Session is set up by making calls to the SetModule(), SetModuleDate, and
SetProgram methods to set these Session properties to an appropriate value.
- If SetSession() is successful, the example program is launched and because
the session is already set up for the program being launched, all this program
has to do is create the Business object and start using it.
- The Session properties displayed on this window (path, company, and user)
are also kept current by the MAS90_Examples.vb program.
• When MAS90_Examples.vb is closed, the StartUpModule.vb program resumes to
destroy the Session object and clean up.

Page 70 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

MAS90_Examples.vb Listing
The following Form_Load logic just displays the Session properties initially set in the
StartUpModule.vb program. (Path, Company, User, Module, and Date).
Public Class MAS90_Examples
Inherits System.Windows.Forms.Form

Private Sub Form_Load(ByVal sender As System.Object, ByVal e As _


System.EventArgs) Handles MyBase.Load
'display some Session Properties
1. Me.Text = oSS.sCaption & "Examples(" & oSS.sCompanyCode & ")"
& oSS.sFormatDate((oSS.sSystemDate))
2. PathRoot.Text = oSS.sPathRoot
3. Company.Text = oSS.sCompanyName
4. UserName.Text = oSS.sUserName
5. ModuleName.Text = oSS.sModuleName
6. ModuleDate.Text = oSS.sFormatDate((oSS.sSystemDate))
End Sub

1 Display the caption, company, and date properties in the Title Bar.
2 Display path to Sage MAS 90.
3 Display the name of the current company.
4 Display the user name.
5 Display the name of the current module.
6 Display the module date.

Certified Student Course Curriculum - Version 2.0 Page 71


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

This is the SetSession() logic which sets up the session for each of the example
programs launched from the buttons on the MAS90_Examples.vb window. It requires
the use of the module code and the UI program name of the Business object in the
example to be passed as parameters.
• If this function succeeds, then the module and date displayed on the window are
updated and the example program is launched.
• If this function fails, then the LastErrorMsg property displays, the module is set
back to Library Master, and the program does not launch.
Private Function SetSession(ByVal Module, ByVal ProgramName)

Dim TaskID As Integer = 0


Dim MASDate As String = ""
Dim tmpModuleName As String = ""
Dim ExpirationDate As String = ""

1. If (CBool(oSS.nGetModuleInfo(Module, tmpModuleName,
ExpirationDate))) Then
2. TaskID = oSS.nLookupTask(ProgramName)
3. If TaskID <> 0 Then
4. If Not (CBool(oSS.nGetDate(ModuleCode, MASDate))) Then
5. DateDLG.Label1.Text = "Select date for " &
tmpModuleName
6. DateDLG.ModuleDate.Text = oSS.sFormatDate
((oSS.sModuleDate))
7. DateDLG.ShowDialog()
8. If Not (DateDLG.DialogResult=DialogResult.Cancel) Then
9. MASDate = DateDLG.ModuleDate.Text
End If
End If
10. If MASDate = "" Then Return False

Page 72 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

11. If (CBool(oSS.nSetDate(ModuleCode, MASDate))) Then


12. If (CBool(oSS.nSetModule(ModuleCode))) Then
13. If (CBool(oSS.nSetProgram(TaskID))) Then
14. ModuleName.Text = oSS.sModuleName
15. ModuleDate.Text = oSS.sFormatDate
((oSS.sModuleDate))
16. Return True

End If
End If
End If
End If
End If
17. MessageBox.Show(oSS.sLastErrorMsg)
18. oSS.nSetModule("SYS")
19. Return False

End Function

Certified Student Course Curriculum - Version 2.0 Page 73


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

1 Call to the GetModuleInfo() method to get the module name.


2 Get the TaskID of the given ProgramName. Is used to Set Program.
3 Fail now if a valid TaskID was not returned.
4 If a date is not set for the given module, then prompt user for date.
5 Set the text to display on the prompt for date dialog box.
6 Set the text to display in the Title Bar of the date dialog.
7 Launch the prompt for date program and display the dialog box.
8 If the user did not click the Cancel button on the date dialog.
9 Save the date selected in a local variable to use later.
10 Fail now if we do not have a valid module date.
11 Fail now if we are not able to set the module's date.
12 Fail now if we are not able to set the current module.
13 Fail now if we are not able to set the program and get security.
14 Session was set up successfully, update the displayed module name.
15 Session was set up successfully, update the displayed module date.
16 Session was set up successfully, return Success or True.
17 Setup Failed, display the reason for failure.
18 Setup Failed, reset the current module to Library Master.
19 Setup Failed, return Failure or zero.

Page 74 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

This is a listing of one of the button-click event handlers in the MAS90_Examples.vb


program which launches the example program. In this case, AddAccount.vb, if
SetSession returns success. The SetSession() function is called with the module code
and UI program name of the Business object used in the example.
• If the SetSession returns success, the AddAccount.vb program is launched. This
logic is the same for each of the buttons that launch an example program.
Private Sub BT_AddAccount_Click(ByVal sender As System....

1. If SetSession("G/L", "GL_Account_ui") Then

2. Dim AddAccount As New AddAccount


3. AddAccount.ShowDialog()
4. AddAccount = Nothing

End If

End Sub

1 If SetProgram() returns success, then launch the example program.


2 Create a new object of the AddAccount.vb class.
3 Launch the AddAccount.vb example program.
4 Set the AddAccount object handle to nothing.

Certified Student Course Curriculum - Version 2.0 Page 75


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

AddAccount.vb
The BT_AddAccount_Click() method launches the AddAccount.vb program.
AddAccount.vb uses the G/L Account Business object to maintain account records
and it uses a Report object to run the General Ledger Chart of Accounts report. This
example also demonstrates how to work with user-defined fields (UDFs) and tables
(UDTs) defined in the Sage MAS 90 Customizer module. The information needed, if
you want to set up the UDFs and UDTs so this part of the example works, is included
later in this curriculum.
Public Class AddAccount
Inherits System.Windows.Forms.Form

1. Dim oBusObjB As Object


2. Private oProjSvc As Object
3. Private UDFSetup As Boolean = True

+ Windows Form Designer generated code

Private Sub AddAccount_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

Try
4. oBusObjB = oScript.NewObject("GL_Account_bus", oSS)
Catch
5. MessageBox.Show(oSS.sLastErrorMsg)
Exit Sub
End Try

Try
' Get an object handle for the Project UDF child object
6. oProjSvc = oBusObjB.oGetChildHandle("UDF_PROJECTCODE")
Catch ex As Exception
' If this fails the Project UDF/UDT setup is not present
lblProjDesc.Text = "Project UDF/UDT setup is not present"
7. UDFSetup = False
End Try

End Sub

Page 76 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

Private Sub btnMoveFirst_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnMoveFirst.Click

8. oBusObjB.nMoveFirst()
9. Call SetFields()

End Sub

Private Sub btnMovePrev_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnMovePrev.Click

8. oBusObjB.nMovePrevious()
9. Call SetFields()

End Sub

Private Sub btnMoveNext_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnMoveNext.Click

8. oBusObjB.nMoveNext()
9. Call SetFields()

End Sub

Private Sub btnMoveLast_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnMoveLast.Click

8. oBusObjB.nMoveLast()
9. Call SetFields()

End Sub

10. Private Sub SetFields()


11. oBusObjB.nGetValue("Account$", txtMainAccount.Text)
12. txtMainAccount.Enabled = False

Certified Student Course Curriculum - Version 2.0 Page 77


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

11. oBusObjB.nGetValue("AccountDesc$", txtDescription.Text)


12. txtDescription.Enabled = True
13. If UDFSetup Then
11. oBusObjB.nGetValue("UDF_ProjectCode$", txtProject.Text)
14. oBusObjB.nReadAdditional("UDF_ProjectCode")
11. oProjSvc.nGetValue("UDF_ProjectDesc$", lblProjDesc.Text)
12. txtProject.Enabled = True
End If

End Sub

Private Sub btnClear_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnClear.Click

15. oBusObjB.nClear()
9. Call SetFields()
12. lblNewRecord.Text = ""
12. txtDescription.Enabled = False
12. txtProject.Enabled = False
12. txtMainAccount.Enabled = True

End Sub

Private Sub txtMainAccount_Leave(ByVal sender As Object, _


ByVal e As System.EventArgs) Handles txtMainAccount.Leave

If txtMainAccount.Text <> "" Then


16. retVAL = oBusObjB.nSetKey(txtMainAccount.Text)
If retVAL = 0 Then
17. MessageBox.Show(oBusObjB.sLastErrorMsg)
18. btnClear.PerformClick()
Else
19. If retVAL = 2 Then lblNewRecord.Text = "New Record"
9. Call SetFields()
End If
End If

Page 78 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

End Sub

Private Sub btnWrite_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnWrite.Click

20. retVAL = oBusObjB.nWrite()

If retVAL = 0 Then
17. MessageBox.Show(oBusObjB.sLastErrorMsg)
End If

18. btnClear.PerformClick()

End Sub

Private Sub txtDescription_Leave(ByVal sender As Object, _


ByVal e As System.EventArgs) Handles txtDescription.Leave

21. retVAL = oBusObjB.nSetValue("AccountDesc$", txtDescription.Text)

If retVAL = 0 Then
17. MessageBox.Show(oBusObjB.sLastErrorMsg)
lblProjDesc.Text = ""
End If

End Sub

Private Sub txtProject_Leave(ByVal sender As Object, ByVal e As _


System.EventArgs) Handles txtProject.Leave

20. retVAL=oBusObjB.nSetValue("UDF_ProjectCode$",txtProject.Text)

If retVAL = 0 Then
17. MessageBox.Show(oBusObjB.sLastErrorMsg)
lblProjDesc.Text = ""
Else

Certified Student Course Curriculum - Version 2.0 Page 79


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

11. oProjSvc.nGetValue("UDF_ProjectDesc$", lblProjDesc.Text)


End If

End Sub

Private Sub btnPrint_Click(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles btnPrint.Click

22. Dim oRpt As Object


23. oRpt = oScript.NewObject("GL_ChartOfAccounts_rpt", oSS)
24. oRpt.nSelectReportSetting("STANDARD")
25. If oSS.nUI = 0 Then oSS.nInitiateUI()
26. retVAL = oRpt.nProcessReport("PREVIEW")
If retVAL = 0 Then
17. MessageBox.Show(oRpt.sLastErrorMsg)
End If
27. oRpt.DropObject()
oRpt = Nothing

End Sub

Private Sub AddAccount_Closing(ByVal sender As Object, ByVal e As _


System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

27.oBusObjB.DropObject()
28.If UDFSetup Then oProjSvc.DropObject()

oBusObjB = Nothing
oProjSvc = Nothing

End Sub
End Class

Page 80 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

1 Define an Object handle for the Sage MAS 90 GL_Account_bus object.


2 Define an Object handle for the Project UDF Child object.
3 Boolean variable used to indicate if the Project UDF is set up.
4 Create NewObject of the GL_Account_bus class.
5 If NewObject method fails, display LastErrorMsg for reason and exit.
6 Try to get a Child object for a DataSource named UDF_PROJECTCODE.
7 If GetChild fails, then the UDF is not setup. Set UDFSetup to False.
8 Move file pointer to First, Previous, Next, or Last record.
9 Update the screen controls with the current record.
10 This routine is called when the screen controls need to update.
11 Get the value for a field from the current record.
12 Enable/Disable a Screen control (when the record state changes).
13 If the UDF is set up, get the UDFs value for the current record.
14 Perform finds for the UDF Child Object Key Collection.
15 Clear the Business objects record. Sets the current record to None.
16 Sets the file pointer to the given Key. Sets the current record.
17 If the method returns failure, display the object's LastErrorMsg.
18 Invoke the Clear button logic. Clears the record and screen.
19 SetKey() returns 2 if the given key is not found. New record.
20 Writes the current record to file.
21 Update the column in the current record to the given value.
22 Define an Object handle for a General Ledger Chart of Accounts Report
object.
23 Create the GL_ChartOfAccounts_rpt Report object.
24 Reads Report Settings and Options for the STANDARD report setting.
25 Instantiate the UI class. Required for the Print/Preview window.

Certified Student Course Curriculum - Version 2.0 Page 81


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

26 Prepare report and pass it to Crystal Reports – Destination Preview.


27 Call the objects destructor and delete the object from memory.
28 If the UDF is set up, then call the UDF Child Objects destructor.

Page 82 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Visual Basic .NET Example Programs (continued)


0

The UDF/UDT Setup for the AddAccount.vb and JournalEntry.vb Programs


The AddAccount.vb and JournalEntry.vb examples include logic to demonstrate how
to work with Sage MAS 90 user defined fields and tables (UDFs and UDTs). This
logic is conditionalized so the examples still work if this setup is not done. The
following outlines the steps to set up the UDF and UDT for logic in the examples to
work correctly. If you are not familiar with this process, step-by-step instructions with
screen shots are found in Appendix B.
1. Create a User-Defined Table for the General Ledger module as follows:
Enter Table Name: PROJECTS (Customizer will prefix this with GL_UDT)
Accept defaults for the remaining fields and click OK

Table Name: GL_UDT_PROJECTS


Key Field Name: UDF_PROJECT_CODE
Key Field Length: 10

Add Field: UDF_PROJECTDESC, Multi-Line, String, and Length=30


Click 'Ok', then 'Ok' again to recompile the dictionary
2. Enter a few rows in the GL Projects UDT.
Right-click GL Projects (UDT) and select 'Maintain UDT Data'
3. Create a UDF for the GL Account Master table.
Field Name: UDF_PROJECTCODE
Source: Manual Entry
Object Type: Multi-Line
Data Type: String, Length: 10
Validation: User-Defined Table – GL_UDT_PROJECTS
4. Create a UDF for the GL General Journal Detail table.
Field Name: UDF_PROJECT
Source for UDF: Business Object
Data Source: AccountKey
Column: UDF_PROJECTCODE
Validation: User-Defined Table - GL_UDT_PROJECTS

Certified Student Course Curriculum - Version 2.0 Page 83


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

1
Appendix
The following topics are included in this Appendix:
• Appendix A - Example Program Listings and Documentation
• Appendix B - UDF / UDT Setup for Example Programs
• Appendix C - Message Library Reference
• Appendix D - Sage MAS 90 Security Events and Module Options

Page 84 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and


Documentation
1

General Journal Transaction Entry - VBS


'GL General Journal Transaction Entry VBX
'Copyright 2005 Sage Software, Inc.
1. Set oReg=GetObject("winmgmts:\\.\root\default:StdRegProv")
2. Reg.GetExpandedStringValue&H80000001,
"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
3. PathHome = PathRoot & "\Home"

1 Set Object handle to Windows Registry provider


2 Get the ODBC path for the last installed version of Sage MAS 90
3 Assign the Home path based on the value from the Windows Registry

4. Set oScript = CreateObject ("ProvideX.Script")


5. oScript.Init(PathHome)

4 Create new ProvideX Script object


5 Initialize the ProvideX Script object with the ..\MAS90\Home path

6. Set oss = oScript.NewObject("SY_SESSION")

6 Create new Sage MAS 90 Session object

'The Logon method returns 1 if Sage MAS 90 Security is not enabled


or if Sage MAS 90 has been configured to use Windows Security
7. retVAL = oss.nlogon()
'If the Logon method fails then you must use the SetUser method to
'be allowed access
8. If retVAL = 0 Then
9. ---User = Trim(InputBox("Enter User Name"))
10. --Password = Trim(InputBox("Enter Password"))
11. --retVAL = oSS.nSetUser(User,Password)
End If

Certified Student Course Curriculum - Version 2.0 Page 85


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

7 Call the Logon method to log on to Sage MAS 90


8 If the Logon method failed, take appropriate action
9 Assign user from value in input box
10 Assign password from value in input box
11 Set the user in Sage MAS 90 using the values assigned

'If the Logon fails, display LastErrorMsg and quit


12. If retVAL = 0 Then
13. ---MsgBox(CStr(retVAL) & " - " & oSS.sLastErrorMsg & vbCRLF &
"Quiting")
14. ...WScript.Quit
End If

12 If the SetUser method failed, take appropriate action


13 Display the last error message of the Session object
14 Quit the script

15. oSS.nSetCompany ("ABC")


16. retVAL = oss.nSetDate("G/L", "20050125")
17. oss.nSetModule("G/L")

15 Set the Sage MAS 90 company using the method from the Session object
16 Set the module date using the method from the Session object
17 Set the Sage MAS 90 module using the method from the Session object

'Create new GL General Journal Business Object


18. retVAL = oSS.nSetProgram(oss.nLookupTask("GL_
GeneralJournal_ui"))
19. Set oGLJournalEntry = oScript.NewObject("GL_GeneralJournal_
bus",oSS)
20. Set oGLJournalLines = oGLJournalEntry.oLines
21. Set oGLSJObject = oScript.NewObject("GL_SourceJournal_svc", oSS)

Page 86 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

18 Set the Sage MAS 90 program by Task ID using the method from the
Session object. This method also creates a Security object for the program
to run. If no Security object is created, the program cannot run
19 Set the Object handle to the General Journal Business object
20 Set the Object handle to the General Journal Detail Business object for
handling the line entry for the transaction
21 Set the Object handle to the Source Journal Service object

22. retVAL = oGLJournalEntry.nSetKeyValue("SourceJournal$","AP")


23. strEntryNo = ""
24. retVAL = oGLSJObject.nGetNextJournalNo("AP",strEntryNo)
25. retVAL = oGLJournalEntry.nSetKeyValue("Entryno$",strEntryNo)
26. retVAL = oGLJournalEntry.nSetKey()

22 Use the SetKeyValue Method in the General Journal Business object to set
the Key Column value for the Source Journal to Accounts Payable used in
this transaction
23 Assign a string value to the variable used to accept an entry number from
the GetNextJournalNo ( ) method
24 Use the GetNextJournalNo method in the Source Journal Service object to
assign the next available General Journal Entry number
25 Use the SetKeyValue method in the General Journal Business object to set
the Key Column value for the Entry Number used in this transaction
26 Use the SetKey method in the General Journal Business object to set the
key based on the values assigned by the SetKeyValue method calls

27. retVAL = oGLJournalEntry.nSetValue("PostingDate$","01/07/2005")


28. retVAL = oGLJournalEntry.nSetValue("JournalComment$","This is a
VBS Entry")

27 Use the SetValue method in the General Journal Business object to set the
value for the PostingDate column
28 Use the SetValue method in the General Journal Business object to set the
value for the JournalComment column

Certified Student Course Curriculum - Version 2.0 Page 87


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation


1

'Write Debit line


29. retVAL = oGLJournalLines.nAddLine()
30. retVAL = oGLJournalLines.nSetValue("AccountKey$","100-00-00",
"kACCOUNT")
31. retVAL = oGLJournalLines.nSetValue("PostingComment$","VBS Debit
Amount")
32. retVAL = oGLJournalLines.nSetValue("DebitAmount", 200)
33. retVAL = oGLJournalLines.nWrite()

29 Use the AddLine method in the General Journal Detail Business object to
create a new line
30 Use the SetValue method in the General Journal Detail Business object to
set the value for the AccountKey column
31 Use the SetValue method in the General Journal Detail Business object to
set the value for the PostingComment column
32 Use the SetValue method in the General Journal Detail Business object to
set the value for the Debit Amount column
33 Use the Write method in the General Journal Detail Business object to
write the line to the memory file

'Write Credit line


34. retVAL = oGLJournalLines.nAddLine()
35. retVAL = oGLJournalLines.nSetValue("AccountKey$","205-00-00",
"kACCOUNT")
36. retVAL = oGLJournalLines.nSetValue("PostingComment$","VBS Credit
Amount")
37. retVAL = oGLJournalLines.nSetValue("CreditAmount", 200)
38. retVAL = oGLJournalLines.nWrite()

Page 88 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

34 Use the Add method in the General Journal Detail Business object to create
a new line
35 Use the SetValue method in the General Journal Detail Business object to
set the value for the AccountKey column
36 Use the SetValue method in the General Journal Detail Business object to
set the value for the Posting Comment column
37 Use the SetValue method in the General Journal Detail Business object to
set the value for the Credit Amount column
38 Use the Write method in the General Journal Detail Business object to write
the line to the memory file

'Write Header
39. retVAL = oGLJournalEntry.nWrite()

39 Use the Write method in the General Journal Business object to write the
header record and the detail records to disk

40. If retVal = 0 Then


41. ...MsgBox (oGLJournalEntry.sLastErrorMsg)
Else
42. ...MsgBox ("Gl Account Transaction Write complete - Script
...Complete")
End If

40 Test the return value of the Write method to take appropriate action
41 If the Write method failed, display the LastErrorMsg property of the
Business object
42 Display a message box that the write was successful

43. oGLJournalLines.DropObject()
44. oGLJournalEntry.DropObject()
45. oGLSJObject.DropObject()
46. oSS.nCleanUp()
47. oSS.DropObject()

Certified Student Course Curriculum - Version 2.0 Page 89


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Set oGLJournalLines = Nothing


Set oGLJournalEntry = Nothing
Set oGLSJObject = Nothing
Set oss = Nothing
Set oScript = Nothing

43 Destroy the General Journal Detail Business object


44 Destroy the General Journal Business object
45 Destroy the Source Journal Service object
46 Clean up all the objects in the Session object before it is dropped
47 Destroy the Session object

Budget from Excel - VBS


' General Ledger Revised Budgets from Excell VBS
' Copyright 2005 Sage Software, Inc.
' This program requires Microsoft Office and Glbudgetreport.xls
' This spreadsheet is available with the class downloads and you must
' save it to C:\Temp
1. Set oReg=GetObject("winmgmts:\\.\root\default:StdRegProv")
2. oReg.GetExpandedStringValue&H80000001,
"Software\ODBC\ODBC.INI\SOTAMAS90","Directory",PathRoot
3. PathHome = PathRoot & "\Home"

1 Set an Object handle to Windows Registry provider


2 Get the ODBC path for the last installed version of Sage MAS 90
3 Assign the Home path based on the value from the Windows Registry

4. Set oScript = CreateObject ("ProvideX.Script")


5. oScript.Init(PathHome)

4 Create new ProvideX Script object


5 Initialize the ProvideX Scrip object with the ..\MAS90\Home path

Page 90 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

6. Set oss = oScript.NewObject("SY_SESSION")

6 Create new Sage MAS 90 SY_Session object

...'The Logon method returns 1 if MAS90 Security is not enabled or if


...'MAS90 has been configured to use Windows Security
7. retVAL = oss.nlogon()
...'If the Logon method fails then you must use the SetUser method to
be allowed access
8. If retVAL = 0 Then
9. ---User = Trim(InputBox("Enter User Name"))
10. --Password = Trim(InputBox("Enter Password"))
11. --retVAL = oSS.nSetUser(User,Password)
...End If

7 Call the Logon method to log on to Sage MAS 90


8 If the Logon method failed, take appropriate action
9 Assign user from value in input box
10 Assign password from value in input box
11 Set the user in Sage MAS 90 using the values assigned

....'If the Logon fails, display LastErrorMsg and quit


12. If retVAL = 0 Then
13. ---MsgBox(CStr(retVAL) & " - " & oSS.sLastErrorMsg & vbCRLF &
"Quiting")
14. ---WScript.Quit
.. .End If

12 If the SetUser method failed, take appropriate action


13 Display the last error message of the Session object
14 Quit the script

Certified Student Course Curriculum - Version 2.0 Page 91


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

.. .'Set MAS 90 Company and Module


15. retVAL = oss.nSetCompany("ABC")
16. retVAL = oss.nSetDate("G/L","20050125")
17. retVAL = oss.nSetModule("G/L")

15 Set the Sage MAS 90 company using the method from the Session object
16 Set the Sage MAS 90 module date using the method from the Session
object
17 Set the Sage MAS 90 module using the method from the Session object

.. .'Set Security for MAS 90 and create Budget Objects


18. retVAL = oss.nSetProgram(oss.nLookupTask("GL_Budget
Maintenance_ui"))
19. If retVAL = 0 Then
20. ..MsgBox(oss.sLastErrorMsg)
21. . Wscript.Quit
.. .End IF
22. Set oGLBudget = oScript.NewObject("GL_PeriodBudgetDetail_bus",
oss)
23. set oGLService = oScript.NewObject("GL_Account_svc", oss)

18 Set the Sage MAS 90 program by Task ID using the method from the
Session object. This method also creates a Security object for the program
to run. If no Security object is created, the program cannot run
19 Test the return value of SetProgram( ) to take appropriate action
20 If SetProgram( ) fails, display the Session object’s last error
21 Quit
22 Create a new General Journal Period Budget Detail Business object
23 Create a new General Journal Service object

Page 92 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

.. .'SetIndex for Service object to retrieve surrogate key for


Account
24. retVAL=oGLService.nSetIndex("kACCOUNT")

24 Use the SetIndex method from the General Journal Service object to set the
index for the table, default index is always kPRIMARY

.. .'Instantiate the Excel Application through COM


25. Set objExcel = CreateObject("Excel.Application")
26. Set objWkbk = objExcel.Workbooks.Open("C:\Temp\GLbudget
report.xls")

25 Create a new Excel Application object


26 Create a new Excel Workbooks object and open the spreadsheet

.. .'Set Initial Row and Column dnumbers to the required values


27. InitRow=9
28. RowIncrement=7
29. colIncrement=1
30. InitFiscalPeriodColumn=3

27 Assign a starting row in the spreadsheet where the data starts


28 Assign a row increment to skip the spreadsheet rows with no data
29 Assign a column increment to skip the spreadsheet columns with no data
30 Assign a column where Fiscal Period is located in the spreadsheet

.. .' Loop through account information


31. Do Until objExcel.cells(InitRow,1).Value = ""

31 Begin loop to read Excel spreadsheet

.--. .' Get Account Information


32. --tmpAccount= objExcel.cells(InitRow, 1).value

32 Get general ledger account from the spreadsheet

Certified Student Course Curriculum - Version 2.0 Page 93


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

--- 'Loop through fiscal periods and amounts


33. tmpFiscalPeriod=0
34. Do Until
objExcel.cells(InitRow+2,InitFiscalPeriodColumn).Value=""

33 Clear Fiscal Period variable


34 Begin looping through the fiscal period information for the selected
account

'Get first budget


35. TmpFiscalYear= objExcel.cells(InitRow+2, 1).value
36. TmpBudgetCode= objExcel.cells(InitRow+2, 2).value
37.-tmpFiscalPeriod=tmpFiscalPeriod+1
38. tmpAmount=objExcel.cells
(InitRow+2,InitFiscalPeriodColumn).Value

35 Assign fiscal year from Excel spreadsheet


36 Assign budget code from Excel spreadsheet
37 Assign fiscal period from Excel spreadsheet
38 Assign amount from Excel spreadsheet to a temporary variable

----' Find Surrogate Key for GL Account


39. retVAL=oGlService.nFind(tmpAccount)
40. record=""
41. list=""
42. retVAL=oGLService.nGetRecord(Record,List)
43. tmpAccountKey=""
44. tmpAccountKey=split(Record,Chr(138))
45. AccountKey=tmpaccountkey(0)

Page 94 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

39 Find the surrogate key in the Sage MAS 90 GL_Account table for the
formatted general ledger account from the spreadsheet
40 Assign a string value to the variable to set its data type before using it to
receive a string value from the GetRecord( ) method
41 Assign a string value to the variable to set its data type before using it to
receive a string value from the GetRecord( ) method
42 Use the GetRecord method from the General Journal Service object to
retrieve the record for the account
43 Clear the temporary Account Key variable
44 Assign the surrogate key from the record retrieved by GetRecord to the
temporary Account Key variable
45 Assign the temporary Account Key to the Account Key variable

----' Write Record


46. retVAL = oGLBudget.nSetKeyValue("AccountKey$", Accountkey)
47. retVAL = oGLBudget.nSetKeyValue("BudgetCode$", tmpBudgetCode)
48. retVAL = oGLBudget.nSetKeyValue("FiscalYear$", tmpFiscalYear)
49. retVAL = oGLBudget.nSetKeyValue("FiscalPeriod$",
CStr(tmpFiscalPeriod))
50. retVAL = oGLBudget.nSetKey()

46 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the surrogate Account Key
47 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the budget code
48 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the fiscal year
49 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the fiscal period
50 Use the SetKey method in the General Journal Period Budget Detail
Business object to set the Key for the Budget record for this account

Certified Student Course Curriculum - Version 2.0 Page 95


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

51. If tmpAmount > 0 then


52. ----retVAL = oGLBudget.nSetValue("DebitAmount", tmpAmount)
----Else
53. -----retVAL = oGLBudget.nSetValue("CreditAmount", tmpAmount)
----End If

51 Test the value of the amount assigned from the Excel spreadsheet and take
appropriate action. If the amount in tmpAmount is greater than zero, the
amount is a debit. If the amount is less than zero, the amount is a credit
52 Use the SetValue method from the General Journal Period Budget Detail
Business object to assign the debit amount
53 Use the SetValue method from the General Journal Period Budget Detail
Business object to assign the credit amount

54. retVAL=oGLBudget.nWrite()
55.-If TmpFiscalPeriod ="12" Then oGLBudget.nSetKeyValue_
("AccountKey$", "")
----End If

54 Use the Write method from the General Journal Period Budget Detail
Business object to write the Budget record for this period
55 If the fiscal period is period 12, clear the Account Key value to release the
lock and update the Fiscal Period one values

----'Clear tmp variables


56. TmpFiscalYear=0
57. TmpBudgetCode=""
58. tmpAmount=""

56 Clear Temporary Fiscal Year variable


57 Clear Temporary Budget Code variable
58 Clear Temporary Amount variable

Page 96 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

----'Get Second Budget


59.-TmpFiscalYear= objExcel.cells(InitRow+4, 1).value
60.-TmpBudgetCode= objExcel.cells(InitRow+4, 2).value
61.-tmpAmount=objExcel.cells(InitRow+4,InitFiscalPeriodColumn).value

59 Assign fiscal year from Excel spreadsheet


60 Assign budget code from Excel spreadsheet
61 Assign amount from Excel spreadsheet to a temporary variable

----' Find Surrogate Key for GL Account


62. retVAL=oGlService.nFind(tmpAccount)
63.-record=""
64. list=""
65. retVAL=oGLService.nGetRecord(Record,List)
66. tmpAccountKey2=""
67.-tmpAccountKey2=split(Record,Chr(138))
68. AccountKey2=tmpaccountkey2(0)

62 Find the surrogate key in the Sage MAS 90 GL_Account table for the
formatted general ledger account from the spreadsheet
63 Assign a string value to the variable to set its data type before using it to
receive a string value from the GetRecord( ) method
64 Assign a string value to the variable to set its data type before using it to
receive a string value from the GetRecord( ) method
68 Use the GetRecord method from the General Journal Service object to
retrieve the record for the account
66 Clear the temporary Account Key 2 variable
67 Assign the surrogate key from the record retrieved by GetRecord to the
temporary Account Key 2 variable
68 Assign the temporary Account Key to the Account Key 2 variable

Certified Student Course Curriculum - Version 2.0 Page 97


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

----' Write Record


69.-retVAL = oGLBudget.nSetKeyValue("AccountKey$",AccountKey2)
70.-retVAL = oGLBudget.nSetKeyValue("BudgetCode$", tmpBudgetCode)
71. retVAL = oGLBudget.nSetKeyValue("FiscalYear$", tmpFiscalYear)
72. retVAL = oGLBudget.nSetKeyValue("FiscalPeriod$",
CStr(tmpFiscalPeriod))
73. retVAL = oGLBudget.nSetKey()

69 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the surrogate Account Key
70 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the budget code
71 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the fiscal year
72 Use the SetKeyValue method in the General Journal Period Budget Detail
Business object to set the Key Column value for the fiscal period
73 Use the SetKey method in the General Journal Period Budget Detail
Business object to set the Key for the Budget record for this account

74. If tmpAmount > 0 then


75. ---retVAL = oGLBudget.nSetValue("DebitAmount", tmpAmount)
----Else
76. ---retVAL = oGLBudget.nSetValue("CreditAmount", tmpAmount)
----End If

74 Test the value of the amount assigned from the Excel spreadsheet and take
appropriate action. If the amount in tmpAmount is greater than zero, the
amount is a debit. If it is less than zero, the amount is a credit.
75 Use the SetValue method from the General Journal Period Budget Detail
Business object to assign the debit amount
76 Use the SetValue method from the General Journal Period Budget Detail
Business object to assign the credit amount

77. retVAL = oGLBudget.nWrite()


78. If TmpFiscalPeriod ="12" Then retVAL=oGLBudget.nSetKeyValue
("AccountKey$", "")

Page 98 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

77 Use the Write method from the General Journal Period Budget Detail
Business object to write the Budget record for this period
78 If the fiscal period is period 12, clear the Account Key value to release the
lock and update the Fiscal Period one values

- - - -'Clear tmp variables


79. - -TmpFiscalYear=0
80.- - TmpBudgetCode=""
81. - -tmpAmount=""

79 Clear Temporary Fiscal Year variable


80 Clear Temporary Budget Code variable
81 Clear Temporary Amount variable

----- -'Increment loop variable


82. -- InitFiscalPeriodColumn = InitFiscalPeriodColumn + 1
83. -Loop
84. -InitRow = InitRow + RowIncrement
85. Loop

82 Increment loop for fiscal period information


83 End loop for fiscal period
84 Increment loop for account information
85 End loop for account information

Certified Student Course Curriculum - Version 2.0 Page 99


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

- - 'Quit Excel - Indicate that workbook was saved to avoid prompt


86. objWkbk.Saved = true
87. objExcel.Quit()
88. Set objWkbk = Nothing
89. Set objExcel = Nothing

86 Set the Saved property of the worksheet to True to avoid prompt


87 Quit Excel Application
88 Clear the Object handle to Worksheet object
89 Clear the Object handle to Excel object

90. oGLBudget.DropObject()
91. oGLService.DropObject()
92. oSS.nCleanup()
93. oSS.DropObject()

- - Set oGLBudget = Nothing


- - Set oGLService = Nothing
- - Set oSS = Nothing
- - Set oScript = Nothing

90 DropObject destroys the object and releases its resources


91 DropObject destroys the object and releases its resources
92 Call Cleanup() before dropping the Session object
93 DropObject destroys the object and releases its resources

Page 100 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

MAS90_VB2 Program Documentation


StartUpModule.vb source
1. Imports System.Text
2. Module StartUpModule
3. Public oScript
4. Public oSS
5. Public CompanyDLG As New MAS90_Company()
6. Public LogonDLG As New MAS90_Logon()
7. Public DateDLG As New MAS90_Date()
8. Public retVAL As Integer
9. Sub Main()
10. Dim SOTAMAS90Key = Microsoft.Win32.Registry.CurrentUser._
OpenSubKey("Software\ODBC\ODBC.INI\SOTAMAS90")
11. Dim InitPath = SOTAMAS90Key.GetValue("Directory") &
"\Home"
12. oScript = CreateObject("ProvideX.Script")
13. oScript.Init(InitPath)
14. oSS = oScript.NewObject("SY_SESSION")
15. If Not (CBool(oSS.nLogon())) Then
16. Do
17. LogonDLG.ShowDialog()
18. If LogonDLG.DialogResult = DialogResult.Cancel Then_
GoTo CLEANUP
19. Loop Until CBool(oSS.nSetUser(LogonDLG.UserName.Text,
LogonDLG.Password.Text))
20. End If
21. oSS.nSetDate("SYS", (oSS.sSystemDate))
22. oSS.nSetModule("SYS")
23. CompanyDLG.ShowDialog()
24. oSS.nSetCompany(Left(CompanyDLG.Company.Text, 3))
25. System.Windows.Forms.Application.Run(New MAS90_Examples ())
26. CLEANUP:
27. oSS.nCleanUp()

Certified Student Course Curriculum - Version 2.0 Page 101


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

28. oSS.DropObject()
29. oSS = Nothing
30. oScript = Nothing
31. End Sub
32. End Module

1 Imports the namespace for System.Text


2 Begin Module StartUpModule
3 Define a public object handle to the ProvideX.Script object
4 Define a public object handle to the Sage MAS 90 Session object
5 Define a public handle to the MAS 90 Select Company dialog
(MAS90_Company.vb)
6 Define a public handle to the Sage MAS 90 Logon/Change User dialog
(MAS90_Logon.vb)
7 Define a public handle to the Sage MAS 90 Change Date dialog
(MAS90_Date.vb)
8 Define a public integer variable to accept numeric return values of methods
9 Begin Sub Main routine
10 Declare SOTAMAS90 as RegistryKey and set its value to the
SOTAMAS90 user dsn key
11 Declare InitPath as String and set its value to the SOTAMAS90\Directory
value

Page 102 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

12 New object of ProvideX.Script, assign the value of the object's handle to


oScript
13 Initialize the ProvideX.Script object using the path to MAS90\Home
14 The NewObject method creates a new object, the object's handle is assigned
to oSS
15 If the Logon method returns zero, the user must log on to Sage MAS 90
(security enabled)
16 Begin Do loop
17 Display Sage MAS 90 Logon dialog which returns UserName and
Password (MAS90_Logon.vb)
18 If user clicks the Cancel button, the program terminates
19 Loop until the SetUser method returns success
20 End if
21 Set the Library Master module date with the Session's SystemDate property
22 Set the module to Library Master
23 Display the Select Company dialog which returns CompanyCode
(MAS90_Company.vb)
24 Set the current company to the company selected from the Select Company
dialog
25 Launch MAS90_Examples.vb (this is the form where all other examples
are run from)
26 Line label referenced by Goto on line 19
27 Calls the Session Cleanup method
28 Destroys the Session object
29 Set the Session object handle to nothing
30 Set the ProvideX.Script handle to nothing
31 End Sub Main
32 End Module StartUpModule

Certified Student Course Curriculum - Version 2.0 Page 103


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

MAS90_Examples.vb source
1.Public Class MAS90_Examples
2.Inherits System.Windows.Forms.Form

(Windows Form Designer generated code)


3.Private Sub Form_Load(ByVal sender As System....
4. Me.Text = oSS.sCaption & " Examples(" & oSS.sCompanyCode & _
")" & oSS.sFormatDate((oSS.sSystemDate))
5. Company.Text = oSS.sCompanyName
6. UserName.Text = oSS.sUserName
7. ModuleName.Text = oSS.sModuleName
8. ModuleDate.Text = oSS.sFormatDate((oSS.sSystemDate))
9.End Sub

1 MAS90_Examples - MAS90_Examples.vb
2 Inherits Windows.Forms class
3 Begin Form_Load sub, logic executed before the form displays
4 Sets the Title Bar text to the value of the Session properties
5 Sets the Company text box to the value of the CompanyName property
6 Sets the UserName text box to the value of the UserName property
7 Sets the ModuleName text box the value of the ModuleName property
8 Sets the ModuleDate text box to the value of the ModuleDate property
9 End of Form_Load sub

Page 104 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Private Function SetSession(ByVal Module, ByVal ProgramName)

Dim TaskID As Integer = 0


Dim MASDate As String = ""
Dim tmpModuleName As String = ""
Dim ExpirationDate As String = ""

1. If (CBool(oSS.nGetModuleInfo(Module, tmpModuleName,
ExpirationDate))) Then
2. TaskID = oSS.nLookupTask(ProgramName)
3. If TaskID <> 0 Then
4. If Not (CBool(oSS.nGetDate(ModuleCode, MASDate))) Then
5. DateDLG.Label1.Text = "Select date for " &
tmpModuleName
6. DateDLG.ModuleDate.Text = oSS.sFormatDate(
(oSS.sModuleDate))
7. DateDLG.ShowDialog()
8. If Not (DateDLG.DialogResult=DialogResult.Cancel) Then
9. MASDate = DateDLG.ModuleDate.Text
End If
End If
10. If MASDate = "" Then Return False
11. If (CBool(oSS.nSetDate(ModuleCode, MASDate))) Then
12. If (CBool(oSS.nSetModule(ModuleCode))) Then
13. If (CBool(oSS.nSetProgram(TaskID))) Then
14. ModuleName.Text = oSS.sModuleName
15. ModuleDate.Text = oSS.sFormatDate(_
(oSS.sModuleDate))
16. Return True

End If
End If
End If
End If
End If

Certified Student Course Curriculum - Version 2.0 Page 105


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

17. MessageBox.Show(oSS.sLastErrorMsg)
18. oSS.nSetModule("SYS")
19. Return False

End Function

1 Call to the GetModuleInfo() method to get the module name


2 Get the TaskID of the given ProgramName; is used to Set Program
3 Fail now if a valid TaskID was not returned
4 If a date is not set for the given module, prompt user for date
5 Set the module to display on the prompt for date dialog box
6 Set the text to display in the Title Bar of the date dialog
7 Launch the prompt for date program and display the dialog box
8 If the user did not click the Cancel button on the date dialog
9 Save the date selected in a local variable to use later
10 Fail now if we do not have a valid module date
11 Fail now if we are not able to set the module's date
12 Fail now if we are not able to set the current module
13 Fail now if we are not able to set the program and get security
14 Session was setup successfully, update the displayed module name
15 Session was setup successfully, update the displayed module date
16 Session was setup successfully, Return Success or True
17 Setup failed, display the reason for failure
18 Setup failed, reset the current module to Library Master
19 Setup failed, return Failure or zero

Page 106 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1.Private Sub BT_ChangeCompany_Click(ByVal sender As System....


2. oSS.nSetModule("SYS")
3. ModuleName.Text = oSS.sModuleName
4. ModuleDate.Text = oSS.sFormatDate((oSS.sModuleDate))
5. CompanyDLG.Cancel.Visible = True
6. CompanyDLG.ShowDialog()
7. If Not (CompanyDLG.DialogResult = DialogResult.Cancel) Then
8. If Not (oSS.nSetCompany(Mid(CompanyDLG.Company.Text, 1, 3))
9. MessageBox.Show(oSS.sLastErrorMsg)
10. Exit Sub

Else

11. Me.Text = oSS.sCaption & " Examples(" & oSS.sCompanyCode & _


")" & oSS.sFormatDate((oSS.sSystemDate))
12. Company.Text = oSS.sCompanyName

End If

End Sub

1 BT_ChangeCompany_Click sub. 'Change Company' button clicked event


2 Reset the current module back to Library Master
3 Update the displayed module name
4 Update the displayed module date
5 Display Cancel button on Change Company dialog so user can cancel
6 Display the Change Company dialog – (Run MAS90_Company.vb)
7 If user clicks Cancel ChangeCompany routine terminates
8 If the SetCompany method fails, routine terminates
9 Display LastErrorMsg for reason SetCompany failed
10 Exit Sub
11 Update the company code displayed in the Title Bar
12 Update the company name displayed in the CompanyName text box

Certified Student Course Curriculum - Version 2.0 Page 107


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1.Private Sub BT_ChangeDate_Click(ByVal sender As System....


2. If oSS.sModuleCode = "SYS" Then
3. MessageBox.Show(oScript.Evaluate_("MSG(""SY_SystemDate"")")
,oSS.sCaption)
Exit Sub

End If

4. DateDLG.Label1.Text = "Change date for " & oSS.sModuleName


5. DateDLG.ModuleDate.Text = oSS.sFormatDate((oSS.sModuleDate))
6. DateDLG.ShowDialog()
7. If Not (DateDLG.Dialog.Result = DialogResult.Cancel) Then
8. If CBool(oSS.nSetDate((oSS.sModuleCode),_
DateDLG.ModuleDate.Text)) Then
9. ModuleDate.Text = oSS.sFormatDate((oSS.sModuleDate))
Else
10. MessageBox.Show(oSS.LastErrorMsg)
End If

End If

End Sub

1 Begin BT_ChangeDate_Click sub; Change Module Date button clicked


2 If the current module is Library Master, exit
3 Retrieve SY_SystemDate message from Sage MAS 90 Message Library
4 Display current module in the Change Date dialog box
5 Set the Date control to default to the current module date
6 Launch the Change Date dialog (run MAS90_Date.vb)
7 If the user clicks the Cancel button, exit
8 If the SetDate method succeeds, the modules date is changed
9 Update the module date displayed on the window
1 Display LastErrorMsg for reason the date cannot change
Page 108 Certified Student Course Curriculum - Version 2.0
Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1.Private Sub BT_ChangeUser_Click(ByVal sender As System....


2. oSS.nSetModule("SYS")
3. ModuleName.Text = oSS.sModuleName
4. ModuleDate.Text = oSS.sFormatDate((oSS.sModuleDate))
5. If oSS.sUserCode = "###" Then
6. MessageBox.Show(oScript.Evaluate("MSG(""SY_NoUsersDefined"")"))
Exit Sub

Else
7. oSS.sLastErrorMsg = ""
Do
8. LogonDLG.ShowDialog()
9. If LogonDLG.DialogResult = DialogResult.Cancel Then Exit Do
10. ret = oSS.nSetUser(LogonDLG.UserName.Text, LogonDLG
.Password.Text))
11. Loop Until ret = 1
12. UserName.Text = oSS.sUserName

End If

End Sub

1 Begin BT_ChangeUser_Click sub (Change User button clicked)


2 Reset current module to the Library Master module
3 Update the module name displayed on the window
4 Update the module date displayed on the window
5 If no Sage MAS 90 users are defined, display message and exit routine
6 Retrieve the SY_NoUsersDefined message from the Sage MAS 90
Message Library
7 Clear LastErrorMsg because it is displayed on the LogonDLG form
8 Display the LogonDLG dialog (run MAS90_Logon.vb)
9 If the user clicks Cancel; ChangeUser routine terminates
11 Loop until the SetUser method returns nonzero (success)
12 Set the UserName text box to the new value of the UserName property

Certified Student Course Curriculum - Version 2.0 Page 109


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Private Sub BT_AddAccount_Click(ByVal sender As System....

1. If SetSession("G/L", "GL_Account_ui") Then


2. Dim AddAccount As New AddAccount
3. AddAccount.ShowDialog()
4. AddAccount = Nothing

End If

End Sub

1 If SetProgram() returns success, launch the example program


2 Create a new object of the AddAccount.vb class
3 Launch the AddAccount.vb example program
4 Set the AddAccount object handle to nothing

Private Sub BT_JournalEntry_Click(ByVal sender As System....

1. If SetSession("G/L", "GL_GeneralJournal_ui") Then


2. Dim JournalEntry As New JournalEntry
3. JournalEntry.ShowDialog()
4. JournalEntry = Nothing

End If

End Sub

1 If SetProgram() returns success, launch the example program


2 Create a new object of the JournalEntry.vb class
3 Launch the JournalEntry.vb example program
4 Set the JournalEntry object handle to nothing

Page 110 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Private Sub BT_SalesOrderEntry_Click(ByVal sender As System....

1. If SetSession("S/O", "SO_SalesOrder_ui") Then


2. Dim SalesOrderEntry As New SalesOrderEntry
3. SalesOrderEntry.ShowDialog()
4. SalesOrderEntry = Nothing

End If

End Sub

1 If SetProgram() returns success, launch the example program


2 Create a new object of the SalesOrderEntry.vb class
3 Launch the SalesOrderEntry.vb example program
4 Set the SalesOrderEntry object handle to nothing

Private Sub BT_SourceJournal_Click(ByVal sender As System....

1. If SetSession("G/L", "GL_SourceJournal_ui") Then


2. Dim oSrcJrnl As Object
3. oSrcJrnl = oScript.NewObject(GL_SourceJournal_ui", oSS)
4. oSrcJrnl.nProcess()
5. oSrcJrnl.DropObject()
6. oSrcJrnl = Nothing

End If

End Sub

Certified Student Course Curriculum - Version 2.0 Page 111


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1 If SetProgram() returns success, launch the example program


2 Define an object handle to a ProvideX object
3 Create a new Source Journal object; the object's handle is oSrcJrnl
4 Launch the Sage MAS 90 Source Journal Maintenance program
5 Destroys the Source Journal Maintenance object
6 Set the Source Journal Maintenance object handle to nothing

Private Sub BT_BudgetFromExcel_Click (ByVal sender As System....

1. If SetSession("G/L", " GL_BudgetMaintenance_ui") Then


2. Dim BudgetFromExcel As New BudgetFromExcel
3. BudgetFromExcel.ShowDialog()
4. BudgetFromExcel= Nothing

End If

End Sub

1 If SetProgram() returns success, launch the example program


2 Create a new object of the BudgetFromExcel.vb class
3 Launch the BudgetFromExcel.vb example program
4 Set the BudgetFromExcel object handle to nothing

Page 112 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

MAS90_Company.vb source
1. Public Class MAS90_Company
2. Inherits System.Windows.Forms.Form
(Windows Form Designer generated code)
3. Private Sub Form_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
4. CompanyDLG.Text = oSS.sCaption & " Select Company"
5. CompanyDLG.Company.Items.Clear()
6. CompanyDLG.Company.Text = oSS.sCompanyCode & " (" &
oSS.sCompanyName & ")"
7. CompanyDLG.Company.Items.AddRange(Split(oSS.sCompanyList,
Chr(138)))
8. End Sub

1 Change Sage MAS 90 Company Class (MAS90_Company.vb)


2 Inherits Windows.Forms class
3 Begin Form_Load sub. This logic sets up the form before it displays
4 Set the form's Title Bar text to the Session's Caption property + program
description
5 Clear the Company ComboBox
6 Set the Company ComboBox Text to the current Company Code +
Company Name
7 Load the Company ComboBox with contained in the Session's
CompanyList property
8 End of Select Company sub

Certified Student Course Curriculum - Version 2.0 Page 113


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

MAS90_Date.vb source
1. Public Class MAS90_Date
2. Inherits System.Windows.Forms.Form
(Windows Form Designer generated code)
3. Private Sub Ok_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Ok.Click
4. Dim AccDate As Date
5. Try
6. AccDate = CType(ModuleDate.Text, Date)
7. Catch
8. ModuleDate.Text = ""
9. Exit Sub
10. End Try
11. ModuleDate.Text = AccDate.Year & _
AccDate.Month.ToString.PadLeft(2, "0") & _
AccDate.Day.ToString.PadLeft(2, "0")
12. End Sub
13. Private Sub Cancel_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Cancel.Click
14. ModuleDate.Text = ""
15. End Sub
16. End Class

Page 114 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1 Change Sage MAS 90 Date class (MAS90_Date.vb)


2 Inherits Windows.Form class
3 Begin Ok_Click sub; Ok Button clicked
4 Define a variable of type date to use with VB date functions
5 Try
6 Convert ModuleDate Text box value to Date type
7 Catch; Convert to Date type fails if date entered is invalid
8 Set ModuleDate Text box to null
9 Exit Change Date routine
10 End Try
11 Format ModuleDate to Sage MAS 90 date format YYYYMMDD
12 End of Ok_Click sub
13 Begin Cancel_Click sub; Cancel button clicked
14 Set ModuleDate Text box to null
15 End of Cancel_Click sub
16 End of Change Sage MAS 90 Date class

Certified Student Course Curriculum - Version 2.0 Page 115


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

MAS90_Logon.vb source
1. Public Class MAS90_Logon
2. Inherits System.Windows.Forms.Form
(Windows Form Designer generated code)
3. Private Sub Form_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
4. AddHandler UserName.Enter, New System.EventHandler_
(AddressOf UserName_Enter)
5. AddHandler Password.Enter, New System.EventHandler_
(AddressOf Password_Enter)
6. Me.Text = oSS.sCaption & " Logon"
7. Me.UserName.Text = ""
8. Me.Password.Text = ""
9. Me.LastErrorMsg.Text = oSS.sLastErrorMsg
10. End Sub
11. Private Sub UserName_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles UserName.TextChanged
12. LastErrorMsg.Text = ""
13. End Sub
14. Private Sub Password_Enter(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Password.TextChanged
15. LastErrorMsg.Text = ""
16. End Sub
17. End Class

Page 116 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1 MAS90_Logon class; MAS90_Logon.vb used for logging on and changing


user
2 Inherits Windows.Form class
3 Begin Form_Load sub; logic to setup the form before it displays
4 Add Event Handler for when the UserName Text Box is selected
5 Add Event Handler for when the Password Text Box is selected
6 Set the form title bar the value of the Caption property + "Logon"
7 Clear the UserName Text Box
8 Clear the Password Text Box
9 Set the LastErrorMsg Text Box to the Session object's LastErrorMsg
10 End of Form_Load sub
11 Begin UserName_Enter sub – Logic executed on UserName.Enter Event
12 Clear the LastErrorMsg displayed after the user begins another logon
attempt
13 End of UserName_Enter sub
14 Begin Password_Enter sub. Logic executed on Password.Enter Event
15 Clear the LastErrorMsg displayed after the user begins another logon
attempt
16 End of Password_Enter sub
17 End MAS90_Logon class

Certified Student Course Curriculum - Version 2.0 Page 117


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

SalesOrderEntry.vb source
1. Public Class SalesOrderEntry
Inherits System.Windows.Forms.Form
Private MyDataTable As DataTable
2. Dim oSOOrder As Object

+ Windows Form Designer generated code

3. Private Sub SalesOrderEntry_Load(ByVal sender As System.Object,


....

'new up Sales Order business object


Try
4. oSOOrder = oScript.NewObject("SO_SalesOrder_bus", oSS)
Catch
5. MessageBox.Show(oSS.sLastErrorMsg)
Exit Sub
End Try

'Initialize Order Form and load Division and Item combo boxes
6. FormatDataGrid()
7. GetDivisionList()
8. GetCIItems()
9. ResetOrderForm()

End Sub

Page 118 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1 Enter Sage MAS 90 Sales Orders Class (SalesOrderEntry.vb)


2 Define an Object handle to a ProvideX Class
3 Begin SalesOrderEntry.vb Load Routine
4 Create new SO_SalesOrder_bus object
5 If NewObject failed – Display LastErrorMsg property of the Session object
6 Format the DataGrid
7 Load the AR-Divisions combo box
8 Load the Inventory Items combo box
9 Clear/Enable/Disable Order Form Screen controls

Private Sub GetDivisionList()

'Get list of division numbers and load division combo box

Dim strResults As String = ""


Dim strJunk As String = ""
10. Dim oARDivisionSrvcObj As Object

'start up ar_division_svc object to get list of divisions


Try
11. oARDivisionSrvcObj = oScript.NewObject("ar_division_svc", oSS)
Catch
12. MsgBox(oSS.sLastErrorMsg)
Exit Sub
End Try

'get list of division numbers for combo box


13. oARDivisionSrvcObj.nGetResultSets("ARDivisionNo$",
"ARDivisionNo$", strResults, strJunk, "", "", "")
'split division numbers into combo box
cboDivision.Items.Clear()
14. cboDivision.Items.AddRange(Split(Mid( strResults, 3,
Len(strResults)- 3), Chr(138)))

Certified Student Course Curriculum - Version 2.0 Page 119


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

'get rid of object and clean up


15. oARDivisionSrvcObj.DropObject()
16. oARDivisionSrvcObj = Nothing

End Sub

10 Define an object handle to a ProvideX Class


11 Create a new AR Division Service object
12 If NewObject failed, display LastErrorMsg property of the Session object
13 Return list of divisions in strResults
14 Load combo box with division list, excluding leading and trailing
delimeters
15 Destroy the AR Division Service object
16 Set the Service object handle to nothing

Private Sub GetCIItems()

'Get list of item numbers and load combo box

Dim strResults As String = ""


Dim strJunk As String = ""
17. Dim oCIItemsSvcObj As Object

'start up service object to get list of customers


Try
18. oCIItemsSvcObj = oScript.NewObject("ci_itemcode_svc", oSS)
Catch
19. MsgBox(oSS.sLastErrorMsg)
End Try

'get list of item numbers for combo box


20. oCIItemsSvcObj.nGetResultSets("ItemCode$", "ItemCode$",_
strResults, strJunk, "ItemType$ = " & Chr(34) & "1" & Chr(34) &
" AND UseInSO$=" & Chr(34) & "Y" & Chr(34), "", "")

Page 120 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

'split item numbers into combo box


CBOItems.Items.Clear()
21. CBOItems.Items.AddRange(Split(Mid( _
strResults, 3, Len(strResults) - 3), Chr(138)))

'get rid of object and clean up


22. oCIItemsSvcObj.DropObject()
23. oCIItemsSvcObj = Nothing

End Sub

17 Define an object handle to a ProvideX Class


18 Create a new CI Items Service object
19 If NewObject failed, display LastErrorMsg property of the Session object
20 Return list of inventory items in strResults, filtered by ItemType = 1 AND
UseInSO = Y
21 Load combo box with Items list, excluding leading and trailing delimeters
22 Destroy the CI Items Service object
23 Set the Service object handle to nothing

Private Sub GetCustomerList(ByVal strDivision As String)

'Get list of customer numbers and load combo box, filtered by


division

Dim strResults As String = ""


Dim strJunk As String = ""
24. Dim oARCustomerSrvcObj As Object

'start up ar_customer_svc object to get list of customers


Try
25. ....oARCustomerSrvcObj = oScript.NewObject("ar_customer_svc",
oSS)
Catch
26. ....MsgBox(oSS.SLastErrorMsg)
End Try

Certified Student Course Curriculum - Version 2.0 Page 121


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

'get list of numbers by division for combo box


27. ..oARCustomerSrvcObj.nGetResultSets("CustomerNo$","Customer
Key$", strResults, strJunk, "ARDivisionNo$ = " & Chr(34) &
strDivision & Chr(34), "", "")

'split customer numbers into combo box - If customers exist


for div
If CBool(Len(strResults)) Then
cboCustomer.Items.Clear()
28. ....cboCustomer.Items.AddRange(Split(Mid( _ strResults, 3,
Len(strResults) - 3), Chr(138)))
cboCustomer.Enabled = True
End If

.....'get rid of object and clean up


29. oARCustomerSrvcObj.DropObject()
30. oARCustomerSrvcObj = Nothing

End If

End Sub

24 Define an object handle to a ProvideX Class


25 Create a new AR Customer Service object
26 If NewObject failed, display LastErrorMsg property of the Session object
27 Return list of customer numbers in strResults, filtered by strDivision
28 If customers exist for this division, load the list of customer numbers into
the combo box, excluding leading and trailing delimeters
29 Destroy the AR Customer Service object
30 Set the Service object handle to nothing

Page 122 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Private Sub GetShipToList(ByVal strDivision As String, ....

'Get list of ShipTo Addresses and load combo box

Dim ShipToCodes As String = ""


Dim ShipToNames As String = ""
Dim ShipToCodeArray(), shipto, ShipToNameArray() As String
31. Dim oShipToAddress As Object

'start up so_shiptoaddress_svc object to get list of ship to


addresses
Try
32. oShipToAddress = oScript.NewObject("so_shiptoaddress_svc", oSS)
Catch
33. MsgBox(oSS.sLastErrorMsg)
.....Exit Sub
End Try

'get list of Ship To Codes and Names filtered by division and


customer
34. oShipToAddress.nGetResultSets("ShipToCode$", "ShipToName$",
ShipToCodes, ShipToNames, "ARDivisionNo$=" & Chr(34) &
strDivision & Chr(34) & " AND CustomerNo$=" & Chr(34) &
strCustomer & Chr(34), "", "")

cboShipTo.Items.Clear()
'Skip this if multiple ship to codes do not exist for this customer
If CBool(Len(ShipToCodes)) Then

'split Ship To Codes and Names into string array


35. ShipToCodeArray = Split(Mid( ShipToCodes, 3, Len(ShipToCodes)
- 3), Chr(138))
36. ShipToNameArray = Split(Mid( ShipToNames, 3, Len(ShipToNames)
- 3), Chr(138))

'Load combo box with Ship To Code + Ship To Name


Dim tmp, i As Integer
ShipToCount = ShipToCodeArray.GetUpperBound(0)

Certified Student Course Curriculum - Version 2.0 Page 123


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

For i = 0 To ShipToCount
37. ..cboShipTo.Items.Add(ShipToCodeArray(i) &"-"&
ShipToNameArray(i))
Next
cboShipTo.Enabled = True

End IF

'get rid of object and clean up


38. oShipToAddress.DropObject()
39. oShipToAddress = Nothing

End Sub

31 Define an object handle to a ProvideX Class


32 Create a new SO Ship To Address Service object
33 If NewObject failed, display LastErrorMsg property of the Session object
34 Return list of ShipTo Codes and Names in ShipToCodes and ShipToNames
filtered by Division and Customer Number
35 Load array with ShipToCodes, excluding leading and trailing delimeters
36 Load array with ShipToNames, excluding leading and trailing delimeters
37 Load combo box with ShipToCode plus "–" plus ShipToName
38 Destroy the SO Ship To Address Service object
39 Set the Service object handle to nothing

#. Private Sub FormatDataGrid()


...
End Sub

# You can view the FormatDataGrid routine from the SalesOrderEntry.vb


source file. It is not documented here because it does not contain any code
specific to the ProvideX OLE Server or Sage MAS 90

Page 124 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

41. Private Sub btnNextNew_Click(ByVal sender As System.Object, ....

.....'Get Next Sales Order Number

42. If CBool(oSOOrder.nGetNextSalesOrderNo(OrderNumber.Text)) Then


43. If CBool(oSOOrder.nSetKey(OrderNumber.Text)) Then

'display order date and enable/disable screen controls


44. oSOOrder.nGetValue("OrderDate$", OrderDate.Text)
45. OrderDate.Text = oSS.sFormatDate(OrderDate.Text)
46. btnNextNew.Enabled = False
47. btnCancel.Enabled = True
48. cboDivision.Enabled = True
Exit Sub

End If

End If

49. MessageBox.Show(oSOOrder.sLastErrorMsg)

End Sub

Certified Student Course Curriculum - Version 2.0 Page 125


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

41 Routine to handle the Next Sales Order button clicked event


42 Get the Next Sales Order Number and store it in the OrderNumber text box
43 Set the file pointer to the given key; if the key does not exist, a new record
is created
44 Get the order date from the new Sales Order record
45 Format the order date for display; formatDate takes YYYYMMDD and
returns MM/DD/YYYY
46 Disable the Get Next Sales Order Number button
47 Enable the Cancel button
48 Enable the Division combo box
49 If GetNextSalesOrderNo or SetKey failed, display the LastErrorMsg for
the reason why it failed

50. Private Sub cboDivision_SelectedValueChanged(ByVal sender ...


51. If CBool(oSOOrder.nSetValue("ARDivisionNo$", cboDivision.Text))
Then
52. cboDivision.Enabled = False
53. GetCustomerList(cboDivision.Text)

Else

54. MessageBox.Show(oSOOrder.sLastErrorMsg)

End If

End Sub

Page 126 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

50 Routine to handle Division Number selected event


51 Set the value of the ARDivisionNo$ field of the new sales order record
52 Disable the Division combo box control
53 Load the Customer Number combo box
54 If SetValue failed, display LastErrorMsg for reason

55. Private Sub cboCustomer_SelectedValueChanged(ByVal sender ....


56. If CBool(oSOOrder.nSetValue("CustomerNo$", cboCustomer.Text))
Then
57. GetShipToList(cboDivision.Text, cboCustomer.Text)
58. cboCustomer.Enabled = False
59. CustomerPO.Enabled = True
60. cboItems.Enabled = True
61. SetBillTo()
62. SetShipTo()

Else

63. MessageBox.Show(oSOOrder.sLastErrorMsg)

End If

End Sub

Certified Student Course Curriculum - Version 2.0 Page 127


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

55 Routine to handle Customer Number selected event


56 Set the value of the CustomerNo field of the new Sales Order record
57 Load the Ship To combo box
58 Disable the Customer Number combo box control
59 Enable the Customer PO text box control
60 Enable the Items combo box control
61 Set the Bill To Address screen controls from the customer record values
62 Set the Ship To Address screen controls from the customer record values
63 If SetValue failed, display LastErrorMsg for the reason

64. Private Sub cboShipTo_SelectedValueChanged(ByVal sender ....


65. Dim ShipToCode As String = Trim(Mid(cboShipTo.Text, 1, _
(InStr(cboShipTo.Text, "-") - 1)))
66. If CBool(oSOOrder.nSetValue("ShipToCode$", ShipToCode)) Then
67. SetShipTo()
Else
68. MessageBox.Show(oSOOrder.sLastErrorMsg)
End If

End Sub

64 Routine to handle Ship To Address combo box selected event


65 Assign the ShipToCode portion of the combo box item to ShipToCode
66 Set the value of the ShipToCode field of the new Sales Order record
67 Set the Ship To Address screen controls from the customer record values
68 If SetValue failed, display LastErrorMsg for the reason

Page 128 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

69. Private Sub cboItems_SelectedValueChanged(ByVal sender ....


70. If cboItems.SelectedIndex = -1 Then Exit Sub
71. If CBool(oSOOrder.oLines.nSetValue("ItemCode$",cboItems.Text))
Then
72. txtQuantity.Enabled = True
Else
73. MessageBox.Show(oSOOrder.oLines.sLastErrorMsg)
End If

End Sub

69 Routine to handle Inventory Item selected event


70 If an item was not selected from the combo box, exit
71 Set the value of the ItemCode field of the Sales Order detail record
72 Enable the Quantity text box screen control
73 If SetValue failed, display LastErrorMsg for the reason

74. Private Sub txtQuantity_TextChanged(ByVal sender ....

Try

75. Dim tmpDecimal = CType(txtQuantity.Text, Decimal)

Catch ex As Exception

76. btnAddLine.Enabled = False


77. .... txtQuantity.Text = ""
........ Exit Sub
End Try

78. btnAddLine.Enabled = True

End Sub

Certified Student Course Curriculum - Version 2.0 Page 129


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

74 Routine to handle Quantity entered changed event


75 Verify the Quantity text box contains a numeric value
76 If a valid quantity was not entered, disable the Add Line button
77 If a valid quantity was not entered, clear the invalid entry and exit
78 Enable the Add Line button if the quantity entered was valid

79. Private Sub btnAddLine_Click(ByVal sender As System.Object ....


80. Dim LineAdded As Boolean = False

'create new Sales Order Detail line


81. If CBool(oSOOrder.nAddLine()) Then

'get the Line Key of the new line


82. Dim LineKey As String = oSOOrder.oLines.sGetKey()

'convert Quantity to numeric


83. Dim QuantityOrdered As Decimal = CType(txtQuantity.Text, Decimal)

'set the value for the ItemCode field of the new line record
84. If CBool(oSOOrder.oLines.nSetValue("ItemCode$",cboItems.Text))
Then

'set the value for the QuantityOrdered field of the new line
record
85. If CBool(oSOOrder.oLines.nSetValue("QuantityOrdered", _
QuantityOrdered)) Then

'get desc, price, and extended amt for display in the grid
Dim ItemCodeDesc As String = ""
86. ...oSOOrder.oLines.nGetValue("ItemCodeDesc$", ItemCodeDesc)
Dim UnitPrice As Decimal = 0
87. ...oSOOrder.oLines.nGetValue("UnitPrice", UnitPrice)
Dim ExtensionAmt As Decimal = 0

Page 130 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

88. -oSOOrder.oLines.nGetValue("ExtensionAmt", ExtensionAmt)

'write the new detail line to the memory file


89. If CBool(oSOOrder.oLines.nWrite()) Then
90. LineAdded = True

'Display the new line in the screen grid


91. Dim NewLine As DataRow = MyDataTable.NewRow
91. NewLine(0) = cboItems.Text
91. NewLine(1) = ItemCodeDesc
91. NewLine(2) = QuantityOrdered
91. NewLine(3) = UnitPrice
91. NewLine(4) = ExtensionAmt
91. NewLine(5) = LineKey
91. MyDataTable.Rows.Add(NewLine)

'update screen totals, enable Accept, DeleteRow buttons


92. UpdateTotals()
92. btnUpdate.Enabled = True
92. btnDeleteRow.Enabled = True

End If

End If

End If

End If

'Reset the line entry screen controls


92. txtQuantity.Text = ""
92. txtQuantity.Enabled = False
92. btnAddLine.Enabled = False
92. cboItems.SelectedIndex = -1
92. cboItems.Focus()

Certified Student Course Curriculum - Version 2.0 Page 131


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

If Not (LineAdded) Then

93. MessageBox.Show(oSOOrder.oLines.sLastErrorMsg)

End If

End Sub

79 Routine to handle the Add Line button clicked event


80 Declare a boolean variable that is set to True if the new line is added
successfully
81 Create a new Sales Order detail record
82 Get the line key of the new detail record, required to select an existing
detail line for editing or deleting
83 Convert the quantity entered in text box to numeric
84 Set the value of the ItemCode field in the new detail record
85 Set the value of the QuantityOrdered field in the new detail record
86 Get the ItemCodeDesc field from the new detail record for display on
window
87 Get the UnitPrice field from the new detail record for display on window
88 Get the Extended Amt field from the new detail record for display on
window
89 Write the new detail record to the Sales Order Detail Business object’s
memory file
91 Set boolean variable to True to indicate the new line was added
91 Set the values of the Visual Basic grid columns and display the grid row
92 Update / Reset / Enable / Disable the Visual Basic screen controls
93 If the new line was not added, display LastErrorMsg for reason

Page 132 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

94. Private Sub btnDeleteRow_Click(ByVal sender As System.Object ....

'delete the line by the key stored in the current row of the grid
95. Dim LineKey As String = Trim(dgOrderDetail.Item(dgOrderDetail.
CurrentRowIndex, 5))
96. If CBool(oSOOrder.nDeleteLine(LineKey)) Then

........'remove line from screen grid and update screen totals


97. MyDataTable.Rows.RemoveAt(dgOrderDetail.CurrentRowIndex)
98. UpdateTotals()
99. cboItems.Focus()

Else

100. MessageBox.Show(oSOOrder.sLastErrorMsg)

End If

End Sub

94 Routine to handle the Delete Row button clicked event


95 Retrieve the Line Key stored in column 5 of the grid row
96 Delete the line record from the memory file for the given key
97 Remove the line from the Visual Basic grid (display)
98 Update the totals displayed on the window
99 Put focus on the Items combo box
100 If DeleteLine failed, display LastErrorMsg for the reason

Certified Student Course Curriculum - Version 2.0 Page 133


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

101. Private Sub btnUpdate_Click(ByVal sender As System.Object ....

......'set fields not already set


102. oSOOrder.nSetValue("CustomerPONo$", CustomerPO.Text)

......'write order header and detail records to disk


103. If Not (CBool(oSOOrder.nWRITE())) Then
104. MessageBox.Show(oSOOrder.sLastErrorMsg)
End If

... . 'clear Business object and reset screen controls


105. btnCancel.PerformClick()

End Sub

101 Routine to handle the Update (Accept) button clicked event


102 Set the value of the CustomerPONo field in the sales order record
103 Write the Sales Order header and detail records to disk
104 If the Write failed, display LastErrorMsg for reason
105 Perform Cancel Logic; clear Business object and reset the Order Form

106. Private Sub btnCancel_Click(ByVal sender As System.Object ....

......'clear Business object and reset screen controls


107. oSOOrder.nClear()
108. ResetOrderForm()

End Sub

106 Routine to handle the Cancel button clicked event


107 Clear the records in the object and the detail object’s memory file
108 Reset the Visual Basic order form screen controls

Page 134 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Private Sub UpdateTotals()

......'update the totals displayed on the screen


109. If CBool(oSOOrder.nSalesTaxReCalculation()) Then

Dim tmp As Decimal = 0


Dim OrderTotal As Decimal = 0

110. ...oSOOrder.nGetValue("TaxableAmt", tmp)


txtTaxableAmt.Text = tmp.ToString("c")
OrderTotal += tmp

111. ...oSOOrder.nGetValue("NonTaxableAmt", tmp)


txtNonTaxableAmt.Text = tmp.ToString("c")
OrderTotal += tmp

112. ...oSOOrder.nGetValue("SalesTaxAmt", tmp)


txtSalesTaxAmt.Text = tmp.ToString("c")
OrderTotal += tmp

113. ...oSOOrder.nGetValue("FreightAmt", tmp)


txtFreightAmt.Text = tmp.ToString("c")
OrderTotal += tmp

114. txtOrderTotal.Text = OrderTotal.ToString("c")

Else

115. MessageBox.Show(oSOOrder.sLastErrorMsg)

End If

End Sub

Certified Student Course Curriculum - Version 2.0 Page 135


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

109 Recalculate sales tax for the current items entered into the sales order. This
method is only called to update the totals displayed on the window
110 Get the value of the TaxableAmt field, display it on the window, and add it
to the OrderTotal variable
111 Get the value of the NonTaxableAmt field, display it on the window, and
add it to the OrderTotal variable
112 Get the value of the SalesTaxAmt field, display it on the window, and add it
to the OrderTotal variable
113 Get the value of the FreightAmt field, display it on the window, and add it
to the OrderTotal variable
114 Display the OrderTotal on the window
115 If SalesTaxReCalculation failed, display LastErrorMsg for reason

Private Sub SetBillTo()

116. oSOOrder.nGetValue("BillToName$", txtBillToName.Text)


117. oSOOrder.nGetValue("BillToAddress1$", txtBillToAddress1.Text)
118. oSOOrder.nGetValue("BillToAddress2$", txtBillToAddress2.Text)
119. oSOOrder.nGetValue("BillToAddress3$", txtBillToAddress3.Text)
120. oSOOrder.nGetValue("BillToCity$", txtBillToCity.Text)
121. oSOOrder.nGetValue("BillToState$", txtBillToState.Text)
122. oSOOrder.nGetValue("BillToZipcode$", txtBillToZipcode.Text)
End Sub

Private Sub SetShipTo()

116. oSOOrder.nGetValue("ShipToName$", txtShipToName.Text)


117. oSOOrder.nGetValue("ShipToAddress1$", txtShipToAddress1.Text)
118. oSOOrder.nGetValue("ShipToAddress2$", txtShipToAddress2.Text)
119. oSOOrder.nGetValue("ShipToAddress3$", txtShipToAddress3.Text)
120. oSOOrder.nGetValue("ShipToCity$", txtShipToCity.Text)
121. oSOOrder.nGetValue("ShipToState$", txtShipToState.Text)
122. oSOOrder.nGetValue("ShipToZipcode$", txtShipToZipcode.Text)
End Sub

Page 136 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

116 Get the value of BillTo/ShipTo Name from the current Sales Order header
record
117 Get the value of BillTo/ShipTo Address line 1 from the current Sales Order
header record
118 Get the value of BillTo/ShipTo Address line 2 from the current Sales Order
header record
119 Get the value of BillTo/ShipTo Address line 3 from the current Sales Order
header record
120 Get the value of BillTo/ShipTo City from the current Sales Order header
record
121 Get the value of BillTo/ShipTo State from the current Sales Order header
record
122 Get the value of BillTo/ShipTo Zip Code from the current Sales Order
header record

Private Sub ResetOrderForm()

'Clear Text Values displayed on Order Form


'Clear Items in Combo Box controls
'Enable/Disable Order Form controls

End Sub

# You can view the ResetOrderForm routine from the SalesOrderEntry.vb


source file; it is not documented here because it does not contain any code
specific to the ProvideX OLE Server or Sage MAS 90

Certified Student Course Curriculum - Version 2.0 Page 137


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

123. Private Function ErrorTrap(ByVal retVAL As Integer, ByRef sender


As Object) As Integer

'Accepts two arguments, the numeric return value of a MAS90 method _


'and the object to check for the LastErrorMsg if the method fails
'
'Example: ErrorTrap(oSS.nLogon(), oSS)
'
'Returns numeric return value of MAS90 method (1=success 0=failure)
'Displays LastErrorMsg of the MAS90 object on failure

124. If retVAL = 0 Then MessageBox.Show(sender.sLastErrorMsg)


125. ErrorTrap = retVAL

End Function

123 Function accepts the numeric return value of a Sage MAS 90 method and
the handle of the Sage MAS 90 object
124 If the method returns zero, the LastErrorMsg of the object displays
125 The function returns the return value of the method

126. Private Sub SalesOrderEntry_Closing(ByVal ....

127. oSOOrder.DropObject()
128. oSOOrder = Nothing

---End Sub

129. End Class

126 Routine to handle the SalesOrderEntry.vb program closing event


127 Call the Sage MAS 90 Object’s destructor
128 Set the Object handle to nothing
129 End of SalesOrderEntry.vb

Page 138 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

AddAccount.vb source
1. Public Class AddAccount
.......Inherits System.Windows.Forms.Form
(Windows Form Designer generated code)
.......'
2. Dim oBusObjB As Object
3. Dim oProjSvc As Object

4. Private Sub AddAccount_Load(ByVal sender As System.Object, _


ByVal e As System.EventArgs) Handles MyBase.Load
5. lblNewRecord.Text = ""
...........Try
6. oBusObjB = oScript.NewObject("GL_Account_bus", oSS)
............Catch
7. MessageBox.Show(oSS.sLastErrorMsg)
............End Try
8. .oProjSvc = oBusObjB.oGetChildHandle("UDF_PROJECTCODE")

........End Sub

1 AddAccount class – (AddAccount.vb)


2 Object handle for the Sage MAS 90 GL_Account_bus object
3 Object handle for a Child object of the Business object
4 Begin AddAccount_Load sub
5 Blank out NewRecord text label so New Record does not appear on the
form
6 Create NewObject of the GL_Account_bus class, assign object's handle to
oBusObjB
7 If NewObject method fails, display the LastErrorMsg property of the
Session object
8 Get a Child object's handle and assign it to oProjSvc

Certified Student Course Curriculum - Version 2.0 Page 139


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

9. Private Sub btnMoveFirst_Click(ByVal sender As ...


10. oBusObjB.nMoveFirst()
11. Call SetFields()
.... .. End Sub
12. Private Sub btnMovePrev_Click(ByVal sender As ...
13. oBusObjB.nMovePrevious()
14. Call SetFields()
........End Sub
15. Private Sub btnMoveNext_Click(ByVal sender As ...
16. oBusObjB.nMoveNext()
17. Call SetFields()
........End Sub
18. Private Sub btnMoveLast_Click(ByVal sender As ...
19. oBusObjB.nMoveLast()
20. Call SetFields()
........End Sub

9 Begin btnMoveFirst_Click sub, btnMoveFirst button clicked


10 Call the Business object's MoveFirst method to get the first row in the table
11 Call the SetFields routine to get values of the columns in the first row
12 Begin btnMovePrev_Click sub, btnMovePrev button clicked
13 Call the Business object's MovePrevious method to get the previous row in
the table
14 Call the SetFields routine to get values of the columns in the row
15 Begin btnMoveNext_Click sub, btnMoveNext button clicked
16 Call the Business object's MoveNext method to get the Next row in the
table
17 Call the SetFields routine to get values of the columns in the row
18 Begin btnMoveLast_Click sub, btnMoveLast button clicked
19 Call the Business object's MoveLast method to get the Last row in the table
20 Call the SetFields routine to get values of the columns in the last row

Page 140 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

21. Private Sub SetFields()


........22. Dim AccountCode As String = ""
23. Dim AccountDesc As String = ""

24. oBusObjB.nGetValue("AccountDesc$", AccountDesc)


25. oBusObjB.nGetValue("Account$", AccountCode)
26. oBusObjB.nGetValue("UDF_ProjectCode$", txtProject.Text)

27. txtMainAccount.Text = AccountCode


28. txtDescription.Text = AccountDesc

29. oBusObjB.nReadAdditional("UDF_ProjectCode")
30. oProjSvc.nGetValue("UDF_ProjectDesc$", lblProjDesc.Text)

....End Sub

21 Begin SetFields sub, to get and display the values of the current row's
columns
22 Declare AccountCode as String assign it a value (null) so it is typed
23 Declare AccountDesc as String assign it a value (null) so it is typed
24 Call the Business object's GetValue method, return value of the
AccountDesc column
25 Call the Business object's GetValue method, return value of the Account
column
26 Call Business object's GetValue method, return value of the
UDF_ProjectCode column
27 Assign the value of AccountCode to the txtMainAccount text box
28 Assign the value of AccountDesc to the txtDescription text box
29 Do additional reads with the UDF_ProjectCode Child Collection
30 The Child object's GetValue method returns value of UDF_ProjectDesc and
assigns it to the llbProjDesc text label

Certified Student Course Curriculum - Version 2.0 Page 141


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

31. Private Sub btnClear_Click(ByVal sender As ...


32. oBusObjB.nClear()
33. Call SetFields()
........34. lblNewRecord.Text = ""

..... . End Sub

31 Begin btnClear_Click sub; btnClear button clicked


32 The Clear method from SY_Service Initializes the Business object’s record
33 Call SetFields to display a blank record
34 Blank out the New Record text label on the form

35. Private Sub TestNew()

36. retVAL = oBusObjB.nSetKey(txtMainAccount.Text)


37. If retVAL = 0 Then
38. MessageBox.Show(oBusObjB.sLastErrorMsg)
............Else
39. Select Case retVAL
40. Case 1
41. lblNewRecord.Text = ""
42. Call SetFields()
43. Case 2
44. lblNewRecord.Text = "New Record"
45. Call SetFields()
................End Select
...... ...End If

........End Sub

Page 142 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

35 Begin TestNew sub, checks if the current record is new and changes the
form to match
36 The SetKey method returns 1 if the key was found and 2 if it is a new key
37 If SetKey returns zero if it fails validation ...
38 Display LastErrorMsg for reason of failure
39 Select Case of the SetKey return value
40 Case 1 – (EditState = edtExists)
41 Blank out the New Record text label on the form
42 Call SetFields to get and display record
43 Case 2 – (EditState = edtNew)
44 Set the New Record text label on the form to "New Record" to indicate
new record
45 Call SetFields to set any default values and display them on the form

46. Private Sub txtMainAccount_Leave(ByVal sender As ...


47. If txtMainAccount.Text <> "" Then
48. Call TestNew()
........End If

....End Sub

46 Begin txtMainAccount_Leave sub; when the txtMainAccount Text Box


looses focus
47 If the Text Box is not blank
48 Call the TestNew sub to find out if this is a new record

Certified Student Course Curriculum - Version 2.0 Page 143


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

49. Private Sub btnWrite_Click(ByVal sender As ...

50. retVAL = oBusObjB.nWrite()


51. If retVAL = 0 Then
52. MessageBox.Show(oBusObjB.sLastErrorMsg)
............Else
53. btnClear.PerformClick()
................'
54. lblNewRecord.Text = ""
............End If

....End Sub

49 Begin btnWrite_Clic, btnWrite button clicked


50 Call Business object's Write method, writes record to disk
51 If Write returned 0, the Write method failed
52 Display LastErrorMsg for reason of failure
53 Run the btnClear_Click routine
54 Blank out the New Record text label on the form

55. Private Sub txtProject_Leave(ByVal sender As ...

56. retVAL = oBusObjB.nSetValue("UDF_ProjectCode$",txtProject.Text)


57. If retVAL = 0 Then
58. MessageBox.Show(oBusObjB.sLastErrorMsg)
59. lblProjDesc.Text = ""
............Else
60. oProjSvc.nGetValue("UDF_ProjectDesc$",
lblProjDesc.Text)
............End If

....End Sub

Page 144 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

55 Begin txtProject_Leave sub; when the txtProject Text Box looses focus
56 Set the UDF_ProjectCode column value to the value of the txtProject Text
box
57 If the SetValue method fails, it returns 0 (zero)
58 Display the LastErrorMsg property for reason of failure
59 Blank the text displayed in the txtProjectDesc Text Label
60 Set the txtProjectDesc Text Label with the value of the UDF_ProjectDesc
column

61. Private Sub btnPrint_Click(ByVal sender As ...

62. Dim oRpt As Object

63. oRpt = oScript.NewObject("GL_ChartOfAccounts_rpt", oSS)


64. oRpt.nSelectReportSetting("STANDARD")

65. If oSS.nUI = 0 Then


66. oSS.nInitiateUI() 'Init UI to allow preview
............End If

67. retVAL = oRpt.nProcessReport("PREVIEW")


68. If retVAL = 0 Then
69. MessageBox.Show(oRpt.sLastErrorMsg)
............End If

70. oRpt.DropObject()
............oRpt = Nothing
....End Sub

Certified Student Course Curriculum - Version 2.0 Page 145


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

61 Begin btnPrint_Click sub; btnPrint button clicked


62 Declare Object handle to use for the GL Chart of Accounts Report Class
63 Create NewObject of the GL_ChartOfAccounts_rpt class, assign object's
handle to oRpt
64 Set the Report object's ReportSetting property to "Standard"
65 If the Sage MAS 90 Session has not had a UI object initiated
66 Initiate the Sessions UI object
67 Run the Chart Of Accounts report in preview mode
68 If the ProcessReport method fails it returns 0 (zero)
69 Display LastErrorMsg for reason of failure
70 Call the Report Objects destructor to delete the object from memory

71. Private Sub AddAccount_Closing(ByVal sender As ...


........72. oBusObjB.DropObject()
73. oProjSvc.DropObject()
............oBusObjB = Nothing
............oProjSvc = Nothing
.....End Sub

74. End Class

71 Begin AddAccount_Closing sub – when the AddAccount program is


closed
72 Call the Business object's destructor
73 Call the Service (Child) object's destructor
74 End of AddAccount class (AddAccount.vb)

Page 146 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

JournalEntry.vb source
1. Public Class JournalEntry
.......Inherits System.Windows.Forms.Form
(Windows Form Designer generated code)
'string to contain batch number for processing
2. Private strBatchNo As String = ""
'data table bound to data grid for lines
3. Private MyDataTable As DataTable
4. Private colAccount As New DataGridTextBoxColumn()
5. Private WithEvents cboAccount As New ComboBox()

6. Dim AccountDialog As New AddAccount()

7. Private Sub Form_Load(ByVal sender As System.Object, ...


8. .Call GetAccountList()
9. .Call LoadSrcJrnlLB()
........10. Call FormatDataGrid()

'init controls
11. txtBalance.Text = "0"
12. txtCredit.Text = "0"
........13. txtDebit.Text = "0"

...End Sub

Certified Student Course Curriculum - Version 2.0 Page 147


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

1 JournalEntry class – JournalEntry.vb


2 Declare a String Variable used for Sage MAS 90 GeneralJournal Batch
Number
3 VB Specific - used with VB DataGrid named MyGrid
4 VB Specific - used with VB DataGrid named MyGrid
5 cboAccount ComboBox is used to list Sage MAS 90 GL Account numbers
6 Define a handle to the AddAccount dialog – AddAccount.vb
7 Begin Form_Load sub – logic executed before the form displays
8 Call GetAccountList loads the cboAccount ComboBox with Account
Numbers
9 Call LoadSrcJrnlLB loads the cboJournal ComboBox with Sage MAS 90
GL Source Journals
10 VB Specific - Call FormatDataGrid – Define MyDataTable and MyGrid
for Journal Detail
11 Initialize Textbox value to zero
12 Initialize Textbox value to zero
13 Initialize Textbox value to zero

# Private Sub FormatDataGrid() ...You can view the FormatDataGrid routine


from the JournalEntry.vb source file; it is not documented here because it
does not contain any code specific to the ProvideX OLE Server or Sage
MAS 90

# Private Sub SetcboAccount() ... You can view the SetcboAccount routine
from the JournalEntry.vb source file; it is not documented here because it
does not contain any code specific to the ProvideX OLE Server or Sage
MAS 90

# Private Sub CalculateBalance() ... You can view the CalculateBalance


routine from the JournalEntry.vb source file; it is not documented here
because it does not contain any code specific to the ProvideX OLE Server
or Sage MAS 90

Page 148 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

# Private Sub MyGrid_CurrentCellChanged () ... You can view the


MyGrid_CurrentCellChanged routine from the JournalEntry.vb source file;
it is not documented here because it does not contain any code specific to
the ProvideX OLE Server or Sage MAS 90

14. Private Sub txtDate_Leave(ByVal sender As Object, ...


15. txtDate.Text = FormatPostDate(txtDate.Text, 1)

........End Sub

16. Private Function FormatPostDate(ByVal strDate As String, _


ByVal intType As Integer) As String
..........Try
..........17. Dim PostDate As Date
..........18. PostDate = CType(strDate, Date)

..........19. Select Case intType


..............20. Case 1
..................'for display: MM/DD/YYYY
...... .21. strDate = PostDate.Month.ToString.PadLeft(2, "0") & "/"
........22. strDate &= PostDate.Day.ToString.PadLeft(2, "0") & "/"
................23. strDate &= PostDate.Year
..............24. Case 2
..................'for return to MAS 90: YYYYMMDD
................25. strDate = PostDate.Year
..............26. strDate &= PostDate.Month.ToString.PadLeft(2, "0")
................27. strDate &= PostDate.Day.ToString.PadLeft(2,"0")
........End Select
28. Return strDate
............Catch
'can't format
............End Try

........End Function

Certified Student Course Curriculum - Version 2.0 Page 149


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

14 Begin txtDate_Leave sub, when txtDate Textbox looses focus


15 Format txtDate for display with the FormatPostDate function
16 Begin FormatPostDate function; accepts date as string, 1 for display, 2 for
Sage MAS 90
17 Define a Date type variable
18 Convert string date to Date type so you can use VB date functions on the
date
19 Select Case intType
20 Case 1 – Format date for display MM/DD/YYYY
21 Set string date to MM/
22 Set string date to MM/DD/
23 Set string date to MM/DD/YYYY
24 Case 2 – Format date for Sage MAS 90 YYYYMMDD
25 Set string date to YYYY
26 Set string date to YYYYMM
27 Set string date to YYYYMMDD
28 Return string date

Page 150 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

29. Private Sub btnUpdate_Click(ByVal sender As ...

30. If MyDataTable.Rows.Count > 0 Then

31. Dim blnSuccess As Boolean = True


32. Dim oGLJrnl As Object
33. Dim oGLJrnlLines As Object
34. Dim oSJObj As Object

35. retVAL =
oSS.nSetProgram(oSS.nLookupTask("GL_GeneralJournal_ui"))
36. If retVAL = 0 Then
37. MessageBox.Show(oSS.sLastErrorMsg)
............... End If
................Try
38. oGLJrnl = oScript.NewObject("GL_GeneralJournal_bus",
oSS)
................Catch
39. MessageBox.Show(oSS.sLastErrorMsg)
................End Try
40. oGLJrnlLines = oGLJrnl.oLines
................Try
41. oSJObj = oScript.NewObject("gl_SourceJournal_svc",
oSS)
................Catch
42. MessageBox.Show(oSS.sLastErrorMsg)
................End Try

Certified Student Course Curriculum - Version 2.0 Page 151


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

29 Begin btnUpdate_Click sub; btnUpdate button clicked


30 If at least one journal entry detail line is entered, continue processing
31 Define a Boolean variable used to indicate if update is successful, initiate to
True
32 Define an Object handle for the General Journal Business object
33 Define an Object handle for the General Journal Lines object
34 Define an Object handle for the Source Journal Service object
35 Get Security object for General Journal
36 If the SetProgram method fails it returns zero
37 Display LastErrorMsg for reason of failure
38 Create new GL_GeneralJournal_bus Business object, set oBusObjB to the
objects handle
39 Display LastErrorMsg if NewObject fails
40 Set oGLJrnlLines to the value of the oLines object handle
41 Create new GL_SourceJournal_svc Service object, set oSJObj to the
objects handle
42 Display LastErrorMsg if NewObject fails

Page 152 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

'Establish header and assign values


43. retVAL = oGLJrnl.nSelectBatch(strBatchNo)
44. If retVAL = 0 Then
45. MessageBox.Show(oSS.sLastErrorMsg)
................Else
46. lblBatchNo.Text = strBatchNo
................End If
47. If Not CBool(oGLJrnl.nSetKeyValue("Source
Journal$", cboJournal.Text)) Then
48. MessageBox.Show(oGLJrnl.sLastErrorMsg)
.....End If
49. Dim strEntryNo As String = ""
50. oSJObj.nGetNextJournalNo(cboJournal.Text, strEntryNo)
51. oGLJrnl.nSetKeyValue("EntryNo$", strEntryNo)
52. oGLJrnl.nSetKey()
53. Dim strPostDate As String
54. strPostDate = FormatPostDate(txtDate.Text, 2)
55. oGLJrnl.nSetValue("PostingDate$",
strPostDate)
56. oGLJrnl.nSetValue("JournalComment$", txtPostComment
.Text)

43 Select the GeneralJournal batch number, if Batches are not enabled,


BatchNo will be 1
44 If SelectBatch fails it returns zero
45 Display LastErrorMsg for reason for failure
46 Displays the batch number on the form in the text label lblBatchNo
47 SetKeyValue for the SourceJournal column, This method returns 0 (false) if
it fails
48 Display LastErrorMsg for reason for failure
49 Define strEntryNo as String, assign it a value to force type

Certified Student Course Curriculum - Version 2.0 Page 153


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

50 Get the Next Journal Number and return it in strEntryNo


51 SetKeyValue for the EntryNo column
52 Set the file pointer to the given key, if the key does not exist a new key is
created
53 Define strPostDate as String
54 Format the displayed txtDate to Sage MAS 90 date YYYYMMDD and
store it in strPostDate
55 Set value of the PostingDate column to strPostDate
56 Set value of the JournalComment column to contents of the
txtPostComment TextBox

'Process line entry


57. Dim intRow
58. Dim decDebit As Decimal = 0
59. Dim decCredit As Decimal = 0
60. Dim strAccountNumber As String = ""
61. Dim strDescription As String = ""
62. Dim strProject As String = ""

63. For intRow = 0 To MyDataTable.Rows.Count - 1

'make sure there is an account number


64. If MyDataTable.Rows.Item(intRow).Item(0) > "" Then

65. strAccountNumber = CStr(MyDataTable.Rows.Item(intRow).Item(0))


66. strDescription = CStr(MyDataTable.Rows.Item(intRow).Item(1))
67. decDebit = CDec(MyDataTable.Rows.Item(intRow).Item(2))
68. decCredit = CDec(MyDataTable.Rows.Item(intRow).Item(3))
69. strProject = CStr(MyDataTable.Rows.Item(intRow).Item(4))

70. oGLJrnl.nAddLine()

Page 154 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

71. oGLJrnlLines.nSetValue("AccountKey$", strAccountNumber,


"kACCOUNT")
72. oGLJrnlLines.nSetValue("PostingComment$", strDescription)

73. If decDebit > 0 Then


74. oGLJrnlLines.nSetValue("DebitAmount", decDebit)
.......Else
75. oGLJrnlLines.nSetValue("CreditAmount", decCredit)
......End If

76. retVAL = oGLJrnlLines.nSetValue("UDF_Project$", strProject)


77. If retVAL = 0 Then
78. MessageBox.Show("Invalid project code in line" & CStr(int
Row+1))
79. blnSuccess = False
......End If

80. If Not CBool(oGLJrnlLines.nWRITE()) Then


81. MessageBox.Show(oGLJrnlLines.sLastErrorMsg)
......End If
...Else
85. blnSuccess = False
..... End If
...Next

Certified Student Course Curriculum - Version 2.0 Page 155


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

57 Define intRow as Integer


58 Define decDebit as Decimal, initial value zero
59 Define decCredit as Decimal, initial value zero
60 Define strAccountNumber as String, initial value empty string
61 Define strDescription as String, initial value empty string
62 Define strProject as String, initial value empty string
63 For-next Loop to process all lines in MyDataTable
64 If the value of the Account column is not empty, process the row
65 Set strAccountNumber to the value in the Account column for the current
row
66 Set strDescription to the value in the PostingComment column for the
current row
67 Set decDebit to the value in the Debit column for the current row
68 Set decCredit to the value in the Credit column for the current row
69 Set strProject to the value in the Project column for the current row
70 Add a new detail line in the Business object for the current row
71 Set the value of the Lines object's AccountKey column to
strAccountNumber. The kACCOUNT index is used to address the Index
on the file for GL_Accounts.
72 Set the value of the Lines object's PostingComment column to
strDescription
73 If a value was entered into the Debit column, set debit and not credit
74 Set the value of the DebitAmount column to decDebit
75 Set the value of CreditAmount to decCredit
76 Set the value of the Sage MAS 90 user-defined field UDF_Project
77 If SetValue fails it returns zero

Page 156 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

78 Display message indicating the value in the Project column failed


validation as defined in Customizer
79 Set Boolean variable which indicates if the update was successful to
FALSE
80 Call the Lines object Write method to write the current line to memory file
(SetMode), returns 0 if failure
81 Display LastErrorMsg if Write failed
82 Set Boolean variable which indicates if the update was successful to True

'done with lines now commit to MAS 90


83. If blnSuccess Then
84. If Not CBool(oGLJrnl.nWRITE()) Then
85. MessageBox.Show(oGLJrnl.sLastErrorMsg)
...Else
86. btnPost.Enabled = True
......End If
...Else
87. MessageBox.Show("Unable to Create Journal Entry")
......End If

88. oSJObj.DropObject()
89. oGLJrnlLines.DropObject()
90. oGLJrnl.DropObject()
....oSJObj = Nothing
....oGLJrnlLines = Nothing
....oGLJrnl = Nothing

......End If

...End Sub

Certified Student Course Curriculum - Version 2.0 Page 157


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

83 If Update was successful then


84 Write Header and Lines to disk file, if the Write method fails it returns zero
85 Display LastErrorMsg if Write failed
86 Enable the 'Print/Update' button, which Posts the updated journal entry
87 Display message that journal entry was not created
88 Drop SourceJournal Service object
89 Drop General Journal Lines object
90 Drop General Journal Business object

91. Private Sub btnPost_Click(ByVal sender As Object, ....


92. Dim oGLPost As Object
93. retVAL = oSS.nSetProgram(oSS.nLookupTask("GL_GeneralJournal
Update_ui"))

If retVAL = 0 Then
94. MessageBox.Show(oSS.sLastErrorMsg)
Exit Sub
End If
.....Try
95. oGLPost = oScript.NewObject("GL_GeneralJournal_upd", oSS)
.....Catch
96. MessageBox.Show(oSS.sLastErrorMsg)
.....End Try

97. retVAL = oGLPost.nSelectBatch(strBatchNo)

98. If CBool(oGLPost.nProcessReport("DEFERRED")) Then


99. retVAL = oGLPost.nUpdate()

Page 158 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

100. Select Case retVAL


101. Case 0
102. MessageBox.Show(oGLPost.slasterrormsg)
103. Case 1
104. MessageBox.Show("Update Successful")
..........End Select

105. btnPost.Enabled = False


106. lblBatchNo.Text = ""
107. ---strBatchNo = ""
.....Else
108. MessageBox.Show(oGLPost.sLastErrorMsg)
.....End If

109. oGLPost.DropObject()
.....oGLPost = Nothing
.....End Sub

Certified Student Course Curriculum - Version 2.0 Page 159


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

91 Begin btnPost_Click sub, btnPost button clicked


92 Define an Object handle for the General Journal Update object
93 Get Security object for GL_GeneralJournalUpdate
94 Display LastErrorMsg for reason of failure
95 Create new GL_GeneralJournal_bus object; object handle = oGLPost
96 Display LastErrorMsg for reason of failure
97 Select the GeneralJournal batch number
98 If General Journal Report prints to deferred successfully, then
99 Update General Journal
100 Select Case retVAL
101 Case retVAL = 0
102 Display LastErrorMsg for reason of failure
103 Case retVAL = 1
104 Display message box stating Update Successful
105 Disable the btnPost button control
106 Set the Batch Number text label to blank
107 Set the Batch Number control to blank
108 Display LastErrorMsg for reason ProcessReport() on Line 11 failed
109 Drop GLPost object

Page 160 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

# Private Sub btnAddJournal() ... The btnAddJournal sub is documented


under the MAS90_Examples.vb Source section of this document, see
Private Sub BT_SourceJournal_Click

110. Private Sub LoadSrcJrnlLB()

111. Dim strResults As String = ""


112. Dim strJunk As String = ""
113. Dim oGLSrcJrnlSrvcObj As Object
114. Dim MyArray() As String

115. cboJournal.Items.Clear()

116. retVAL =
oSS.nSetProgram(oSS.nLookupTask("GL_SourceJournal_ui"))
117. If retVAL = 0 Then
118. MessageBox.Show(oSS.sLastErrorMsg)
............Exit Sub
..............End If

..............Try
119. oGLSrcJrnlSrvcObj = oScript.NewObject("gl_SourceJournal_svc",
oSS)
..............Catch
120. MessageBox.Show(oSS.sLastErrorMsg)
..............End Try

121. oGLSrcJrnlSrvcObj.nGetResultSets("SourceJournal$",_
"SourceJournal$", strResults, strJunk, "", "", "")
122. MyArray = Split(strResults, Chr(138))

123. cboJournal.Items.AddRange(MyArray)

124. oGLSrcJrnlSrvcObj.DropObject()
.............oGLSrcJrnlSrvcObj = Nothing
........End Sub

Certified Student Course Curriculum - Version 2.0 Page 161


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

110 Begin the LoadSrcJrnlLB subroutine which loads the Source Journal
Combobox control
111 Declare strResults as String assign it a value (null) so it is "typed"
112 Declare strJunk as String assign it a value (null) so it is "typed"
113 Define an Object handle for the SourceJournal Service object
114 Declare MyArray as String Array
115 Clear any items currently in the Source Journal Combobox
116 Get Security object for GL Source Journal
117 If SetProgram fails, it returns zero
118 Display LastErrorMsg for reason of failure
119 Create new GL_SourceJournal_svc Service object, object handle –
oGLSrcJrnlSrvcObj
120 Display LastErrorMsg for reason of failure
121 GetResultSets is an inherited method which returns a separated (Chr(138))
list
122 Split the separated list into MyArray elements specify Chr(138) as
delimiter
123 Add MyArray elements to the Source Journal Combobox
124 Drop Object oGLSrcJrnlSrvcObj
125 Set oGLSrcJrnlSrvcObj object handle to nothing

Page 162 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

126. Private Sub GetAccountList()

127. Dim strResults As String = ""


128. Dim strJunk As String = ""
129. Dim oGLAcctSrvcObj As Object
130. Dim strAccountArray() As String

131. retVAL =
oSS.nSetProgram(oSS.nLookupTask("GL_Account_ui"))

132. If retVAL = 0 Then


133. MessageBox.Show(oSS.sLastErrorMsg)
.................Exit Sub
............End If

............Try
134. oGLAcctSrvcObj = oScript.NewObject("gl_Account_svc",
oSS)
..............Catch
135. MsgBox("NewObject(GL_Account_svc) " & oSS.sLastError
Msg)
..............End Try

136. oGLAcctSrvcObj.nGetResultSets("Account$", _
"AccountKey$", strResults, strJunk, "", "", "",
"kAccount")
137. strAccountArray = Split(strResults, Chr(138))
138. cboAccount.Items.Clear()
139. cboAccount.Items.AddRange(strAccountArray)

140. oGLAcctSrvcObj.DropObject()
141. oGLAcctSrvcObj = Nothing
.......
........End Sub

Certified Student Course Curriculum - Version 2.0 Page 163


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

126 Begin sub GetAccountList which loads the cboAccount control with
Account #'s
127 Declare strResults as String assign it a value (null) so it is "typed"
128 Declare strJunk as String assign it a value (null) so it is "typed"
129 Define an Object handle for the SourceJournal Service object
130 Declare MyArray as String Array
131 Get Security object for GL Source Journal
132 If SetProgram fails it returns zero
133 Display LastErrorMsg for reason of failure
134 Create new GL_Account_svc Service object, object handle –
oGLAcctSrvcObj
135 Display LastErrorMsg for reason of failure
136 GetResultSets is an inherited method which returns a separated (Chr(138))
list
137 Split the separated list into MyArray elements specify Chr(138) as
delimiter
138 Clear any existing items in the Account Number Combobox
139 Add MyArray elements to the Account Number Combobox
140 Drop Object oGLAcctSrvcObj
141 Set oGLAcctSrvcObj object handle to nothing

Page 164 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

BudgetFromExcel.vb source
1. Public Class BudgetFromExcel
Inherits System.Windows.Forms.Form

2. Dim oGLBudget As Object


3. Dim oGLService As Object
4. Private retVAL As Integer

5. Dim objExcel As New Excel.Application()


6. Dim objWkSheet As New Excel.Worksheet()

7. Dim Record As String = ""


8. Dim IOList As String = ""
9. Dim AccountKey As String = ""
10. Dim Column() As String
11. Dim excelExists As Boolean
12. Dim FiscalPeriod As Integer
13. Dim sFiscalPeriod As String
14. Dim CreditAmount, rCreditAmount, DebitAmount, rDebitAmount_
As Decimal

15. Private Sub BudgetFromExcel_Load(ByVal sender As ...

16. Dim dropBoxLoad As String = ""


17. Dim comboBoxLoad() As String

.......................Try
18. oGLBudget = oScript.NewObject("GL_PeriodBudgetDetail_bus",
oSS)
19. oGLService = oScript.NewObject("GL_Account_svc", oSS)
........................Catch
20. MessageBox.Show(oSS.sLastErrorMsg)
........................End Try

21. retVAL = oGLService.nSetIndex("kACCOUNT")

Certified Student Course Curriculum - Version 2.0 Page 165


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

22. oGLService.nGetResultSets("Account$", "AccountKey$",_


dropBoxLoad, "", "", "", "", "kAccount")
23. comboBoxLoad = Split(dropBoxLoad, Chr(138))
24. CB_AccountList.Items.AddRange(comboBoxLoad)

25. excelExists = False

................End Sub

1 BudgetFromExcel class – BudgetFromExcel.vb


2 Define an Object handle for the GL Period Budget Detail Business object
3 Define an Object handle for the GL Account Service object
4 Define a private Integer variable to accept integer return value of methods
5 Define an Object handle for an Excel.Application object
6 Define an Object handle for an Excel.WorkSheet object
7 Declare Record as String assign it a value (null) so it is "typed"
8 Declare IOList as String assign it a value (null) so it is "typed"
9 Declare AccountKey as String assign it a value (null) so it is "typed"
10 Declare Column as an Array of String
11 Declare excelExists as Boolean
12 Declare FiscalPeriod as Integer
13 Declare sFiscalPeriod as String
14 Declare CreditAmount, rCreditAmount, DebitAmount, rDebitAmount as
decimal
15 Begin BudgetFromExcel_Load sub; logic executed before the form is
displayed
16 Define dropBoxLoad as String; used to accept result of GetResultSets on
line 26
17 Define comboBoxLoad as Array of string; used to accept result of Split on
line 27

Page 166 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

18 Create new GL_PeriodBudgetDetail_bus Business object, set oGLBudget


to the obj handle
19 Create new GL_Account_svc Service object, set oGLService to the
objects handle
20 Display LastErrorMsg for reason of failure
21 Set Index for service object to retrieve surrogate key for GL Account
22 GetResultSets is an inherited method which returns a separated (Chr(138))
list
23 Split the separated list into comboBoxLoad elements specify Chr(138) as
delimiter
24 Add comboBoxLoad elements to the CB_AccountList Combobox
25 Initialize Boolean variable to false

26. Private Sub CB_AccountList_SelectedIndexChanged(ByVal ...

27. If CB_AccountList.Text = "" Then Exit Sub

28. Record = ""


29. IOList = ""
30. oGLService.nFind(CB_AccountList.Text)
31. retVAL = oGLService.nGetRecord(Record, IOList)

32. Column = Split(Record, Chr(138))


33. AccountKey = Column(0)
34. AccountDesc.Text = Column(1)
................35. Call InitializeExcelWorkSheet()
36. TextBox1.Text = "Period" & "Original" & "Revised" & vbCrLf
37. TextBox1.AppendText(" Db" & " Cr" & " Db" &_
"Cr" & vbCrLf)
..............38. For FiscalPeriod = 1 To 12
.. .... ..... ..........39. DebitAmount = 0
........................40. CreditAmount = 0
............. . . . . .....41. sFiscalPeriod = FiscalPeriod.ToString.PadLeft(2, "0")

Certified Student Course Curriculum - Version 2.0 Page 167


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

..............42. retVAL = oGLBudget.nSetKeyValue("AccountKey$", AccountKey)


43. retVAL = oGLBudget.nSetKeyValue("BudgetCode$", "ORIGINAL")
44. retVAL = oGLBudget.nSetKeyValue("FiscalYear$", "2003")
45. retVAL = oGLBudget.nSetKeyValue("FiscalPeriod$",_
sFiscalPeriod)
49. retVAL = oGLBudget.nSetKey()

47. If retVAL = 1 Then


48. oGLBudget.nGetValue("DebitAmount", DebitAmount)
49. oGLBudget.nGetValue("CreditAmount", CreditAmount)
End If

50 objWkSheet.Cells(FiscalPeriod, 1) = sFiscalPeriod
51. objWkSheet.Cells(FiscalPeriod, 2) = DebitAmount
52. objWkSheet.Cells(FiscalPeriod, 3) = CreditAmount
53. rDebitAmount = objWkSheet.Cells(FiscalPeriod, 4).Value
54. rCreditAmount = objWkSheet.Cells(FiscalPeriod, 5).Value

55. TextBox1.AppendText(sFiscalPeriod & vbTab & Format(DebitAmount,


"#,##0.00").PadLeft(10, " ") & vbTab & vbTab & Format(Credit
Amount,"#,##0.00").PadLeft(10, " ") & vbTab & vbTab& vbTab &
Format(rDebitAmount, "#,##0.00").PadLeft(10, " ") & vbTab &
vbTab & _ Format(rCreditAmount, "#,##0.00").PadLeft(10, " ") &
vbCrLf)

...... Next
......End Sub

Page 168 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

26 Begin CB_AccountList_SelectedIndexChanged; executed when account


selected from combo-box
27 If a blank item was selected just exit
28 Set Record to null
29 Set IOList to null
30 Set the GL_Account file pointer using the specified key
31 Read the GL_Account file at the pointer location, data returned in Record
as separated list, column names returned in IOList as separated list
32 Split the separated list into Column elements specify Chr(138) as delimiter
33 Set AccountKey as value of first column array element
34 Set AccountDesc as value of second column array element
35 Call the InitializeExcelWorksheet subroutine – line 98
36 Setup column heading line 1 in TextBox1 textbox control
37 Setup column heading line 2 in TextBox1 textbox control
38 For Loop – 12 iterations
39 Set DebitAmount to zero
40 Set CreditAmount to zero
41 Convert loopcounter (FiscalPeriod) to String (sFiscalPeriod) with leading
zero
42 SetKeyValue for the AccountKey column, this method returns 0 (false) if it
fails
43 SetKeyValue for the BudgetCode column, this method returns 0 (false) if it
fails
44 SetKeyValue for the FiscalYear column, this method returns 0 (false) if it
fails
45 SetKeyValue for the FiscalPeriod column, this method returns 0 (false) if it
fails
46 The SetKey method returns 1 if the key was found or 2 if it is a new key
47 If the record was found (retVAL = 1)

Certified Student Course Curriculum - Version 2.0 Page 169


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

48 Call the GetValue method, return value of the DebitAmount column


49 Call the GetValue method, return value of the CreditAmount column
50 Set the value of the Excel worksheet cell (loopcounter,1) to sFiscalPeriod
51 Set the value of the Excel worksheet cell (loopcounter,2) to DebitAmount
52 Set the value of the Excel worksheet cell (loopcounter,2) to CreditAmount
53 Set the value of rDebitAmount to the Excel worksheet cell (loopcounter,4)
54 Set the value of rCreditAmount to the Excel worksheet cell (loopcounter,5)
55 Write a line to the TextBox1 control for Fiscal Period, Original and Revised
amounts

56. Private Sub BT_Accept_Click(ByVal sender As ...

57. Dim retSETKEY, retSETVALUE, retWRITE As Integer

58. For FiscalPeriod = 1 To 12

59. sFiscalPeriod = FiscalPeriod.ToString.PadLeft(2, "0")


60. rDebitAmount = objWkSheet.Cells(FiscalPeriod, 4).Value
61. rCreditAmount = objWkSheet.Cells(FiscalPeriod, 5).Value

62. retVAL = oGLBudget.nSetKeyValue("AccountKey$",


AccountKey)
63. retVAL = oGLBudget.nSetKeyValue("BudgetCode$", "REVISED")
64. retVAL = oGLBudget.nSetKeyValue("FiscalYear$", "2003")
65. retVAL = oGLBudget.nSetKeyValue("FiscalPeriod$",
sFiscalPeriod)
66. retSETKEY = oGLBudget.nSetKey()
...... . ...67. oGLBudget.nSetValue("DebitAmount$", rDebitAmount)
68. oGLBudget.nSetValue("CreditAmount$", rCreditAmount)
69. retVAL = oGLBudget.nWrite()

.....................Next

Page 170 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

70. CB_AccountList.Text = ""


71. AccountDesc.Text = ""
72. TextBox1.Text = ""

..............End Sub

56 Begin BT_Accept_Click - BT_Accept button clicked


57 Declare retSETKEY, retSETVALUE, retWRITE as integer for return
values
58 For Loop – 12 iterations
59 Convert loopcounter (FicalPeriod) to String (sFiscalPeriod) with leading
zero
60 Set rDebitAmount from the value in Excel worksheet cell (loopcounter,4)
61 Set rCreditAmount from the value in Excel worksheet cell (loopcounter,5)
62 SetKeyValue for the AccountKey column, this method returns 0 (false) if it
fails
63 SetKeyValue for the BudgetCode column, this method returns 0 (false) if it
fails
64 SetKeyValue for the FiscalYear column, this method returns 0 (false) if it
fails
65 SetKeyValue for the FiscalPeriod column, this method returns 0 (false) if it
fails
66 The SetKey method returns 1 if the key was found or 2 if it is a new key
67 Set value of the DebitAmount column to rDebitAmount
68 Set value of the CreditAmount column to rCreditAmount
69 Call the oGLBudget object Write method to write the current record
70 Set Account List drop box displayed item to Null
71 Set Account Description displayed to Null
72 Set TextBox1 text displayed to Null

Certified Student Course Curriculum - Version 2.0 Page 171


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

........73. Private Sub InitializeExcelWorkSheet()

......................Try
74. retVAL = Len(objWkSheet.Name())
......................Catch
75. objWkSheet = objExcel.Workbooks.Add(1).Worksheets.Item(1)
76. excelExists = True
......................End Try

77. objWkSheet.Range("A1", "E12").ClearContents()


78. objWkSheet.Columns("A").NumberFormat = "@"

79. For FiscalPeriod = 1 To 12


80. objWkSheet.Cells(FiscalPeriod, 4).Value = _
"=ROUND((B" & CStr(FiscalPeriod) & "*1.0775),2)"
81. objWkSheet.Cells(FiscalPeriod, 5).Value = _
"=ROUND((C" & CStr(FiscalPeriod) & "*1.0775),2)"
......................Next

...............End Sub

73 Begin InitializeExcelWorkSheet sub


74 If len on Excel worksheet name fails, then Excel has not yet initialize
75 Create new Excel worksheet in memory
76 Set Boolean value to true
77 Clear the contents of the worksheet cells in the range from A1 to E12
78 Set the number format for the worksheet columm A
79 For Loop – 12 iterations
80 Set the 4th columns to a formula to calculate the revised budget
81 Set the 5th columns to a formula to calculate the revised budget

Page 172 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

82. Private Sub BudgetFromExcel_Closing(ByVal sender As Object,


ByVal e As System.ComponentModel.CancelEventArgs) Handles
MyBase.Closing
83. oGLBudget.DropObject()
84. oGLService.DropObject()
.......................oGLBudget = Nothing
.......................oGLService = Nothing

85. If excelExists Then


86. objExcel.Workbooks(1).Saved = True
87. objExcel.Quit()
..............................objWkSheet = Nothing
..............................objExcel = Nothing
..................... .End If

.................End Sub

......... .End Class

...........

82 Begin BudgetFromExcel_Closing sub; executes when BudgetFromExcel


closes
83 Drop oGLBudget Business object
84 Drop oGLService Service object
85 If Excel application and worksheet objects exist in memory
86 Set Excel application Saved flag to true so user is not prompted to save
87 Quit Excel application

Certified Student Course Curriculum - Version 2.0 Page 173


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

Demo ProvideX Script - VBS


' Demo the Properties and Methods of the ProvideX OLE Server object
' Copyright 2005 Sage Software, Inc.

'Get the Sage MAS 90 path from the SOTAMAS90 registry entry
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
oReg.GetExpandedStringValue &H80000001,
"Software\ODBC\ODBC.INI\SOTAMAS90", "Directory",PathRoot
PathHome = PathRoot & "\Home"
Set oReg = Nothing

'Create ProvideX COM Object


Set oScript = CreateObject ("ProvideX.Script")

'The Init() method must be the first method called


'Init() requires the path to the MAS90 home directory
oScript.Init(PathHome)

'Demo ProvideX.Script Properties & Methods

Page 174 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix A - Example Program Listings and Documentation (continued)


1

'Evaluate - Return the value of the ProvideX LWD system variable


WorkingDir = oScript.Evaluate("LWD")
MsgBox ("ProvideX working directory: " & WorlingDir)

'Execute the ProvideX CWDIR directive to change the working directory


oScript.Execute("CWDIR ""..""")

'Verify the working directory has changed


NewDir = oScript.Evaluate("LWD")
MsgBox ("Now the ProvideX working directory: " & NewDir)

'Better change the working directory back or can't create MAS 90


objects!
oScript.Execute("CWDIR """ & WorkingDir & """")
NowDir = oScript.Evaluate("LWD")
MsgBox ("ProvideX working directory back to: " & NowDir)

'Returns the result of the ProvideX SQR function in NumVar


NumVar = oScript.Evaluate("SQR(9)")

'Display and set the value of ProvideX System Parameters


'These are set by the MAS 90 start up logic and should not be changed
TurboMode = oScript.Parameter("TU")
MsgBox("TurboMode = " & turbomode)
oScript.Parameter("TU") = 0
TurboMode = oScript.Parameter("TU")
MsgBox("TurboMode = " & turbomode)

'NewObject() creates a ProvideX object and returns an object handle


Set oSS = oScript.NewObject("SY_Session")

'DropObject() destroys a ProvideX object and releases its resources


oSS.DropObject()

Set oSS = Nothing


Set oScript= Nothing

Certified Student Course Curriculum - Version 2.0 Page 175


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example


Programs
1

Create a user-fefined table for General Ledger as follows:


• Table Name: GL_UDT_PROJECTS
• Key Field Name: UDF_PROJECT_CODE
• Key Field Length: 10
• Add Field: UDF_PROJECTDESC, Multi-Line, String, and Length=30
1. From the Custom Office Main menu, select User-Defined Field and Table
Maintenance.
2. Right-click General Ledger and select Add a User-Defined Table.
3. At the Table Name field, enter PROJECT. The table name is prefixed with
GL_UDT_.
4. Tab through the remaining fields to automatically set the default values.

Figure 1

5. Accept the defaults for the remaining fields and click OK.

Page 176 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

6. Click Add to add a field to the GL Project table.

Figure 2

7. At the Field Name field, enter PROJECTDESC. The field name is prefixed with
UDF_.
8. At the Maximum Length field, enter 30.

Figure 3

Certified Student Course Curriculum - Version 2.0 Page 177


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

9. Accept the remaining defaults and click OK and OK again to finish.

Figure 4

10. Click OK to update the data dictionary.

Figure 5

Page 178 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

11. Right-click GL Projects (UDT) and select Maintain UDT Data.

Figure 6

12. Enter a few records in the User-Defined Table Maintenance program and click
Accept to save when finished.

Figure 7
Certified Student Course Curriculum - Version 2.0 Page 179
Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

Create a UDF for the GL Account Master table.


• Field Name: UDF_PROJECTCODE
• Source: Manual Entry
• Object Type: Multi-Line
• Data Type: String, Length: 10
• Validation: User-Defined Table - GL_UDT_PROJECTS
1. From the Custom Office Main menu, select User-Defined Field and Table
Maintenance.
2. From the General Ledger menu, right-click GL Account Master and select Edit
Fields.

Figure 8

Page 180 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

3. At the User-Defined Fields window, click Add.


4. At the Field Name field, enter PROJECTCODE. The field name is prefixed with
UDF_.

Figure 9

5. At the Source field, select Manual Entry and click OK.


6. On the Attributes tab, select Multi-Line as the object type, String as the data type,
and set the maximum length to 10.

Figure 10

Certified Student Course Curriculum - Version 2.0 Page 181


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

7. On the Validation tab, select User-Defined Table as the validation method.


8. At the User-Defined Table field, select GL_UDT_PROJECTS.

Figure 11

9. Accept the defaults for the remaining fields and click OK.
10. Click OK to finish defining fields for the GL Account Master table.

Figure 12

Page 182 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

11. Click OK to update the data dictionary.

Figure 13

Certified Student Course Curriculum - Version 2.0 Page 183


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1
1

Create a UDF for the GL General Journal Detail table.


• Field Name: UDF_PROJECT
• Source for UDF: Business Object
• Data Source: AccountKey
• Column: UDF_PROJECTCODE
• Validation: GL_UDT_PROJECTS
1. From the Custom Office Main menu, select User-Defined Field and Table
Maintenance.
2. From the General Ledger menu, right-click GL Account Master and select Edit
Fields.

Figure 14

Page 184 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

3. At the User-Defined Fields window, click Add.


4. At the Field Name field, enter PROJECT. The field name is prefixed with UDF_.
5. Select Business Object as the source of this UDF.
6. At the Data Source field, select AccountKey.
7. At the Column field, select UDF_PROJECTCODE.

Figure 15

8. Click OK.

Certified Student Course Curriculum - Version 2.0 Page 185


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

9. The Object Type and Attributes are set from the selected data source.

Figure 16

10. Click the Validation tab and select User-Defined Table as the validation method.
11. Select GL_UDT_PROJECTS as the user-defined table.

Figure 17

Page 186 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix B - UDF / UDT Setup for Example Programs (continued)


1

12. Accept the defaults for the remaining fields and click OK.
13. Click OK to finish defining fields for the GL Account Master table.

Figure 18

14. Click OK to update the data dictionary.

Figure 19

15. Close User-Defined Field and Table Maintenance.

Certified Student Course Curriculum - Version 2.0 Page 187


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix C - Message Library Reference


1

The following are common Sage MAS 90 error codes:


Error Code Description
CI_Cannot Cannot percent 1
Cannot delete percent 1
CI_DateFormat The date entered is in a nonsupported format
CI_NoKey The percent 1 is invalid
SY_NoUserSet The SetUser method is not called to set a user for
this session
SY_NoCompanySet The SetCompany method is not called to set a
company
SY_NoModule The module code passed does not exist in
SY_Module.M4T
SY_RegExpired This module is in trial mode (45 days free access)
SY_NoRegistration This module’s registration has expired or the
registration information is corrupted
SY_NotActivated The module accessed is not activated for this
company
SY_NoDate A date record does not exist for this module,
company, and user
SY_NoGeneralLedger The General Ledger module is not activated or
configured for this company
SY_NewSystem This module is not accessed for this company and
you need to configure it (run through all the setup
options or the new setup wizard)
SY_NeedToConvert This module needs to conversion (run conversion
from Company Maintenance before proceeding)
SY_NotActivated There is no data for this module
SY_NotActive The percent 1 module is not activated for this
company
SY_SecurityObject A security object is not initialized

Page 188 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix D - Sage MAS 90 Security Events and


Module Options
1

Use the following as a reference when using the CheckSecurityEvent(SecurityEvent$


| ModuleOption$) method.

Accounts Receivable Security Events


Security Event Description
SE_ARALLOWCUSTOMERHISTORYEDIT Allows editing of history data in Customer
Maintenance
SE_ARALLOWCUSTOMERSTATISTICEDT Allows editing of statistic data in Customer
Maintenance
SE_ARPRIVATEBATCHES Allows access to private batches
SE_ARALLOWSALESPERSONHISTEDIT Allows editing of history data in
Salesperson Maintenance
SE_ARALLOWCUSTOMERAUDITPURGE Allows purging of customer audit
SE_ARUPDATEFROMPREVIEW Allows updating of journals from the
Preview window

Accounts Receivable Module Options


Module Option Description
SE_ARALLOWCUSTOMERDATAMAINT Allows maintenance of customer data
during data entry
SE_ARALLOWCOMMISSIONOVERRIDE Allows commission override
SE_ARALLOWCREDITLIMITOVERRIDE Allows credit limit override
SE_ARALLOWOTFCUSTOMERS Allows on the fly customers
SE_ARMERGEBATCH Allows to merge batches
SE_ARRENUMBERBATCH Allows to renumber batches
SE_ARVERIFYBATCH Allows to verify batches
SE_ARMODIFYNEXTBATCHNO Allows to modify the next batch number

Certified Student Course Curriculum - Version 2.0 Page 189


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix D - Sage MAS 90 Security Events and Module Options


(continued)
1

General Ledger Security Events


SecurityEvent Description
SE_GLFISCALYEARRECALC Allows fiscal year recalculation
SE_GLALLOWOUTOFBALANCE Allows out-of-balance journal entries
SE_GLUPDATEFROMPREVIEW Allows updating of journals from the
Preview window
SE_GLPRIVATEBATCHES Allows access to private batches

General Ledger Module Options


Module Option Description
SE_GLREADONLYREPORTS Allows access to read-only reports
SE_GLAUTOCREATE Allows automatic creation of accounts
SE_GLOTFMAINACCT Allows on the fly main accounts in General
Ledger
SE_GLOTFSUBACCT Allows on the fly subaccounts in General
Ledger
SE_GLMODIFYNEXTBATCHNO Allows to modify the next batch number
SE_GLVERIFYBATCH Allows to verify batches
SE_GLRENUMBERBATCH Allows to renumber batches
SE_GLMERGEBATCH Allows to merge batches
SE_GLFRXACCESS Enables FRx access

Sales Order Security Events


SecurityEvent Description
SE_SOPRIVATEBATCHES Allows access to private batches
SE_SOALLOWBACKORDERALLITEMS Allows to back order all items
SE_SOUPDATEFROMPREVIEW Allows updating of journals from the
Preview window

Page 190 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix D - Sage MAS 90 Security Events and Module Options


(continued)
1

Sales Order Module Options


Module Option Description
SE_SOMERGEBATCH Allows to merge batches
SE_SORENUMBERBATCH Allows to renumber batches
SE_SOVERIFYBATCH Allows to verify batches
SE_SOMODIFYNEXTBATCHNO Allows to modify the next batch number
SE_SOALLOWINVOICEORDERSONHOLD Allow to invoice orders with a Hold
status
SE_SOALLOWEXCEEDQUANTITYONHAND Allows to exceed quantity on hand
SE_SOALLOWPRICEOVERRIDE Allows price override in Sales Order data
entries
SE_SOALLOWPROFITMARGINOVERRIDE Allows profit margin percentage override
in Sales Order data entries
SE_SOALLOWWARRANTYOVERRIDE Allows warranty override in Sales Order
and RMA data entries
SE_SOALLOWALTERNATEITEMS Allows to use alternate items in shipping
SE_SOALLOWMODIFYCOMMENTS Allows to modify comments on item lines
in shipping
SE_SOALLOWOVERSHIP Allows to overship invoice in shipping
SE_SOALLOWMISCFIELDSMODIFY Allows to modify miscellaneous fields in
shipping
SE_SOALLOWOTFCANCELREASONCODES Allow on the fly cancel codes

Certified Student Course Curriculum - Version 2.0 Page 191


Copyright © 2008 Sage Software, Inc. All rights reserved.
Sage MAS 90 and 200 Object Interface

Appendix E - Running PVXCOM on a Remote


Machine
1

To run PVXCOM on a remote machine such as the MAS 200 Server or other server
do the following:
1. On the server, setup the DCOM Configuration for the ProvideX OLE Server.
• Run Microsoft Component Services - dcomcnfg.exe.
• Select Component Services/Computers/My Computer/DCOM Config.
• Right-click the ProvideX OLE Server object and select properties.
• Setup the properties according to your implementation. This will vary with
different security configurations, etc.
2. On the client, specify the server name in the command when creating the
ProvideX.Script objects. The syntax for this depends on the language you are
programming in.

In ProvideX the syntax for this is as follows:


DEF OBJECT X, "[DCOM]ServerName;ProvideX.Script"

In VBScript the syntax is:


Set X = CreateObject("ProvideX.Script","ServerName")

3. The Init() method will use the path to ..\mas90\home from the DCOM server's
perspective.

Page 192 Certified Student Course Curriculum - Version 2.0


Copyright © 2008 Sage Software, Inc. All rights reserved.

You might also like