国庆前为生产部门弄一个报表,期间涉及到从另一个公司获取仓库的库位数据,再次用到_compnr来跨公司的获取数据,在这里记录一下,为以后查找方便。另外一个涉及到的函数get.compnr(),一般做判断的时候,会用到。
_compnr通常用法如下
tdpur401._compnr = :current.compnr
get.compnr()返回的是一个long的公司号
function long get.compnr ()
以下是关于_compnr来自官方的帮助文档:
The company number used during execution of a BAAN 4GL query is the current company number. The current company number is always inherited from the parent session. The root session (Worktop/Webtop) reads the company number from the default company number ( defined in the session "Maintain User Data" ). This company number can be changed by calling the function compnr.check()
The <table>._compnr field
The <table>._compnr field enables the use of different company numbers. This field specifies the actual company number of the table. When this field is undefined, the current company number is taken as the default. 'Undefined' is denoted by the value -1.
When a record is selected with 'select <table>.*', the field <table>._compnr in the record contains the company number of the table. When inserting a record in a table with a specific company number, you must fill <table>._compnr with the corresponding company number. The function db.insert() takes care of this and writes the record in the correct (physical) table. No special file pointers are necessary (for example, by using db.bind() ).
Example
The record where the field ttadv100._compnr = 000 belongs to the (physical) table ttadv100000 The record where the field ttadv100._compnr = 200 belongs to the (physical) table ttadv100200
Using <table>._compnr in the WHERE clause
You can also use <table>._compnr in the WHERE clause of a Infor ERP LN SQL statement. In this case it is used as a search condition. For example:
SELECT ttadv100.* FROM ttadv100 WHERE ttadv100._compnr = 200 AND ttadv100.cpac = 'tt'
This query lists all records from table ttadv100200 where ttadv100.cpac has the value 'tt'.
You can use <table>._compnr in the following ways:
-
<table>._compnr = <number> or <number> = <table>._compnr where <number> specifies an integer number. The value of <number> is taken as the company number. It must be a 3-digit number.
-
<table>._compnr = <bind variable> or <bind variable> = <table>._compnr where <bind variable> specifies an integer number. When the query is executed the value of <bind variable> is taken as the company number. It must be a 3-digit number.
Combining <table>._compnr conditions
-
A list of AND conditions can contain only one condition that includes <table>._compnr. So, the following construction is possible:
WHERE <table>._compnr = 100 AND <condition>
but the following is not possible:
WHERE <table>._compnr = 100 AND <table>._compnr = 200
It is possible to include multiple <table>._compnr._compnr conditions that specify the company number of different table references. For example, the following construction is possible:
WHERE <table1>._compnr = 100 AND <table2>._compnr = 200
-
In a list of OR conditions, none of the conditions may contain a condition on <table>._compnr.