1. Home
  2. Brazil Localization

Historical description: a Portuguese text on every accounting line

Brazilian books need a clear description for every line item. SAP leaves many of them empty. Here is SAP’s standard fix, step by step, with the code corrected for Portuguese.

The requirement

What a historical description is

The historical description (histórico) is a clear explanation of each line posted in the Brazilian accounting books, shown in the accounting statements. Brazilian bookkeeping rules require it, and the books must be in Portuguese.

The issue

Many postings in SAP are automatic and leave the line-item text (BSEG-SGTXT) empty, and key users can post manual entries without one. The books then don’t meet the Brazilian requirement.

SAP’s fix

SAP Note 108559: a substitution fills every empty line-item text of Brazilian company codes with an automatic description.

Before and after

LineAccountText beforeText after the substitution
001Supplier · search term ACMEINDemptyFatura de fornecedor ACMEIND como ref.
002G/L · Matéria-primaemptyFatura de fornecedor Matéria-prima como ref.
003G/L · ICMS a recuperaremptyFatura de fornecedor ICMS a recuperar como ref.
004G/L · FreteFrete NF 12345Frete NF 12345 (kept: it wasn’t empty)

The text is built from the document type description, the partner’s search term or the G/L account name, and a fixed ending (“como ref.”, “as reference”). Illustrative example.

Step by step

Six steps, two people

ABAP developer · steps 1, 2, 3, 6 FI consultant · steps 4, 5

  1. 1

    Create the function module SE37 ABAP

    Name it Z_1B_HISTORICAL_DESCRIPTION. The version below already reads texts in Portuguese and leaves out tables the original example declared but never used.

    FUNCTION z_1b_historical_description.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *"  IMPORTING
    *"     VALUE(LINE_BSEG) TYPE  BSEG
    *"     VALUE(LINE_BKPF) TYPE  BKPF
    *"  EXPORTING
    *"     VALUE(E_SGTXT) TYPE  CHAR50
    *"----------------------------------------------------------------------
      TABLES: kna1, lfa1, skat, t001, t003t.
    
      DATA: hlp_text(100)    TYPE c,
            account_name(20) TYPE c.
    
    * Brazilian books are kept in Portuguese: read texts in language 'P'
    * (SAP's one-character key for Portuguese), not in the user's logon language
      CONSTANTS c_langu TYPE spras VALUE 'P'.
    
      e_sgtxt = line_bseg-sgtxt.
    
    * Keep any text the user or the posting already filled in
      CHECK line_bseg-sgtxt = space.
    
      CLEAR e_sgtxt.
    
    * Document type description
      SELECT SINGLE * FROM t003t WHERE spras = c_langu
                                   AND blart = line_bkpf-blart.
      e_sgtxt(20) = t003t-ltext.
    
      CASE line_bseg-koart.
        WHEN 'D'.                                   " customer
          SELECT SINGLE * FROM kna1 WHERE kunnr = line_bseg-kunnr.
          account_name = kna1-sortl.
        WHEN 'K'.                                   " supplier
          SELECT SINGLE * FROM lfa1 WHERE lifnr = line_bseg-lifnr.
          account_name = lfa1-sortl.
        WHEN OTHERS.                                " G/L account
          SELECT SINGLE * FROM t001 WHERE bukrs = line_bseg-bukrs.
          SELECT SINGLE * FROM skat WHERE spras = c_langu
                                      AND ktopl = t001-ktopl
                                      AND saknr = line_bseg-hkont.
          account_name = skat-txt20.
      ENDCASE.
    
      hlp_text = e_sgtxt.
      CONCATENATE hlp_text account_name INTO e_sgtxt SEPARATED BY space.
    
    * TEXT-001 = 'como ref.' (free text, keep it under 10 characters)
      hlp_text = e_sgtxt.
      CONCATENATE hlp_text TEXT-001 INTO e_sgtxt SEPARATED BY space.
    
    ENDFUNCTION.
    ParameterKindTypingAssociated type
    LINE_BSEGImportTYPEBSEG
    LINE_BKPFImportTYPEBKPF
    E_SGTXTExportTYPECHAR50

    Older releases use reference fields instead: LINE_BSEG LIKE BSEG, LINE_BKPF LIKE BKPF, E_SGTXT type C.

  2. 2

    Create the text element ABAP

    In the function group, text symbol TEXT-001 = como ref. (Portuguese for “as reference”).

  3. 3

    Add the user exit GCX2 ABAP

    For application area GBLS, copy SAP’s exit program RGGBS000 to your own (for example ZGGBS000), assign it in GCX2 and add an exit named HISTO:

    FORM get_exit_titles TABLES etab.
      ...
    * >>> begin insert
      exits-name  = 'HISTO'.
      exits-param = c_exit_param_none.
      exits-title = TEXT-103.                " Historical description
      APPEND exits.
    * <<< end insert
      ...
    ENDFORM.
    
    * >>> begin insert
    FORM histo.
      CALL FUNCTION 'Z_1B_HISTORICAL_DESCRIPTION'
        EXPORTING
          line_bseg = bseg
          line_bkpf = bkpf
        IMPORTING
          e_sgtxt   = bseg-sgtxt
        EXCEPTIONS
          OTHERS    = 1.
    ENDFORM.
    * <<< end insert
  4. 4

    Create the substitution GGB1 FI

    Open Financial Accounting › Line Item, create a substitution (for example HISTO), add a step for the field BSEG-SGTXT, choose Exit and enter the exit HISTO under “is substituted by”.

  5. 5

    Activate it OBBH FI

    For each Brazilian company code: callup point 2 (line item), substitution HISTO, activation level 1.

  6. 6

    Improve the logic (optional) ABAP

    If the business wants richer texts (the nota fiscal number, the PO, the asset), the FI consultant writes a functional spec and the developer extends the function.

Watch out

Why the language key matters

The trap

The original example reads texts with sy-langu, the user’s logon language. When key users abroad post centrally for a Brazilian company code, the descriptions come out in English or German, and Portuguese is the only language the Brazilian authorities accept.

The fix

Read the document type and G/L account texts in 'P', as in the code above. SPRAS holds SAP’s one-character language key: 'P' is Portuguese. 'PT' is the two-letter ISO code and would never match.

Also

Make sure every document type and G/L account has a Portuguese text, or the description comes out half empty. Transactions, paths and screens can differ by SAP release; test in a sandbox before transporting.