Skip to Content
3

Issue with COND operator in the expression of VALUE operator

Dec 15, 2017 at 01:30 PM

148

avatar image

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?

debugger.jpg (47.5 kB)
debugger-2.jpg (24.7 kB)
debugger-3.jpg (43.0 kB)
10 |10000 characters needed characters left characters exceeded

strange ...

0
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Horst Keller
Dec 16, 2017 at 03:03 PM
3

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.

Share
10 |10000 characters needed characters left characters exceeded
Jörgen Lindqvist Dec 15, 2017 at 03:03 PM
0

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?

Show 2 Share
10 |10000 characters needed characters left characters exceeded
(and I personally use CONVERT_ITF_TO_STREAM_TEXT and CONVERT_STREAM_TO_ITF_TEXT ; they also work like a charm ;-) )
0

That seems more coherent. I'm in!

1