Table sharing across companies and branches
Gets a table branch value according to its sharing mode.
Overview
Do not hard-code branch values in lookups and queries. xFilial follows table-sharing context in SX2; its result need not equal the login branch. Build keys and filters for the actual alias and index. The example only obtains the branch applicable to SA1 and logs its length without exposing records. Changing sharing affects data and uniqueness rules rather than merely replacing a source-code string; plan migration through the supported procedure. (TOTVS, n.d., ref. 1)
Commented example
#Include "Protheus.ch"
User Function Ed307()
Local cBranch := xFilial("SA1")
// Assumes no fixed code and does not alter SX2.
ConOut(cValToChar(Len(cBranch)))
Return NilLength depends on the dictionary; no configuration change or customer lookup. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.
- Review relationships, indexes and duplicate data before sharing. Use the correct alias branch, especially in joins across different sharing modes.
- Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Comments
There are no approved comments yet.
Sign in with Google or Microsoft to comment.