1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

  2. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

Ler arquivo DBF - Fox Pro

Discussão em 'Outros/Diversos' iniciado por berriel, Julho 30, 2012.

  1. berriel

    berriel Membro Participativo

    Preciso muito de ajuda. Alguém sabe como abrir e ler os registros de uma arquivo DBF, de dentro do Progress 10? Preciso ler este arquivo e realizar um processamento, relacionando com o cadastro de funcionários do HCM.
    Peço que caso alguém saiba fazer esta leitura do DBF, coloque um exemplo do código desta leitura.

    Abraços,
    Luiz Berriel
  2. rhemati

    rhemati Membro Participativo

    Luiz, bom dia.

    Segue anexo/abaixo um exemplo.

    Código:
    /* Variaveis para uso do ODBC */
    Def var ObjRecordSet    as com-handle  no-undo. 
    Def var ObjConnection   as com-handle  no-undo. 
    Def var ObjCommand      as com-handle  no-undo. 
    Def var ODBC-DSN        as character   no-undo. 
    Def var ODBC-SERVER     as character   no-undo. 
    Def var ODBC-USERID     as character   no-undo. 
    Def var ODBC-PASSWD     as character   no-undo. 
    Def var ODBC-QUERY      as character   format '300' no-undo. 
    Def var ODBC-STATUS     as character   no-undo. 
    Def var ODBC-RECCOUNT   as integer     no-undo. 
    Def var ODBC-NULL       as character   no-undo. 
    Def var ODBC-CURSOR     as integer     no-undo. 
    def var l-ok        as log initial no.
    
    def temp-table tt-movto
        field it_codigo     as char
        field data_entrada  as date
        field numero        as int.
    
    l-ok = FALSE.
    RUN pi-conecta-odbc (INPUT-OUTPUT l-ok).
    
    IF l-ok <> TRUE THEN DO:
       MESSAGE "NÆo foi poss¡vel fazer a conexÆo com o FoxPro!" SKIP
               "Favor tentar saindo do programa e entrando novamente."
               VIEW-AS ALERT-BOX WARNING TITLE " ATENۂO".
       RETURN NO-APPLY.
    END.
    
    
    PROCEDURE pi-conecta-odbc:
        def var c-data-ini as char.
        def var c-data-fim as char.
    
        DEF INPUT-OUTPUT PARAMETER p-ok  AS LOG.
    
        empty temp-table tt-movto.
       
        /* Create the connection object for the link to SQL */ 
        Create "ADODB.Connection" ObjConnection. 
       
        /* Create a recordset object ready to return the data */ 
        Create "ADODB.RecordSet" ObjRecordSet. 
       
        /* Create a command object for sending the SQL statement */ 
        Create "ADODB.Command" ObjCommand. 
       
        /* Change the below values as necessary */ 
        /* mm/dd/yyyy */
        /* Formato da data deve ser {^AAAA/MM/DD}  */
        assign  c-data-ini  =   Chr(123) + "^2010/01/19" + Chr(125)
                c-data-fim  =   Chr(123) + "^2010/01/19" + Chr(125).
    
        /*MESSAGE c-data-ini 
                c-data-fim 
            VIEW-AS ALERT-BOX INFO BUTTONS OK.*/
            
        Assign  ODBC-DSN    = "\\palet01go\Sistemas\producao\bancos\producao.dbc"        /* The ODBC DSN */ 
                ODBC-SERVER = ""     /* The name of the server hosting the SQL DB and DSN  nomeservidor 10.1.0.95*/ 
                ODBC-USERID = ""   /* The user id for access to the SQL Database */ 
                ODBC-PASSWD = ""  /* Password required by above user-id */ 
                ODBC-QUERY  = " SELECT it_codigo, numero, quant_caixas, data_entrada "
                ODBC-QUERY  = ODBC-QUERY + " FROM movto_palets"
                ODBC-QUERY  = ODBC-QUERY + " Where data_entrada >= " + c-data-ini
                ODBC-QUERY  = ODBC-QUERY + " and data_entrada <= " + c-data-fim.
    
        output to 'c:\magat\spool\odbc-query-fox-pro.txt' convert target 'iso8859-1'.
            put 'ODBC-QUERY:' ODBC-QUERY format 'x(300)'.
        output close.
       
       /* Open up the connecti.on to the ODBC Layer */ 
       ObjConnection:Open ( "provider=vfpoledb;" + "data source=" + ODBC-DSN + ";server=" + ODBC-SERVER, ODBC-USERID, ODBC-PASSWD, 0 ) no-error. 
    
        /* Inicializando o arquivo */
    
       /* Check for connection errors */ 
       If ( error-status:num-messages > 0 ) then DO:
          MESSAGE "Falha na conexÆo!" SKIP
                  "Favor configurar corretamente o Drive ODBC."
                  VIEW-AS ALERT-BOX ERROR TITLE " ERRO".
          
          ODBC-STATUS = "Error: Could not establish connection.". 
       END.
       Else DO: 
          Assign ObjCommand:ActiveConnection  =   ObjConnection
                 ObjCommand:CommandText       =   ODBC-QUERY
                 ObjCommand:CommandType       =   1 /* adCmdText */ 
                 ObjConnection:CursorLocation =   3 /* adUseClient */ 
                 ObjRecordSet:CursorType      =   3 /* adOpenStatic */ 
                 ObjRecordSet                 =   ObjCommand:Execute ( output ODBC-NULL, "", 32 ) 
                 ODBC-RECCOUNT                =   ObjRecordSet:RecordCount. 
          
          /* Have we returned any rows ? */ 
          If ( ODBC-RECCOUNT > 0 ) and not ( ODBC-RECCOUNT = ? ) then Do: 
             ObjRecordSet:MoveFirst no-error. 
          
            Do while ODBC-CURSOR < ODBC-RECCOUNT: 
            /* Display the data from the query (or create a Progress temp-table for future use) */ 
            /* Display ObjRecordSet:Fields ("name"):Value format "x(20)". */ 
        
                /* yyyymmdd */
                CREATE  tt-movto.
                ASSIGN  tt-movto.it_codigo      =   ObjRecordSet:Fields ("it_codigo" ):value
                        tt-movto.data_entrada   =   ObjRecordSet:Fields ("data_entrada" ):value
                        tt-movto.numero         =   ObjRecordSet:Fields ("numero" ):value.
    
                Assign ODBC-CURSOR = ODBC-CURSOR + 1. 
                ObjRecordSet:MoveNext no-error. 
                p-ok = TRUE.
             End. /* retrieved a single data row */ 
          End. /* retrieved all data rows */ 
          ELSE DO: 
             Assign ODBC-STATUS = "No records found.". 
             MESSAGE "Nenhum registro encontrado!"
                     VIEW-AS ALERT-BOX WARNING TITLE "Aten‡Æo ()".
          END.
          
          /* Close the ADO connection */ 
          ObjConnection:Close no-error. 
       
       End. /* The connection opened correctly */ 
    
        output to 'c:\magat\spool\tt-movto-fox.txt' convert target 'iso8859-1'.
        for each tt-movto no-lock:
            disp    tt-movto.it_codigo      
                    tt-movto.data_entrada   
                    tt-movto.numero         skip(1)
                with 1 col width 350.
        end.
        output close.
       
       /* Don't forget to release the memory!! */ 
       Release object ObjConnection no-error. 
       Release object ObjCommand no-error. 
       Release object ObjRecordSet no-error. 
       
       Assign ObjConnection   =   ? 
              ObjCommand      =   ? 
              ObjRecordSet    =   ?. 
    
    END PROCEDURE.
    
    
    Att.,

Compartilhe esta Página