2008 Apr 26 8:40 PM
Hi All,
I am new to ABAP and need help to achieve this functionality
I have to build a string with fixed lenth . my input string
is always lesser than equal to X . I need to calculate and
add that many spaces at the end of the input string .
I tried to do this and getting the following error
please help on this :
if strlen( t_resultc ) < 525.
RFILL(t_resultc,' ',525)
endif.
Error : Comma without preceding colon(after RFILL(T_RESULTC ?)
Q: Can I use RFILL with out Select statement in a ABAP program
Thanks & Regards
KLK
2008 Apr 26 10:05 PM
Hi KLK,
you can not use the rfill statement, but this coding seems to work:
DATA:
t_resultc TYPE string,
spaces TYPE i.
t_resultc = 'test'.
spaces = 525 - STRLEN( t_resultc ).
DO spaces TIMES.
CONCATENATE t_resultc space INTO t_resultc
RESPECTING BLANKS.
ENDDO.
If t_resultc has a fixed length of 525 characters you could also define it like this:
data t_resultc(525) type c.
It would then automatically contain 525 spaces as default value.
Regards
Thomas Langen
2008 Apr 26 10:00 PM
if t_resultc is a character field it ill be carrying spaces by default.
if its not character type just say
t_resultc = space.
2008 Apr 26 10:05 PM
Hi KLK,
you can not use the rfill statement, but this coding seems to work:
DATA:
t_resultc TYPE string,
spaces TYPE i.
t_resultc = 'test'.
spaces = 525 - STRLEN( t_resultc ).
DO spaces TIMES.
CONCATENATE t_resultc space INTO t_resultc
RESPECTING BLANKS.
ENDDO.
If t_resultc has a fixed length of 525 characters you could also define it like this:
data t_resultc(525) type c.
It would then automatically contain 525 spaces as default value.
Regards
Thomas Langen
2008 Apr 27 12:01 AM
Hi Thomas,
Thanks for the quick responce .
t_resultc is of the type String not Char of fixed length.
I have one question with above code it would add integer
values to the string upto the length of 525
But I need spaces upto the fixed length so can I add character to string ?
I will test and get back.
Thanks & Regards
KLK
2008 Apr 27 9:26 AM
Hi KLK,
the coding above adds space characters, not integers. It think you possibly have confused the data element spaces I defined in the coding with the SPACE character which I used in the concatenate statement.
Regards
Thomas
2008 Apr 27 6:13 PM
Hi Thomas ,
Yes , I was confussed .
So I have added ' ' instead of space .
Thanks a lot for the Do usage syntax .
Please suggest any links or documentations to help me
learn these basic syntax in ABAP .
Thanks once again ,
KLK
2008 Apr 28 8:40 AM
Hi,
I used the book "ABAP Objects" written by Keller and Krüger to learn the basics. The online help is quite useful, too.
Regards,
Thomas Langen
2013 Jul 11 7:58 AM
Hi mate,
Don't we have a simple function for this than manipulating characters.
2013 Jul 11 11:28 AM
Hi,
YOU CAN WRITE YOUR LOGIC LIKE THIS:
if strlen( t_resultc ) < 525.
DO.
CONACTENATE T_RESULTC SPACE INTO T_RESULTC.
IF STRLEN(T_RESULTC) = 525.
EXIT.
ENDIF.
ENDDO.
ENDIF.
2013 Jul 11 12:12 PM
Hi,
Try the following code but kindly make a note..
Note:-USE quote like this ` `, Instead of normal single quotes ‘ ’
WHILE strlen( T_RESULTC ) < 525. “Check the length
CONCATENATE T_RESULTC ` ` INTO T_RESULTC. ”Add spaces at the end
ENDWHILE.
Hope this helps,
Andrew
2016 Jul 05 11:01 AM
With string templates you could do something like this:
t_resultc = |{ t_resultc WIDTH = 525 PAD = space }|.
2021 Dec 07 2:36 PM
see The ABAPVARCHARMODE: Blanks and Empty Strings in ABAP and SQLScript - Brandeis Consulting
data: lv_kunnr_tmp type string.
DATA(cnt_kunnr) = strlen( kna1-kunnr ).
IF NOT cnt_kunnr = 10.
lv_kunnr_tmp = |{ kna1-kunnr WIDTH = 10 PAD = space }|.
ELSE.
lv_kunnr_tmp = kna1-kunnr.
ENDIF.
2024 Aug 13 3:07 PM