Segue um exemplo funcional que utilizo e funciona bem:
OpenSxs(,,,,,"SX3TRB","SX3",,.F.)
If Select("SX3TRB") > 0
dbSelectArea('SX3TRB')
SX3TRB->( dbSetOrder( 1 ) ) //ORDENA POR ALIAS
SX3TRB->( dbGoTop( ) )
If SX3TRB->( msSeek( cTabela ) )
While SX3TRB->(!Eof()) .AND. SX3TRB->X3_ARQUIVO==cTabela
if AT("_FILIAL",SX3TRB->X3_CAMPO) > 0
cAliasFil := SX3TRB->X3_CAMPO
cExpressao:= Space(TamSx3(cAliasFil)[1])
Endif
if SX3TRB->X3_TIPO <> "M" .AND. SX3TRB->X3_CONTEXT <> "V"
aadd(aCampos,SX3TRB->X3_CAMPO + "=" + SX3TRB->X3_TITULO)
Endif
SX3TRB->(dbSkip())
End
Endif
SX3TRB->( DbCloseArea() )
Endif
Local aCampos := {"C5_NUM","C5_CLIENTE","C5_LOJACLI","C5_EMISSAO","C5_PBRUTO"}
For i := 1 to Len(aCampos)
OpenSxs(,,,,,"SX3TRB","SX3",,.F.)
If Select("SX3TRB") > 0
dbSelectArea('SX3TRB')
SX3TRB->( dbSetOrder( 2 ) ) //ORDENA POR CAMPOS
SX3TRB->( dbGoTop( ) )
If SX3TRB->( msSeek( aCampos[i] ) )
if SX3TRB->X3_TIPO == "N"
aadd(aAuxDet,{'Right','<NumberFormat ss:Format="0.00"/>'})
Elseif SX3TRB->X3_TIPO == "D"
aadd(aAuxDet,{'Left','<NumberFormat ss:Format="Short Date"/>'})
Else
aadd(aAuxDet,{'Left',''})
ENDIF
Endif
SX3TRB->( DbCloseArea() )
Endif
Next