Usina BRAdvPL Guide
Sign in
← All topics
PRACTICAL GUIDEUnder review

Table sharing across companies and branches

Gets a table branch value according to its sharing mode.

Table sharing across companies and branchesAdvPL
01 · OVERVIEW

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)

03 · PRACTICAL EXAMPLE

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 Nil
Expected result

Length 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.

BEST PRACTICES
  • 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.

Related content

REFERENCES
  1. TOTVS. XFILIAL(). TDN. Accessed on 2026-10-26.
Status
Under review
Page created on
Last reviewed on
Original language
Portuguese
Reviewed by
Usina.BR
0 approved comment(s)

Comments

There are no approved comments yet.

Sign in with Google or Microsoft to comment.

Powered by Usina Docs · Alpha