Application Development 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: 

comparison of 2 internal tables and pass the values in new internal tables?

Former Member
0 Kudos

hi all

one problem am facing in abap

please any one solve this...

am having 2 files in desktop i upload that files by using gui_upload,

that 2 flies having data that 2 flies data i can transfer to 2 internal tables,

ex: file1 having

customer sortl

110  yb03

139  yb04

150  yb03

2nd file having

customer sortl

110  yb03

149  yb05

160  yb04

same values i don't want in 3 and 4 internal table

pls any one help me these is my coding where was the mistake i don't no...

DATA : BEGIN OF str1,

       customer TYPE kna1-kunnr,

       search   TYPE kna1-sortl,

*       loevm    TYPE kna1-loevm,

END OF str1.

DATA : BEGIN OF str2,

       customer TYPE kna1-kunnr,

       search   TYPE kna1-sortl,

*       loevm    TYPE kna1-loevm,

END OF str2.

DATA: it_upload LIKE TABLE OF str1,

      it_upload1 LIKE TABLE OF str2,

      it_1 LIKE TABLE OF str1,

      it_2 LIKE TABLE OF str2,

      wa_1         LIKE str1,

      wa_2         LIKE str2.

CALL FUNCTION 'GUI_UPLOAD'

  EXPORTING

    filename                      = 'C:\Users\RR\Desktop\headr.txt'

    HAS_FIELD_SEPARATOR           = 'X'

  TABLES

    data_tab                      = it_upload.

CALL FUNCTION 'GUI_UPLOAD'

  EXPORTING

    filename                      = 'C:\Users\RR\Desktop\headr1.txt'

    HAS_FIELD_SEPARATOR           = 'X'

  TABLES

    data_tab                      = it_upload1

 

loop at it_upload INTO wa_1.

read table it_upload1 INTO wa_2 with key search = wa_1-search.

APPEND wa_1 to it_1.

endloop.

loop at it_upload1 INTO wa_2.

read table it_upload1 INTO wa_1 with key search = wa_2-search.

APPEND wa_2 to it_2.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

  EXPORTING

    filename                = 'C:\Users\RR\Desktop\DOWNLOAD.txt' "filepath

    filetype                = 'DAT'

    write_field_separator   = 'X'

  TABLES

    data_tab                = it_1

 

CALL FUNCTION 'GUI_DOWNLOAD'

  EXPORTING

    filename                = 'C:\Users\RR\Desktop\DOWNLOAD1.txt' "filepath

    filetype                = 'DAT'

    write_field_separator   = 'X'

  TABLES

    data_tab                = it_2

1 ACCEPTED SOLUTION

Former Member
0 Kudos

these is actuval correct codeing...

thank u to all..

DATA : BEGIN OF str1,

        customer TYPE kna1-kunnr,

        search   TYPE kna1-sortl,

END OF str1.

DATA : BEGIN OF str2,

        customer TYPE kna1-kunnr,

        search   TYPE kna1-sortl,

END OF str2.

DATA: it_upload LIKE TABLE OF str1,

       it_upload1 LIKE TABLE OF str2,

       it_1 LIKE TABLE OF str1,

       it_2 LIKE TABLE OF str2,

       wa_1         LIKE str1,

       wa_2         LIKE str2.

CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     filename                      = 'C:\Users\Roopa\Desktop\headr.txt'

     HAS_FIELD_SEPARATOR           = 'X'

   TABLES

     data_tab                      = it_upload

CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     filename                      = 'C:\Users\Roopa\Desktop\headr1.txt'

   TABLES

     data_tab                      = it_upload1

loop at it_upload INTO wa_1.

read table it_upload1 INTO wa_2 with key search = wa_1-search.

if sy-subrc ne 0.

APPEND wa_1 to it_1.

endif.

endloop.

loop at it_upload1 INTO wa_2.

read table it_upload INTO wa_1 with key search = wa_2-search.

if sy-subrc ne 0.

APPEND wa_2 to it_2.

endif.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

   EXPORTING

     filename                = 'C:\Users\Roopa\Desktop\DOWNLOAD.txt' "filepath

     filetype                = 'DAT'

     write_field_separator   = 'X'

   TABLES

     data_tab                = it_1

CALL FUNCTION 'GUI_DOWNLOAD'

   EXPORTING

     filename                = 'C:\Users\Roopa\Desktop\DOWNLOAD1.txt' "filepath

     filetype                = 'DAT'

     write_field_separator   = 'X'

   TABLES

     data_tab                = it_2

  

input is :

file 1

customersortl
110  yb06
139  yb04
150  yb07

file2

customersortl
110  yb03
149  yb05
160  yb04
179  yb08
170  yb09

out put is

table 3

110  yb06
150  yb07

table4

110  yb03
149  yb05
179  yb08
170  yb09

thanks & regards,

roopa.

7 REPLIES 7

former_member249399
Active Participant
0 Kudos

loop at it_upload INTO wa_1.

read table it_upload1 INTO wa_2 with key search = wa_1-search.

if sy-subrc ne 0.

APPEND wa_1 to it_1.

endif.

endloop.

loop at it_upload1 INTO wa_2.

read table it_upload INTO wa_1 with key search = wa_2-search.

if sy-subrc ne 0.

APPEND wa_2 to it_2.

endloop.

endif.

0 Kudos

hi

ranjana,

i tried these also 3rd table is having no data

4 th table is shown correctly..

now am passing  1st file value is

customersortl
110  yb03
139  yb04
150  yb03

129            yb06

159            yb07

2nd file

customersortl
110  yb03
149  yb05
160  yb04
179  yb08
170  yb09

3rd internal table having only

129
159

4th table showing corectly

149  yb05
179  yb08
170  yb09

thanks& regards,

roopa

0 Kudos

Hi Roopa,

Answer is correct if you are comparing only search term.

customersortl
110  yb03
149  yb05
160  yb04
179  yb08
170  yb09

because yb03 and yb04 are already in second internal table, Let me know what is esact requirement whether you want to check both field or only search field?

Former Member
0 Kudos

HI roopa,

at the below logic, append to it_1 instead of It_2.

loop at it_upload1 INTO wa_2.

read table it_upload1 INTO wa_1 with key search = wa_2-search.

***APPEND wa_2 to it_2.

APPEND wa_2 to it_1.

endloop.

it may help you..

Best regards,

Krishna

0 Kudos

hi krishna

we can write append

loop at it_upload1 INTO wa_2.

read table it_upload1 INTO wa_1 with key search = wa_2-search.

***APPEND wa_2 to it_2.

APPEND wa_2 to it_1.

endloop.

like these

every value will pass to the 3rd table, same values we don't want different values e want.

tnaks

roopa.


Former Member
0 Kudos

use debug to see if field search null and all data in customer field if you see that  replace with key search = wa_1-search with with key customer  = wa_1-customer

Former Member
0 Kudos

these is actuval correct codeing...

thank u to all..

DATA : BEGIN OF str1,

        customer TYPE kna1-kunnr,

        search   TYPE kna1-sortl,

END OF str1.

DATA : BEGIN OF str2,

        customer TYPE kna1-kunnr,

        search   TYPE kna1-sortl,

END OF str2.

DATA: it_upload LIKE TABLE OF str1,

       it_upload1 LIKE TABLE OF str2,

       it_1 LIKE TABLE OF str1,

       it_2 LIKE TABLE OF str2,

       wa_1         LIKE str1,

       wa_2         LIKE str2.

CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     filename                      = 'C:\Users\Roopa\Desktop\headr.txt'

     HAS_FIELD_SEPARATOR           = 'X'

   TABLES

     data_tab                      = it_upload

CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     filename                      = 'C:\Users\Roopa\Desktop\headr1.txt'

   TABLES

     data_tab                      = it_upload1

loop at it_upload INTO wa_1.

read table it_upload1 INTO wa_2 with key search = wa_1-search.

if sy-subrc ne 0.

APPEND wa_1 to it_1.

endif.

endloop.

loop at it_upload1 INTO wa_2.

read table it_upload INTO wa_1 with key search = wa_2-search.

if sy-subrc ne 0.

APPEND wa_2 to it_2.

endif.

endloop.

CALL FUNCTION 'GUI_DOWNLOAD'

   EXPORTING

     filename                = 'C:\Users\Roopa\Desktop\DOWNLOAD.txt' "filepath

     filetype                = 'DAT'

     write_field_separator   = 'X'

   TABLES

     data_tab                = it_1

CALL FUNCTION 'GUI_DOWNLOAD'

   EXPORTING

     filename                = 'C:\Users\Roopa\Desktop\DOWNLOAD1.txt' "filepath

     filetype                = 'DAT'

     write_field_separator   = 'X'

   TABLES

     data_tab                = it_2

  

input is :

file 1

customersortl
110  yb06
139  yb04
150  yb07

file2

customersortl
110  yb03
149  yb05
160  yb04
179  yb08
170  yb09

out put is

table 3

110  yb06
150  yb07

table4

110  yb03
149  yb05
179  yb08
170  yb09

thanks & regards,

roopa.