‎2006 Mar 07 2:44 AM
Hi Experts,
I am not getting output properly. it should write struct1 value whenever Tcode not equal to FS00 and FSp0. it should write itab_t001 value whenever Tcode equal to FS00 and FSp0.
1.Its working fine whenevr tcode not equal to FS00 and FSp0.
2.also its working fine whenever tcode equal to FS00 and FSp0. first looping (itab_t001) time its writing itab_t001 value when Tcode eq FS00 .then second time looping its writting so many values when tcode eq FS00 .
3.I think the problem may be here
"append lines of it_t001 to itab_t001."
can anyone help me to get exact result.
loop at struct1.
if struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
select bukrs KTOPL from t001 into table it_t001
where KTOPL eq w_KTOPL.
check sy-subrc eq 0.
if struct1-TCODE eq 'FS00'.
append lines of it_t001 to itab_t001.
clear it_t001.
loop at itab_t001 where KTOPL eq w_KTOPL..
struct1-bukrs = itab_t001-w_bukrs.
append struct1.
clear struct1.
endloop.
endif.
endif.
endloop.
‎2006 Mar 07 2:55 AM
HI silviya
correct this
loop at struct1.
if struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
select bukrs KTOPL from t001 into table it_t001
where KTOPL eq w_KTOPL.
check sy-subrc eq 0.
append lines of it_t001 to itab_t001.
else
loop at itab_t001 where KTOPL eq w_KTOPL..
struct1-bukrs = itab_t001-w_bukrs.
append struct1.
clear struct1.
endloop.
endif.
endloop.
regards
kishore
‎2006 Mar 07 3:03 AM
1. it is giving so many values means what?
what is so many?
exactly what values u want?
loop at struct1.
if struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
select bukrs KTOPL from t001 into table it_t001
where KTOPL eq w_KTOPL.
check sy-subrc eq 0.
if struct1-TCODE eq 'FS00'.
append lines of it_t001 to itab_t001.
clear it_t001.
loop at itab_t001 where KTOPL eq w_KTOPL..
struct1-bukrs = itab_t001-w_bukrs.
append struct1.
clear struct1.
endloop.
endif.
endif.
endloop
FROM THE ABOVE, i understood,
1. u r looping at stuct1 and when tcode is either FS00 OR FSP0, U ARE SELECTING DATA FROM T001 TO TABLE IT_T001.
2.IF TCODE = FS00, U R APPENDING TABLE ITAB_T001.
HERE EXACTLY WHAT IS UR PURPOSE?
IF U WANT TO MOVE THE CONTENTS TO ITAB_T001, U CAN USE
MOVE-CORRESPONDING right!!
then y r u using itab_t001??
is already some data there in itab_t001 and u want to append this data to it? then what u did is right.
3. U R LOOPING INSIDE STRUCT1 and again u r appending STRUCT1??? Y LIKE THIS?
THIS IS NOT GOOD FOR PERFORMANNCE.
‎2006 Mar 07 3:12 AM
Hi Hymavathi,
1.I am looping at stuct1 and when tcode is either FS00 OR FSP0 & i am SELECTING DATA FROM T001 TO TABLE IT_T001.
2.I have to add it_t001 (companycode) value in the last field of strcut1.
Thanks
‎2006 Mar 07 3:16 AM
Hi Silviya,
>>> have to add it_t001 (companycode) value in the last field of strcut1.
In that casem you should use MODIFY strcut1 INDEX SY-TABIX.
Append will keep on adding records to struct1 with each loop pass & the table will grow.
As Oruganti already cautioned, it will lead to performance issues too..
Regards,
Suresh Datti
‎2006 Mar 07 3:41 AM
Hi Suresh,
1.Requirement: it should write struct1 value whenever Tcode not equal to FS00 and FSp0. it should write it_t001 value (company code) in last field of struct1 value whenever Tcode equal to FS00 and FSp0.
2. problem: Its only displying struct1 value whenever tcode eq FS00 or FSP0.i coded like this..
loop at struct1.
if struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
select bukrs KTOPL from t001 into table it_t001
where KTOPL eq w_KTOPL.
check sy-subrc eq 0.
loop at it_t001.
struct1-bukrs = it_t001-w_bukrs.
MODIFY struct1 INDEX SY-TABIX.
endloop.
endif.
endif.
endloop.
‎2006 Mar 07 3:44 AM
Hi Silviya,
LOOP AT struct1.
IF struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
SELECT bukrs ktopl FROM t001 INTO TABLE it_t001
WHERE ktopl EQ w_ktopl.
CHECK sy-subrc EQ 0.
LOOP AT it_t001.
struct1-bukrs = it_t001-w_bukrs.
<b>MODIFY struct1 TRANSPORTING bukrs.</b>
ENDLOOP.
ELSE.
WRITE : struct1-bukrs.
ENDIF.
ENDLOOP.
‎2006 Mar 07 3:57 AM
Hi Silviya,
Pl try the following code..
data w_bukrs type bukrs.
loop at struct1 where tcode = 'FS00'
or tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
select bukrs up to 1 rows from t001 into w_bukrs
where KTOPL eq w_KTOPL.
endselect.
check sy-subrc eq 0.
struct1-bukrs = itab_t001-w_bukrs.
modify struct1 index sy-tabix transporting bukrs.
endloop.
Regards,
Suresh Datti
‎2006 Mar 07 3:59 AM
Hi Wenceslaus,
its working fine. it_t001 contains 7 records.But its 7th (last ) record only added to struct1.
I want to add 7 (all) records in struct1.Please check the coding.
loop at struct1.
if struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0' .
w_KTOPL = struct1-objectid(4).
select bukrs KTOPL from t001 into table it_t001
where KTOPL eq w_KTOPL.
check sy-subrc eq 0.
if struct1-TCODE eq 'FS00'.
loop at it_t001.
struct1-bukrs = it_t001-w_bukrs.
MODIFY struct1 TRANSPORTING bukrs.
endloop.
endif.
endif.
endloop.
‎2006 Mar 07 4:02 AM
Hi Silviya,
DATA cnt TYPE i.
LOOP AT struct1.
IF struct1-tcode = 'FS00' Or struct1-tcode = 'FSP0'.
w_KTOPL = struct1-objectid(4).
cnt = 0.
SELECT bukrs ktopl FROM t001 INTO TABLE it_t001
WHERE ktopl EQ w_ktopl.
CHECK sy-subrc EQ 0.
LOOP AT it_t001.
IF cnt NE 0.
<b> MOVE-CORRESPONDING it_t001 TO struct1.
APPEND struct1.</b>
ELSE.
<b> struct1-bukrs = it_t001-w_bukrs.
MODIFY struct1 TRANSPORTING bukrs.</b>
cnt = 1.
ENDIF.
ENDLOOP.
ELSE.
WRITE : struct1-bukrs.
ENDIF.
ENDLOOP.
‎2006 Mar 07 3:47 AM
if we knew the format of struct1 it might be easier to give a better loop... and the tables too.
But in the short term you will probably get the results you want by putting this at the end:
sort struct1.
DELETE ADJACENT DUPLICATES FROM struct1.
sort itab_t001.
DELETE ADJACENT DUPLICATES FROM itab_t001.
‎2006 Mar 07 4:21 AM
I'm sure the other answers are good. In addition, you should move the select of T001 outside of the loop. You can simply select all entries into an internal table and sort it in company code sequence. Then in the loop, you can do a binary read of that table to get the company code.
Rob