Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Internal Table Manipulation

Former Member
0 Likes
830

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
752

did u tried CP.

can you pls post your code here

regards

5 REPLIES 5
Read only

Former Member
0 Likes
753

did u tried CP.

can you pls post your code here

regards

Read only

Former Member
0 Likes
752

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.

Read only

former_member221770
Contributor
0 Likes
752

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

Read only

andreas_mann3
Active Contributor
0 Likes
752

.

Read only

andreas_mann3
Active Contributor
0 Likes
752

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