Skip to Content
1
Former Member
Sep 08, 2016 at 09:08 AM

IBAN formatting: String offset operations with ABAP 740

323 Views

Hello SDNers,

I am trying to format IBAN for printing purposes, like this

Input: DE89370400440532013000

Output: DE89 3704 0044 0532 0130 00

With my search-skills i couldn't find any standard solution provided by SAP 😭, hence the custom solution.

ABAP 740 approach using REDUCE...FOR iteration:

    rv_formatted_iban
      = REDUCE #(
          LET iban = condense( iv_iban ) IN
          INIT fiban = `` " Formatierte IBAN
          FOR n = 0 THEN n + 4 WHILE n < strlen( iban )
          NEXT fiban = fiban && |{ iban+n(4) } |
        ).

This led to the exception cx_sy_range_out_of_bounds, which obvious because German IBANs are 22 character long.

I had to use the trusted WHILE iteration to achieve this:

    WHILE lv_offset < strlen( lv_iban_condensed ) .

      TRY.
          rv_formatted_iban = rv_formatted_iban && |{ lv_iban_condensed+lv_offset(4) } |.
        CATCH cx_sy_range_out_of_bounds.
          rv_formatted_iban = rv_formatted_iban && |{ lv_iban_condensed+lv_offset }|.
      ENDTRY.

      ADD 4 TO lv_offset.
    ENDWHILE. " lv_offset < strlen( lv_iban )

Can i implement this using functional ABAP?

BR,

Suhas