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: 

ABAP Logic - tables with different format

Former Member
0 Kudos

I have no idea why my topic has been deleted so I am posting again.

Moderators: if there was a problem with my topic, please let me know.

I still have issues.  I am gonna try to explain better this time.

I need to compare data that comes from an interface.

Data from SAP have this format in table:

TYPES:  BEGIN OF lt_A,

nachn TYPE pad_nachn,

vorna TYPE pad_vorna,

stras TYPE pad_stras,

pstlz TYPE pstlz_hr,

ort01 TYPE pad_ort01,

END OF lt_A.

Data from table that is created with after I receive data from interface

TYPES: BEGIN OF lt_b,

name  TYPE string,

vorname TYPE string,

strasse TYPE string,

haus_nr TYPE int4,

haus_nr_zusatz TYPE string,

plz TYPE string,

ort18 TYPE string,

END OF lt_b.

I need now to create another table to store only data that matches.

Criteria is:   If name, last name, Street, PLZ and ORT from table 1 = table 2, populate table 3.

If they are not equal, message INCORRECT and do not populate table 3.

I am struglying to create table 3 as the other 2 tables have complete differente format.   Can someone please help?

Thank you,

F

1 ACCEPTED SOLUTION

nabheetscn
Active Contributor
0 Kudos
Can you please paste a screen shot of the data from two formats which you want to compare. It will be easy for usto understand your to understand your problem
23 REPLIES 23

nabheetscn
Active Contributor
0 Kudos

Why cant you keep both format same. Do a simple loop one and read other.

0 Kudos

I really wish I could Nabheet.   But as my first post states, first table is SAP format and second table is outsourced company results format, which is not equal at all to SAP format.

ThomasZloch
Active Contributor
0 Kudos

I think your initial title was just "abap logic". All posts here are (or rather should be) about ABAP logic. Imagine an entire discussion overview, all with titles like "abap logic". Which one to look at first as an expert who wants to help but doesn't have much time to spend?

Now it looks a little better.

Thomas

0 Kudos

Thank you so much Thomas. I am sorry for my lack of attention.

former_member184569
Active Contributor
0 Kudos

Even if the field names are different, if the order of the corresponding fields are same, you can do it like this using field symbols.

data : flag.
FIELD-SYMBOLS:  <fs_comp1>, <fs_comp2>, <fs_comp3>.
clear : wa_ty1, wa_ty2, wa_ty3.
loop at tab_a into wa_ty1.
  loop at tab_b into wa_ty2.
    flag = 'X'.
   do .

        check flag = 'X'.

        ASSIGN COMPONENT sy-tabix of STRUCTURE wa_ty1 to <fs_comp1>.
        ASSIGN COMPONENT sy-tabix of STRUCTURE wa_ty2 to <fs_comp2>.
        ASSIGN COMPONENT sy-tabix of STRUCTURE wa_ty3 to <fs_comp3>.
       if <fs_comp1> is ASSIGNED and <fs_comp2> is ASSIGNED.
          if <fs_comp1> ne <fs_comp2>.
            clear flag.
         else.
           <fs_comp3> = <fs_comp1>.
        endif.
     endif.
   enddo.
   if flag = 'X'.
*  Move any other extra fields to the third work area if the third table contains more fields than table 1.

       append wa_ty3 to tab_c.
   endif .
   clear : wa_ty1, wa_ty2, wa_ty3.
  endloop.

endloop.

0 Kudos

Not working.   I have already converted the internals tables to the same format.   Any news ideas to compare them then?   Thanks.   F

nabheetscn
Active Contributor
0 Kudos
Can you please paste a screen shot of the data from two formats which you want to compare. It will be easy for usto understand your to understand your problem

0 Kudos

OK, Please see in attachment the screen shot.   What I need ( since I have already converted all tables to the same format ), is to compare data from the fields:   pad_vorna, pas_stras, pstlz-hr and pad_ort01.   If values are the same in those fields in both tables, populate the table 3.   If value is not the same or does not exist, message "error".

0 Kudos

You have values in table now..why cant you loop on one and read other table with key and check..? I am not able to get what is the issue may be you need to show us the data of both table and what is the challenge

0 Kudos

I think that the problem I am having in the street number which I need to separate before and that when I convert to sap format brings a lot of spaces to the field ... and the rest does not get passed ...

0 Kudos

What is the value of street in both table which needs to be compared?

0 Kudos

no especific value. value just needs to be the same in both tables.  then fill the 3rd table if there is a match.  for some reason I cannot put together the correct loop.

0 Kudos

Please paste your code here..

Loop at ITAB1

read table ITAB2 with key

if sy-subrc eq 0.

match found append it to itab3

else.

message abcd

endif

endloop

0 Kudos

loop at li_addr1 into ls_addr2.    read table li_addr2  WITH KEY ls_addr1-vorna = ls_addr2-vorname. if sy-subrc eq 0.  match found append li_addr1 to li_addr3  else.  message Incorrect Address  endif.  endloop   sorry, the code is too long and I confused myself ...

0 Kudos

code looks ok..I guess you should switch on debugger and check where it fails show the contents of the variable.

0 Kudos

Thing is I still cannot activate because tells me I have errors.

0 Kudos

What are the errros?

0 Kudos

li_addr_2  is neither specified under "TABLES" nor is it defined as an internal table.

0 Kudos

Li_addr_2 should be declared as table. Declare a work area also for it.

Do read like this read table lt_addr_2 into lwa_addr_2

0 Kudos

Interesting enough ... tables were ok, but the thing is the interface returns a change in the table structure. Filds names change ....  that I have already caught and corrected.   Variable is not working now. Maybe the line of code with that are wrong ...

0 Kudos

I combined the tips of  nabheet madan and suneesh thampi and ALL seems to be working now.  I will run many tests this afternoon and in case I find issues, I will post.   Thank you guys!

Former Member
0 Kudos

Hi

You can a for all entries to retirve all datas that matches certain conditions just like a join.

Eg.

select name place etc from table1 into table internal-tab where condition.

select  field1 field2 etc from table2 for all entries in internal-tab1 into internal-tab2

where condition.

loop internal-tab into w_internal-tab.

     read table internal-tab2 into w_internal-tab2 with key (the joining condition fields) name = w_internal-tab-name.

append the field to the new structure or use move corresponding.

endloop

With regards

Suneesh

praveenboss
Participant
0 Kudos

Hi Fafa,

  May Be A Problem Of Data  Mismatch,

   And I Think This Case Should Be Solved By

   inside Your Internal Table Which Filled By Other interface data

   you Move Your Checked Data to Other Column

   And Then Match with Internal Table which Filled By sap table data,

Ex.

  Loop At IT_Other INTO W_other.

UNPACK P_FIELD TO C_FIELD.

modify IT_Other from W_Other . 

ENDLOOP.

Now C_FIELD IS IN FORMAT AS Your internal table which filled by sap table data.

http://help.sap.com/abapdocu_731/en/abapunpack.htm

http://sapbrainsonline.com/abap-tutorial/syntax/unpack-sap-abap-keyword.html

                                  THANKS.

                                   PRAVEEN