ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Character String and Byte String Processing →  Expressions and Functions for String Processing →  string_exp - String Expressions →  string_exp - String Templates →  Examples of string templates → 

Character String Templates, Number Formats

The example demonstrates the various number formats for embedded expressions.

Source Code

REPORT demo_string_template_numb_form.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    CLASS-METHODS: setup,
                   teardown,
                   check_system.
ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.
    DATA: land   TYPE t005x-land,
          xdezp  TYPE t005x-xdezp,
          number TYPE p DECIMALS 2 VALUE '1234567.89'.

    DATA: BEGIN OF result,
            xdezp  TYPE string,
            format TYPE string,
          END OF result,
          results LIKE TABLE OF result.

    setup( ).

    SELECT land xdezp
           FROM t005x
           INTO (land,xdezp)
           WHERE land LIKE '@%'.
      result-xdezp  = xdezp.
      result-format = |{ number COUNTRY = land }|.
      APPEND result TO results.
    ENDSELECT.

    teardown( ).

    cl_demo_output=>display( results ).

  ENDMETHOD.
  METHOD setup.
    CONSTANTS xdezp_values TYPE string VALUE ` XY`.
    DATA: t005x_wa TYPE t005x,
          ans      TYPE c LENGTH 1,
          key      TYPE c LENGTH 1.
    check_system( ).
    SELECT SINGLE land
           FROM t005x
           INTO (t005x_wa-land)
           WHERE land LIKE '@%'.
    IF sy-subrc = 0.
      CALL FUNCTION 'POPUP_TO_CONFIRM'
        EXPORTING
          titlebar                  = 'Confirmation'
          text_question             = 'Delete existing'
          &
          ' entries with keys'
          &
          ' @1, @2, ...  in T005X?'
          text_button_1             = 'Yes'
          text_button_2             = 'No'
          display_cancel_button     = ' '
        IMPORTING
          answer                    = ans.
      IF ans = 1.
        teardown( ).
      ELSE.
        cl_demo_output=>display( 'Execution not possible' ).
        LEAVE PROGRAM.
      ENDIF.
    ENDIF.
    DO strlen( xdezp_values ) TIMES.
      key = |{ substring( val =  xdezp_values
                          off = sy-index - 1
                          len = 1 )  }|.
      t005x_wa-land = '@' && key.
      t005x_wa-xdezp = key.
      INSERT t005x FROM t005x_wa.
    ENDDO.
    COMMIT WORK.
  ENDMETHOD.
  METHOD teardown.
    DELETE FROM t005x WHERE land LIKE '@%'.
    COMMIT WORK.
  ENDMETHOD.
  METHOD check_system.
    IF cl_abap_demo_services=>is_production_system( ) = abap_true.
      cl_demo_output=>display(
        'This demo cannot be executed in a production system' ).
      LEAVE PROGRAM.
    ENDIF.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  demo=>main( ).

Description

A number is output in all possible country-specific number formats using parameter COUNTRY. For this purpose, in the setup and teardown help methods, temporary rows with the possible values of column XDEZP are inserted into database table T005X and are deleted again once they have been used.