SVBATCH

Concept Link IconSee also Concept Link IconSpecifics

SVBATCH produces a user configurable record of the start and end of a production batch in a database style format. Along with the start and end times, each batch record contains 1 LONG attribute (that may also be treated as 32 individual bits) and up to 32 string attributes. You can have one or more databases that are loaded into memory for rapid access.

Modes are provided to create, delete and modify and save the batch records. The string attributes may be configured as keys (as in a database system such as Microsoft Access) and used to rapidly search and filter very large numbers of batch records.

Before using SVBATCH, it is essential to read the reference topic Batch Data Structures.

For the network mode, see the topic Network Mode of SVBATCH.

WebVue support - Yes.

Mode

Mnemonic

Syntax

1 CREATEBASE 1
2 SELECTBASE 2
3 BASELIST 3, 9
4 CREATE 4
5 UPDATE 5, 10
6 EXIST 6, 11
7 GETVALUE 7, 12
8 DELETE 3, 13
9 SELECT 8, 16
10 SAVEBASE 2
11 LOADBASE 2
12 GETNEXTBUFFER 3
13 CANCEL 3
14 ARCHIVE 13
15 ARCHIVELIST 3
16 BATCHLIST 3
17 NETWORKBROADCAST 14
18 NEXTCOMMAND 15

SVBATCH execution is not protected at the session level. In addition, only variables of scope 'Shared' are supported.

All syntaxes

Argument

Meaning

Basename

The name of the batch database. Type STR.

Handle

A handle representing a memory location. Type LONG.

Type

A mnemonic for one of the fields forming a batch record.

 

#I1 IdName

 

#I2 StartDate

 

#I3 EndDate

 

[#A1 to #A32] Modification of a text attribute.

 

[#B] Modification of a LONG attribute.

 

[#B1 to #B32] Modification of a binary attribute.

Value

The new value for the selected field:

 

STR for Type = [#I1 to #I3] or [#A1 to #A32]

 

DOUBLE for Type= [#I2 to #I3]

 

LONG for Type = [#B]

 

INTEGER for Type = [#B1 to #B32]

Table

The name of a batch database table. Type STR.

StartDate

The start date and time of a batch record. Type DOUBLE or STR.

EndDate

The end date and time of a batch record. Type DOUBLE or STR.

If the parameters StartDate and EndDate are of type DOUBLE they may be calculated using the instruction DATETIMEVALUE which returns a date and time in the form of a DOUBLE. If the date is supplied as a string it must conform to the following syntax: DD/MM/YYYY hh:mm:ss.lll For example, : 12/05/2001 21:49:01.100.

The instruction DATETIMESTRING may be used to convert a date saved as a DOUBLE to text format.

Syntax 1

IntVal = SVBATCH (Mode, Basename , Unused, [NbAttribute, NbBackup])

Return type: INTEGER.

Argument

Meaning

Unused

This field is unused but must be included as a null string "". Type STR.

NbAttribute

The number of attribute fields. Default 4. Type INTEGER. Range 1 to 32.

NbBackup

The number of backup copies of the database that are created. Default 3. Type INTEGER. Range 3 to 9.

Execution

Mode

Mnemonic

Action

1

CREATEBASE

Create a batch database. The database is created in memory.

Return: 0 the database was not created, 1 it was created.

The batch database is saved in the folder PER of the project when PcVue is shut down.

The Unused argument must be included in the syntax as a null string.
Example: SVBATCH ("CREATEBASE", "MyDatabase", "");

Syntax 2

IntVal = SVBATCH (Mode, Basename);

Return type: INTEGER.

Execution

Mode

Mnemonic

Action

2

SELECTBASE

Select the operational batch database. The database must have been previously created or loaded in memory.

Return:

0 Batch database is not available.
1 Batch database is selected OK.
-100 Error in the arguments.

10

SAVEBASE

Save the batch database. The database is saved in the PER folder in a sub-folder with the same name as that of the database.

Return: 0 Error when saving. 1 Save successful.

11

LOADBASE

Load the batch database from the folder \PER\BaseName into memory.

Return:

0 Error when loading.
1 Load successful.
-100 Error in the arguments.

Syntax 3

IntVal = SVBATCH (Mode, Handle)

Return type: INTEGER.

Execution

Mode

Mnemonic

Action

3

BASELIST

List the names of the loaded batch databases, separated by commas. The list is saved in a memory buffer using the supplied memory location.

Return:

The number of databases.

-100 Error in the arguments.

8

DELETE

Delete a batch record using the supplied memory location.

Return:

0 Deletion failed.
1 Deletion successful.

12

GETNEXTBUFFER

Used after mode SELECT to retrieve the next buffer of information.

The handle used must be the same as that used for the ResultHandle in the SELECT.

If the size of the buffer is not large enough, this mode lets you extend it.

When the final buffer of data is retrieved the internal storage used by mode SELECT is released. You still need to execute a free-buffer command to release the memory allocated to the handle.

Return type INTEGER:

0 Final buffer of data.
1 One or more buffers of data still to retrieve.
-100 Error in the arguments.

13

CANCEL

Cancel a previous SELECT mode, releasing its memory area.

The handle used must be the same as that used for the ResultHandle in the SELECT.

CANCEL may be used before all the data has been retrieved by mode GETNEXTBUFFER.

Return:

0 There is no outstanding SELECT to cancel.
1 Mode SELECT cancelled OK.
-100 Error in the arguments.

15

ARCHIVELIST

Return, in a buffer, a list of start and end dates for archived records.

Return:

0 No records to return.
-100 Error in the arguments.

Else, the number of table names returned.

The mode GETNEXTBUFFER can be used when the buffer Handle cannot contain all the data to be archived.

16

BATCHLIST

Return, in a buffer, a list of tables contained in the selected batch database. The table names are delimited by commas.

Return:

0 No table names to return.
-100 Error in the arguments.

Else, the number of table names returned.

When using BASELIST (mode 3) the format of the returned data is as follows:

Batch record name, number of records \n
Batch record name, number of records \n
(where \n = Chr(10) or line feed)

For GETNEXTBUFFER (mode 12) and CANCEL (mode 13), the buffer Handle must be the same as that used by the SELECT command.

Example of a buffer list

The contents of the buffer Handle could be as follows:

14/10/1997 10:17:55:870 14/10/1998 11:46:09:100\n

14/10/1997 10:17:55:870 14/10/1998 12:40:40:574\n

14/10/1998 10:17:55:870 14/10/1998 11:18:05:870\n

14/10/1998 11:03:11:678 14/10/1998 11:03:21:678\n

14/10/1998 11:15:34:066 14/10/1998 11:15:44:066\n

14/10/1998 11:17:55:870 14/10/1998 11:18:05:870\n

14/10/1998 11:47:36:901 14/10/1998 12:43:19:052\n

14/10/1998 12:43:09:242 14/10/1998 12:43:24:249\n

Syntax 4

IntVal =SVBATCH (Mode, Table, StartDate [, EndDate])

Return type: LONG.

Execution

Mode

Mnemonic

Action

4

CREATE

Create a new record in the currently selected batch database. If the table does not exist, it will be created.

Return: The handle of the batch record in memory, or 0 if creation failed.

 

 

 

The location returned may be used in the modes UPDATE, EXIST, and DELETE.

The start date and time must be unique. Creation with a date and time already used will cause a failure. The end date and time may be changed subsequently using the mode UPDATE.

Syntax 5

IntVal = SVBATCH (Mode, Handle, Type, Value)

Return type: INTEGER

Execution

Mode

Mnemonic

Action

5

UPDATE

Update the batch record changing the value of the specified field.

Return:

0 Update impossible.
1 Update successful.

A batch record may be updated using either the memory location returned by modes CREATE or SELECT, or by using the Table and StartDate parameters which identify uniquely a record. The EndDate is not necessary to identify a record (you can use 0.0 for the EndDate).

Syntax 6

IntVal = SVBATCH (Mode, Handle)

Return type: LONG.

Execution

Mode

Mnemonic

Action

6

EXIST

Test the existence of a batch record using the supplied memory location.

Return: The handle of the batch record, else 0 if it does not exist.

Syntax 7

IntVal = SVBATCH (Mode, Handle, Type)

Execution

Mode

Mnemonic

Action

7

GETVALUE

Retrieve the value of a single field from the selected batch record.

Return: Depends on the field type.

Syntax 8

IntVal = SVBATCH (Mode, Table, StartDate, EndDate, FormatHandle, ResultHandle [, ExpHandle [, LogVarName]]);

Return type: INTEGER.

Argument

Meaning

FormatHandle

The handle of a location in memory containing a string of comma separated mnemonics that specifies the data to be retrieved. The possible mnemonics are :

[#I1 to #I3](Table name, Start date and End date)
[#A1 to #A32] (Text attributes 1 to 32)
[#B] (Long attribute)
[#B1 to #B32] (Binary attributes 1 to 32)

ResultHandle

The handle of a memory location in which the result is placed. Each record is terminated with a carriage return character. Type LONG.

ExpHandle

The handle of a buffer containing a filter expression. See the instruction SVALA for information on filter expressions. Type LONG.

LogVarName

The name of a bit variable that is set to 1 either when the instruction has finished, or the result buffer is full. Type STR

Execution

Mode

Mnemonic

Action

9

SELECT

Selection of records in memory between two dates, optionally using an expression.

Return:

-100 Error in the arguments.
-1 No batch record selected.
-2 Table name unknown.

Else number of records returned.

The operation of mode 9 is asynchronous. That is, once the instruction executed the program thread carries on. When selecting or searching large numbers of records the return of the results may occur after a few seconds.

To manage this, create an event that is triggered when the LogVarName changes to 1.

The event can then run a function that processes the results or runs another SVBATCH instruction with the mode GETNEXTBUFFER.

Syntax 9

IntVal = SVBATCH (Mode, FileName)

Return type: INTEGER.

Argument

Meaning

FileName

The name of a file. Type STR.

Execution

Mode

Mnemonic

Action

3

BASELIST

Create a file containing the names of the batch databases that have been loaded into memory.

Return:

The number of databases.
-100 Error in the arguments.

When using Mode 3 the format of the returned data is as follows.

Batch record name, number of records \n
Batch record name, number of records \n

where \n = Chr(10) or line feed.

Syntax 10

IntVal = SVBATCH (Mode, Table, StartDate, EndDate, Type, Value)

Return type: INTEGER

Execution

Mode

Mnemonic

Action

5

UPDATE

Update a batch record in memory.

Return:

0 Update impossible.
1 Update successful.

A batch record may be updated using either the memory location returned by modes CREATE or SELECT, or by using the Table and StartDate parameters which identify uniquely a record. The EndDate is not necessary to identify a record (you can use 0.0 for the EndDate).

Syntax 11

IntVal = SVBATCH (Mode, Table, StartDate, EndDate)

Return type: LONG.

Execution

Mode

Mnemonic

Action

6

EXIST

Test the existence of a batch record.

Return: The memory location of the batch record, else 0 if it does not exist.

Syntax 12

IntVal = SVBATCH (Mode, Table, StartDate, EndDate, Type)

Execution

Mode

Mnemonic

Action

7

GETVALUE

Retrieve the value of a single field from the selected batch record.

Return: Depends on the field type.

Syntax 13

IntVal = SVBATCH (Mode, Table, StartDate, EndDate)

Return type: Integer.

Execution

Mode

Mnemonic

Action

8

DELETE

Delete a batch record from memory.

Return:

0 Deletion failed.
1 Deletion successful.

14

ARCHIVE

Archive all records from the specified table between the two dates. The records are removed from the database and saved in a file named STARTDATE_ENDDATE. The file is located in the folder Per\"BaseName"\AR\"Table", where BaseName and Table are the names of the selected batch database and table respectively. If the table is not specified (null string) all tables from the selected batch database are archived.

Return:

0 Archiving did not take place.
1 Archiving completed.

else:

-1 No database was selected.
-2 Conversion of
StartDate failed.
-3 Conversion of
EndDate failed.
-100 Parameter error.

Effects of archiving

If the batch identifier is absent, the archiving is applied to all of the data.

Archiving automatically purges the batches archived in the current database.

The archive files are created as follows in the PER folder of the project:

Folder: BatchName

File: StartDate EndDate

Syntax 14

IntVal = SVBATCH (Mode, StationList, StatusHandle, EventVarName)

Argument

Meaning

StationList

The name of a station list as in the Network Station configuration dialog (Configure.Communication.Network Stations). Type STR.

StatusHandle

The handle of a memory location that receives information about the progress of SVBATCH requests. Type LONG.

EventVarName

The name of a bit variable that is set to 1 when either the instruction has finished, or the result buffer is full. Type STR

Execution

Mode

Mnemonic

Action

17

NETWORKBROADCAST

Broadcast SVBATCH commands to all the stations contained in the station list.

Commands are held in a queue and then executed each time a NEXTCOMMAND command is issued. When a command has completed and its results are available, the bit specified by the argument EventVarName is set to 1. The status of each command is reported in the buffer pointed to by StatusHandle in the format Mode, Station Number, Result.

All requests are asynchronous; the result of the request becomes available when the EventVarName changes to 1.

At that point, the results may be processed and a NEXTCOMMAND issued.

NETWORKBROADCAST may be used with these modes:

SELECT, UPDATE, DELETE, CANCEL, ARCHIVE, BATCHLIST, ARCHIVELIST and GETNEXTBUFFER.

Buffer formats

On completion of the request, the format of the Status buffer is as follows:

Mode,StationName,Result

Field

Meaning

Mode

Mode of the SELECT command (e.g. 9 for SELECT).

StationName

Name of the station (as specified in the topic Communications.Multi-station).

Result

Result code returned by the station.

Syntax 15

IntVal = SVBATCH (Mode);

Execution

Mode

Mnemonic

Action

18

NEXTCOMMAND

Execute the next SVBATCH command in the queue when using NETWORKBROADCAST.

Syntax 16

IntVal = SVBATCH (Mode, IdName, StartDate, EndDate, FormatHandle, ResultHandle, [, ExpHandle [, LogVarName]]);

Argument

Meaning

ExpHandle

The handle of a buffer containing a filter expression. See the instruction SVALA for information on filter expressions. Type LONG.

LogVarName

The name of a bit variable that is set to 1 when either the instruction has finished, or the result buffer is full. Type STR.

Execution

Mode

Mnemonic

Action

16

SELECT

Select records between 2 dates.

The selection works whether the entries have been archived or not.

When the requested batch records are retrieved, LogName is set to 1. The buffer ResultHandle contains the records up to the limit of its size.

In this mode, you need to create an event on LogVarName. The request is carried out asynchronously, then LogVarName becomes 1 and ResultHandle identifies the buffer used. For details, see Syntax 8 above.

The event can be created by the Actions menu or dynamically by the verb EVENT.