Kadrin


Hello all,

I am trying to perform a SEEK in 2 different tables, I will first SEEK 1 and if nothing is found search the other but I am having difficulty putting this into an IF statement. Any help is well appreciated.


Thanks
Kadrin



Re: seeking in an IF

Mark OSVATH


select 1

if not seek("to search for")

select 2

if seek("to search for")

else

not found!

endif

endif

is that you need






Re: seeking in an IF

Alex Feldstein

Standard way:

Code Snippet

* open tables and index tags

use table1 tag mytag in 0

use table2 tag mytag in 0

select table1

if not seek(condition)

select table2

if not seek(condition)

* not found in either table

endif

endif

You can have variations by using INDEXSEEK() instead, or the older SEEK command which I wouldn't use here.






Re: seeking in an IF

Kadrin

select table1

if not seek(condition)

select table2

if not seek(condition)

* not found in either table

endif

endif


This is what I had in mind to an extend however, where would the expression go Here is what i have now:

SELECT table1
SEEK lcName
SELECT table2
APPEND FROM table1

SELECT table3
SEEK lcName
SELECT table2
APPEND FROM table3

I need only to SEEK in table3 if the lcName wasn't found in table1.




Re: seeking in an IF

Alex Feldstein

Kadrin wrote:

This is what I had in mind to an extend however, where would the expression go Here is what i have now:

SELECT table1
SEEK lcName
SELECT table2
APPEND FROM table1

SELECT table3
SEEK lcName
SELECT table2
APPEND FROM table3

I need only to SEEK in table3 if the lcName wasn't found in table1.

Your sample has problems:

- You are using SEEK command instead of SEEK function and you are not checking to see if it indeed found lcName

- You are appending all Table1 into Table2, not just the record you seeked. I don't think that is what you want.

Code Snippet

select Table1

if seek(lcName)

* copy found record to memory

scatter memvar

* copy record to table2

select Table2

append from memvar

else

* not found in Table1

select Table3

if seek(lcName)

* copy found record to memory

scatter memvar

* copy record to table3

select Table3

append from memvar

else

*not found in Table2

endif

endif

This should give you an idea.





Re: seeking in an IF

CetinBasoz

Kadrin,

You can also seek() w/o changing workareas and/or current order. ie:

if !seek(condition, "table1", "tagToSearch") and !seek(condition, "table2", "tagToSearch")

* not found in both

endif

It's hard to determine where your code would go because it's unclear what you're trying to do. Please sample. Probably 'append from' is a very wrong choice there (it would append multiple records unless controlled with some scope,for,while).

if !seek(condition, "table1", "tagToSearch") and seek(condition, "table3", "tagToSearch")

* not found in table1, found in table3

endif

Here is a sample that would insert a record's data into table2:

If record is found in table1, get the found record and insert into table2

Else check table3. If found there, get the record from table3 and insert into table2

-Remark: No error checking, assuming key field info would be available or filled by defaults etc.

Code Snippet

luToFind = "ALFKI" && key sampling from testdata!customer

if seek(m.luToFind, "table1", "keyTag")

InsertFromTo("table1", "table2")

else

if seek(m.luToFind, "table3", "keyTag")

InsertFromTo("table3", "table2")

endif

endif

Procedure InsertFromTo(tcFrom, tcTo)

local lnSelect,loRecord

lnSelect = select()

select (m.tcFrom)

scatter name loRecord memo

insert into (m.tcTo) from name loRecord

select (m.lnSelect)

endproc





Re: seeking in an IF

Kadrin

Okay, that is alot more accurate in what I was looking for. But what do I use instead of an Append The memvar doesn't work as intended.




Re: seeking in an IF

Alex Feldstein

Kadrin wrote:
Okay, that is alot more accurate in what I was looking for. But what do I use instead of an Append The memvar doesn't work as intended.

If memvar does not work for you (and why not as long as it's in scope it should have the data as in the examples), you can replace Append with Insert Into as in Cetin's detailed example. Either way should work.





Re: seeking in an IF

CetinBasoz

It's a typo there.Alex meant:

insert into myTable from memvar

instead of 'append from'