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: 

COND Operator at string template formatting option summary functional operand position..?

Private_Member_7726
Active Contributor

Hi,

I'm probably missing obvious explanation as to why or not reading carefully enough, but I can't get the commented code below to compile (NW 740 SP12) and don't understand why:

* <SIGNATURE>---------------------------------------------------------------
* | Instance Public Method /FWW/CL_GL_BEZ_WRWO_HELPER->BUILD_BEZ_WRWO
* +-------------------------------------------------------------------------
* | [--->] I_PATTERN                      TYPE        /FWW/WRW_PATTERN (default =/FWW/CL_GL_BEZ_WRWO_HELPER=>C_DEFAULT_PATTERN)
* | [--->] I_STIEGE                       TYPE        AD_HSNM2(optional)
* | [--->] I_ROOMNUMBER                   TYPE        AD_ROOMNUM
* | [<-()] R_BEZ_WRWO                     TYPE        /FWW/WRW_MOBJ50
* | [!CX!] /FWW/CX_GL_BEZ_WRWO_HELPER
* +-------------------------------------------------------------</SIGNATURE>
METHOD build_bez_wrwo.
  me->check_pattern( i_pattern ).
  "Stiege aus Vorlage, falls leer
  DATA(l_stiege) = COND #(
    WHEN i_stiege IS INITIAL THEN i_pattern+12(3)
    ELSE i_stiege
  ).
  "Stiege Ausrichtung und Auffüllzeichen bestimmen
  DATA(l_align_stiege) = COND i(
    WHEN l_stiege CO '0123456789 ' THEN cl_abap_format=>a_right
    ELSE cl_abap_format=>a_left
  ).
  DATA(l_pad_stiege) = COND string(
    WHEN l_stiege CO '0123456798 ' THEN '0'
    ELSE space
  ).
  "Raumnummer Ausrichting und Auffüllzeichen bestimmen
  DATA(l_align_room) = COND i(
    WHEN i_roomnumber CO '0123456789 ' THEN cl_abap_format=>a_right
    ELSE cl_abap_format=>a_left
  ).
  DATA(l_pad_room) = COND string(
    WHEN i_roomnumber CO '0123456798 ' THEN '0'
    ELSE space
  ).

  r_bez_wrwo =
      |{ i_pattern(12) WIDTH = 12 ALIGN = LEFT }| &&
      |{ condense( val = l_stiege )
           WIDTH = 3
           ALIGN = (l_align_stiege)
*This does not compile...************************************************
*           ALIGN = ( COND i(
*             WHEN l_stiege CO '0123456789 ' THEN cl_abap_format=>a_right
*             ELSE cl_abap_format=>a_left
*           ) )
*************************************************************************
           PAD = l_pad_stiege
      } | &&
      |{ condense( val = i_roomnumber )
           WIDTH = 3
           ALIGN = (l_align_room)
           PAD = l_pad_room
      }|.

ENDMETHOD.

I tried with or without space between the COND and opening parenthesis of summary functional operand position - the compiler error message does change (I can't understand either of the messages...). Is the operator simply not meant to go at that position (I have to refactor that condition out to a functional method)?

Thank you,
Jānis

1 ACCEPTED SOLUTION

Private_Member_7726
Active Contributor
0 Kudos

No such luck with padding though 🙂 And autocomplete is screwed up as well.

I ended up with the following:

METHOD build_bez_wrwo.
  me->check_pattern( i_pattern ).

  "Stiege aus Vorlage, falls leer
  DATA(l_stiege) = COND #(
    WHEN i_stiege IS INITIAL THEN i_pattern+12(3)
    ELSE i_stiege
  ).

  DATA(l_pad_stiege) = me->pad_alphanumeric( CONV #( l_stiege ) ).
  DATA(l_pad_roomnumber) = me->pad_alphanumeric( CONV #( i_roomnumber ) ).

  r_bez_wrwo =
      |{ i_pattern(12) WIDTH = 12 ALIGN = LEFT }| &&
      |{ condense( val = l_stiege )
           WIDTH = 3
           ALIGN = ME->align_alphanumeric( CONV #( l_stiege ) )
           PAD = l_pad_stiege
      } | && "Leerzeichen braucht man hier...
      |{ condense( val = i_roomnumber )
           WIDTH = 3
           ALIGN = me->align_alphanumeric( CONV #( i_roomnumber ) )
           PAD = l_pad_roomnumber
      }|.

ENDMETHOD.
6 REPLIES 6

Sandra_Rossi
Active Contributor

It seems that the nature of the arguments may vary according to the option. For LEN, it may be a "numeric expression position" (you may indicate a function) ; for ALIGN, it may be a "data object" only (source: format_options)

You are right, I believe - the ALIGN and PAD positions should take only data objects (of course, it even says so in the documentation...). This, however, compiles and even seems to work:

  r_bez_wrwo =
      |{ i_pattern(12) WIDTH = 12 ALIGN = LEFT }| &&
      |{ condense( val = l_stiege )
           WIDTH = 3
*           ALIGN = (l_align_stiege)
            align = me->align_alphanumeric( l_stiege )
*           ALIGN = ( COND i(
*             WHEN l_stiege CO '0123456789 ' THEN cl_abap_format=>a_right
*             ELSE cl_abap_format=>a_left
*           ))
           PAD = l_pad_stiege
      } | && "Leerzeichen braucht man hier...
      |{ condense( val = i_roomnumber )
           WIDTH = 3
           ALIGN = (l_align_room)
           PAD = l_pad_room
      }|.

And the COND without parentheses compiles and works as well! 🙂 Syntax highlighting gets confused, however.

0 Kudos

Ok, I'm not good at reading documentation "diagonally" today 🙂 PAD, unlike ALIGN, can not take dynamic values - so says the documentation.

0 Kudos

Great! My fault, I had looked at the 7.02 documentation. It works well in 7.40.

Private_Member_7726
Active Contributor
0 Kudos

No such luck with padding though 🙂 And autocomplete is screwed up as well.

I ended up with the following:

METHOD build_bez_wrwo.
  me->check_pattern( i_pattern ).

  "Stiege aus Vorlage, falls leer
  DATA(l_stiege) = COND #(
    WHEN i_stiege IS INITIAL THEN i_pattern+12(3)
    ELSE i_stiege
  ).

  DATA(l_pad_stiege) = me->pad_alphanumeric( CONV #( l_stiege ) ).
  DATA(l_pad_roomnumber) = me->pad_alphanumeric( CONV #( i_roomnumber ) ).

  r_bez_wrwo =
      |{ i_pattern(12) WIDTH = 12 ALIGN = LEFT }| &&
      |{ condense( val = l_stiege )
           WIDTH = 3
           ALIGN = ME->align_alphanumeric( CONV #( l_stiege ) )
           PAD = l_pad_stiege
      } | && "Leerzeichen braucht man hier...
      |{ condense( val = i_roomnumber )
           WIDTH = 3
           ALIGN = me->align_alphanumeric( CONV #( i_roomnumber ) )
           PAD = l_pad_roomnumber
      }|.

ENDMETHOD.

And Pretty Printer is confused as well... 😐