‎2010 Feb 11 3:28 AM
Hi ,
My internal table is like this
ANL DAT CNT
4000001507 20070612
4000001507 20070602
4000001507 20070523
4000001506 20070602
4000001506 20070523
4000001501 20070612
4000001501 20070511
4000001501 20070412
4000001501 20070313
I want to output as
CNT
4000001507 20070612 1
4000001507 20070602 2
4000001507 20070523 3
4000001506 20070602 1
4000001506 20070523 2
4000001501 20070612 1
4000001501 20070511 2
4000001501 20070412 3
4000001501 20070313 4
I want to increment cnt.
I written code as
but not working
loop at lt_erdz into asdf.
at new anl.
cnt = cnt + 1.
asdf-cnt = cnt.
modify lt_erdz from asdf transporting cnt.
endat.
clear asdf-cnt.
endloop.
Thanks,
Asha
‎2010 Feb 11 6:12 AM
Hello Asha,
Check out the code below. Have a look at the loop statement. I think this works fine as per your requirement.
TYPES: BEGIN OF tab1,
f1 type i,
f2 TYPE i,
f3 type i,
END OF tab1.
DATA: it1 TYPE TABLE OF tab1,
wa1 TYPE tab1.
START-OF-SELECTION.
wa1-f1 = 10. "SAMPLE DATA
wa1-f2 = 1.
append wa1 to it1.
wa1-f1 = 10.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 10.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 20.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 20.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 30.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 30.
wa1-f2 = 2.
append wa1 to it1.
START-OF-SELECTION.
DATA: count TYPE i.
loop at it1 INTO wa1.
on CHANGE OF wa1-f1.
count = 1.
endon.
wa1-f3 = count.
modify it1 INDEX sy-tabix FROM wa1 TRANSPORTING f3.
count = count + 1.
ENDLOOP.
‎2010 Feb 11 3:44 AM
Hello,
Please try the following
sort lt_erdz by anl.
loop at lt_erdz into asdf.
at new anl.
cnt = 1
endat..
asdf-cnt = cnt.
modify lt_erdz from asdf transporting cnt.
clear asdf-cnt.
cnt = cnt + 1.
endloop.
Hope this helps.
Regards,
Sachin
‎2010 Feb 11 3:45 AM
Hi,
You can try this way. Declare a variable with data type of field ANL called v_anl.
cnt = 0.
loop at lt_erdz into asdf.
if sy-tabix > 1.
read table lt_erdz into wa_erdz "with index 'sy-tabix -1'.
if sy-subrc eq 0.
v_anl = wa_erdz-anl.
endif.
if asdf-anl = v_anl.
cnt = cnt + 1.
asdf-cnt = cnt.
modify lt_erdz from asdf transporting cnt.
else.
cnt = 1.
endif.
else.
cnt = 1.
asdf-cnt = cnt.
modify lt_erdz from asdf transporting cnt.
endif.
endloop.It will definitely work.
Thanks,
Archana
Edited by: Archana Pawar on Feb 11, 2010 4:46 AM
Edited by: Archana Pawar on Feb 11, 2010 5:31 AM
‎2010 Feb 11 4:06 AM
Hi,
Try with this code. Hope this helps.
data temp_ANL type ANL.
sort lt_erdz by anl DAT.
loop at lt_erdz into asdf.
if temp_ANL = asdf-ANL.
asdf-cnt = asdf-cnt + 1.
else.
asdf-cnt = 1.
endif.
temp_ANL = asdf-ANL.
modify lt_erdz from asdf transporting cnt.
clear asdf-cnt.
endloop.
Thanks and Regards,
Daz.
‎2010 Feb 11 4:07 AM
TRY THIS CODE.. YOUR PROBLEM WILL GET SOLVED..
report ZTEST_S1.
DATA : STR TYPE STRING,TEMP_STR TYPE STRING.
DATA : BEGIN OF MATRL OCCURS 10,
DES(10),
NO TYPE I,
END OF MATRL.
DATA IT_MATRL LIKE MATRL OCCURS 10.
DATA I TYPE I VALUE 1.
DATA : WA_MATRL LIKE LINE OF MATRL, FIRST_FLAG(1), NEW_FLAG.
WA_MATRL-NO = 0001.
WA_MATRL-DES = 'MAT1'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0002.
WA_MATRL-DES = 'MAT1'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0003.
WA_MATRL-DES = 'MAT1'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0004.
WA_MATRL-DES = 'MAT2'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0004.
WA_MATRL-DES = 'MAT2'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0004.
WA_MATRL-DES = 'MAT2'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0004.
WA_MATRL-DES = 'MAT2'.
APPEND WA_MATRL TO MATRL.
WA_MATRL-NO = 0004.
WA_MATRL-DES = 'MAT2'.
APPEND WA_MATRL TO MATRL.
LOOP AT MATRL INTO WA_MATRL.
AT NEW DES.
I = 1.
NEW_FLAG = 1.
ENDAT.
IF NEW_FLAG EQ 1.
WA_MATRL-NO = 1.
ENDIF.
IF NEW_FLAG NE 1.
I = I + 1.
WA_MATRL-NO = I.
ENDIF.
CLEAR NEW_FLAG.
APPEND WA_MATRL TO IT_MATRL.
ENDLOOP.
LOOP AT IT_MATRL INTO WA_MATRL.
WRITE: WA_MATRL-DES,WA_MATRL-NO.
WRITE /.
ENDLOOP.Regards,
Sumit
‎2010 Feb 11 4:37 AM
Hi,
From the way I interpreted ur problem,
I think modifications u need to make is in
Modify statement we have to use TABLE with the statement that is, (Considering the fact that IT_ERDZ is an internal table.)
instead of
modify lt_erdz from asdf transporting cnt.
u have to add
modify table lt_erdz from asdf transporting cnt.
Check F1 help incase of doubt.
Also set CNT to 0 after ENDAT.
I think this will solve ur problem...
‎2010 Feb 11 6:12 AM
Hello Asha,
Check out the code below. Have a look at the loop statement. I think this works fine as per your requirement.
TYPES: BEGIN OF tab1,
f1 type i,
f2 TYPE i,
f3 type i,
END OF tab1.
DATA: it1 TYPE TABLE OF tab1,
wa1 TYPE tab1.
START-OF-SELECTION.
wa1-f1 = 10. "SAMPLE DATA
wa1-f2 = 1.
append wa1 to it1.
wa1-f1 = 10.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 10.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 20.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 20.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 30.
wa1-f2 = 2.
append wa1 to it1.
wa1-f1 = 30.
wa1-f2 = 2.
append wa1 to it1.
START-OF-SELECTION.
DATA: count TYPE i.
loop at it1 INTO wa1.
on CHANGE OF wa1-f1.
count = 1.
endon.
wa1-f3 = count.
modify it1 INDEX sy-tabix FROM wa1 TRANSPORTING f3.
count = count + 1.
ENDLOOP.
‎2010 Feb 11 6:24 AM
HI Asha,
" The Simplest solution is Like this.
Take a Temp Internal table like your Main Table.
Suppose
Data : main_tab TYPE STANDARD TABLE OF VBAK WITH HEADER LINE.
data : temp_tab like main_tab. " Create this one.
temp_tab[] = main_tab[]. Pass the contents to tempTab.
sort temp_tab by vbeln ascending " Sort it
delete adjacent duplicates from temp_Tab comparing vbeln.
now
loop at temp_tab.
Clear count " You can have it here aswell
loop at main_Tab where vbeln = temp_tab-vbeln. " For Each VBELN (for your program ANL )
main_tab-count = count + 1.
modify main_tab index sy-tabix.
endloop
clear coutn. " This makes the Count Value cleared
endloop.Cheerz
Ram