Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Date select-option (range) restricting Timestamp database field.

afordham
Participant
0 Kudos

Hi,

I'm writing a report that requires a Date select-option on the selection screen, but the field that I want to restrict on in the database is a timestamp. While I'm sure I could write something that converts my date select-option into a timestamp range, I was wondering if there is a standard FMod or something that achieves the same thing.

Thanks in advance,

Andrew

5 REPLIES 5

former_member203501
Active Contributor
0 Kudos

hi use this ...

OIL_DATE_TO_TIMESTAMP

Former Member
0 Kudos

Hi,

I thing you have to concatenate sy-datum sy-uzeit into xyz.

Tks,

Krishna..

0 Kudos

Hi Andrew,

I'm facing the same issue. Did this get resolved?

Thanks,

Gauri

sivaganesh_krishnan
Contributor
0 Kudos

Hi Andrew,

Use could also use the function Module

ABI_TIMESTAMP_CONVERT_INTO

dmitry_sharshatkin
Active Participant
0 Kudos

Hello Andrew,

I know it's too late, but maybe can be useful for others:


types:  gty_ts_range   type range of timestamp .
types:  gty_date_range type range of dats .

Parameters:
IT_DATE_RANGE	        Importing	Type	GTY_DATE_RANGE	                                IV_TIME_ZONE	        Importing	Type	SY-ZONLO	'UTC'
RT_TIMESTAMP_RANGE	Returning	Type	GTY_TS_RANGE	 

  method date_to_ts_range.

    types: begin of lty_date_result,
             date  type dats,
             shift type i,
           end of lty_date_result.

    constants: lc_min_date    type dats value '19000101',
               lc_max_date    type dats value '21000101',
               lc_end_of_days type dats value '99991231',
               lc_min_time    type tims value '000000',
               lc_max_time    type tims value '235959'.

    statics: st_all_dates type sorted table of dats with unique key table_line.

    data: lv_date              type dats.
    data: lv_max_timestamp     type timestamp.
    data: lv_min_timestamp     type timestamp.
    data: lv_ts                type timestamp.
    data: lt_date_result       type sorted table of lty_date_result with unique key date
                                                                    with non-unique sorted key k2 components shift.
    data: ls_prev_date_result  type lty_date_result.
    data: ls_ts_range          like line of rt_timestamp_range.

    check: it_date_range[] is not initial.

    " Get All Dates...
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    if st_all_dates[] is initial.
      lv_date = lc_min_date.
      while lv_date <= lc_max_date.
        insert lv_date into table st_all_dates[].
        add 1 to lv_date.
      endwhile.
    endif.

    lv_min_timestamp = date_time_to_ts( iv_date      = lc_min_date
                                        iv_time      = lc_min_time
                                        iv_time_zone = iv_time_zone  ).

    lv_max_timestamp = date_time_to_ts( iv_date      = lc_max_date
                                        iv_time      = lc_max_time
                                        iv_time_zone = iv_time_zone  ).

    " Collect Date Result...
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    loop at st_all_dates into lv_date where table_line in it_date_range. "#EC CI_SORTSEQ
      insert value #( date = lv_date shift = 0 ) into table lt_date_result[].
    endloop.

    " Optimize Date Result...
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    check lt_date_result[] is not initial.

    " Step 1: Calculate Shifts...
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    loop at lt_date_result[] assigning field-symbol(<fs_date_result>).
      if sy-tabix = 1.
        lv_date = <fs_date_result>-date.
        <fs_date_result>-shift = 8.
      else.
        <fs_date_result>-shift = <fs_date_result>-date - lv_date.
        lv_date = <fs_date_result>-date.
      endif.
    endloop.
    insert value #( date = lc_end_of_days shift = 8 ) into table lt_date_result[]. " Needed for last loop...

    " Step 2: Collect Results...
    """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
    clear: ls_ts_range.
    loop at lt_date_result[] assigning <fs_date_result> where shift <> 1.

      " Start Date...
      if ls_ts_range is initial.
        ls_ts_range-sign   = 'I'.
        ls_ts_range-option = 'BT'.
        clear: lv_ts.
        lv_ts = date_time_to_ts( iv_date      = <fs_date_result>-date
                                 iv_time      = lc_min_time
                                 iv_time_zone = iv_time_zone ).
        ls_ts_range-low  = lv_ts.
      endif.

      " End Date...
      data(lv_prev_line) = sy-tabix - 1.
      if ls_ts_range is not initial and lv_prev_line > 0.
        read table lt_date_result into ls_prev_date_result index lv_prev_line.
        if sy-subrc = 0.
          clear: lv_ts.
          lv_ts = date_time_to_ts( iv_date      = ls_prev_date_result-date
                                   iv_time      = lc_max_time
                                   iv_time_zone = iv_time_zone ).
          ls_ts_range-high = lv_ts.

          " Optimize Selections...
          " GE:
          if ls_ts_range-high = lv_max_timestamp and ls_ts_range-low is not initial.
            ls_ts_range-option = 'GE'.
            clear: ls_ts_range-high.
          endif.
          " LE:
          if ls_ts_range-low = lv_min_timestamp and ls_ts_range-high is not initial.
            ls_ts_range-option = 'LE'.
            ls_ts_range-low = ls_ts_range-high.
            clear: ls_ts_range-high.
          endif.

          append ls_ts_range to rt_timestamp_range[].


          " Renewal of Start Date...
          clear: ls_ts_range.
          ls_ts_range-sign   = 'I'.
          ls_ts_range-option = 'BT'.
          clear: lv_ts.
          lv_ts = date_time_to_ts( iv_date      = <fs_date_result>-date
                                   iv_time      = lc_min_time
                                   iv_time_zone = iv_time_zone ).
          ls_ts_range-low  = lv_ts.
        endif.
      endif.

    endloop.

  endmethod.

BR, Dmitrii