SAP NetWeaver AS ABAP Release 740, ©Copyright 2014 SAP AG. All rights reserved.
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, Time Formats
The example demonstrates the various time formats for embedded expressions.
Source Code
REPORT demo_string_template_time_form.
CLASS demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS: main.
PRIVATE SECTION.
CLASS-METHODS: setup,
teardown,
check_system.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DATA: seconds TYPE i,
timetable TYPE TABLE OF t,
land TYPE t005x-land,
comp TYPE i.
CONSTANTS n TYPE i VALUE 4.
DATA: BEGIN OF result,
raw TYPE string,
iso TYPE string,
h24 TYPE string,
h12_1_12_a TYPE string,
h12_1_12_b TYPE string,
h12_0_11_a TYPE string,
h12_0_11_b TYPE string,
END OF result,
results LIKE TABLE OF result.
FIELD-SYMBOLS: <time> TYPE t,
<col> TYPE string.
setup( ).
DO 24 / n TIMES.
seconds = ( sy-index - 1 ) * 3600 * n.
APPEND seconds TO timetable.
seconds = seconds + 1.
APPEND seconds TO timetable.
seconds = seconds + ( n - 1 ) * 3600 + 59 * 60 + 58.
APPEND seconds TO timetable.
ENDDO.
LOOP AT timetable ASSIGNING <time>.
result-raw = |{ <time> TIME = RAW }|.
result-iso = |{ <time> TIME = ISO }|.
SELECT land
FROM t005x
INTO (land)
WHERE land LIKE '@%'.
comp = sy-dbcnt + 2.
ASSIGN COMPONENT comp OF STRUCTURE result TO <col>.
<col> = |{ <time> COUNTRY = land }|.
ENDSELECT.
APPEND result TO results.
ENDLOOP.
teardown( ).
cl_demo_output=>display( results ).
ENDMETHOD.
METHOD setup.
DATA: t005x_wa TYPE t005x,
descr TYPE REF TO cl_abap_elemdescr,
fixvals TYPE ddfixvalues,
fixval LIKE LINE OF fixvals,
ans 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.
descr ?= cl_abap_elemdescr=>describe_by_name( 'T005X-TIMEFM' ).
fixvals = descr->get_ddic_fixed_values( ).
LOOP AT fixvals INTO fixval.
IF fixval-low IS INITIAL.
CONTINUE.
ENDIF.
t005x_wa-land = '@' && |{ fixval-low }|.
t005x_wa-timefm = |{ fixval-low }|.
INSERT t005x FROM t005x_wa.
ENDLOOP.
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
An internal table timetable is filled with various times, and these times are output in all possible country-specific time formats using parameter COUNTRY. For this purpose, in the setup and teardown help methods, temporary rows with the possible values of column TIMEFM are inserted into database table T005X and are deleted again once they have been used.