‎2008 Nov 11 10:40 AM
hi
i have a loop of 10 records.
now within that loop, I want to copy some values of the second record to the first record, then 3rd record to 2nd record etc
How can I do it?
‎2008 Nov 11 10:51 AM
Hi Anjali,
Just check the below code,
data : begin of itab occurs 0,
name(10),
des(10),
end of itab.
data : num type i .
itab-name = 'salman'.
itab-des = 'khan'.
append itab.
itab-name = 'Sharuk'.
itab-des = 'Raj'.
append itab.
itab-name = 'akshay'.
itab-des = 'kumar'.
append itab.
loop at itab.
num = sy-tabix - 1.
if num is not initial.
modify itab index num transporting des .
endif.
endloop.
regards
kumar M
‎2008 Nov 11 10:51 AM
Hi Anjali,
Just check the below code,
data : begin of itab occurs 0,
name(10),
des(10),
end of itab.
data : num type i .
itab-name = 'salman'.
itab-des = 'khan'.
append itab.
itab-name = 'Sharuk'.
itab-des = 'Raj'.
append itab.
itab-name = 'akshay'.
itab-des = 'kumar'.
append itab.
loop at itab.
num = sy-tabix - 1.
if num is not initial.
modify itab index num transporting des .
endif.
endloop.
regards
kumar M
‎2008 Nov 11 11:03 AM
hi,
Try this.
itab[] = jtab[].
loop at jtab into wa_jtab.
if v_variable is initial.
v_variable = sy-tabix + 1.
else.
modify itab from wa_jtab index sy-tabix .
endif.
endloop.
Thanks
Rk
‎2008 Nov 11 11:10 AM
loop at itab into wa_itab.
if wa_itab1 ne wa_itab and ind gt 0.
wa_itab2 = wa_itab1.
....keep the values which u want from wa_itab in wa_itab2.
modify itab from wa_itab2 index ind.
endif.
wa_itab1 = wa_itab.
ind = ind + 1.
endloop.
‎2008 Nov 11 11:31 AM
You have to create another table like the table given thru which you want to loop. Now for each step you have to store the record in the 2nd table. Copy that value there in the next step. Then do the next. In this way after doing 10 steps, copy the value of the 2nd table to 1st table.
Regards,
Subhasish
‎2008 Nov 11 11:33 AM
Hi Sia,
Check out the sample code for your requirement.
REPORT zcc_test .
data: count type i value 0.
types:begin of t_itab,
matnr type mara-matnr,
werks type marc-werks,
end of t_itab.
data: v_tabix type sy-tabix.
data: itab type standard table of t_itab with header line.
data: ifinal type standard table of t_itab with header line.
data: watab type t_itab.
do 10 times.
count = count + 1.
itab-matnr = count.
itab-werks = 'werk'.
append itab.
enddo.
write:/.
loop at itab.
write:/ itab-matnr , itab-werks.
endloop.
ifinal[] = itab[].
loop at itab.
v_tabix = sy-tabix.
if v_tabix > 1.
v_tabix = v_tabix - 1.
read table ifinal index v_tabix.
if sy-subrc = 0.
itab-werks = 'XXXX'.
v_tabix = v_tabix + 1.
modify itab index v_tabix transporting werks .
endif.
endif.
endloop.
loop at itab.
write:/ itab-matnr , itab-werks.
endloop.
Thanks,
Chidanand
‎2008 Nov 11 11:46 AM
Hi Sia Anjali,
Say you have a SELECT statement which brings the records from the table to the internal table and now you want to manipulate these records.
As per your requirement you want to move the 2nd records to 1st, 3rd to 2nd and so on.
For this try this code:-
I have taken a Z table for employee and then manipulating the internal table as per your query.
TABLES : ZTG_EMP.
TYPES : BEGIN OF EMPLOYEE,
EMPNO LIKE ZTG_EMP-EMPNO,
FIRST_NAME LIKE ZTG_EMP-FIRST_NAME,
LAST_NAME LIKE ZTG_EMP-LAST_NAME,
END OF EMPLOYEE.
DATA : EMPTAB TYPE STANDARD TABLE OF EMPLOYEE INITIAL SIZE 10 WITH HEADER LINE,
A TYPE I,
B LIKE A.
INITIALIZATION.
A = 2.
B = 1.
START-OF-SELECTION.
SELECT * FROM ZTG_EMP INTO CORRESPONDING FIELDS OF TABLE EMPTAB.
LOOP AT EMPTAB.
READ TABLE EMPTAB INDEX A.
MODIFY EMPTAB INDEX B.
A = A + 1.
B = B + 1.
ENDLOOP.
END-OF-SELECTION.
ULINE.
WRITE : /1 'Emp ID' COLOR COL_GROUP, 12 'First Name' COLOR COL_GROUP, 38 'Last Name' COLOR COL_GROUP.
ULINE.
LOOP AT EMPTAB.
WRITE : /1 EMPTAB-EMPNO, 12 EMPTAB-FIRST_NAME, 38 EMPTAB-LAST_NAME.
ENDLOOP.
ULINE.
Hope this solves your problem.
Thanks & Regards.
Tarun Gambhir.