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: 

Why does it print only the last value?

friendlycoder
Participant
0 Kudos

Hi all

I am looping through an internal table in abap programm and print the value from the table out on the sap script form.

data: begin of gt_addr occurs 0,
text TYPE text50.
data: end of gt_addr.

form print_addr USING pf_ADRNR Type AD_ADDRNUM.
 data ls_addr_s LIKE LINE OF gt_addr.
 data(lo_addr) = new ZCL_ADDR_CREATOR( iv_addr = pf_adrnr ).
 data(lt_addr) = lo_addr->format( ).
 REFRESH gt_addr.
 LOOP AT lt_addr REFERENCE INTO data(ls_addr).
 ls_addr_s-text = conv text50( ls_addr->text ).
 append ls_addr_s to gt_addr.
 ENDLOOP.
 LOOP AT gt_addr.
 call function 'WRITE_FORM'
 exporting
 element = 'CUSTOMER_ADDR'
 window = 'KADR_B'
 function = 'APPEND'
 exceptions
 element = 1
 window = 2.
 if sy-subrc ne 0.
 perform protocol_update.
 endif.
 ENDLOOP.
ENDFORM.

The problem is, it is printing the last value, instead all values from the table:

What am I doing wrong?

Thanks

13 REPLIES 13

Florian
Active Contributor
0 Kudos

because you may have a problem in your class

ZCL_ADDR_CREATOR

I guess 🙂

0 Kudos

First of all, thanks for your help.

I think not, here is the content of the table:

Thanks

0 Kudos

It is even loop correctly and the value changes every time. But the output is always the last line of the table.

And on SapScript:

Florian
Active Contributor

Then your window is too small. It looks like you just have one line in your window, so it's overwritten by the next line over and over again.

You can test it, when you just delete the last line of your table and see if then "Seestrasse..."

0 Kudos

No, the window is not too small, look above, how it prints out on formular.

It prints 5 times of:

8820 Zuerich

Florian
Active Contributor
0 Kudos

Ok... you need to share more details about your form to get help.

By the way, it's also not nice to downvote answers which just try to help you.. but that is only a sidenote.

0 Kudos

I thought votes were to address the quality of the question/answer, not to encourage/discourage people. It's a personal vote, even if the vote is not justified nobody should go against that liberty (so many people ask "who dared downvoting me", no need to be over-sensitive).

Florian
Active Contributor

Hi sandra.rossi , absolutely agree with you... I just tried to do it an other way this time and didn't comment with all my question in mind, because of this seem to "scare" some people. So I felt like it's not ok to downvote the answer, just because of adding additional information at that moment... but yes, no need to discuss it further and thanks for the hint 😉

Sandra_Rossi
Active Contributor

Maybe it stores temporarily a reference to the global variable. Maybe an explanation in the documentation : "All other window are processed after the main window. The system first gathers all output directed to them. It stores the text lines to be output in the ITF format; it does not format them at the moment when the function modules WRITE_FORM or WRITE_FORM_LINES are called. Only if the main window triggers a page break does the system format the texts in the other windows and places them in the output queue. This is of special importance when you use variables. They are replaced with the values valid after processing the main window."

Workaround: use WRITE_FORM_LINES (and you don't need to use &...& in your SAPscript).

0 Kudos

For information, I reproduced your issue and could solve with WRITE_FORM_LINES.

p244500
Active Contributor
0 Kudos

Hi,

can you remove the function from your FM and try.

CALL FUNCTION 'WRITE_FORM'
    EXPORTING
      element = 'CUSTOMER_ADDR'
      window  = 'KADR_B'
    EXCEPTIONS
      element = 1
      window  = 2.

DoanManhQuynh
Active Contributor
0 Kudos

I thought your sapscript format should be IL (item line) instead of UA. anw, you could check the demo RSTXEXP2

Sandra_Rossi
Active Contributor
0 Kudos

Quynh Doan Manh Why is it a problem to choose one format or another? Paragraph formats can be defined freely, they can be different in every SAPscript form (UA or IL might not exist in lots of forms). Anyway, formats don't change the values.