‎2005 Mar 09 3:10 PM
Do MOVE:... to itab-... statements insert new records to itabs within a loop? Or will it continually replace the first record in the internal table?
Ex.
Loop at TableA.
Move: TABLEA-NAME TO vName.
SELECT NAME INTO tempname FROM TableB WHERE NAME=vName.
ENDSELECT.
IF SY-SUBRC <> 0.
MOVE: tempname INTO ITAB_nameholder-Name.
ENDIF.
ENDLOOP.The reason why I ask is because later down in my program I loop at my internal table, but it does not recognize it as a table. (Even though I declared it earlier.) So I think it may be that my inserts to the itab are not working.
N L
‎2005 Mar 09 3:25 PM
If your LOOP AT is syntactically correct, then you are
using tables with header lines.
I added a couple of lines to your code:
Loop at TableA.
Move: TABLEA-NAME TO vName.
SELECT NAME INTO tempname FROM TableB WHERE NAME=vName.
ENDSELECT.
IF SY-SUBRC <> 0.
<b>CLEAR ITAB_NAMEHOLDER.</b>
MOVE: tempname INTO ITAB_nameholder-Name.
<b>APPEND ITAB_NAMEHOLDER.</b>
ENDIF.
ENDLOOP.
‎2005 Mar 09 3:15 PM
If your internal table has a header line, then moving values to it would only move it in the header line. Use APPEND ITAB statement after fill the header line.
ex..
Data: imara type table of mara with header line.
Data: itab type table of mara with header line.
loop at imara.
move-corresponding imara to itab.
append itab.
endloop.if your itab is defined like...
data: begin of itab <b>occurs 0 </b>,
field(1) type c,
end of itab.then by default it has a header line.
Regards,
Rich Heilman
Message was edited by: Rich Heilman
‎2005 Mar 09 3:26 PM
my itab is defined like
data: begin of itab occurs 0 ,
field(1) type c,
end of itab.and when I try to append the itab, it says my syntax should be like:
APPEND fld TO itab
I'm reading up on APPEND in F1, but is APPEND similar to INSERT in SQL?
like, instead of doing
MOVE: VAL to ITAB-val.should I do:
APPEND VAL TO ITAB-VAL.?? (I require several inserts to the different fields of the itab.)
Natasha
‎2005 Mar 09 3:34 PM
if my itab contains fields name, value, catalog.
Can I do an append like:
APPEND NAME, VALUE, CATALOG TO ITAB.? If name, value, and catalog correspond are variables and correspond to the field names of the itab.
I saw something similar in F1, but it looked like it only inserted values to an itab that only had one field- basically a list. I'm going to test this now.
N L
‎2005 Mar 09 3:36 PM
You should be filling all your fields of the table structure then doing an append.
ex..
data: begin of itab occurs 0,
field1 type c,
field2 type c,
field3 type c,
end of itab.
itab-field1 = 'A'.
itab-field2 = 'B'.
itab-field3 = 'C'.
append itab.
If your internal table has no header line, then you need a work area to hold you data.
types: begin of ttab,
field1 type c,
field2 type c,
field3 type c,
end of ttab.
data: itab type table of ttab.
data: xtab type ttab.
xtab-field1 = 'A'.
xtab-field2 = 'B'.
xtab-field3 = 'C'.
append xtab to itab.
Regards,
Rich Heilman
‎2005 Mar 09 4:04 PM
the reason why my itabs were not getting populated was because I was looping at a database table.
Thanks for your help gentlemen.
N L
‎2005 Mar 09 3:25 PM
If your LOOP AT is syntactically correct, then you are
using tables with header lines.
I added a couple of lines to your code:
Loop at TableA.
Move: TABLEA-NAME TO vName.
SELECT NAME INTO tempname FROM TableB WHERE NAME=vName.
ENDSELECT.
IF SY-SUBRC <> 0.
<b>CLEAR ITAB_NAMEHOLDER.</b>
MOVE: tempname INTO ITAB_nameholder-Name.
<b>APPEND ITAB_NAMEHOLDER.</b>
ENDIF.
ENDLOOP.