cancel
Showing results for 
Search instead for 
Did you mean: 

SAP HANA- How to add spaces to string to complete 10 characters

former_member627791
Participant
0 Kudos

Dear team,

I have a field I need to send in an interface and it supposed to be always be 10 characters.

The SBO field I am sending may be shorter then 10 characters, for example if my field is '13' I need to send '13 ' and if my field is '4753' I need to send '4753 '

How can I do this?

Thank you,

Or Cohen

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi ,

you can modify like below

RPAD(T0."U_CaseNum",10,'0') as "U_CaseNum"

former_member627791
Participant
0 Kudos

Thank you!

Answers (1)

Answers (1)

0 Kudos

Hi ,

If it has to be always one space in the end in case your string is less than 10 characters then you can first check the length of string using length function

length(<string>) and then applyying padding using if statement

if(length(<string>) = 10, <string>, RPAD(<string>,length(<string>)+1,' '))

In case you need all the spaces to make it to character 10 for example '13' would become '13 '

after adding 8 spaces in the end then direct padding can be used RPAD(<string>,15,' '))

former_member627791
Participant
0 Kudos

Thank you for your answer,

So I tried to write it like this (for the example I used '0' instead of space):

LPAD('0',10,T0."U_CaseNum") as "U_CaseNum"

and the result is:

1111111110

(T0."U_CaseNum"='1').

I need that the result will be 1000000000

Do you know what I need to change?

Thank you,

Or