2023 Feb 16 3:24 PM
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.
2023 Feb 16 6:09 PM
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.
2023 Feb 16 5:53 PM
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.
2023 Feb 16 6:09 PM
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.
2023 Feb 16 9:35 PM
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
2023 Feb 17 7:11 AM
Strange to you 😉
Read the ABAP doc and you'll better understand the "strange" logic by SAP.
2023 Feb 17 7:38 AM
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 }|.
2023 Feb 18 10:56 PM
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
2023 Feb 18 11:15 PM
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)