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: 

ABAP expression ALPHA CONDENSE NO-GAPS

chaouki_akir
Contributor
0 Kudos
4,866

Hello,

I am using an expression that is not giving the expected result. Is there a way to reach the expected result using modern syntax ?

To reach the expected result I have to use instruction CONDENSE NO-GAPS

Here the piece of code that you can use (sorry the code formatting is not working for me) :

REPORT ztest.

START-OF-SELECTION.

DATA ls_lips TYPE lips.
DATA goodsmvt_header TYPE bapi2017_gm_head_01.


ls_lips-vbeln = '1981000A'.
ls_lips-posnr = 10.

NEW-LINE.
POSITION 30.
WRITE '*'.

NEW-LINE.
WRITE 'Expression '.
POSITION 30.
WRITE '|{ ls_lips-vbeln ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|' COLOR COL_GROUP NO-GROUPING.
NEW-LINE.
POSITION 31.
WRITE / 'where ls_lips-vbeln = ''1981000A'' and ls_lips-posnr = 10' COLOR COL_GROUP NO-GROUPING.


goodsmvt_header-ref_doc_no = |{ ls_lips-vbeln ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }| .
NEW-LINE.
WRITE 'Result'.
POSITION 30.
WRITE goodsmvt_header-ref_doc_no COLOR COL_NEGATIVE.


*
NEW-LINE.
WRITE 'Expected Result'.
CONDENSE goodsmvt_header-ref_doc_no NO-GAPS.
POSITION 30.
WRITE goodsmvt_header-ref_doc_no COLOR COL_POSITIVE.
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor
4,023

If you debug your code, you will notice that LS_LIPS-VBELN is of type C and length 10.

So, your only question about this code...

DATA(vbeln) = CONV lips-vbeln( '1981000A' ).
DATA(dummy) = |{ vbeln ALPHA = OUT }|.

... is why DUMMY contains 2 trailing spaces (as you can see with the debugger)?

Look at ABAP documentation for explanations about ALPHA = OUT.

Etc.

7 REPLIES 7

Sandra_Rossi
Active Contributor
4,023

As you say that you can't make [CODE] formatting, for unknown reason, here it is:

REPORT ztest.

START-OF-SELECTION.

  DATA ls_lips TYPE lips.
  DATA goodsmvt_header TYPE bapi2017_gm_head_01.

  ls_lips-vbeln = '1981000A'.
  ls_lips-posnr = 10.

  NEW-LINE.
  POSITION 30.
  WRITE '*'.

  NEW-LINE.
  WRITE 'Expression '.
  POSITION 30.
  WRITE '|{ ls_lips-vbeln ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|' COLOR COL_GROUP NO-GROUPING.
  NEW-LINE.
  POSITION 31.
  WRITE / 'where ls_lips-vbeln = ''1981000A'' and ls_lips-posnr = 10' COLOR COL_GROUP NO-GROUPING.

  goodsmvt_header-ref_doc_no = |{ ls_lips-vbeln ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }| .
  NEW-LINE.
  WRITE 'Result'.
  POSITION 30.
  WRITE goodsmvt_header-ref_doc_no COLOR COL_NEGATIVE.

  NEW-LINE.
  WRITE 'Expected Result'.
  CONDENSE goodsmvt_header-ref_doc_no NO-GAPS.
  POSITION 30.
  WRITE goodsmvt_header-ref_doc_no COLOR COL_POSITIVE.

Sandra_Rossi
Active Contributor
4,024

If you debug your code, you will notice that LS_LIPS-VBELN is of type C and length 10.

So, your only question about this code...

DATA(vbeln) = CONV lips-vbeln( '1981000A' ).
DATA(dummy) = |{ vbeln ALPHA = OUT }|.

... is why DUMMY contains 2 trailing spaces (as you can see with the debugger)?

Look at ABAP documentation for explanations about ALPHA = OUT.

Etc.

0 Kudos
4,023

Thank you. Some results that might be strange

DATA lv_char TYPE c LENGTH 16.
ls_lips-vbeln = '1981000A'.
lv_char = |{ ls_lips-vbeln ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|."=>1981000A -10
lv_char = |{ condense( ls_lips-vbeln ) ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|."=>1981000A-10
lv_char = |{ conv string( ls_lips-vbeln ) ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|."=>1981000A-10

ls_lips-vbeln = '0001981000'.
lv_char = |{ ls_lips-vbeln ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|."=>1981000 -10
lv_char = |{ condense( ls_lips-vbeln ) ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|."=>1981000 -10
lv_char = |{ conv string( ls_lips-vbeln ) ALPHA = OUT }-{ ls_lips-posnr ALPHA = OUT }|."=>1981000 -10






0 Kudos
4,023

Strange to you 😉

Read the ABAP doc and you'll better understand the "strange" logic by SAP.

4,023

chaouki.akir In your last example in comment you are using CONDENSE before doing ALPHA OUT conversion. That is why it is giving you "strange" output. Try doing CONDENSE after the ALPHA conversion 🙂

ls_lips-vbeln = '0001981000'.
lv_char = condense( |{ ls_lips-vbeln ALPHA = OUT }| ) && |-{ ls_lips-posnr ALPHA = OUT }|.
-- Tomas --

4,023

tomas.buryanekYou are right the result is consistent with CONDENSE whatever the value of lips-vbeln is

ls_lips-vbeln = '1981000A'.
lv_char = |{ ls_lips-vbeln ALPHA = OUT }|.
lv_char = lv_char && |-{ ls_lips-posnr ALPHA = OUT }|."1981000A-10
lv_char = |{ ls_lips-vbeln ALPHA = OUT }| && |-{ ls_lips-posnr ALPHA = OUT }|."1981000A -10
lv_char = condense( |{ ls_lips-vbeln ALPHA = OUT }| ) && |-{ ls_lips-posnr ALPHA = OUT }|."1981000A-10

ls_lips-vbeln = '0001981000'.
lv_char = |{ ls_lips-vbeln ALPHA = OUT }|.
lv_char = lv_char && |-{ ls_lips-posnr ALPHA = OUT }|."1981000-10
lv_char = |{ ls_lips-vbeln ALPHA = OUT }| && |-{ ls_lips-posnr ALPHA = OUT }|."1981000 -10
lv_char = condense( |{ ls_lips-vbeln ALPHA = OUT }| ) && |-{ ls_lips-posnr ALPHA = OUT }|."1981000-10


4,023

sandra.rossi you are right, it was counter intuitive for me that the result was varying depending on the value of the variable lips-vbeln (spaces before "-" if value is numeric ; no spaces before if value is not entirely numeric)