CONTENTS

01. OVERVIEW

Execution examples via automatic routine in the Assets Register (ATFA012) routine, showing examples of use and related tables.

02. EXAMPLE

See below some examples of use.

If table SN3 has more than one line, you must fill in the field N3_SEQ.

You can use this execauto to add data to tables SN1 and SN3. You cannot add data to table SN2 through automatic routine.

When you add the data, the program uses the depreciation rates entered in the asset group register, provided the Group Code is entered in the cGroup variable, and the corresponding rate fields are not filled in the items array of the ExecAuto of the Assets Register (ATFA012) routine.

If you want to use any question from the routine's F12 within the automatic routine, you need to fill in the aParam in the fourth parameter of execauto.

Example:

Local aParam := {}

aAdd( aParam, {"MV_PAR01", 2} ) //Display Entry CTB = No
aAdd( aParam, {"MV_PAR02", 1} ) //Repeat Reg. No. = Yes
aAdd( aParam, {"MV_PAR03", 2} ) //Copy Values = All
aAdd( aParam, {"MV_PAR04", 1} ) //Display Details Panel ? = Yes
aAdd( aParam, {"MV_PAR05", 2} ) //Book Online ? = No
aAdd( aParam, {"MV_PAR06", 2} ) //Group Entries ? = No

... //Rest of execauto segment

MSExecAuto({|w,x,y,z| Atfa012(w,x,y,z)},aCab,Nil,4,aParam)


If aParam is not filled in, only what is saved in the profiler of selected user related to this routine is used.


Addition:

#INCLUDE "Protheus.CH"
#include "rwmake.ch"
#include "TOTVS.ch"
#include "TBICONN.ch"

User Function MyAtfa012
    Local aArea := GetArea()
	Local cBase := "ATFX01"//"0000000000"
	Local cItem := "0002"
	Local nQtd := 1
	Local cChapa := "AJEDS10"//"00000"
	Local cPatrim := "N"
	Local cTipo := "01"//"01"

	Local cGrupo := ""
	Local dAquisic //:= dDataBase //:= CTOD("01/06/20")//dDataBase
	Local dIndDepr //:= RetDinDepr(dDataBase)
	Local cDescric := "Test 01"

	Local cHistor := "TEST "
	Local cContab := "11101"
	Local cCusto := "CDL"
	Local cSubCon := "000000001"
	Local cClvlCon := "000000000"

	Local nValor := 1000
	Local nTaxa := 10
	Local nTamBase //:= TamSX3("N3_CBASE")[1]
	Local nTamChapa //:= TamSX3("N3_CBASE")[1]

	Local aParam := {}
	Local aCab := {}
	Local aItens := {}

	Private lMsErroAuto := .F.
	Private lMsHelpAuto := .T.

	PREPARE ENVIRONMENT COMPANY "T1" BRANCH "D MG 01 " MODULE "ATF" TABLES "SN1","SN3"

		dAquisic := dDataBase //:= CTOD("01/06/20")//dDataBase
		dIndDepr := RetDinDepr(dDataBase)

		DBSelectArea(aArea)
		nTamBase := TamSX3("N3_CBASE")[1]
		nTamChapa := TamSX3("N3_CBASE")[1]

		aCab := {}
		AAdd(aCab,{"N1_CBASE" , cBase ,NIL})
		AAdd(aCab,{"N1_ITEM" , cItem ,NIL})
		AAdd(aCab,{"N1_AQUISIC", dDataBase ,NIL})
		AAdd(aCab,{"N1_DESCRIC", cDescric ,NIL})
		AAdd(aCab,{"N1_QUANTD" , nQtd ,NIL})
		AAdd(aCab,{"N1_CHAPA" , cChapa ,NIL})
		AAdd(aCab,{"N1_PATRIM" , cPatrim ,NIL})
		AAdd(aCab,{"N1_GRUPO" , cGrupo ,NIL})
		//Place the fields desired here 

		aItens := {}
		//-- Fill in items


		AAdd(aItens,{;
		{"N3_CBASE" , cBase ,NIL},;
		{"N3_ITEM" , cItem ,NIL},;
		{"N3_TIPO" , cTipo ,NIL},;
		{"N3_BAIXA" , "0" ,NIL},;
		{"N3_HISTOR" , cHistor ,NIL},;
		{"N3_CCONTAB" , cContab ,NIL},;
		{"N3_CUSTBEM" , cCusto ,NIL},;
		{"N3_CDEPREC" , cContab ,NIL},;
		{"N3_CDESP" , cContab ,NIL},;
		{"N3_CCORREC" , cContab ,NIL},;
		{"N3_CCUSTO" , cCusto ,NIL},;
		{"N3_DINDEPR" , dIndDepr ,NIL},;
		{"N3_VORIG1" , nValor ,NIL},;
		{"N3_TXDEPR1" , nTaxa ,NIL},;
		{"N3_VORIG2" , nValor ,NIL},;
		{"N3_TXDEPR2" , nTaxa ,NIL},;
		{"N3_VORIG3" , nValor ,NIL},;
		{"N3_TXDEPR3" , nTaxa ,NIL},;
		{"N3_VORIG4" , nValor ,NIL},;
		{"N3_TXDEPR4" , nTaxa ,NIL},;
		{"N3_VORIG5" , nValor ,NIL},;
		{"N3_SUBCCON" , cSubCon ,NIL},;
		{"N3_CLVLCON" , cClvlCon ,NIL},;
		{"N3_TXDEPR5" , nTaxa ,NIL};
		})
		//Place the fields desired here

		Begin Transaction

			MSExecAuto({|x,y,z| Atfa012(x,y,z)},aCab,aItens,3,aParam)
			If lMsErroAuto 

			MostraErro()
				DisarmTransaction()
			Endif
		End Transaction

		RestArea(aArea)
	RESET ENVIRONMENT

Return

Multiple Additions:

#include "rwmake.ch"
#include "TOTVS.ch"
#include "TBICONN.ch"

User Function MyA012

  Local aArea
  Local cBase, cItem ,cGrupo, cChapa , cDescric:= " "
  Local cTipo := "13"
  Local cPatrim := "N"
  Local dIndDepr 
  Local cHistor := "TESTE EXEC"
  Local cContab := "PLANODECONTA00000000"

  Local cCusto := "CENTR0001"
  Local cSubCon :="000000001"
  Local cClvlCon:="000000000"

  Local nQtd := 1
  Local nValor := 10
  Local nTaxa := 1
  Local nTaxa2:= 1  

  Local nX
  Local aParam := {}
  Local aCab := {}
  Local aItens := {}
  Private lMsErroAuto := .F.
  Private lMsHelpAuto := .T.

  PREPARE ENVIRONMENT COMPANY "T1" BRANCH "D MG 01 " MODULE "ATF" TABLES "SN1","SN3"
        
    /*entry for addition of more Assets 
    ----------------------------------------------*/
    For nX :=1 To 2//How many records will be added

      aArea := GetArea()

      cBase   :=PadR("AG"+cValToChar(nX),TamSX3("A3_COD")[1])
      cItem   :=PadR("AG"+cValToChar(nX),TamSX3("N1_ITEM")[1],"")
      cChapa  :=PadR("AG"+cValToChar(nX),TamSX3("N1_CHAPA")[1])
      cDescric:=PadR("EXECAUT : "+ cValToChar(nX), TamSX3("N1_CHAPA")[1])
      dIndDepr := RetDinDepr(dDataBase)

      aCab := {}
      AAdd(aCab,{"N1_CBASE"   , cBase     ,NIL})
      AAdd(aCab,{"N1_ITEM"    , cItem     ,NIL})
      AAdd(aCab,{"N1_AQUISIC" , dDataBase ,NIL})
      AAdd(aCab,{"N1_DESCRIC" , cDescric  ,NIL})
      AAdd(aCab,{"N1_QUANTD"  , nQtd      ,NIL})
      AAdd(aCab,{"N1_CHAPA"   , cChapa    ,NIL})
      AAdd(aCab,{"N1_PATRIM"  , cPatrim   ,NIL})
      AAdd(aCab,{"N1_GRUPO"   , cGrupo    ,NIL})
      AAdd(aCab,{"N1_MARGEM"   ,"000000"  ,NIL})
      //add desired fields here
      
      aItens := {}
      //-- Fill in item 1
      AAdd(aItens,{;
                  {"N3_CBASE"   , cBase       ,NIL},;
                  {"N3_ITEM"    , cItem       ,NIL},;
                  {"N3_TIPO"    , cTipo       ,NIL},;
                  {"N3_BAIXA"   , "0"         ,NIL},;
                  {"N3_HISTOR"  , cHistor     ,NIL},;
                  {"N3_CCONTAB" , cContab     ,NIL},;
                  {"N3_CUSTBEM" , cCusto      ,NIL},;
                  {"N3_CDEPREC" , cContab     ,NIL},;
                  {"N3_CDESP"   , cContab     ,NIL},;
                  {"N3_CCORREC" , cContab     ,NIL},;
                  {"N3_CCUSTO"  , cCusto      ,NIL},;
                  {"N3_DINDEPR" , dIndDepr    ,NIL},;
                  {"N3_VORIG1"  , nValor      ,NIL},;
                  {"N3_TXDEPR1" , nTaxa       ,NIL},;
                  {"N3_VORIG2"  , nValor      ,NIL},;
                  {"N3_TXDEPR2" , nTaxa       ,NIL},;
                  {"N3_VORIG3"  , nValor      ,NIL},;
                  {"N3_TXDEPR3" , nTaxa       ,NIL},;
                  {"N3_VORIG4"  , nValor      ,NIL},;
                  {"N3_TXDEPR4" , nTaxa       ,NIL},;
                  {"N3_VORIG5"  , nValor      ,NIL},;
                  {"N3_TXDEPR5" , nTaxa       ,NIL},;
                  {"N3_VRDACM1" , nTaxa2      ,NIL},;
                  {"N3_SUBCCON" , cSubCon     ,NIL},;
                  {"N3_SEQ"     , SN3->N3_SEQ ,NIL},;
                  {"N3_CLVLCON" , cClvlCon    ,NIL};
                  })
                  //add desired fields above

      //Transaction control
      Begin Transaction

        conOut('Start of Automatic Routine '+ Team())
        MSExecAuto({|x,y,z| Atfa012(x,y,z)},aCab,aItens,3,aParam)
        conOut('END' +Team())

        If lMsErroAuto 
             MostraErro()
             DisarmTransaction()
        else
          ConfirmSx8()
          conOut('INCLUIDO ATIVO N3_CBASE: '+ cBase + ", N3_ITEM : "+cItem+ ", N3_CUSTBEM : "+cCusto+ ", N3_SUBCCON : "+cSubCon+ ", N3_CLVLCON : "+cClvlCon)
        ENDIF    

        RestArea(aArea)
      End Transaction

      //Changing fields for second execution
      cCusto  :="CENTR0002"
      cSubCon :="000000002"
      cClvlCon:="000000002"
      
    Next nX

  RESET ENVIRONMENT

Return

Editing:

#INCLUDE "Protheus.CH"

User Function AltAtfa012()

	Local aArea := GetArea()
	Local nQtd := 1
	Local dAquisic := dDataBase
	Local dIndDepr := RetDinDepr(dDataBase)
	Local nQtd := 2
	Local nValor := 1000
	Local nTaxa := 10
	Local nTamBase := TamSX3("N3_CBASE")[1]
	Local nTamChapa := TamSX3("N3_CBASE")[1]
	Local cGrupo := "0001"
	Local aParam := {}

	Local aCab := {}
	Local aItens := {}

	Private lMsErroAuto := .F.
	Private lMsHelpAuto := .T.

	 
	SN1->(DbSetOrder(1)) //N1_FILIAL+N1_CBASE+N1_ITEM
	If SN1->(DbSeek(xFilial("SN1")+"0000000000"+"0001"))

		aCab := {}
		AAdd(aCab,{"N1_CBASE" , SN1->N1_CBASE ,NIL})
		AAdd(aCab,{"N1_ITEM" , SN1->N1_ITEM ,NIL})
		AAdd(aCab,{"N1_AQUISIC", SN1->N1_AQUISIC ,NIL})
		AAdd(aCab,{"N1_DESCRIC", "TEST MYAATF012 2" ,NIL})
		AAdd(aCab,{"N1_QUANTD" , SN1->N1_QUANTD ,NIL})
		AAdd(aCab,{"N1_CHAPA" , SN1->N1_CHAPA ,NIL})
		AAdd(aCab,{"N1_PATRIM" , SN1->N1_PATRIM ,NIL})
		AAdd(aCab,{"N1_GRUPO" , SN1->N1_GRUPO ,NIL})

		aItens := {}
		//-- Fill in items
		SN3->(DbSetOrder(1))//N3_FILIAL+N3_CBASE+N3_ITEM+N3_TIPO+N3_BAIXA+N3_SEQ
		If SN3->(DbSeek(xFilial("SN3")+"0000000000"+"0001"+"01"+"0"+"001"))

			AAdd(aItens,{;
			{"N3_CBASE" , SN3->N3_CBASE ,NIL},;
			{"N3_ITEM" , SN3->N3_ITEM ,NIL},;
			{"N3_TIPO" , SN3->N3_TIPO ,NIL},;
			{"N3_BAIXA" , SN3->N3_BAIXA ,NIL},;
			{"N3_HISTOR" , "TESTE MYAATF012 2" ,NIL},;
			{"N3_CCONTAB" , SN3->N3_CCONTAB ,NIL},;
			{"N3_CUSTBEM" , SN3->N3_CUSTBEM ,NIL},;
			{"N3_CDEPREC" , SN3->N3_CDEPREC ,NIL},;
			{"N3_CDESP" , SN3->N3_CDESP ,NIL},;
			{"N3_CCORREC" , SN3->N3_CCORREC ,NIL},;
			{"N3_CCUSTO" , SN3->N3_CCUSTO ,NIL},;
			{"N3_DINDEPR" , SN3->N3_DINDEPR ,NIL},;
			{"N3_VORIG1" , SN3->N3_VORIG1 ,NIL},;
			{"N3_TXDEPR1" , SN3->N3_TXDEPR1 ,NIL},;
			{"N3_VORIG2" , SN3->N3_VORIG2 ,NIL},;
			{"N3_TXDEPR2" , SN3->N3_TXDEPR2 ,NIL},;
			{"N3_VORIG3" , SN3->N3_VORIG3 ,NIL},;
			{"N3_TXDEPR3" , SN3->N3_TXDEPR3 ,NIL},;
			{"N3_VORIG4" , SN3->N3_VORIG4 ,NIL},;
			{"N3_TXDEPR4" , SN3->N3_TXDEPR4 ,NIL},;
			{"N3_VORIG5" , SN3->N3_VORIG5 ,NIL},;
			{"N3_TXDEPR5" , SN3->N3_TXDEPR5 ,NIL}})

		EndIf

		Begin Transaction

			MSExecAuto({|x,y,z| Atfa012(x,y,z)},aCab,aItens,4,aParam)

			If lMsErroAuto
				MostraErro()
				DisarmTransaction()
			Endif

		End Transaction
	EndIf

	RestArea(aArea)
Return

Deletion:

#INCLUDE "Protheus.CH"

User Function Exc012

	Local aArea := GetArea()
	Local nQtd := 1
	Local dAquisic := dDataBase
	Local dIndDepr := RetDinDepr(dDataBase)
	Local nQtd := 2
	Local nValor := 1000
	Local nTaxa := 10
	Local nTamBase := TamSX3("N3_CBASE")[1]
	Local nTamChapa := TamSX3("N3_CBASE")[1]
	Local cGrupo := "0001"
	Local aParam := {}

	Local aCab := {}
	Local aItens := {}

	Private lMsErroAuto := .F.
	Private lMsHelpAuto := .T.

	SN1->(DbSetOrder(1)) //N1_FILIAL+N1_CBASE+N1_ITEM
	If SN1->(DbSeek(xFilial("SN1")+"0000000000"+"0001")) 

        aCab := {}
        AAdd(aCab,{"N1_CBASE" , SN1->N1_CBASE ,NIL})
        AAdd(aCab,{"N1_ITEM" , SN1->N1_ITEM ,NIL})
        AAdd(aCab,{"N1_AQUISIC", SN1->N1_AQUISIC ,NIL})
        AAdd(aCab,{"N1_DESCRIC", "TEST MYAATF012" ,NIL})
        AAdd(aCab,{"N1_QUANTD" , SN1->N1_QUANTD ,NIL})
        AAdd(aCab,{"N1_CHAPA" , SN1->N1_CHAPA ,NIL})
        AAdd(aCab,{"N1_PATRIM" , SN1->N1_PATRIM ,NIL})
        AAdd(aCab,{"N1_GRUPO" , SN1->N1_GRUPO ,NIL})

	EndIf

	Begin Transaction

        MSExecAuto({|x,y,z| Atfa012(x,y,z)},aCab,Nil,5,aParam)

        If lMsErroAuto

            MostraErro()
            DisarmTransaction()

        Endif

	End Transaction

	RestArea(aArea)

Return 


05. TABLES