PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example 1: Merging files that have a partial common structure
  • Example 2: Copying a record while keeping the value of its automatic identifier
  • Example 3: Copying a record while keeping the value of its automatic identifier
  • Example 4: Copying a record by using items with different names
HCopyRecord (Example)
Example 1: Merging files that have a partial common structure
WEBDEV - Server codeAjaxHFSQLHFSQL Client/ServerHyper File 5.5 The following example is used to merge the files named CUSTOMER and CUSTOMER2. The characteristics of these data files are as follows:
  • the LASTNAME and FIRSTNAME items are character strings in both data files
  • the customer code CUSTCODE is an integer in CUSTOMER.FIC
  • the customer code CUSTCODE is a string in CUSTOMER2.FIC
  • the ADDRESS item exists in CUSTOMER2 only
Once this code has been run, the CUSTCODE integer of CUSTOMER.FIC file was converted into a string in the CUSTOMER2.FIC file according to the conversion rules of WLanguage. ADDRESS was initialized to its default value in all the records copied into CUSTOMER2.
// Show the number of records in CUSTOMER2.FIC
Trace(HNbRec(CUSTOMER2))

HReadFirst(CUSTOMER, NAME)
// Browse the records of CUSTOMER.FIC
WHILE NOT HOut(CUSTOMER)
// Add the record to CUSTOMER2
HCopyRecord(CUSTOMER2, CUSTOMER, hDefaultVal)
HAdd(CUSTOMER2)
 // Show the new number of records
Trace(HNbRec(CUSTOMER2))
// Go to next record
HReadNext(CUSTOMER, NAME)
END
Example 2: Copying a record while keeping the value of its automatic identifier
WEBDEV - Server codeAjaxHFSQLHFSQL Client/ServerHyper File 5.5 The following code is used to copy a record from CUSTOMER to CUSTOMER2. These two files contain three common items:
  • LASTNAME, FIRSTNAME are character strings in both data files,
  • the customer code CUSTCODE is the automatic identifier in both data files.
The record for the customer named Smith must be copied from the CUSTOMER file to the CUSTOMER2 file. Using HModify allows you to keep the automatic identifier (HAdd would have generated a new identifier automatically, and therefore it is not used in this example).
HReadSeekFirst(CUSTOMER, "Smith")
HCopyRecord(CUSTOMER2, CUSTOMER, hCopyAutoId + hDefaultVal)
HModify(CUSTOMER2) // HModify keeps the automatic identifier
Example 3: Copying a record while keeping the value of its automatic identifier
WEBDEV - Server codeAjaxHFSQLHFSQL Client/ServerHyper File 5.5 The following code is used to copy all the records from CUSTOMER to CUSTOMERBIS.
The automatic identifier is copied and its value is kept during the addition (hSetIdAuto parameter in HAdd).
// Transfer the records from 'CUSTOMER' to 'CUSTOMERBIS'
EXTERN CUSTOMERBIS
HAlias(CUSTOMER, "CUSTOMERBIS")
HCreationIfNotFound("CUSTOMERBIS")
HReadFirst(CUSTOMER, CUUNIKKEY)
WHILE NOT HOut(CUSTOMER)
HCopyRecord(CUSTOMERBIS, CUSTOMER, hCopyAutoId)
HAdd(CUSTOMERBIS, hSetIdAuto)
HReadNext(CUSTOMER, CUUNIKKEY)
END
Example 4: Copying a record by using items with different names
WEBDEV - Server codeAjaxHFSQLHFSQL Client/ServerHyper File 5.5 The following code is used to copy a record from CUSTOMER to CUSTOMER2. The characteristics of these data files are as follows:
  • LASTNAME, FIRSTNAME are character strings in both data files,
  • IDAUTO is the automatic identifier in both data files,
  • the customer code CUSTCODE is an integer and it exists in CUSTOMER only,
  • the ADDRESS item exists in CUSTOMER2 only,
  • the CUSTOMERIDENTIFIER item is a string and it exists in CUSTOMER2 only.
This example is used to:
  • copy the CUSTOMER file into the CUSTOMER2 file by copying the customer code CUSTCODE into CUSTOMERIDENTIFIER.
  • store the value of the automatic identifier AUTOID.
  • initialize the address ADDRESS with its default value.
HCreation(CUSTOMER2)
HReadFirst(CUSTOMER, NAME)
// Browse the records of CUSTOMER.FIC
WHILE not HOut(CUSTOMER)
// Add the record to CUSTOMER2
  HCopyRecord(CUSTOMER2, CUSTOMER, ...
"LASTNAME, FIRSTNAME, AUTOID, CUSTCODE", ...
"LASTNAME, FIRSTNAME, AUTOID, CUSTOMERIDENTIFIER", ...
hDefaultVal + hCopyAutoId)
HModify(CUSTOMER2)
// Go to next record
HReadNext(CUSTOMER, NAME)
END
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment