12-15-2017 1:30 PM
Hi all,
I have a problem with my code. As for me there is definitely something wrong in ABAP, but I'm not quite sure which behaviour is the buggy one.
Here's the code:
DATA:
gv_offset TYPE i,
gt_text TYPE STANDARD TABLE OF tline.
DATA(gv_text) = 'Text Text Text' && cl_abap_char_utilities=>cr_lf && cl_abap_char_utilities=>cr_lf
&& 'Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text Text'.
SPLIT gv_text AT cl_abap_char_utilities=>cr_lf INTO TABLE DATA(gt_split_result).
LOOP AT gt_split_result ASSIGNING FIELD-SYMBOL(<wa_split_result>).
CLEAR: gv_offset.
DO.
APPEND VALUE #( tdformat = COND #( WHEN sy-index EQ 1 THEN '*' ) tdline = <wa_split_result>+gv_offset ) TO gt_text.
IF strlen( <wa_split_result>+gv_offset ) LE 132.
EXIT.
ENDIF.
gv_offset = gv_offset + 132.
ENDDO.
ENDLOOP.
What I would like to achive, is to split the text at every line break and then split it further in blocks of at most 132 characters each, whereas for each new line the special format character (*) should be set.
What I get is this:
By the 4th APPEND the value in gv_offset is not taken into consideration!
It doesn't help, when I replace the #-character with the expected type – I get the same result.
First I thought, perhaps if the COND operator always returns a value, then it will work:
APPEND VALUE #( tdformat = COND #( WHEN sy-index EQ 1 THEN '*'
ELSE space ) tdline = <wa_split_result>+gv_offset ) TO gt_text.
But no, now it is the other way round – first three APPENDs failed and only the last one did the job:
How can I combine the results? It doesn't help, when I use the expected types instead of #-character. I even tried to use a properly typed constant with initial value instead of space, but with no effect.
Actually it's even worse when I put this code into a method, because then it dumps, saying that Field symbol has not been assigned yet, but only in the variant with WHEN …THEN …ELSE.
But when I change the order of the fields, everything works as expected:
APPEND VALUE #( tdline = <wa_split_result>+gv_offset tdformat = COND #( WHEN sy-index EQ 1 THEN '*' ) ) TO gt_text.
Result:
According to the documentation A constructor expression can be specified in general expression positions and one of the possible general expression positions is Right side of an assignment with the assignment operator = That's why I think I should get the expected result in all cases. Or am I wrong?
12-16-2017 3:03 PM
Y a un bug.
COND and Offset/Length don't harmonize.
Development is informed and kernel fix is initiated down to kernel 7.45.
Thanks for notifying.
12-15-2017 2:14 PM
12-15-2017 3:03 PM
How odd...
My answer here doesn't really answer your question about what is wrong, but it seems you want convert between string and "table of tline". I use FMs VB_CP_CONVERT_STRING_2_ITF and IDMX_DI_TLINE_INTO_STRING for those conversions back and forth. Works like a charm. I don't know your reasons for implementing this yourself, but maybe you can use them instead while your figure out what's up?
12-15-2017 3:17 PM
12-15-2017 3:21 PM
12-16-2017 3:03 PM
Y a un bug.
COND and Offset/Length don't harmonize.
Development is informed and kernel fix is initiated down to kernel 7.45.
Thanks for notifying.