5 1 1 1 1 1 Rating 100% (1 Vote)
In one of the previous articles I described how to Convert date to and from external date type, so we can display in grid or in screen field properly formated date. Today I will show how to create a F4 help for such external date. I will use today FM 'F4_DATE' to show the date popup and already know FM 'PERIOD_AND_DATE_CONVERT_OUTPUT' to convert internal date to external type.

Importing:

IM_DISPLAY TYPE CHAR1  - Display only? (no selection)
IM_ELPEI TYPE TPRG-PRGBZ (OPTIONAL) -  External date type

Exporting:

EX_EEIND TYPE RVDAT-EXTDATUM   - External date
EX_ELPEI TYPE TPRG-PRGBZ       - External date type

Exception:

FAILED - Failed

Implementation:

method f4_for_date.
  datal_eindt type workflds-gkday,
        ls_tprg type tprg,
        l_display  type char1.

  if im_display eq 'D'.
    l_display 'X'.
  endif.

*- check date type
  if im_elpei is initial.
    ls_tprg-prgrs '1'.
  else.
    select single from tprg into ls_tprg
    
where spras eq sy-langu
    
and prgbz eq im_elpei.
    if sy-subrc ne 0.
*  message e346(v1) with e_lpein.
      message s346(v1with im_elpei.
      raise failed.
    endif.
  endif.

*- call F4 for date
  call function 'F4_DATE'
    exporting
      date_for_first_month sy-datlo
      display              
l_display
    
importing
      select_date          l_eindt
    
exceptions
      others               8.
  if sy-subrc ne 0.
*  message e845(06).
    message s845(06).
    raise failed.
  endif.

*- Convert to external format
  if not l_eindt is initial.
    call function 'PERIOD_AND_DATE_CONVERT_OUTPUT'
      exporting
        internal_date   l_eindt
        internal_period 
ls_tprg-prgrs
      
importing
        external_date   ex_eeind
        external_period 
ex_elpei.
  endif.
endmethod.

Enjoy!