Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to Compare Data Files

Former Member
0 Likes
1,536

Hi All,

I've two files[txt] having data's [flat file]. I've to compare these 2 files files 'n' check both the files data's are same or not.

Kindly let me know how to compare, is there any standard function is available.....

Thanks

Tina

1 ACCEPTED SOLUTION
Read only

Former Member
930

Hi,

REPORT  ZTEST  message-id zz  .

data: itab1 type table of vbak,
      itab2 type table of vbak.
data: p_file1 type string,
      p_file2 type string.

      p_file1 = 'C:test.txt'.
      p_file2 = 'C:test1.txt'.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = P_file1
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  TABLES
    DATA_TAB                      = itab1
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = P_file2
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  TABLES
    DATA_TAB                      = itab2
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

if itab1[] <> itab2[].
message i000 with 'They are not same'.
endif.

Regards

vijay

5 REPLIES 5
Read only

Former Member
0 Likes
930

Hi tina,

1. first upload both files data

in two internal tables (say itab, ptab)

of same type.

eg: data :

begin of itab occurs 0,

f(500) type c,

end of itab.

2. then just compare like this.

<b> if itab[] = ptab[]</b>

regards,

amit m.

Read only

Lakshmant1
Active Contributor
0 Likes
930

Hi Tina,

Upload data from both the files into internal tables and then use function module COMPARE_TABLES.

Hope this helps.

Thanks

Lakshman

Read only

0 Likes
930

Read only

Former Member
931

Hi,

REPORT  ZTEST  message-id zz  .

data: itab1 type table of vbak,
      itab2 type table of vbak.
data: p_file1 type string,
      p_file2 type string.

      p_file1 = 'C:test.txt'.
      p_file2 = 'C:test1.txt'.
CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = P_file1
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  TABLES
    DATA_TAB                      = itab1
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


CALL FUNCTION 'GUI_UPLOAD'
  EXPORTING
    FILENAME                      = P_file2
   FILETYPE                      = 'ASC'
   HAS_FIELD_SEPARATOR           = 'X'
  TABLES
    DATA_TAB                      = itab2
 EXCEPTIONS
   FILE_OPEN_ERROR               = 1
   FILE_READ_ERROR               = 2
   NO_BATCH                      = 3
   GUI_REFUSE_FILETRANSFER       = 4
   INVALID_TYPE                  = 5
   NO_AUTHORITY                  = 6
   UNKNOWN_ERROR                 = 7
   BAD_DATA_FORMAT               = 8
   HEADER_NOT_ALLOWED            = 9
   SEPARATOR_NOT_ALLOWED         = 10
   HEADER_TOO_LONG               = 11
   UNKNOWN_DP_ERROR              = 12
   ACCESS_DENIED                 = 13
   DP_OUT_OF_MEMORY              = 14
   DISK_FULL                     = 15
   DP_TIMEOUT                    = 16
   OTHERS                        = 17
          .
IF SY-SUBRC <> 0.
 MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

if itab1[] <> itab2[].
message i000 with 'They are not same'.
endif.

Regards

vijay

Read only

Former Member
0 Likes
930

HI

GOOD

IF YOU WANT TO CHECK THE DATA BETWEEN TWO FILES THAN YOU HAVE COMPARE BETWEEN TWO FILES WHICH WILL RETRUN WHEATHER BOTH THE FILES ARE SAME OR DIFFERENT.

THANKS

MRUTYUN