Application Development and Automation 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: 
Read only

modify internal table

Former Member
0 Likes
1,039

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

9 REPLIES 9
Read only

Former Member
0 Likes
981

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.

Read only

0 Likes
981

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

Read only

0 Likes
981

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

Read only

former_member182354
Contributor
0 Likes
981

When you loop table it_mseg then read table it and modify it if sy-subrc check is successful...

Raghav

Read only

GauthamV
Active Contributor
0 Likes
981

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.

Read only

Former Member
0 Likes
981

Better use Field symbols so that there will be no change of failing modify statement. Its always better to use field symbols.

Read only

Former Member
0 Likes
981

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

Read only

Former Member
0 Likes
981

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.

Read only

Former Member
0 Likes
981

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