Question

I wanna add the missing spaces in a character variable.

For instance bu_partner is char10 and has the value 31. In a standard database table there is only the value 0000000031.

I tried the overlay command, but 31 is at the beginning and not at the end.

DATA: mask TYPE bu_partner VALUE '0000000000',
      partner TYPE bu_partner.

partner = '31'.

OVERLAY partner WITH mask.

write partner.

Output:

3100000000

Is there any way to achieve 0000000031?

Was it helpful?

Solution

Use the appropriate conversion exit as designated by the domain:

conversion exit

DATA: some_value TYPE c LENGTH 10,
      partner    TYPE bu_partner.

some_value = '31'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = some_value
  IMPORTING
    output = partner.

WRITE: / partner USING NO EDIT MASK.

Be aware that you need to WRITE ... USING NO EDIT MASK in this case - if you don't use this addition, the list processing will automatically invoke CONVERSION_EXIT_ALPHA_OUTPUT which will eliminate the leading zeroes.

OTHER TIPS

Please check the conversion routine mapped to the domain of bu_partner. You can check that in the domain which is mapped to the data element of bu_partner. I am guessing it would be ALPHA. Which means you should use the FM CONVERSION_EXIT_ALPHA_INPUT to convert external data to internal format ( if you input 31 then you would get output as 0000000031 ) . If you want to convert internal to external then use the FM CONVERSION_EXIT_ALPHA_OUTPUT where appropriate.

After some digging, I found the command UNPACK.

DATA: lv_partner_leading_zeros(10) type c,
      lv_partner TYPE bu_partner.

lv_partner = '31'.

UNPACK lv_partner to lv_partner_leading_zeros.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top