Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with Append from

Status
Not open for further replies.

castgb

Programmer
Jul 16, 2012
6
IT
I still have problems with Clipper code to convert to VFP9.
I will return an error code in the red line,

append from

why?

Gianni


Code:
******************inizio processo di creazione attivit…***********
use giorni
index on giorno to gio
set index to gio
GOTO TOP
DO WHILE .NOT. EOF()
STORE RECNO() TO NREC_GIO
store giorNO to mgiorno
STORE GIORNO TO MGIO


     use dipend
        do while .not. eof()
        store recno() to nrec_dip
        store badge to mbadge
        STORE BADGE TO MBAD
        store nome to mnome
        store alltrim(file)+".dbf" to mfile

        use prd1 EXCLUSIVE 
        zap
        [COLOR=red]append from prd.dbf for giorno=mgiorno .and. badge=mbadge[/color]
        use
        
        USE prd1
        SORT ON DA TO PRD2
        use

       use PRD2
        goto top
        store recno() to nrec_tmp
        store e_u to me_u
        do while .not. eof()
        store recno() to nrec_tmp
        store e_u to me_u

       if me_u="E"
        
             
        if NREC_TMP<RECCOUNT()
        SKIP
        STORE E_U TO mE_U
        store da to mda
        store numero to mnumero
        
        GOTO NREC_TMP
        IF ME_U="U" 
        REPLACE E_U WITH "U"
        ENDIF
        replace a with mda
        replace numero with mnumero
        
        endif
       endif

      if me_u=" "
        GOTO NREC_TMP  
                  

        if NREC_TMP<RECCOUNT()
        SKIP
        STORE E_U TO mE_U
        store da to mda
        store numero to mnumero

        GOTO NREC_TMP
        IF ME_U="U" 
        REPLACE E_U WITH "U"
        ENDIF

        replace a with mda
        replace numero with mnumero
        ENDIF
      endif

      skip
      enddo
        DELETE ALL FOR E_U="U" .AND. EMPTY(A)
        DELETE ALL FOR EMPTY(E_U) .AND. EMPTY(A)
        PACK
        close all
        **** PRD2
       ***********************trasporto ore e lavorazioni negli archivi
       ***********************dei dipendenti
       use prd2
       do while .not. eof()
        store recno() to nrec_prod
        STORE DA TO MDA
        STORE A TO MA
        store val(numero) to mnumero
        store ore to more
        store e_u to me_u
       use elelav
       locate for numero=mnumero
       if found()
          store identific to mident
       ELSE
          MIDENT=" "
       endif
       use (mfile)
       locate for day(data)=day(mgio) .and. month(data)=month(mgio)
       *if .not. found()
       append blank
       replace data with mgio
       REPLACE DA WITH MDA
       REPLACE A WITH MA
       replace n_lav with mnumero
       replace descr with mident
       if empty(mda) .or. empty(ma)
       replace n_ore with 0
       else
       min11=(VAL(SUBSTR(mda,1,2))*60)+(VAL(SUBSTR(mda,4,2)))  
       min22=(VAL(SUBSTR(ma,1,2))*60)+(VAL(SUBSTR(ma,4,2)))  
       
       REPLACE N_ORE WITH (min22/60)-(min11/60)

       replace e_u with me_u
       endif
       *endif
       use
       use prd2
       GOto nrec_prod
       SKIP
       ENDDO
       USE PRD2
       ZAP
       USE
       

     use dipend
     goto nrec_dip
     skip
     enddo


use giorni index gio
goto nrec_gio
skip
enddo
********************fine ciclo giorni

 
Sorry Mike, forgot
returns: "giorno" variable not found ...
bat "giorno" not is variable..is field of table
as if he saw the PRD table from which data should be taken ..
maybe I have to open it first?

thanks Gianni
 
Gianni,

If Giorno is a field in Giorni, then you are right. Giorni is not open at the time that you do the Append.

The problem is that you are opening several tables, but they are all in the same work area. Each time you open a table in a given work area, it will close whatever other table was already open in that area. That's why you are getting the error.

The preferred way of doing it is like this:

Code:
USE SomeTable IN 0
SELECT SomeTable

That way, each table is in a separate work area.

Actually, your problem goes deeper than that. You appear to be constantly opening and closing tables inside your nested loops. That won't cause the error you are seeing, but it is not good practice. In general, you open a table once, and leave it open until you don't need it any more.

I suspect that this a relic of the time when we were only allowed ten open tables (or two, in the case of dBASE II).

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy
 
There's another problem here, and it's one where Clipper behaves differently than Foxpro.

The FOR clause of APPEND FROM is scoped to the currently selected table, NOT from the "from" table. From the help file:

FOR lExpression
Appends a new record for each record in the currently selected table for which lExpression evaluates to True (.T.).

A far better (and more Fox-like) way to do this would be:

Code:
Insert Into prd1 ;
  Select * from prd ;
  Where prd.giorno=mgiorno .and. prd.badge=mbadge

(This would accidentally mitigate the file opening problem, but take Mike's advice on that anyway.)
 
Thanks to all
I understand I have to use SQL ..
I am converting a huge program written with Clipper Summer 87 but I have to rewrite so I correct the errors a little at a time.
But not being an expert in FoxPro often happens to me does not understand the logic.

I used:

Code:
Insert Into prd1 ;
  Select * from prd ;
  Where prd.giorno=mgiorno .and. prd.badge=mbadge

and works

thanks Gianni
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top