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: 

Auto-populate selection screen field

former_member215781
Active Participant
0 Kudos


I have 2 selection-screen fields - quarter and year.

If I select quater as Q2 and year as 2011, my 3rd selecion screen field should auto-populate with start and end date of that year quarter.

I am able to achieve this once I press ENTER, after populating year. But on manullay filling quarter and year and clicking the third field using cursor, it does not auto-populate.

I want the dates to auto-populate as soon as the cursor moves from year - by doing tab or mouse click or enter hit.

1 ACCEPTED SOLUTION

former_member184569
Active Contributor
0 Kudos

Use the events AT SELECTION-SCREEN ON <Field> for quarter and year.

And do the coding here using the  FM DYNP_VALUES_READ.

13 REPLIES 13

former_member184569
Active Contributor
0 Kudos

Use the events AT SELECTION-SCREEN ON <Field> for quarter and year.

And do the coding here using the  FM DYNP_VALUES_READ.

0 Kudos

I have already tried and it does not seem to work. At present I have added the code in the vent AT SELECTION_SCREEN ON <field year>.

It does populate the dates but only when I hit ENTER. My requirement is to populate the dates irrespective of hitting ENTER.

0 Kudos

Hi Sim,

İ think it should be on at selection screen output and for year field you should use USER-COMMAND COM

0 Kudos

Hi Sim,

I would suggest that you put quarter and year, or atleast quarter as listbox.

With list box you can have a user command associated with it. So whenever these fields are populated, the at selection screen field event will be triggered without clicking enter.

You may use the DYNP_VALUES_READ to read the input for quarter and year and DYNP_VALUES_UPDATE to update the selection screen parameters for dates.  I dont think it would be required. The Values of quarter and year would be available in the at selection screen event.

0 Kudos

Check this code.

TYPE-POOLS: vrm.

PARAMETERS :   p_qrtr AS LISTBOX VISIBLE LENGTH 10 USER-COMMAND abc,
     p_year type gjahr AS LISTBOX VISIBLE LENGTH 10 USER-COMMAND abc.

PARAMETERS : p_begda type begda, p_endda type endda.

DATA: name TYPE vrm_id, list TYPE vrm_values, value LIKE LINE OF list.

AT SELECTION-SCREEN OUTPUT.
   clear : list, value, name.
   name = 'P_QRTR'.
   value-key = '1'. value-text = 'Quarter 1'. APPEND value TO list.
   value-key = '2'. value-text = 'Quarter 2'. APPEND value TO list.
   value-key = '3'. value-text = 'Quarter 3'. APPEND value TO list.
   value-key = '4'. value-text = 'Quarter 4'. APPEND value TO list.

* Set list box with value
   CALL FUNCTION 'VRM_SET_VALUES'
     EXPORTING
       id     = name
       values = list.

clear list. refresh list.
data : lv_year(4) type n.
name = 'P_YEAR'.
lv_year = '1900'.
do 150 times.
clear value.
value-key = lv_year.
value-text = lv_year.
append value to list.
add 1 to lv_year.
enddo.

call function 'VRM_SET_VALUES'
exporting
id = name
values = list.

at SELECTION-SCREEN.
   if sy-ucomm = 'ABC'.
     if p_year is INITIAL or p_qrtr is INITIAL.
       exit.
     endif.

    case p_qrtr.
      when '1'.
        concatenate p_year '0101' into p_begda.
        concatenate p_year '0331' into p_endda.
      when '2'.
        concatenate p_year '0401' into p_begda.
        concatenate p_year '0630' into p_endda.
     when '3'.
        concatenate p_year '0701' into p_begda.
        concatenate p_year '0930' into p_endda.
     when '4'.
        concatenate p_year '1001' into p_begda.
        concatenate p_year '1231' into p_endda.
    endcase.

endif.

0 Kudos

Year field is input text field and not list box as per my requirement

0 Kudos

Cant you not change it to a list box as given above? After all, year field can have only those set of values. So I guess, it will not make any difference to program, but provide the additional benefit of having a user command linked to it.

0 Kudos

When I select a year for example, 2007 from the dropdown, it populates the correct dates based on the quarter. But if I change the year from 2007 to 2008, dates are not automatically changed

0 Kudos

You have the user command for the year drop down field also right?


PARAMETERS :   p_qrtr AS LISTBOX VISIBLE LENGTH 10 USER-COMMAND abc,
     p_year type gjahr AS LISTBOX VISIBLE LENGTH 10 USER-COMMAND abc.


Check the sample code I have posted. Here whether you change year or quarter, the dates would be automatically changed. Use that same logic.

0 Kudos

Hi,

You can declare quarter field as list-box ( as there may be only 4 quarters in any year) and year field as parameter.

Firstly, enter year say 2014 and as soon as you select quarter from list box your date fields will be populated accordingly.

You can write the desired logic in the event AT SELECTION-SCREEN ON <quarter> .

Hope this helps.

0 Kudos

This will have a small problem when you want to change the year.

Initially, on entering year and then entering quarter, the dates will be populated correctly. However, when you change the year, no event is triggered and hence dates remain the same.

That is why you need the user command associated with both fields if you want to handle the automatic population of dates accurately.

0 Kudos

As prompted rightly date population logic should be carried out on both events( year & quarter).

0 Kudos

User command was added. Problem was with my append statement as I was using select-options for dates and not parameters unlike your pasted code.

Thanks, I have selected your answer as the solution to my main query