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

Insert statement in to internal table

Former Member
0 Likes
614

I have an editable ALV LIST report with the check box to it. When the user checks the check box on the report and hits a push Button it should copy the row from the internal table and insert the row to the same internal table in the next line.

I had my code in this way,

    WHEN 'COPY'.
      LOOP AT t_output INTO wa_output.
        IF wa_output-chkbox = 'X'.
          wa_output-zactual = 0.
          wa_output-zqty = 0.
          INSERT wa_output INTO t_output INDEX sy-tabix.
        ENDIF.
      ENDLOOP.

However the problem was,

For e.g. let say I have only 3 rows in the internal table. So when the user selects the last, 3rd row and hits the push button the 3rd row copied and is inserted in the 3rd row. The user wanted the copied row in the next row, ie the 4th row.

SO I changed the above code as below and now it goes to an endless loop.

    WHEN 'COPY'.
      LOOP AT t_output INTO wa_output.
        IF wa_output-chkbox = 'X'.
          wa_output-zactual = 0.
          wa_output-zqty = 0.
          Sy-tabix = sy-tabix + 1.
          INSERT wa_output INTO t_output INDEX sy-tabix.
        ENDIF.
      ENDLOOP.

<b>I dont want to use another internal table.</b>

I hope I am clear.

Please suggest,

Ster.

1 ACCEPTED SOLUTION
Read only

suresh_datti
Active Contributor
0 Likes
583

try the following..


data :w_indx like sy-tabix.

WHEN 'COPY'.
      LOOP AT t_output INTO wa_output
                         where chkbox = 'X'
                            and zactual = 0
                            and zqty = 0.
         if w_indx ne sy-tabix.
          w_indx = sy-tabix + 1.
          INSERT wa_output INTO t_output INDEX w_indx.
        ENDIF.
      ENDLOOP.

~Suresh

5 REPLIES 5
Read only

suresh_datti
Active Contributor
0 Likes
584

try the following..


data :w_indx like sy-tabix.

WHEN 'COPY'.
      LOOP AT t_output INTO wa_output
                         where chkbox = 'X'
                            and zactual = 0
                            and zqty = 0.
         if w_indx ne sy-tabix.
          w_indx = sy-tabix + 1.
          INSERT wa_output INTO t_output INDEX w_indx.
        ENDIF.
      ENDLOOP.

~Suresh

Read only

0 Likes
583

Thanks Suresh.

Shreekant

Read only

Former Member
0 Likes
583

Declare one variable like

data : v_tabix like sy-tabix.

WHEN 'COPY'.

LOOP AT t_output INTO wa_output.

IF wa_output-chkbox = 'X'.

wa_output-zactual = 0.

wa_output-zqty = 0.

clear v_tabix.

v_tabix = sy-tabix + 1.

INSERT wa_output INTO t_output INDEX V-tabix.

ENDIF.

ENDLOOP.

See the output and let me know the status

Thanks

Seshu

Read only

0 Likes
583

Thanks Everyone.

Problem Solved.

Shreekant

Read only

Former Member
0 Likes
583

Hi,

Change the code as follows.

  data: lv_cnt type i.
     
    describe table t_output lines lv_cnt.
     LOOP AT t_output INTO wa_output where wa_output-chkbox = 'X'           
                                                            and  wa_output-zactual = 0
                                                            and  wa_output-zqty = 0.
          lv_cnt = lv_cnt + 1.
          INSERT wa_output INTO t_output INDEX lv_cnt.
      ENDLOOP.

Regards

Sailaja.