Welcome! Log In Create A New Profile

Advanced

Putting 2 files together (same layout).

Posted by AadG 
Putting 2 files together (same layout).
September 24, 2024 08:28AM
Hi all,

I'd like to put the records from one file to another, so make 1 file from 2 files with the same layout.
Does anyone know if there is a special approach to this? Also indexation will be done automatically
to the appending file or to the new file?

Thanks for any tips.

Best regards,

Aad
Re: Putting 2 files together (same layout).
September 24, 2024 01:17PM
In SQL you can combine both with UNION in a single result.

To physically combine in SQL:
INSERT INTO FILE2 (field2, field3, ...) SELECT field2, field3, ... FROM FILE1

Assuming that field1 is your unique auto assigned ID or UUID field by the database.

Cheers

Peter
Re: Putting 2 files together (same layout).
September 24, 2024 01:23PM
Hi Peter,

Thank you for you reply, I'm not into SQL, so I need a coding solution spinning smiley sticking its tongue out
I know there is a SQL tool somewhere in Windev. Can I use this somehow?

Best regards,

Aad
Re: Putting 2 files together (same layout).
September 24, 2024 03:11PM
Hi Aad

Well, SQL is the de facto standrad for any relational database out there so knowing some basics always helps ;-) ...
In WD you can simply execute a SQL query: hExecuteSQLQuery().
And there is also a query editor.. Maybe you can click your SQL together via the GUI query editor.

In code you can do something like (which is a lot more lines than SQL):
for each FILE1
hCopyRecord(FILE2,FILE1,hdefaultVal)
end

That should do the trick

P.
opss
Re: Putting 2 files together (same layout).
September 25, 2024 02:26PM
Hello Aad
One cannot imagine any serious application without the use of the SQL language. It's like having a Mercedes and keeping it in the garage?!

Try this way:

FOR EACH File1
File1.field = File2.field
Hadd(File2)
END
Argus
Re: Putting 2 files together (same layout).
September 25, 2024 09:29PM
If I understaood correctly the question, you may want to look at hcopyrecord
Re: Putting 2 files together (same layout).
September 26, 2024 08:15AM
Hi guys,

Thanks for all your input. I will look into all the offered solutions.

Best regards,

Aad
Re: Putting 2 files together (same layout).
October 01, 2024 08:35PM
Hi yes with w language this is very easy.


FOR EACH File1
File3.field = File1.field
Hadd(File3)
END

FOR EACH File2
File3.field = File2.field
Hadd(File3)
END

So go line by line through each file and save the record in FILE3 the new file that has all the records is FILE 3.

you might want to take a look at [www.w3schools.com]

SQl is very easy to lurn. But this link lets you quickly find what you are looking for . Use it myself often .


good luck
Re: Putting 2 files together (same layout).
October 02, 2024 12:05PM
Thanks Allard.
Re: Putting 2 files together (same layout).
October 19, 2024 05:37PM
I managed to make a procedure that does what I want with hCopyrecord(), but................
The two files have the same ID's in use, so I can't hAdd a record to the second file without a hDuplicate error.

I have tried several parameters that are given in the Helpfile, but no luck.
Does anybody knows a workaround?

Regards,

Aad
Re: Putting 2 files together (same layout).
October 20, 2024 12:26PM
Hi

The hForceAutoID option is your friend...
PS: you don't have to assign each field individually.
You can simply do File2=File1 which will incur a homonomic assignment on fields with the same names.

Peter H.
Re: Putting 2 files together (same layout).
October 20, 2024 12:39PM
Hi Peter,

Thanks for your tip. I will try that.
With hCopyrecord each record is copied with all the fields.
That is what I need.

Like I said, the key is in the way, I will read the Helpfile about
hForceAutoID.

Regards,

Aad
Re: Putting 2 files together (same layout).
October 20, 2024 01:24PM
Hi Peter,

I can't get it to work. Both files have the same AutoID's, so if I add a record form FileA to FileB, the AutoID's are clashing. The 2 files have the same name. I use hAlias to overcome the same name issue.

Grtz,

Aad
Re: Putting 2 files together (same layout).
October 21, 2024 09:02AM
Look here

[help.windev.com]

[infosonline.net]



Edited 1 time(s). Last edit at 10/21/2024 09:12AM by infos.
Re: Putting 2 files together (same layout).
October 21, 2024 09:19AM
Hi Infos,

I followed the advice Argus gave me above, because I used this before. See the screenshot of the fields used. The filename is TSUsers.fic. So records from a TSUsers file from one directory need to be added to a TSUsers file in another directory (map)

Thanks for your trouble.

Best regards,

Aad



Edited 1 time(s). Last edit at 10/21/2024 09:20AM by AadG.
Attachments:
open | download - TSUsers fields.png (70.2 KB)
Re: Putting 2 files together (same layout).
October 21, 2024 10:57AM
I'm trying to get into your problem
1. Do you use HFSQL C/S or Classic files?
2. Can you use the HChangeDir option (see example [help.windev.com])

I don't know what the logic of your application is

[infosonline.net]
Re: Putting 2 files together (same layout).
October 21, 2024 12:41PM
I use C/S. hChangedir doesn't solve the problem. The keyfield is the problem. Both files have the same keys in use,
so if do a hAdd in the second file in the other map, the key alreay exists and cannot be overwritten. (Duplicate error)
Re: Putting 2 files together (same layout).
October 21, 2024 01:04PM
You can only use one file why copy it to another folder?
Place it in a separate folder and the program calls it with the hChangeDir() option


HChangeDir(HSUser, ".\USER")

[infosonline.net]



Edited 3 time(s). Last edit at 10/21/2024 01:28PM by infos.
Re: Putting 2 files together (same layout).
October 21, 2024 06:05PM
Hi,
you can do it with a third file, same layout, call it C, must start with a empty file

next step: you read your first file A wiht copyrecord to C

next step : you read your second file B wiht copyrecord to C

if files have the same name, you have to put in sep. directores and use hchangedir between


hth, Heinz
Re: Putting 2 files together (same layout).
October 24, 2024 10:38AM
Hi Heinz,

I tried to avoid your solution, but I think this the only way (for me). It worked by the way.
There a few others that already suggested this method.

Thanks to you all for your input.

Aad
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: