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: 

SAP Script: Loop write only last record

Former Member
0 Kudos

Hi

I have been searching and searching, but haven't find anything usefull.

I have a script where I wan't to print different matnr.

From my printprogram I have an internal table with 2 entries.

When I make the print, it is allways the last entries from the internal table that are printed - in both the window for entry no 1 and in the window for entry no 2.

The code in my print program looks like this:



Code: 

  LOOP AT g_caufv_tab. 

    CASE l_count. 

      WHEN 0. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'DESCR' 
                  window  = 'TEXT'. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'BARCODE_OUT' 
                  window  = 'BARCL'. 

      WHEN 1. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'DESCR' 
                  window  = 'TEXT1'. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'BARCODE_OUT' 
                  window  = 'BARCL1'. 

      WHEN 2. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'DESCR' 
                  window  = 'TEXT2'. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'BARCODE_OUT' 
                  window  = 'BARCL2'. 

      WHEN 3. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'DESCR' 
                  window  = 'TEXT'. 

        CALL FUNCTION 'WRITE_FORM' 
             EXPORTING 
                  element = 'BARCODE_OUT' 
                  window  = 'BARCL3'. 

      WHEN OTHERS. 

    ENDCASE. 

    ADD 1 TO l_count. 

  ENDLOOP. 

When I am debugging mode (both in printprogram and Scrip) are looking at my material number, it has the right no. First time Matnr A, and then Matnr B.

Any suggestions ??!!

1 ACCEPTED SOLUTION

Former Member
0 Kudos

I think it is only possible in a main window. Can you test your code there?

4 REPLIES 4

Former Member
0 Kudos

I think it is only possible in a main window. Can you test your code there?

0 Kudos

Thanx.... that was it.

But isn't possible to do a loop in other windows, than MAIN window?

0 Kudos

Hi Lars,

If you do a loop inside a non MAIN window, it will print the values in a single line. So you will get only the last record.

Thanks

Vinod

0 Kudos

Dear Lars,

I think it is not. However I've read quite some posts about using several (more than 1) main windows. However I've no experience with this myself. Perhaps you can do a search on the forum.