‎2007 Dec 05 11:48 AM
Hi
I have an internal table <b>itab</b> ,populated with data.It has a field named "Description".I want to <b>insert</b> a blank line when ever the length of the value in "Description" exceeds 15 characters.Insertion shud be done just after that perticular line and not at the end of internal table.Please suggest hw to go for this
Regards
Rudra
‎2007 Dec 05 11:55 AM
Hi,
pls follow the below code.
data:
l_len type i,
l_index like sy-index.
loop at itab.
l_len = strlen(itab-description).
if l_len > 15.
l_index = sy-index + 1.
clear itab-description.
insert itab index l_index.
endif.
clear itab.
endloop.
reward if it is helpful.
thanks,
sreeram.
‎2007 Dec 05 11:51 AM
It will be somewhat like this -
loop at itab.
vlen = strlen(itab-desc).
if vlen > 15 .
itab-desc = ' '.
modify itab transporting desc.
endif.
endloop.
‎2007 Dec 05 11:53 AM
oh thats quite easy.
dont modify your itab, but build a new one.
data: lv_len type i.
loop at itab.
append itab to itab2.
lv_len = strlen( itab-description ).
if lv:len gt 15.
clear itab.
append itab to itab2.
endif.
endloop.in itab2 all should be like you wanted.
Message was edited by:
Florian Kemmer
‎2007 Dec 05 11:53 AM
loop at itab into wa.
v_len = strlen(wa-description).
if v_len gt 15.
clear wa.
append wa to itab.
endif.
endloop.
‎2007 Dec 05 11:55 AM
Hi,
pls follow the below code.
data:
l_len type i,
l_index like sy-index.
loop at itab.
l_len = strlen(itab-description).
if l_len > 15.
l_index = sy-index + 1.
clear itab-description.
insert itab index l_index.
endif.
clear itab.
endloop.
reward if it is helpful.
thanks,
sreeram.
‎2007 Dec 05 12:01 PM
Hi,
see this example.
it will output as 3.
one initial row and two filled rows.
data:itab like mara occurs 0 WITH HEADER LINE.
data:len(2).
itab-matnr = 'abcd'.
perform test.
itab-matnr = 'abcdefg'.
perform test.
itab-matnr = 'xabcd'.
perform test.
DESCRIBE TABLE itab LINES sy-tfill.
write:/ sy-tfill.
form test.
len = strlen( itab-matnr ).
if len > 5.
APPEND INITIAL LINE TO itab.
else.
APPEND itab.
endif.
ENDFORM.
rgds,
bharat.
‎2007 Dec 05 12:26 PM
Hi Rudra,
Check this code.
DATA : BEGIN OF ITAB1 OCCURS 10,
DESC(25),
END OF ITAB1.
DATA : ITAB2 LIKE TABLE OF ITAB1 WITH HEADER LINE.
DATA : LEN TYPE I.
DO 3 TIMES.
ITAB1-DESC = 'Less than 15'.
APPEND ITAB1.
ITAB1-DESC = 'Greater than 15 chars'.
APPEND ITAB1.
ENDDO.
<b>LOOP AT ITAB1.
APPEND ITAB1 TO ITAB2.
LEN = STRLEN( ITAB1-DESC ).
CLEAR ITAB1.
IF LEN GT 15.
APPEND ITAB1 TO ITAB2.
ENDIF.
ENDLOOP.</b>
WRITE 'ITAB1 RECORDS'.
LOOP AT ITAB1.
WRITE : / SY-TABIX, ITAB1-DESC.
ENDLOOP.
SKIP 2.
WRITE 'ITAB2 RECORDS'.
LOOP AT ITAB2.
WRITE : / SY-TABIX, ITAB2-DESC.
ENDLOOP.
Output:
ITAB1 RECORDS
1 Less than 15
2 Greater than 15 chars
3 Less than 15
4 Greater than 15 chars
5 Less than 15
6 Greater than 15 chars
ITAB2 RECORDS
1 Less than 15
2 Greater than 15 chars
3
4 Less than 15
5 Greater than 15 chars
6
7 Less than 15
8 Greater than 15 chars
9
Regards,
Vijay
‎2007 Dec 06 5:08 AM
hi try this.
data ind type i.
itab_temp[] = itab[].
loop at itab.
if itab-desc > 15.
ind = sy-tabix + 1.
insert intial line into itab_temp[] index ind.
clear ind.
endif.
endloop.
free itab.
itab[] = itab_temp[].
hope this helps.