08-17-2005 5:51 AM
Hi,
I have an internal tables with 5 fields each of type Char - L1 L2 L3 L4 L5.
I have to make the first occurance of 0 after a non zero value as 1.
Example: if i have the values as 1 0 0 0 0, it s'd be made 1 1 0 0 0.
If 1 1 0 0 0 it s'd be made 1 1 1 0 0.
If 0 1 0 0 0 then it should be made 0 1 1 0 0.
If i try this using nested IF statements the code becomes more complex.. Is there any other way out.. like using string operations??
Regards,
Pradhiba
08-17-2005 5:59 AM
08-17-2005 5:59 AM
08-17-2005 7:42 AM
Hi,
The following code will do:
field-symbols:
<field1>,
<field2>.
Loop at inttab
into line_of_inttab.
do 4 times.
assign component syst-index of structure line_of_inttab
to <field1>.
zzl_next_index = syst-index + 1.
assign component zzl_next_index of structure line_of_inttab
to <field2>.
if <field1> NE '0' and
<field2> EQ '0'.
<field2> = '1'.
exit.
endif.
enddo.
modify inttab
from line_of_inttab.
endloop.
Regards,
John.
08-17-2005 8:05 AM
Pradhiba,
You try the following code:
DATA: BEGIN OF tbl_table1 OCCURS 0,
f1 TYPE n,
f2 TYPE n,
f3 TYPE n,
f4 TYPE n,
f5 TYPE n,
END OF tbl_table1.
DATA: g_index LIKE sy-tabix,
g_found TYPE c.
FIELD-SYMBOLS: <fs> TYPE n.
START-OF-SELECTION.
CLEAR tbl_table1.
tbl_table1-f2 = 1.
APPEND tbl_table1.
LOOP AT tbl_table1.
CLEAR: g_index,
g_found.
DO.
ADD 1 TO g_index.
ASSIGN COMPONENT g_index OF STRUCTURE tbl_table1 TO <fs>.
IF sy-subrc NE 0.
EXIT.
ENDIF.
* Was there a 1 in the previous field?
IF g_found = 'X'.
* Yes! Previous field was a 1, now make current field a 1 clear the
* G_FOUND flag and CONTINUE to next field
<fs> = 1.
CLEAR g_found.
CONTINUE.
ENDIF.
* Current field is a 1, mark the G_FOUND flag!
IF <fs> = 1.
g_found = 'X'.
ENDIF.
ENDDO.
MODIFY tbl_table1.
ENDLOOP.
END-OF-SELECTION.
LOOP AT tbl_table1.
WRITE:/ tbl_table1-f1, tbl_table1-f2, tbl_table1-f3, tbl_table1-f4,
tbl_table1-f5.
ENDLOOP.
Cheers,
Pat
08-17-2005 8:29 AM
08-17-2005 10:41 AM
Hi Pradhiba ,
why did you reward me?
-i've nothing written
->but now , i think , i've a solution:
REPORT zforum46 .
DATA: BEGIN OF itab ,
f1, f2, f3, f4, f5,
END OF itab.
DATA pos_1 TYPE sy-fdpos.
itab = '01100'.
SEARCH itab FOR '10'."
MOVE sy-fdpos TO pos_1.
ADD 1 TO pos_1.
MOVE '1' TO itab+pos_1(1).
WRITE: / itab.
best regards Andreas