Application Development 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: 

odd/even rows problem in an internal table

Former Member
0 Kudos

Hi gurus,

actual internal table data

BUZEI     FIPOS                         AMT(WRBTR)

001        00000000000003             80.00

002        00000000000003             20.00

003        10                                     80.00

004        10                                     20.00

final intrnal table

     FIPOS                         NETAMT(WRBTR)         WRBTR(DEDAMT)

     00000000000003           80.00                             20.00

     10                                   80.00                             20.00

iam using below logic

loop at it_vbsegs into ls_vbsegs.

       ls_final-fipos = ls_vbsegs-fipos.

       lv = sy-tabix mod 2.

       if lv = 0.

          ls_final-netamt = ls_ vbsegs-wrbtr.

       elseif lv = 1.

          ls_final-nedamt = ls_ vbsegs-wrbtr.

       endif.

     append ls_final to lt_final.    "if i write append here  target table like below  endloop.                                   

endloop                                                00000000000003        80.00         

                                                             00000000000003                              20.00

                                                              10                               80.00          

                                                              10                                                     20.00

pleas give me reply thanks in advance

4 REPLIES 4

praveenboss
Participant
0 Kudos

Hy Kranthi,

             Please Clear Me What data you get in internal table,

             and what your desired calculated internal table data,

             because you mention three internal tables here so i am not clearly understand your problem,

             same as you mention,

Thanks

PRAVEEN,,

Former Member
0 Kudos

Hi Kranthi,

You can change your code :


loop at it_vbsegs into ls_vbsegs.

       ls_final-fipos = ls_vbsegs-fipos.

       lv = sy-tabix mod 2.

       if lv = 0.

          ls_final-netamt = ls_ vbsegs-wrbtr.

       elseif lv = 1.

          ls_final-nedamt = ls_ vbsegs-wrbtr.

       endif.

     append ls_final to lt_final.    "if i write append here  target table like below  endloop.                                  

endloop   

To below : with if condition for the append statement


loop at it_vbsegs into ls_vbsegs.

       ls_final-fipos = ls_vbsegs-fipos.

       lv = sy-tabix mod 2.

       if lv = 0.

          ls_final-netamt = ls_ vbsegs-wrbtr.

       elseif lv = 1.

          ls_final-nedamt = ls_ vbsegs-wrbtr.

       endif.

    if ls_final-netamt is not initial and ls_final-netdamt is not initial.

   append ls_final to lt_final.   

  clear ls_final.

  endif.                                 

endloop 

Regards,

~Raj

former_member289261
Active Contributor
0 Kudos

Hi,

Use modify instead of append with transporting the value field.

e.g

       if lv = 0.

          ls_final-netamt = ls_ vbsegs-wrbtr.

          modify ls_final from lt_final transporting netamt.

       elseif lv = 1.

          ls_final-nedamt = ls_ vbsegs-wrbtr.

          modify ls_final from lt_final transporting nedamt.

       endif.

Regards,

Ashish Rawat

Former Member
0 Kudos

Hi

Using Control Break event and Modify Internal table , i hope you can achieve your requirement .

check with sample code .

TYPES : BEGIN OF TY_FINAL,

          B(15) TYPE  C,

          A(15) TYPE C,

          C(15) TYPE C,

       END OF TY_FINAL .

DATA : IT_FINAL TYPE TABLE OF TY_FINAL,

         IT_FINAL1 TYPE TABLE OF TY_FINAL,

         WA_FINAL TYPE TY_FINAL,

         WA_FINAL1 TYPE TY_FINAL.

WA_FINAL-A = '001'.

WA_FINAL-B = '00000000000003'.

WA_FINAL-= '80.00'.

APPEND WA_FINAL TO IT_FINAL.

CLEAR WA_FINAL.

WA_FINAL-A = '002'.

WA_FINAL-B = '00000000000003'.

WA_FINAL-= '30.00'.

APPEND WA_FINAL TO IT_FINAL.

CLEAR WA_FINAL.

WA_FINAL-A = '003'.

WA_FINAL-B = '10'.

WA_FINAL-= '80.00'.

APPEND WA_FINAL TO IT_FINAL.

CLEAR WA_FINAL.

WA_FINAL-A = '004'.

WA_FINAL-B = '10'.

WA_FINAL-= '20.00'.

APPEND WA_FINAL TO IT_FINAL.

CLEAR WA_FINAL.

DATA : FLAG(1) TYPE C .

SORT IT_FINAL BY B.

WRITE:/ 'Before Modification'.

LOOP AT IT_FINAL INTO WA_FINAL.

   WRITE :/ WA_FINAL-A,'||', WA_FINAL-B , '||' , WA_FINAL-C.

ENDLOOP.

SKIP.

WRITE:/ 'After Modification'.

LOOP AT IT_FINAL INTO WA_FINAL.

   MOVE WA_FINAL-C TO WA_FINAL1-B .

   AT NEW B.

     MOVE WA_FINAL-B TO WA_FINAL1-A .

     APPEND WA_FINAL1 TO IT_FINAL1 .

     MOVE 'X' TO FLAG .

   ENDAT.

   IF FLAG <> 'X'.

     READ TABLE IT_FINAL1  INTO WA_FINAL1 WITH KEY A = WA_FINAL-B.

     IF SY-SUBRC EQ '0'.

       MOVE WA_FINAL-C TO WA_FINAL1-C .

       MODIFY IT_FINAL1 FROM WA_FINAL1 TRANSPORTING C WHERE A = WA_FINAL-B.

     ENDIF.

   ENDIF.

   CLEAR : FLAG .

ENDLOOP.

LOOP AT IT_FINAL1 INTO WA_FINAL1.

   WRITE :/ WA_FINAL1-A,'||', WA_FINAL1-B , '||' , WA_FINAL1-C.

ENDLOOP.




Out Put :


Regard's

Smruti