06-18-2009 2:03 PM
Hi Experts,
As per my requirment I need fetch two different categories of matnr based on movment type
from mseg..
For eg: If I have two itab's : itab1 and itab2.
In itab1 the available records are:
matnr werks lifnr
mat1 unit1 ABC
mat2 unit1 ABC
mat3 unit1 ABC
mat4 unit1 ABC
In itab2 the available records are:
matnr_1 werks_1 lifnr_1
mat5 unit1 ABC
mat6 unit1 ABC
mat7 unit1 ABC
mat8 unit1 ABC
and I want to move this itab1 and itab2 to another itab ie. itab3.
and my o/p shud look like:
matnr werks lifnr matnr_1
mat1 unit1 ABC mat5
mat2 unit1 ABC mat6
mat3 unit1 ABC mat7
mat4 unit1 ABC mat8.
Please advice
Karthik
Edited by: Karthik R on Jun 18, 2009 6:33 PM
06-18-2009 2:14 PM
Hello Karthik,
It is quite easy to do so using LOOP & READ statment combination.
NB: I am assuming you are combining the 2 tables based on Plant(WERKS) & Vendor(LIFNR)
The code will be:
DATA:
BEGIN OF ITAB3 OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
LIFNR TYPE LIFNR,
MATNR_1 TYPE MATNR,
END OF ITAB3.
SORT ITAB1 BY WERKS LIFNR.
SORT ITAB2 BY WERKS LIFNR. "-->This is important for READ TABLE
LOOP AT ITAB1.
ITAB3-MATNR = ITAB1-MATNR.
ITAB3-WERKS = ITAB1-MATNR.
ITAB3-LIFNR = ITAB1-LIFNR.
READ TABLE ITAB2 INDEX SY-TABIX.
IF SY-SUBRC = 0.
ITAB3-MATNR_1 = ITAB2-MATNR_1.
ENDIF.
APPEND ITAB3.
ENDLOOP.
Hope this helps.
BR,
Suhas
06-18-2009 2:07 PM
Not sure but try to do with the join by werks and lifnr
Edited by: sgrshah on Jun 18, 2009 3:07 PM
06-18-2009 2:11 PM
Hi,
Loop at 1st internal table and read the 2nd internal table with the common fields.. now move the respective fields to the new internal table 'Itab3...
here's a sample code..
loop at itab1 into ws_area.
read itab2 into ws_itab2 with key werks_1 = ws_area-werks lifnr_1 = ws_area-lifnr
.
itab3-matnr = ws_area-matnr.
itab3-werks = ws_area-werks.
itab3-lifnr = ws_area-lifnr.
itab3-matnr1 = ws_itab2-matnr.
endloop.
06-18-2009 2:14 PM
Hello Karthik,
It is quite easy to do so using LOOP & READ statment combination.
NB: I am assuming you are combining the 2 tables based on Plant(WERKS) & Vendor(LIFNR)
The code will be:
DATA:
BEGIN OF ITAB3 OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
LIFNR TYPE LIFNR,
MATNR_1 TYPE MATNR,
END OF ITAB3.
SORT ITAB1 BY WERKS LIFNR.
SORT ITAB2 BY WERKS LIFNR. "-->This is important for READ TABLE
LOOP AT ITAB1.
ITAB3-MATNR = ITAB1-MATNR.
ITAB3-WERKS = ITAB1-MATNR.
ITAB3-LIFNR = ITAB1-LIFNR.
READ TABLE ITAB2 INDEX SY-TABIX.
IF SY-SUBRC = 0.
ITAB3-MATNR_1 = ITAB2-MATNR_1.
ENDIF.
APPEND ITAB3.
ENDLOOP.
Hope this helps.
BR,
Suhas
06-18-2009 2:37 PM
Hi Suhas,
Thanks a lot !! Ur logic is working.. but I have some other problem now:
ie. If in itab 1 I have
matnr werks lifnr
mat1 unit1 ABC
mat2 unit1 ABC
In itab2 the available records are:
matnr_1 werks_1 lifnr_1
mat5 unit1 ABC
mat6 unit1 ABC
mat7 unit1 ABC
mat8 unit1 ABC
I want my o/p as :
matnr werks lifnr matnr_1
mat1 unit1 ABC mat5
mat2 unit1 ABC mat6
mat7
mat8.
But as per ur logic I got the o/p as:
matnr werks lifnr matnr_1
mat1 unit1 ABC mat5
mat2 unit1 ABC mat6
Please advice
Karthik
Edited by: Karthik R on Jun 18, 2009 7:07 PM
Edited by: Karthik R on Jun 18, 2009 7:08 PM
06-18-2009 3:01 PM
Hello,
I am not sure about the req. but still try this :
DATA:
BEGIN OF ITAB3 OCCURS 0,
MATNR TYPE MATNR,
WERKS TYPE WERKS_D,
LIFNR TYPE LIFNR,
MATNR_1 TYPE MATNR,
END OF ITAB3,
V_INDEX TYPE SY-TABIX.
SORT ITAB1 BY WERKS LIFNR.
SORT ITAB2 BY WERKS LIFNR. "-->This is important for READ TABLE
LOOP AT ITAB1.
ITAB3-MATNR = ITAB1-MATNR.
ITAB3-WERKS = ITAB1-MATNR.
ITAB3-LIFNR = ITAB1-LIFNR.
READ TABLE ITAB2 INDEX SY-TABIX.
IF SY-SUBRC = 0.
ITAB3-MATNR_1 = ITAB2-MATNR_1.
ENDIF.
APPEND ITAB3.
"--> Add this code to achieve your req.
AT LAST.
V_INDEX = SY-TABIX + 1.
LOOP AT ITAB2 FROM V_INDEX.
ITAB3-MATNR_1 = ITAB2-MATNR_1.
APPEND ITAB3.
ENDLOOP.
ENDAT.
ENDLOOP.
BR,
Suhas
06-18-2009 3:17 PM
06-18-2009 3:19 PM
>
> U Rock !! ........Thanks a lot my issue is sold....
Hello,
I am Suhas ... Plz donot make me a rock
06-18-2009 2:15 PM
Hello
data: counter type i.
loop at itab1.
counter = counter + 1.
clear itab3.
itab3-matnr = itab1-matnr.
itab3-werks = itab1-werks.
itab3-lifnr = itab1-lifnr.
read table itab2 index counter.
if sy-subrc = 0.
itab3-matnr_1 = itab2-matnr_1.
endif.
append itab3.
endloop.
06-18-2009 2:17 PM
Hi,
try this.(sample code)
SELECT ekpo~ebeln
ekpo~matnr
ekpo~werks
ekpo~lifnr
ekko~metnr_1
ekko~lifnr_1
ekko~werks_1
INTO TABLE it_data
FROM it_tab1 JOIN it_tab2 ON it_tab1~werks = it_tab2~werks.
and it_tab1~matnr ne it_tab2~matnr_1
and it_tab1~lifnr = it_tab2~lifnr.
hope it'll help.
Regards,
Sneha.
06-18-2009 2:17 PM
Hello,
You can simply use the command
"APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2. "
This command appends lines of itab1 to itab2 .Now, your table itab2 has all the entries.
In case if you want to append only certain lines from itab1 and itab2 which are common, you can follow the below procedure:
1. loop at itab1.
2. Read itab2 for the values of itab2.
3. append to table itab3.
Hope this helps,
Thanks,
Sowmya Arni
06-18-2009 2:17 PM
Hi Karthik,
data: begin of itab3 occurs 0,
matnr like itab1-matnr,
werks like itab1-werks,
lifnr like itab1-lifnr,
matnr_1 like itab2-matnr_1,
end of itab3.
Data: itab2_temp like itab2.
Itab2_temp[] = Itab2[]. " Total body move from itab2 to Itab2_temp
Loop at itab1.
clear itab2_temp.
Read table itab2_temp with key werks_1 = itab1-werks
lifnr_1 = itab1-lifnr.
If sy-subrc = 0.
itab3-matnr = itab1-matnr.
itab3-werks = itab1-werks.
itab3-lifnr = itab1-lifnr.
itab3-matnr_1= itab2_temp-matnr_1.
Delete itab2_temp.
Append itab3.
Clear itab3.
Endif.
Endloop.
Now you will have required output in Internal table Itab3.
Regards,
K
Edited by: K
Edited by: K
Edited by: Kishore Kumar Karnati on Jun 18, 2009 3:31 PM
06-18-2009 2:26 PM
Hi Karthik,
I could not get exact what logic you want?
Please explain functional requirement also so that I can answer your query.
Do you want to connect first line from itab1 to first line from itab2, 2nd line from itab1 to 2nd line from itab2 ????????Requirement should be clear.
Regards,
Anil
06-18-2009 2:55 PM
Loop at bigger itab, copy required fields to workarea and APPEND to itab3.
Loop at smaller itab, copy required fields to workarea and MODIFY itab3 using index.
Use DESCRIBE TABLE itab LENGTH lines. to find length of itab.
06-18-2009 3:18 PM
Hi Manish ,
U too Rockkk....Ur logic is also working perfectly....
Thanks a lot !
Karthik