cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

loop at itab

Former Member
0 Likes
1,262

Hi experts,

Iam trying to display report like this.


fld1                   fld2                     fld3
---------------------------------------------------------
WQIYDGIWEUDOIUWQL      Site Management          shorttext
                       Material Management      shorttext
                       Quality Management       shorttext
---------------------------------------------------------

The above details are in one row.

fld2 details are in one ITAB1(since many rows are there).

fld3 details are in one itab2(since many rows are there).

While iam looping the above tables, iam getting like this.


fld1                   fld2                     fld3
---------------------------------------------------------
WQIYDGIWEUDOIUWQL      Site Management          
                       Material Management      
                       Quality Management       shorttext
                                                shorttext
                                                shorttext
---------------------------------------------------------

Iam getting some space at FLD3.How can i move up that FLD3 values? Here is my code.

itab1(fld2 see above)


LOOP AT T_DET.
    LOOP AT T_LONG WHERE QMNUM = T_DET-QMNUM.
          FCOUNT = FCOUNT + 1.
          IF FCOUNT = 1.           " IF IT IS FIRST ROW
            <b>WRITE: 42(25) T_LONG-LTEXT.</b>
          ELSE.
            <b>WRITE:/42(25) T_LONG-LTEXT.</b>
          ENDIF.        
        ENDLOOP.

itab2(fild 3)


        SCOUNT = 0.
        LOOP AT ITAB WHERE QMNUM = T_DET-QMNUM.
          SCOUNT = SCOUNT + 1.
          IF SCOUNT EQ 1.
            <b>WRITE:110(80) ITAB-DESC.</b>
          ELSE.
           <b> WRITE:/110(80) ITAB-DESC.</b>
          ENDIF.          
        ENDLOOP.
 ENDLOOP.

Can any one tell me where to make changes?

reward guaranteed

kaki

View Entire Topic
Former Member
0 Likes

Hi Kaki,

Take another variable as follows, and then see my changes in BOLD below,

<b>DATA: lv_start_line TYPE i.</b>

LOOP AT T_DET.
<b>****Are you not writing some thing from this table?
****If so then fill lv_start_line here
    lv_start_line = sy-linno.</b>
    
    LOOP AT T_LONG WHERE QMNUM = T_DET-QMNUM.
          FCOUNT = FCOUNT + 1.
          IF FCOUNT = 1.           " IF IT IS FIRST ROW
            WRITE: 42(25) T_LONG-LTEXT.
<b>****You can also fill lv_start_line here if not above
            lv_start_line = sy-linno.</b>
          ELSE.
            WRITE:/42(25) T_LONG-LTEXT.
          ENDIF.        
        ENDLOOP.
 


itab2(fild 3)

        SCOUNT = 0.
        LOOP AT ITAB WHERE QMNUM = T_DET-QMNUM.
          SCOUNT = SCOUNT + 1.
          IF SCOUNT EQ 1.
<b>****Now lets go to the first line and start printing
            SKIP TO LINE lv_start_line.</b>
            WRITE:110(80) ITAB-DESC.
          ELSE.
            WRITE:/110(80) ITAB-DESC.
          ENDIF.          
        ENDLOOP.
 ENDLOOP.

Also, I wrote a small example below go through it if you have further doubts..

REPORT zsritest.

DATA: lv_cursor_line TYPE i,
      lv_count TYPE i,
      lt_numbers TYPE i OCCURS 0 WITH HEADER LINE,
      BEGIN OF lt_addition OCCURS 0,
        number TYPE i,
        result TYPE i,
      END OF lt_addition,
      lt_multiply LIKE lt_addition OCCURS 0 WITH HEADER LINE.

DO 10 TIMES.

  lt_numbers = lt_addition-number = lt_multiply-number = sy-index.
  APPEND lt_numbers.

  lt_addition-result = sy-index + 1.
  APPEND lt_addition.

  lt_addition-result = sy-index + 2.
  APPEND lt_addition.

  lt_multiply-result = sy-index * 2.
  APPEND lt_multiply.

  lt_multiply-result = sy-index * 3.
  APPEND lt_multiply.

  lt_multiply-result = sy-index * 4.
  APPEND lt_multiply.

ENDDO.

LOOP AT lt_numbers.

  WRITE: /0(10) lt_numbers.
  lv_cursor_line = sy-linno.

  lv_count = 0.
  LOOP AT lt_addition WHERE number EQ lt_numbers.
    ADD 1 TO lv_count.
    IF lv_count EQ 1.
      WRITE: 10(10) lt_addition-result.
    ELSE.
      WRITE: /10(10) lt_addition-result.
    ENDIF.
  ENDLOOP.

  lv_count = 0.
  LOOP AT lt_multiply WHERE number EQ lt_numbers.
    ADD 1 TO lv_count.
    IF lv_count EQ 1.
      SKIP TO LINE lv_cursor_line.
      WRITE: 20(10) lt_multiply-result.
    ELSE.
      WRITE: /20(10) lt_multiply-result.
    ENDIF.
  ENDLOOP.

ENDLOOP.

Hope this helps..

Sri

<b>Did this help??</b>

Message was edited by: Srikanth Pinnamaneni

Former Member
0 Likes

Hi srikanth,

when ITAB values coming up,T_LONG values are getting truncated(iam not getting all the values,except first row).I may have many values T_LONG.


LOOP AT T_DET.
        WRITE:/ SPACE, SNO,
              7(15) T_DET-QMNUM,
             19(20) T_DET-REFNUM,
             69(40) T_DET-QMTXT.

        FCOUNT = 0.
        <b>LOOP AT T_LONG WHERE QMNUM = T_DET-QMNUM.</b>
          FCOUNT = FCOUNT + 1.
          IF FCOUNT = 1.
            WRITE: 42(25) T_LONG-LTEXT.
          ELSE.
            WRITE:/42(25) T_LONG-LTEXT.
          ENDIF.
          PERFORM VLINES.
        ENDLOOP.

        FCOUNT = 0.
  <b>      LOOP AT ITAB WHERE QMNUM = T_DET-QMNUM.</b>
          FCOUNT = FCOUNT + 1.
          IF FCOUNT EQ 1.
            WRITE:110(80) ITAB-DESC.
          ELSE.
            WRITE:/110(80) ITAB-DESC.
          ENDIF.
          PERFORM VLINES.
        ENDLOOP.
ENDLOOP.

<b></b>

Former Member
0 Likes

Hi,

What is in PERFORM VLINES. ? Also did you check and apply the logic from my previous post?

Give your complete code here so that we can go through it.

Also you can proceed according to Amit's suggestion and merge the data into an output table and then write to the list using that table..

Hope this helps..

Sri

jayanthi_jayaraman
Active Contributor
0 Likes

Hi,

Try this sample code and kindly reward points if it helps.

itab1[] = itab[].

LOOP AT T_DET.

WRITE:/ SPACE, SNO,

7(15) T_DET-QMNUM,

19(20) T_DET-REFNUM,

69(40) T_DET-QMTXT.

FCOUNT = 0.

LOOP AT T_LONG WHERE QMNUM = T_DET-QMNUM.

FCOUNT = FCOUNT + 1.

IF FCOUNT = 1.

WRITE 42(25) T_LONG-LTEXT.

read table ITAB1 with key QMNUM = T_DET-QMNUM.

if sy-subrc eq 0.

WRITE 110(80) ITAB-DESC.

delete itab1 where qmnum = t_det-qmnum

<b>and desc = itab1-desc</b>.

endif.

ELSE.

WRITE:/42(25) T_LONG-LTEXT.

read table ITAB1 with key QMNUM = T_DET-QMNUM.

if sy-subrc eq 0.

WRITE 110(80) ITAB-DESC.

delete itab1 where qmnum = t_det-qmnum

<b>desc = itab1-desc.</b> endif.

ENDIF.

PERFORM VLINES.

ENDLOOP.

ENDLOOP.

Message was edited by: Jayanthi Jayaraman

Former Member
0 Likes

Hi Jayanthi,

This code is working fine.But it is reading only first record in the ITAB(WA).


 ITAB1[] = ITAB[].
LOOP AT T_DET.
        WRITE:/ SPACE, SNO,
              7(15) T_DET-QMNUM,
             19(20) T_DET-REFNUM,
             69(40) T_DET-QMTXT.



        FCOUNT = 0.
        LOOP AT T_LONG WHERE QMNUM = T_DET-QMNUM.
          FCOUNT = FCOUNT + 1.
          IF FCOUNT = 1.
            WRITE 42(25) T_LONG-LTEXT.
            READ TABLE ITAB1 INTO WA WITH KEY QMNUM = T_DET-QMNUM.
            IF SY-SUBRC EQ 0.
              <b>WRITE 110(80) WA-DESC.</b>
              DELETE ITAB1 WHERE QMNUM = T_DET-QMNUM.
            ENDIF.
          ELSE.
            WRITE:/42(25) T_LONG-LTEXT.
            READ TABLE ITAB1 INTO WA WITH KEY QMNUM = T_DET-QMNUM.
            IF SY-SUBRC EQ 0.
              <b>WRITE:/110(80) WA-DESC.</b>
              DELETE ITAB1 WHERE QMNUM = T_DET-QMNUM.
            ENDIF.
          ENDIF.
          PERFORM VLINES.
        ENDLOOP.

jayanthi_jayaraman
Active Contributor
0 Likes

Hi,

Here is the updated code.Check it.You missed the AND in delete statements.

itab1[] = itab[].

LOOP AT T_DET.

WRITE:/ SPACE, SNO,

7(15) T_DET-QMNUM,

19(20) T_DET-REFNUM,

69(40) T_DET-QMTXT.

FCOUNT = 0.

LOOP AT T_LONG WHERE QMNUM = T_DET-QMNUM.

FCOUNT = FCOUNT + 1.

IF FCOUNT = 1.

WRITE 42(25) T_LONG-LTEXT.

read table ITAB1 with key QMNUM = T_DET-QMNUM.

if sy-subrc eq 0.

WRITE 110(80) ITAB-DESC.

delete itab1 where <b>qmnum = t_det-qmnum</b><b>and desc = itab1-desc.</b>

endif.

ELSE.

WRITE:/42(25) T_LONG-LTEXT.

read table ITAB1 with key QMNUM = T_DET-QMNUM.

if sy-subrc eq 0.

WRITE 110(80) ITAB-DESC.

delete itab1 where <b>qmnum = t_det-qmnum

and desc = itab1-desc</b>.

endif.

ENDIF.

PERFORM VLINES.

ENDLOOP.

ENDLOOP.

Former Member
0 Likes

Hi Jayanthi & Wenceslaus G

Thanks a lot.

Full points alloted

kaki