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: 

Enable fields in Selection-screen after Invalid date entry

former_member699182
Participant
0 Kudos

Hello All,

I have the below program in which I am trying to replicate a few features of SM37. I want to validate the date From and To.

When I enter 2014/11/45 in the From date, it displays error message Invalid date(since date is 45) but disables entry in all other fields. I dont want this to happen.

How to enable the fields after the invalid date entry message? I debugged SM37 and understood that this has been done in CHAIN-ENDCHAIN there since its a screen flow logic. Since I cannot replicate that in Selection-screen, its quite confusing. I thought of doing an AT SELECTION-SCREEN ON the date field but doesnt seem to work because I am not sure where this program is throwing me the Invalid date error (I am not handling it within my program).

Pasting the pgm below. Can someone help me determine where the Invalid date error is getting thrown and how to enable the fields affter that?

Thanks.

*************************************************************************

*&---------------------------------------------------------------------*
*& Report  ZGUITEST_JOBCONFIRMATION
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZGUITEST_JOBCONFIRMATION.

TABLES: btcuev, btcsev.

DATA: lt_btcjob TYPE TBTCJOB_BK OCCURS 0.

DATA ls_btcselect TYPE BTCSELECT.
DATA wa_job TYPE tbtcjob.
DATA jobcount TYPE I.

* Data declaration for F4 on 'or after event'

DATA: fieldtbl LIKE dfies OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF eventid_hlp_tbl OCCURS 20.
          INCLUDE STRUCTURE btcevthtbl.
DATA: END OF eventid_hlp_tbl.
DATA: selected_eventid LIKE tbtcjob-eventid.
DATA: p_helpvalue_key TYPE ddshpvkey value 'BTC_EVENTID_HELP'.


data: gv_datum type sy-datum.

SELECTION-SCREEN SKIP.
  SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 2(10) JobName FOR FIELD p_jobnm.
    PARAMETERS: p_jobnm LIKE btcselect-jobname DEFAULT '*' OBLIGATORY.
  SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF BLOCK Status WITH FRAME TITLE JobStat.
  SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS: p_pln AS CHECKBOX.
    SELECTION-SCREEN COMMENT 4(10) Planned FOR FIELD p_pln.
    PARAMETERS: p_rel AS CHECKBOX.
    SELECTION-SCREEN COMMENT 19(10) Released FOR FIELD p_rel.
    PARAMETERS: p_rdy AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN COMMENT 34(10) Ready FOR FIELD p_rdy.
    PARAMETERS: p_act AS CHECKBOX DEFAULT 'X'.
    SELECTION-SCREEN COMMENT 49(10) Active FOR FIELD p_act.
    PARAMETERS: p_fin AS CHECKBOX.
    SELECTION-SCREEN COMMENT 64(10) Finished FOR FIELD p_fin.
    PARAMETERS: p_can AS CHECKBOX.
    SELECTION-SCREEN COMMENT 79(17) Canceled FOR FIELD p_can.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK Status.

SELECTION-SCREEN BEGIN OF BLOCK Condition WITH FRAME TITLE JobCond.
  SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 20(5) Frm_Date FOR FIELD p_from.
    PARAMETERS: p_from LIKE btcselect-from_date.
    SELECTION-SCREEN COMMENT 50(5) To_Date FOR FIELD p_to.
    PARAMETERS: p_to LIKE btcselect-to_date DEFAULT SY-DATUM.
  SELECTION-SCREEN END OF LINE.

  SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 20(20) Event FOR FIELD p_event.
    PARAMETERS: p_event LIKE btcselect-eventid AS LISTBOX VISIBLE LENGTH 40.
  SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK Condition.


INITIALIZATION.

  JobName   = 'ジョブ名'.
  JobStat   = 'ジョブステータス'.
  Planned   = '計画済'.
  Released  = 'リリース済'.
  Ready     = '待機中'.
  Active    = '実行中'.
  Finished  = '終了'.
  Canceled  = '中止'.

  JobCond   = 'ジョブ開始条件'.
  Frm_Date  = '開始'.
  To_Date   = '終了'.
  Event     = 'or after event'.

  CALL FUNCTION 'CCM_GO_BACK_MONTHS'
    EXPORTING
      CURRDATE   = p_to
      BACKMONTHS = '1'
    IMPORTING
      NEWDATE    = gv_datum.

   p_from = gv_datum.


* 'Or after event' dropdown list

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_event.

  FREE eventid_hlp_tbl.

  SELECT * FROM btcuev.
    eventid_hlp_tbl-eventid = btcuev-eventid.
    APPEND eventid_hlp_tbl.
  ENDSELECT.

  SELECT * FROM btcsev.
    eventid_hlp_tbl-eventid = btcsev-eventid.
    APPEND eventid_hlp_tbl.
  ENDSELECT.

  eventid_hlp_tbl-eventid = '*'.       " select everything
  APPEND eventid_hlp_tbl.              " for combo box

  SORT eventid_hlp_tbl BY eventid ASCENDING.

  FREE fieldtbl.
  CLEAR fieldtbl.
  REFRESH fieldtbl.

  fieldtbl-tabname    = 'BTCEVTHTBL'.
  fieldtbl-fieldname  = 'EVENTID'.
  APPEND fieldtbl.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'EVENTID'
      pvalkey         = p_helpvalue_key
      dynpprog        = 'SAPLBTCH'
      dynpnr          = sy-dynnr
    TABLES
      value_tab       = eventid_hlp_tbl
      field_tab       = fieldtbl
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.


START-OF-SELECTION.

*   Date validation
    IF ( p_to < p_from ).
      MESSAGE: 'From start date is greater than To start date' TYPE 'S' DISPLAY LIKE 'E'.
      LEAVE LIST-PROCESSING.
    ENDIF.

    REFRESH : lt_btcjob.
    CLEAR: ls_btcselect.

*   Taking care of the time init vs. space
    IF ls_btcselect-from_time IS INITIAL.
       ls_btcselect-from_time = '      '.
    ENDIF.
    IF ls_btcselect-to_time IS INITIAL.
       ls_btcselect-to_time = '      '.
    ENDIF.

*   Assign the Jobname, UserName and Start Conditions
    ls_btcselect-jobname   = p_jobnm.
    ls_btcselect-username  = '*'.
    ls_btcselect-from_date = p_from.
    ls_btcselect-to_date   = p_to.
    ls_btcselect-eventid   = p_event.

*   Assign the Status
    ls_btcselect-prelim   = p_pln.
    ls_btcselect-schedul  = p_rel.
    ls_btcselect-ready    = p_rdy.
    ls_btcselect-running  = p_act.
    ls_btcselect-finished = p_fin.
    ls_btcselect-aborted  = p_can.

* Function module to get the list of jobs for the specified parameters
      CALL FUNCTION 'BP_JOB_SELECT_SM37B'
        EXPORTING
          JOBSELECT_DIALOG          = 'N'
          JOBSEL_PARAM_IN           = ls_btcselect
        TABLES
          JOBSELECT_JOBLIST_B       = lt_btcjob
       EXCEPTIONS
         NO_JOBS_FOUND              = 3
         OTHERS                     = 6
                .

*     no jobs found -> OK, jobs found -> NG
      DESCRIBE TABLE lt_btcjob LINES jobcount.
      IF jobcount NE 0.
        WRITE: 'NG'.
      ELSE.
        WRITE: 'OK'.
      ENDIF.

END-OF-SELECTION.

************************************************************************************************

1 ACCEPTED SOLUTION

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

Move your selection screen validation to "AT SELECTION-SCREEN"  event.

See http://help.sap.com/abapdocu_740/en/abapat_selection-screen_events.htm

http://scn.sap.com/thread/596120

See program  DEMO_SELECTION_SCREEN_EVENTS

Regards.

22 REPLIES 22

former_member210770
Active Participant
0 Kudos

Hi Gita,

You can do 2 things.

1) Convert your Error message in Information Message and write Leave List Processing afterwards.

  Clear : SY-ucomm.

  Message : 'Invalid Date' type 'I'.

Leave-List-Processing.

2) Or You have to clear sy-ucomm before you throw error message.

 

  Clear : SY-ucomm.

  Message : 'Invalid Date' type 'E'.

  

Ones error comes in screen , change the erroneous value and just press enter so every other fields will be again editable.

Hope this will work.

Regards,

Sagar

0 Kudos

Thank you Sagar for the suggestion. But the problem is, right now I am not displaying the Invalid date message in my pgm manually but it is still getting diaplyed somehow if I enter a wrong date. I am not surre which part of the pgm does that even when i tried debugging it. Does system do it automatically? If you are aware of it and still believe your suggestion would work, can you please tell me where to insert your code segment in my program?

Thanks.

0 Kudos

Hi Gita,

If it is system generated message, then you can not change it. Try to remove all your code and run your report only with only this date parameter and check it.

I hope this will help.

Regards,

Sagar

0 Kudos

Hi Gita,

Seeing your comment it could probably be the standard throwing that error.

If it is the standard error, you can't do much until you rectify it.

Thanks,

Naveen

0 Kudos

Thank you Naveen and Sagar.

I will try the suggestion of eliminating everything except Date field and see how it works.

Meanwhile, the thing is, I do not mind the system automatically generating the error. The problem is it disables all other fields when this error occurs. So my query is in which place of my program should I add code to enable the fields? And what code to add to enable the fields?

Thanks.

0 Kudos

Hi Gita,

You have declared of type btcselect-from_date, which has a specific standard format. so it is displaying error if its not in that format.

This is standard functionality and I don't think we can avoid this.

One of the options would be to declare to some other format like CHAR and just validate it separately if required.

Regards

Sri

0 Kudos

Hi Gita,

If you are referencing to a standard date type then you cannot control the visibility of other fields when there is an error unless you change the date type to a custom one or character like one and then do your own validation.

Thanks,

Naveen

0 Kudos

Since I am passing the btcselect-from_date to a FM 'BP_JOB_SELECT_SM37B, I cannot change the date type. Any idea on how else to handle this?

Thanks.

0 Kudos

HHi Gita,

this is is SAP, you will have to live with it.

I Can't think of any other way you can control it. Let's see.

One way you can try changing the field to a character field and do your validation and when you want to pass this to the function module then assign this to a date variable and pass it to the function.

But I would advise you not to do this and stick with standard wherever possible.

THanks,

naveen.

0 Kudos

Thank you Naveen for the suggestion. By workaround I meant a different way of doing it like not allowing the user to enter date other than the valid ones. (Like disallow him to enter 2014/22/42, where 22 is not a valid motnh and 42 is not a valid date) Something of that sort? So that the Invalid date message doesnt occur at all....

Thanks.


rosenberg_eitan
Active Contributor
0 Kudos

Hi,

Move your selection screen validation to "AT SELECTION-SCREEN"  event.

See http://help.sap.com/abapdocu_740/en/abapat_selection-screen_events.htm

http://scn.sap.com/thread/596120

See program  DEMO_SELECTION_SCREEN_EVENTS

Regards.

0 Kudos

Thank you Eitan, That was helpful. But the fields are getting disabled before even I enounter the At Selection-screen block. Checked it in debug mode. Its getting disabled somewhere earlier. Can you help me by just copying my pgm and see how it works for you?

Thanks.

0 Kudos

Hi,

I am at home at the moment .(weekend)

Need to do some shopping (wife orders )

I will log on to work later (I can do that) and I will try your code.

Regards.

0 Kudos

Thank you Eitan. This can wait (and wife's orders should not) Have a lovely weekend. I am glad you offered to help. Will wait for your feedback.

BR,

Gita

former_member289261
Active Contributor
0 Kudos

Hi,

It is a date type field, the error getting generated is controlled by internal system check for the field which you cannot control.

If you manually want to do the process, declare the field as C of length 10. Then in START-OF-SELECTION write your validation code for the field as you need.

Regards,

Ashish

0 Kudos

Thanks Ashish, changing the field to type C will involve including Search help manually. Do you think this can be resolved by some other means? I want my o/p date to be like below (with search help for date)

If someone of you have time, can you run it in your PC and see where the problem is?

0 Kudos

You can use the following code in addition to my program.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_to.



  CALL FUNCTION 'F4_DATE'

   IMPORTING

     SELECT_DATE   = lv_date.



    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

      EXPORTING

        date_internal = lv_date

      IMPORTING

        date_external = p_to.

0 Kudos

Hi,

On F4 event of the field, call function HELP_START  and pass structure HELP_INFOS with the required fields.

In this structure, give CALL as  'V'

OBJECT as 'F'

FIELDTYPE as 'DATE'

and rest fields according to your report.

This will return the selected date in a importing parameters.

Assign it to the field.

Regards,

Ashish

mayur_priyan
Active Participant
0 Kudos

Hi,

Please check the following code.

REPORT  ztest_scn.



PARAMETERS: p_to TYPE char10,

            inp_a TYPE string,

            inp_b TYPE string.



DATA : lv_date TYPE sy-datum.



AT SELECTION-SCREEN OUTPUT.



  IF p_to IS INITIAL.



    CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL'

      EXPORTING

        date_internal = sy-datum

      IMPORTING

        date_external = p_to.



  ENDIF.



START-OF-SELECTION.



" Date validation

IF NOT p_to IS INITIAL.



  CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

    EXPORTING

      date_external                 = p_to

   IMPORTING

     DATE_INTERNAL                  = lv_date

   EXCEPTIONS

     DATE_EXTERNAL_IS_INVALID       = 1

     OTHERS                         = 2.



  IF sy-subrc <> 0.

* Implement suitable error handling here

  ENDIF.



ENDIF.



"Output

WRITE: / inp_a,

       / inp_b,

       / lv_date,

       / p_to.

This code allows invalid date and process the process. But within the program we are validating teh date before using it.

raymond_giuseppi
Active Contributor
0 Kudos

Wrap all your selection fields in a dummy BLOCK (no frame, no text)

Move your checks in a AT SELECTION-SCREEN ON BLOCK event form, so every field of the block will be input allowed.

In the control event you can map a character field to an internal field with tools like FM CONVERT_DATE_INPUT or class CL_ABAP_DATFM (and many other tools, look at threads related to Y2K thru scn search tool or google it.)

Regards,

Raymond

rosenberg_eitan
Active Contributor
0 Kudos

Hi,

Looks like the SAP way of doing things .

Any way This is my attempt.

Note the use of forms and FUNCTION 'SELECT_OPTIONS_RESTRICT'

Regards.

REPORT y_r_eitan_test_61_02 .

TABLES: btcuev, btcsev,btcselect,sflight.

TYPE-POOLS: abap , sscr .

PARAMETERS: p_event TYPE btcselect-eventid AS LISTBOX VISIBLE LENGTH 40.

SELECTION-SCREEN BEGIN OF BLOCK block02 WITH FRAME.
SELECT-OPTIONS: s_date FOR btcselect-from_date .
SELECTION-SCREEN END OF BLOCK block02.

SELECT-OPTIONS: s_carrid FOR sflight-carrid .

INITIALIZATION.
   PERFORM at_initialization .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_event.
   PERFORM at_selection_screen_request_01 .

AT SELECTION-SCREEN .
   PERFORM at_selection_screen_input .

START-OF-SELECTION .
   PERFORM at_start_of_selection .

*----------------------------------------------------------------------*

FORM at_initialization .

   s_date-high = sy-datum .

   CALL FUNCTION 'CCM_GO_BACK_MONTHS'
     EXPORTING
       currdate   = s_date-high
       backmonths = '1'
     IMPORTING
       newdate    = s_date-low.

   s_date-sign   = 'I' .
   s_date-option = 'BT' .

   APPEND s_date .

   DATA: st_restriction TYPE sscr_restrict   .

   DATA: st_opt LIKE LINE OF st_restriction-opt_list_tab .
   DATA: st_ass LIKE LINE OF st_restriction-ass_tab.

   CONSTANTS: c_rule_1 LIKE st_opt-name VALUE 'RULE_1' .
   clear st_opt .
   st_opt-name = c_rule_1 .
   st_opt-options-bt = abap_true .
   APPEND st_opt TO st_restriction-opt_list_tab .

   CONSTANTS: c_rule_2 LIKE st_opt-name VALUE 'RULE_2' .
   clear st_opt .
   st_opt-name = c_rule_2 .
   st_opt-options-eq = abap_true .
   APPEND st_opt TO st_restriction-opt_list_tab .

   st_ass-kind = 'S' .
   st_ass-name = 'S_DATE' .
   st_ass-sg_main = 'I' .
   st_ass-sg_addy = abap_false .
   st_ass-op_main = c_rule_1 .
   APPEND st_ass TO st_restriction-ass_tab.

   st_ass-kind = 'S' .
   st_ass-name = 'S_CARRID' .
   st_ass-sg_main = 'I' .
   st_ass-sg_addy = abap_false .
   st_ass-op_main = c_rule_2 .
   APPEND st_ass TO st_restriction-ass_tab.

   CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
     EXPORTING
       restriction            = st_restriction
     EXCEPTIONS
       too_late               = 1
       repeated               = 2
       selopt_without_options = 3
       selopt_without_signs   = 4
       invalid_sign           = 5
       empty_option_list      = 6
       invalid_kind           = 7
       repeated_kind_a        = 8
       OTHERS                 = 9.

   IF sy-subrc NE 0.
     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDIF.


ENDFORM . "at_initialization

*----------------------------------------------------------------------*

FORM at_selection_screen_request_01 .

   DATA: p_helpvalue_key TYPE ddshpvkey VALUE 'BTC_EVENTID_HELP'.

   DATA: eventid_hlp_tbl TYPE TABLE OF btcevthtbl WITH HEADER LINE .

   SELECT * FROM btcuev.
     eventid_hlp_tbl-eventid = btcuev-eventid.
     APPEND eventid_hlp_tbl.
   ENDSELECT.

   SELECT * FROM btcsev.
     eventid_hlp_tbl-eventid = btcsev-eventid.
     APPEND eventid_hlp_tbl.
   ENDSELECT.

   eventid_hlp_tbl-eventid = '*'.       " select everything
   APPEND eventid_hlp_tbl.              " for combo box

   SORT eventid_hlp_tbl BY eventid ASCENDING.

   DATA: fieldtbl TYPE TABLE OF dfies WITH HEADER LINE.

   fieldtbl-tabname    = 'BTCEVTHTBL'.
   fieldtbl-fieldname  = 'EVENTID'.
   APPEND fieldtbl.

   CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
     EXPORTING
       retfield        = 'EVENTID'
       pvalkey         = p_helpvalue_key
       dynpprog        = 'SAPLBTCH'
       dynpnr          = sy-dynnr
     TABLES
       value_tab       = eventid_hlp_tbl
       field_tab       = fieldtbl
     EXCEPTIONS
       parameter_error = 1
       no_values_found = 2
       OTHERS          = 3.

ENDFORM . "at_selection_screen_request_01

*----------------------------------------------------------------------*

FORM at_selection_screen_input .

* check in code insteat of obligatory

   IF s_carrid IS INITIAL .
     MESSAGE e000(oo) WITH 'Airline Code' 'Missing'.
   ENDIF .

ENDFORM . "at_selection_screen_input

*----------------------------------------------------------------------*

FORM at_start_of_selection .

   DATA: it_sflight TYPE TABLE OF sflight .

   SELECT * INTO TABLE it_sflight
   FROM sflight
   WHERE
     fldate IN s_date .

   IF it_sflight IS INITIAL .
     MESSAGE s668(vl) DISPLAY LIKE 'E'.
     RETURN .
   ENDIF .

ENDFORM. " AT_START_OF_SELECTION

  *----------------------------------------------------------------------*

0 Kudos

Thank you Eitan. That was helpful