How to Make a Field Assignment

Top  Previous  Next

The File Conversion Utility creates source code to convert a file to a different specification. The conversion is automatic except in the following cases:

·

If a field's label is changed

·

If a field is split into two separate fields.

·

If two or more fields are combined.

·

If a date is converted to a Clarion standard date from some other file system date format.

In these cases you must modify the source code to handle the field assignments. The portion of the source code you need to examine is the AssignRecord ROUTINE. This is where field assignments are made. Here is an example:

AssignRecord      ROUTINE

 CLEAR(CUS:Record)

 CUS:NUMBER = IN::NUMBER

 CUS:FIRSTNAME = IN::FIRSTNAME

 CUS:LASTNAME = IN::LASTNAME

 CUS:ADDRESS = IN::ADDRESS

 CUS:CITY = IN::CITY

 CUS:STATE = IN::STATE

 CUS:ZIP = IN::ZIP

 CUS:PHONENUMBER = IN::PHONENUMBER

 CUS:ENTRYDATE = IN::ENTRYDATE

If you examine the source code, you'll see that the first line in the routine clears the record buffer. Next each field in the output file is assigned the value from the matching field in the input file.

 

Changing a Field's Label

However, if the field labels do not match, no assignment is made. For example, if you change the LastName field to Surname, the File Conversion utility generates a comment to alert you of an assignment you may need to make:

AssignRecord      ROUTINE

CLEAR(CUS:Record)

CUS:NUMBER = IN::NUMBER

CUS:FIRSTNAME = IN::FIRSTNAME

! CUS:SURNAME = ''

CUS:ADDRESS = IN::ADDRESS

CUS:CITY = IN::CITY

CUS:STATE = IN::STATE

CUS:ZIP = IN::ZIP

CUS:PHONENUMBER = IN::PHONENUMBER

CUS:ENTRYDATE = IN::ENTRYDATE

To assign the values from the original file, edit the line containing the assignment to assign the value of LastName to the SurName field as shown below:

CUS:SURNAME = IN::LASTNAME

 

Splitting a Field into Two Fields

Writing the assignment statements to split the contents of a field into two fields involves a little more work, but string slicing minimizes the effort. For this example, let's assume you had a single field in the original file for a phone number and area code. You now want to store the area code in one field and the phone number in another. Assuming that these fields are numeric data types, you need to temporarily assign the value to a string, then "slice" the string to assign the desired portion to each new field.

In this example the original PhoneNumber field is a ten-digit number, the area code is a three-digit number, and the new PhoneNumber field is a seven-digit number. The AssignRecord ROUTINE in the generated file conversion source code looks like this:

AssignRecord      ROUTINE

CLEAR(CUS:Record)

CUS:NUMBER = IN::NUMBER

CUS:FIRSTNAME = IN::FIRSTNAME

CUS:LASTNAME = IN::LASTNAME

CUS:ADDRESS = IN::ADDRESS

CUS:CITY = IN::CITY

CUS:STATE = IN::STATE

CUS:ZIP = IN::ZIP

! CUS:AREACODE =

CUS:PHONENUMBER = IN::PHONENUMBER

CUS:ENTRYDATE = IN::ENTRYDATE

Notice there is an assignment from the original PhoneNumber field to the new PhoneNumber field. However, since the new field only stores seven digits, you should change this. To handle the field assignments, create an implicit string variable, assign to it the value of the original PhoneNumber field, then use string slicing to assign the desired portions to the new fields, as shown below:

AssignRecord      ROUTINE

CLEAR(CUS:Record)

CUS:NUMBER = IN::NUMBER

CUS:FIRSTNAME = IN::FIRSTNAME

CUS:LASTNAME = IN::LASTNAME

CUS:ADDRESS = IN::ADDRESS

CUS:CITY = IN::CITY

CUS:STATE = IN::STATE

CUS:ZIP = IN::ZIP

TempPhoneNumber" = IN::PHONENUMBER

CUS:AREACODE = TempPhoneNumber"[1:3]

CUS:PHONENUMBER = TempPhoneNumber"[4:10]

CUS:ENTRYDATE = IN::ENTRYDATE

For more information on String Slicing, see Implicit String Arrays and String Slicing .

 

Combining Two or More Fields

In this example the original PhoneNumber field is a seven-digit number, the AreaCode is a three-digit number, and the new PhoneNumber field is a ten-digit number. The AssignRecord ROUTINE in the generated file conversion source code looks like this:

AssignRecord      ROUTINE

CLEAR(CUS:Record)

CUS:NUMBER = IN::NUMBER

CUS:FIRSTNAME = IN::FIRSTNAME

CUS:LASTNAME = IN::LASTNAME

CUS:ADDRESS = IN::ADDRESS

CUS:CITY = IN::CITY

CUS:STATE = IN::STATE

CUS:ZIP = IN::ZIP

CUS:PHONENUMBER = IN::PHONENUMBER

CUS:ENTRYDATE = IN::ENTRYDATE

Notice there is an assignment from the original PhoneNumber field to the new PhoneNumber field, but the original AreaCode is omitted. To handle the field assignments, create two implicit strings and assign them the original AreaCode and PhoneNumber values, then concatenate the strings and assign the result to the new PhoneNumber as shown below:

AssignRecord      ROUTINE

CLEAR(CUS:Record)

CUS:NUMBER = IN::NUMBER

CUS:FIRSTNAME = IN::FIRSTNAME

CUS:LASTNAME = IN::LASTNAME

CUS:ADDRESS = IN::ADDRESS

CUS:CITY = IN::CITY

CUS:STATE = IN::STATE

CUS:ZIP = IN::ZIP

TempAreaCode" = IN::AREACODE

TempPhoneNumber" = IN::PHONENUMBER

CUS:PHONENUMBER = CLIP(TempAreaCode") & TempPhoneNumber"

CUS:ENTRYDATE = IN::ENTRYDATE

For more information on String Slicing, see Implicit String Arrays and String Slicing .

 

Converting a Date

Let's assume the ENTRYDATE field contains a string date in MM/DD/YY format. We want to convert this string date into a Clarion standard date so we can perform calculations against it and display it in various other formats.

We use the DEFORMAT function to perform the conversion as shown below. The @D1 represents the Clarion Date Picture that corresponds to the MM/DD/YY format. See Date Pictures in the Language Reference for more information.

AssignRecord      ROUTINE

CLEAR(CUS:Record)

CUS:NUMBER = IN::NUMBER

CUS:FIRSTNAME = IN::FIRSTNAME

CUS:LASTNAME = IN::LASTNAME

CUS:ADDRESS = IN::ADDRESS

CUS:CITY = IN::CITY

CUS:STATE = IN::STATE

CUS:ZIP = IN::ZIP

! CUS:AREACODE =

CUS:PHONENUMBER = IN::PHONENUMBER

CUS:ENTRYDATE = DEFORMAT(IN::ENTRYDATE,@D1)