‎2007 May 08 7:38 PM
Hi ,
I have an itab with fields f1,f2,f3 and f4.
I have the values as below:
itab-row1 = 101 US de91 peter
itab-row2 = 101 US de92 cathy
I must show the output like this ..
101
US
<item>
de91
peter
</item>
<item>
de92
cathy
</item>
I can do this code to just put all the rows:
loop at itab.
write 😕 itab-f1.
write 😕 itab-f2.
write 😕 itab-f3.
write 😕 itab-f4.
endloop.
But how can do the above output to avoid the f1 & f2.
Please tell me the logic how I can do this
Thanks in advance.
Message was edited by:
ramana peddu
‎2007 May 09 8:17 PM
Hi,
Please try this.
DATA: WA_ITAB LIKE ITAB.
SORT ITAB.
LOOP AT ITAB INTO WA_ITAB.
AT NEW f1.
WRITE: / WA_ITAB-F1,
/ WA_ITAB-F2.
ENDAT.
WRITE: / WA_ITAB-F3,
/ WA_ITAB-F4.
ENDLOOP.
Regards,
Ferry Lianto
‎2007 May 08 8:18 PM
You can use something like this:
LOOP AT ITAB.
AT NEW f1.
WRITE: / itab-f1,
/ itab-f2.
ENDAT.
WRITE: / itab-f3,
/ itab-f4.
ENDLOOP.
This should only write out the field 1 and field 2 values when field 1 changes.
- April King
‎2007 May 09 8:11 PM
When I do this ...
the data in the itab is like this ..whenever it crosses the line AT NEW f1.
itab-f1 = 101.
itab-f2 = ***.
itab-f3 = ***.
itab-f4 = ***.
Anyone please help me ASAP
‎2007 May 09 8:14 PM
Small correction to April Kings code.
LOOP AT ITAB.
AT NEW f1.
read table itab index sy-index.
if sy-subrc = 0.
WRITE: / itab-f1,
/ itab-f2.
ENDAT.
WRITE: / itab-f3,
/ itab-f4.
endif.
endat.
ENDLOOP.
‎2007 May 09 8:17 PM
Okay. You could try saving the field 1 and field 2 data in comparison fields instead of using the AT NEW. Like this:
data: save_field1 TYPE field1,
save_field2 TYPE field2.
LOOP AT itab.
IF itab-field1 <> save_field1.
WRITE: / itab-field1.
MOVE itab-field1 TO save_field1.
ENDIF.
IF itab-field2 <> save_field2.
WRITE: / itab-field2.
MOVE itab-field2 TO save_field2.
ENDIF.
WRITE: / itab-field3,
/ itab-field4.
ENDLOOP.
- April King
‎2007 May 09 8:17 PM
Hi,
Please try this.
DATA: WA_ITAB LIKE ITAB.
SORT ITAB.
LOOP AT ITAB INTO WA_ITAB.
AT NEW f1.
WRITE: / WA_ITAB-F1,
/ WA_ITAB-F2.
ENDAT.
WRITE: / WA_ITAB-F3,
/ WA_ITAB-F4.
ENDLOOP.
Regards,
Ferry Lianto
‎2007 May 11 12:43 AM
When I do this ...
the data in the itab is like this ..whenever it crosses the line AT NEW f1.
wa_itab-f1 = 101.
wa_itab-f2 = ***.
wa_itab-f3 = ***.
wa_itab-f4 = ***.
Anyone please help me ASAP
‎2007 May 11 1:24 AM
Hi ramana,
Did you see my reply?
YOu have to read the table again once you come into the at new block.
LOOP AT ITAB.
AT NEW f1.
read table itab index sy-index.
if sy-subrc = 0.
WRITE: / itab-f1,
...........
.
WRITE: / itab-f3,
/ itab-f4.
endif.
endat.
ENDLOOP.
‎2007 May 09 8:30 PM
Try using this code.
DATA: w_itab LIKE itab.
SORT itab BY f1 f2.
LOOP AT itab INTO w_itab.
AT NEW f2.
WRITE:/2 w_itab-f1.
WRITE:/2 w_itab-f2.
ENDAT.
SKIP 1.
WRITE:/2 w_itab-f3.
WRITE:/2 w_itab-f4.
ENDLOOP.