10-24-2013 1:31 PM
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
10-24-2013 5:31 PM
10-24-2013 1:54 PM
Why cant you keep both format same. Do a simple loop one and read other.
10-24-2013 1:57 PM
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.
10-24-2013 1:55 PM
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
10-24-2013 1:58 PM
10-24-2013 2:16 PM
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.
10-24-2013 4:01 PM
Not working. I have already converted the internals tables to the same format. Any news ideas to compare them then? Thanks. F
10-24-2013 5:31 PM
10-25-2013 9:17 AM
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".
10-25-2013 9:24 AM
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
10-25-2013 9:30 AM
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 ...
10-25-2013 9:41 AM
What is the value of street in both table which needs to be compared?
10-25-2013 9:45 AM
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.
10-25-2013 9:52 AM
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
10-25-2013 10:12 AM
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 ...
10-25-2013 10:15 AM
code looks ok..I guess you should switch on debugger and check where it fails show the contents of the variable.
10-25-2013 10:26 AM
10-25-2013 10:35 AM
10-25-2013 10:39 AM
li_addr_2 is neither specified under "TABLES" nor is it defined as an internal table.
10-25-2013 10:42 AM
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
10-25-2013 11:05 AM
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 ...
10-25-2013 12:03 PM
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!
10-25-2013 7:44 AM
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
10-25-2013 10:37 AM
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