Goto: 4C Home | 4C Docs | System PCLs List sys.cmp_file()

sys.cmp_file()

Purpose:
sys.cmp_file() compares all fields in the field buffers of two different asfiles.
Usage:
ret = sys.cmp_file(<asfile1>,<fldname1>,<val1>, <asfile2>,<fldname2>,<val2>);
Arguments:

asfile <asfile1> - The asfile name of the first file in the compare.

alpha <fldname1> - An alpha var to return the field name from asfile1 where the compare failed.

alpha <val1> - An alpha var to return the formatted value from asfile1 where the compare failed.

asfile <asfile2> - The asfile name of the second file in the compare.

alpha <fldname2> - An alpha var to return the field name from asfile2 where the compare failed.

alpha <val2> - An alpha var to return the formatted value from asfile2 where the compare failed.
NOTE: The fldname1 and fldname2 variables should be defined large enough to hold a name and a dimension. The val1 and val2 variables should be defined large enough to hold the largest value that you want to see. If these variables are not big enough, they are truncated.

Returns:
0 - All fields compared ok
1 - Compare failed.
The field names and values are stored in fldname1,fldname2,val1, and val2.
-1 - Compare failed because of incompatible data types in compare.
The field names and values are stored in fldname1,fldname2,val1, and val2.
Where Used:
sys.cmp_file() can be called from anywhere.
Example:
The following shows how you can compare all fields in two different asfiles with the same file layout. The two asfiles cm1 and cm2 both use the cust_mstr file definition.

cm1.cm_code = "IBT001";
sys.read_file(cm1,F_LOOKUP);
cm2.cm_code = "IBT002";
sys.read_file(cm2,F_LOOKUP);
while (1) {
    if ((ret=sys.cmp_file(cm1,fldname1,val1,cm2,fldname2,val2))==0)
        break; /* no more different fields */
    if (ret == -1) {
        sys.err_msg("Incompatible rcd types");
        sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
        break;
    }
    sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
    /* make next cmp ok on this fld - may not work as expected
     * due to fldname1 overflowing the display format
     */
    sys.put_fmtfield("cm2",fldname2,val1);
}
The following is another way of doing the same thing, except sys.copy_fields() is used instead of sys.put_fmtfield() This is more accurate since sys.put_fmtfield() will not always make the value of fldname2 equal to the value of fldname1 due to the value not fitting in the display format.

cm1.cm_code = "IBT001";
sys.read_file(cm1,F_LOOKUP);
cm2.cm_code = "IBT002";
sys.read_file(cm2,F_LOOKUP);
while (1) {
    if ((ret=sys.cmp_file(cm1,fldname1,val1,cm2,fldname2,val2))==0)
        break; /* no more different fields */
    if (ret == -1) {
        sys.err_msg("Incompatible rcd types");
        sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
        break;
    }
    sys.err_msg("cmp failed",fldname1,val1,fldname2,val2);
    /* make next cmp ok on this fld */
    fldidx = sys.get_cdef(cm1,fldname1);
    sys.copy_fields(cm1,fldidx,cm2,fldidx,1);
}
Description:
sys.cmp_file() compares each field in two different asfiles until all fields of one file have compared ok or until there is a compare fail. sys.cmp_file() compares even the primary key fields.
Bugs/Features/Comments:
The values returned in val1 and val2 may not reflect the true value of fldname1 and fldname2 because the values may not fit in the display format.
There is no way to tell if one asfile has more fields than the other.
See Also:
sys.cmp_data()


Back to Top