‎2009 Feb 18 7:04 AM
Hi ,
I have a problem in MODIFY statement.
I have 2 internal statement.
1. It and 2. it_mseg.
The number of datas in it_mseg is greater than it.
But i want to loop it_mseg and modify the fields of it.
How can i do this.
my code like this
SELECT c~MBLNR
c~BUDAT
c~BKTXT
d~BWART
d~MATNR
d~KUNNR
d~ERFMG
d~MAT_KDAUF
d~MAT_KDPOS
FROM MKPF AS c INNER JOIN MSEG AS d ON cMBLNR = dMBLNR
INTO CORRESPONDING FIELDS OF TABLE IT1
WHERE c~BUDAT IN DATE
AND d~KUNNR IN CUST
AND d~MATNR IN MAT
AND ( dbwart = '501' or dbwart = '412').
select * from mseg into corresponding fields of table it_mseg
for all entries in it1
where mat_kdauf = it1-mat_kdauf
and bwart = '261' and sobkz = 'E'.
loop at it_mseg.
if IT1-bwart = '412'.
read table it_MSEG with key mat_kdauf = it1-mat_kdauf
matnr = it1-matnr.
IF SY-SUBRC = 0.
IT1-QUN = IT_MSEG-ERFMG.
CLEAR IT1-ERFMG.
ENDIF.
modify it1 index sy-tabix transporting qun.
ENDIF.
endloop.
but it not give me total it_mseg record.
Thanks in Advance.
Regards
Sam
‎2009 Feb 18 7:09 AM
change the code as ..
loop at it_mseg.
read table it1 with key mat_kdauf = it_mseg-mat_kdauf
matnr = it_mseg-matnr.
IF SY-SUBRC = 0 and if IT1-bwart = '412'.
IT1-QUN = IT_MSEG-ERFMG.
modify it1 index sy-tabix transporting qun.
ENDIF.
ENDLOOP.
‎2009 Feb 18 7:33 AM
Hi Shrini vas
Thanks for answer.
but it give me some data it_mseg not total.
Regards.
Sam
Edited by: sam on Feb 18, 2009 8:34 AM
‎2009 Feb 18 7:40 AM
Hi Sam,
Please read Raghavender's and Gauthams answers carefully. What they are trying to point out to you is that you are looping and reading the same table it_mseg within the loop. This is not correct.
regards,
Advait
‎2009 Feb 18 7:10 AM
When you loop table it_mseg then read table it and modify it if sy-subrc check is successful...
Raghav
‎2009 Feb 18 7:10 AM
Sinece you are using loop for it_mseg you should use read
statement for it1 and then check the condition if sy-subrc = 0.
if IT1-bwart = '412'.
___
endif.
‎2009 Feb 18 7:13 AM
Better use Field symbols so that there will be no change of failing modify statement. Its always better to use field symbols.
‎2009 Feb 18 7:14 AM
Hi Sam ,
Please try to modify inside the if codition and try with Append alse ---
SELECT c~MBLNR
c~BUDAT
c~BKTXT
d~BWART
d~MATNR
d~KUNNR
d~ERFMG
d~MAT_KDAUF
d~MAT_KDPOS
FROM MKPF AS c INNER JOIN MSEG AS d ON c~MBLNR = d~MBLNR
INTO CORRESPONDING FIELDS OF TABLE IT1
WHERE c~BUDAT IN DATE
AND d~KUNNR IN CUST
AND d~MATNR IN MAT
AND ( d~bwart = '501' or d~bwart = '412').
select * from mseg into corresponding fields of table it_mseg
for all entries in it1
where mat_kdauf = it1-mat_kdauf
and bwart = '261' and sobkz = 'E'.
loop at it_mseg.
if IT1-bwart = '412'.
read table it_MSEG with key mat_kdauf = it1-mat_kdauf
matnr = it1-matnr.
IF SY-SUBRC = 0.
IT1-QUN = IT_MSEG-ERFMG.
CLEAR IT1-ERFMG.
modify it1 index sy-tabix transporting qun. " Change
Else. " Change
Append it1. " Change
ENDIF.
endloop.Regards
Pinaki
‎2009 Feb 18 7:17 AM
Hi,
loop at IT1.
if IT1-bwart = '412'.
read table it_MSEG with key mat_kdauf = it1-mat_kdauf
matnr = it1-matnr.
IF SY-SUBRC = 0.
IT1-QUN = IT_MSEG-ERFMG.
CLEAR IT1-ERFMG.
ENDIF.
modify it1 index sy-tabix transporting qun.
endloop.
‎2009 Feb 18 7:35 AM
Hi Sam,
Chk with this,.......
loop at it1.
w_idx = sy-tabix.
if IT1-bwart = '412'.
read table it_MSEG with key mat_kdauf = it1-mat_kdauf
matnr = it1-matnr.
IF SY-SUBRC = 0.
IT1-QUN = IT_MSEG-ERFMG.
CLEAR IT1-ERFMG.
ENDIF.
modify it1 index w_idx transporting qun.
ENDIF.
endloop.
Regards,
Mdi.Deeba