Difference between Chaining operator(&&) and Literal Operator(&)

Recently I talked about the Chaining Operator(&&) and how it simplifies dealing with texts and strings. I wanted to talk about a similar-looking operator with some similar functions to the chaining operator which makes it easy to confuse each other.

A literal operator(&) is used to join two or more literals to produce a single literal. However, there is a hard character length limit of 255.

Example of using a literal operator:

There are more features and limitations to a literal operator. Below are the points on which it's similar/different to a Chaining operator.

    - Similar to the chaining operator, you can use join string templates using &.

    - Any trailing blank in text field literals is preserved, unlike chaining operator.

    - Can span multiline:

    - Calculated at compile-time.

Literal Operator compilation error

    - Can not have more than 255 characters(See the error in the above image), if you want to have a longer character,
      use the chaining operator.

    - Can not mix literal types while joining them using the literal operator.


- Can not use variables at operand positions


As you can see, the literal operator has a specific function i.e. to join literals and support multiline declarations while easy to confuse with the chaining operator.
In my opinion, One should refrain from using &(Literal Operator) and use chaining operator or string templates instead.

Popular posts from this blog

ABAP read excel(.XLSX) file to internal table in ABAP using CL_FDT_XL_SPREADSHEET

ABAP convert internal table to excel (.xlsx) format and Send email or download

Use CL_BCS library to send email with ABAP