Usina BRAdvPL Guide
Sign in
← All topics
FUNCTIONUnder review

XFILIAL()

xFilial([cAlias],[cFil]) -> cBranch

Gets the table branch according to its sharing configuration.

XFILIAL()AdvPL
01 · OVERVIEW

Overview

xFilial considers SX2 table sharing. Its value may be the applicable branch or spaces, including company-level sharing; it is not simply cFilAnt. Omitted cAlias uses the current area; omitted cFil uses cFilAnt. Historical examples show different widths: do not hardcode two spaces for current installations. This adaptation of Atilio explicitly queries SB1 without building a lookup or changing company context. (Sources: refs. 1–2.)

02 · SYNTAX

Syntax

xFilial([cAlias],[cFil]) -> cBranch

Parameters

cAlias
CharacterOptional

Table; current area by default.

cFil
CharacterOptional

Reference branch; defaults to cFilAnt.

Return value

Character representation of the table branch.

03 · PRACTICAL EXAMPLE

Commented example

#Include "Protheus.ch"

User Function Ed733()
    // Requires initialized Protheus context and valid SB1 dictionary.
    Local cBranch := xFilial("SB1")
    // The value participates in keys; do not AllTrim it for lookups.
    ConOut(ValType(cBranch))
Return Nil
Expected result

Displays C; content and width depend on configuration. Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

BEST PRACTICES
  • Resolve branch per table, including joins. Correct branch filtering does not replace authorization, deletion filtering or complete keys.
  • Under review: editorial example neither compiled nor run in Protheus. Check includes, release, RDD and context before testing.

Related content

REFERENCES
  1. TOTVS. XFILIAL. Compartilhamento e exemplos por nível. Accessed on 2026-10-28.
  2. Atilio. dan-atilio/AdvPL. Maratona de Exemplos/Exemplo_259_Funcoes_FWxFilial_e_xFilial.prw. Arquivo completo analisado; adaptação editorial. Accessed on 2026-10-28.
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