‎2006 Jun 02 7:24 AM
Hi All,
I m Retreiving reocord from Table and appending in Struct but it is going in infinite loop..
my code is :
loop at struct1.
ind = sy-tabix.
loop at itabstpo where stlnr = struct1-stlnr.
struct1-menge = itabstpo-menge .
struct1-nlfzt = itabstpo-nlfzt .
struct1-roms1 = itabstpo-roms1 .
struct1-idnrk = itabstpo-idnrk .
APPEND struct1 .
endloop.
endloop.
Pls Help...
Regards,
yunus
‎2006 Jun 02 7:26 AM
Hi yunus,
1. The reason is
we are using LOOP at STRUCT,
and inside this loop only,
we are using APPEND STRUCT1.
(we should never code like this,
bcos the results are unpredictable)
2. Its better to APPEND
in another similar internal table
(similar to STRUCT1)
3. Then after this loop completes,
use
LOOP AT NEWITAB.
STRUCT1 = NEWITAB.
APPEND STRUCT1.
ENDLOOP.
4. In this way, u won't have any problem !!!
regards,
amit m.
‎2006 Jun 02 7:26 AM
Hi yunus,
1. The reason is
we are using LOOP at STRUCT,
and inside this loop only,
we are using APPEND STRUCT1.
(we should never code like this,
bcos the results are unpredictable)
2. Its better to APPEND
in another similar internal table
(similar to STRUCT1)
3. Then after this loop completes,
use
LOOP AT NEWITAB.
STRUCT1 = NEWITAB.
APPEND STRUCT1.
ENDLOOP.
4. In this way, u won't have any problem !!!
regards,
amit m.
‎2006 Jun 02 7:30 AM
use only..
<b>modify struct1 .</b>
loop at itabstpo where stlnr = struct1-stlnr.
this line means there are previously value in struct1.and when u append value on it again it goes to infinie loop.
and for performance point of view avoid nested loop. use read statment inside loop.
‎2006 Jun 02 7:44 AM
when i m using modify it is giving me only last record.
Regards,
yunus
‎2006 Jun 02 7:49 AM
ya it show only one value becoz u have one value of strn in struct1 . but 98in internal table u have many value for perticular strn in struct1.
<b>
solution...</b>
make struct2 same as struct1.
loop at struct1.
ind = sy-tabix.
loop at itabstpo where stlnr = struct1-stlnr.
struct2-stlnr = struct1-stlnr.
struct2-menge = itabstpo-menge .
struct2-nlfzt = itabstpo-nlfzt .
struct2-roms1 = itabstpo-roms1 .
struct2-idnrk = itabstpo-idnrk .
APPEND struct2 .
endloop.
endloop.
now it is fine just try it...
‎2006 Jun 02 7:56 AM
Hi,
structure can hold only one value at any time.
if u want all the records to be appended then append in internal table.
Inside loop use read statement to improve performance.
can u give the exact requirement?
rgds,
latheesh
‎2006 Jun 02 10:29 AM
Tables:mast,stpo,vbap,mara.
DATA: BEGIN OF struct occurs 100,
MATNR type VBAP-MATNR,
END OF struct.
DATA: BEGIN OF struct1 occurs 100,
stlnr type mast-stlnr,
idnrk type stpo-idnrk,
menge type stpo-menge,
nlfzt type stpo-nlfzt,
roms1 type stpo-roms1,
EXTWG type MARA-EXTWG,
END OF struct1.
data: itab4 like VBAP occurs 1 with header line.
data: itab1 like MARA occurs 1 with header line.
data: itabstpo like stpo occurs 1 with header line.
select * from mara into table itab1.
select * from VBAP into table itab4.
loop at struct.
ind = sy-tabix.
read table itab4 with key vbeln = struct-vbeln.
if sy-subrc = 0.
move itab4-MATNR to struct-MATNR.
endif.
modify struct index ind transporting matnr.
endloop.
select * from mast into corresponding fields of table struct1 where matnr = struct-matnr and WERKS = company
and stlan = '5' .
select * from stpo into table itabstpo.
// this loop is firing three time and data also showing me at breakpoint but at tha time of printing it is giving me only one record..
loop at struct1.
loop at itabstpo where stlnr = struct1-stlnr.
move itabstpo-menge to struct1-menge.
MODIFY struct1 INDEX SY-TABIX.
move itabstpo-nlfzt to struct1-nlfzt.
MODIFY struct1 INDEX SY-TABIX.
move itabstpo-roms1 to struct1-roms1.
MODIFY struct1 INDEX SY-TABIX.
move itabstpo-idnrk to struct1-idnrk.
MODIFY struct1 INDEX SY-TABIX.
endloop.
endloop.
loop at struct1.
write: / struct1-roms1, struct1-nlfzt ,struct1-menge ,struct1-idnrk.
endloop.
regards,
yunus
‎2006 Jun 02 10:33 AM
<b>data: struct2 like struct1 occurs 0 with header line.</b>
select * from stpo into table itabstpo.
// this loop is firing three time and data also showing me at breakpoint but at tha time of printing it is giving me only one record..
loop at struct1.
loop at itabstpo where stlnr = struct1-stlnr.
move itabstpo-menge to struct2-menge.
move itabstpo-nlfzt to struct2-nlfzt.
move itabstpo-roms1 to struct2-roms1.
move itabstpo-idnrk to struct2-idnrk.
append struct2.
endloop.
endloop.
loop at struct2.
write: / struct2-roms1, struct2-nlfzt ,struct2-menge ,struct2-idnrk.
endloop.
‎2006 Jun 02 11:23 AM
hi kishan,
Thanks for ur help now i m getting all the records in struct2 but when i m passing one the struct2 value in another loop it is giving me last record in that loop.
but while diaplying through write it is displaying all the record.
my code is :
loop at struct1.
ind = sy-tabix.
loop at itabstpo where stlnr = struct1-stlnr.
struct2-menge = itabstpo-menge .
struct2-nlfzt = itabstpo-nlfzt .
struct2-roms1 = itabstpo-roms1 .
struct2-idnrk = itabstpo-idnrk .
APPEND struct2 .
endloop.
endloop.
here i m passing struct2-idnrk in the below loop but it is not giving me first value of idnrk it is giving me last value of idnrk.
loop at struct1.
ind = sy-tabix.
loop at itab1 WHERE matnr = struct2-idnrk.
struct2-EXTWG = itab1-EXTWG .
APPEND struct2.
endloop.
endloop.
pls help.
Regards,
yunus
‎2006 Jun 02 11:29 AM
<b>loop at struct2.</b>
ind = sy-tabix.
loop at itab1 WHERE matnr = struct2-idnrk.
struct2-EXTWG = itab1-EXTWG .
<b>modify struct2.</b>
endloop.
endloop.
<b>note...</b>plz don't use nested loop it decrease ur programm performance....
use read ststment inside loop
like this...
sort itab1.
<b>loop at struct2.</b>
ind = sy-tabix.
read table itab1 binary search with key matnr = struct2-idnrk.
struct2-EXTWG = itab1-EXTWG .
<b>modify struct2.</b>
endloop.
‎2006 Jun 02 11:38 AM
kishan,
below code is giving last record twice. means dulpicate record.
loop at struct1.
ind = sy-tabix.
loop at itabstpo where stlnr = struct1-stlnr.
struct2-menge = itabstpo-menge .
struct2-nlfzt = itabstpo-nlfzt .
struct2-roms1 = itabstpo-roms1 .
struct2-idnrk = itabstpo-idnrk .
APPEND struct2 .
endloop.
endloop.
in table itspstpo only three records r there but after appending struct2. when i m displaying record it displaying four record in that it is displaying last record two times.
regards,
yunus
‎2006 Jun 02 11:41 AM
loop at struct1.
ind = sy-tabix.
loop at itabstpo where stlnr = struct1-stlnr.
struct2-menge = itabstpo-menge .
struct2-nlfzt = itabstpo-nlfzt .
struct2-roms1 = itabstpo-roms1 .
struct2-idnrk = itabstpo-idnrk .
APPEND struct2 .
<b>clear: struct2.</b>
endloop.
endloop.
<b>delete adjacent duplicates from struct2.</b>
‎2006 Jun 02 10:49 AM
Hi Yunus,
MODIFY would help. use Modify STRUCT INDEX ind(as stored by you) or use extension TRANSPORTING field1,field2.
also the alternate solution is loop at struct then use READ itabstpo with key stlnr = struct1-stlnr.
This would also serve the purpose I think.
Reward if useful