Application Development and Automation 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: 
Read only

Populating a reqd. selection field based on other selection field-Reports?

Former Member
0 Likes
731

Hi,

I have a selection screen wherein there are several fields which are mandatory.Now it has fields like customer Number(KNA1-KUNNR) for which there is a standard help coming in and customer name(KNA1-NAME1).

My requirement is as soon as user selects a customer no along with customer no customer name field is also populated without performing any action on screen.Now if I write the code as:-

at selection-screen on p_name1.

select single name1 into p_name1

from kna1

where kunnr = p_kunnr.

There are few problems in this:-

1)It will be executed only when user presses enter or F8 but I dont want that...

2)Also if I perform any action on screen say pressed enter this code will be executed only when i have put in values in all the MANDATORY fields.So will have to put in a dummy value first since its a mandatory field and then this code will be executed which doesn't serve my purpose..

Please suggest a way out..Its really urgent..Have to make an object delivery

Thanks in advance,

Swati

Hi,

I have a selection screen wherein there are several fields which are mandatory.Now it has fields like customer Number(KNA1-KUNNR) for which there is a standard help coming in and customer name(KNA1-NAME1).

My requirement is as soon as user selects a customer no along with customer no customer name field is also populated without performing any action on screen.Now if I write the code as:-

at selection-screen on p_name1.

select single name1 into p_name1

from kna1

where kunnr = p_kunnr.

There are few problems in this:-

1)It will be executed only when user presses enter or F8 but I dont want that...

2)Also if I perform any action on screen say pressed enter this code will be executed only when i have put in values in all the MANDATORY fields.So will have to put in a dummy value first since its a mandatory field and then this code will be executed which doesn't serve my purpose..

Please suggest a way out..Its really urgent..Have to make an object delivery

Thanks in advance,

Swati

5 REPLIES 5
Read only

Former Member
0 Likes
709

Hi,

1)It will be executed only when user presses enter or F8 but I dont want that...

I am not sure with out any event like enter or F8, you could populate the customer name corresponding to the customer number (i could be wrong in this...)

2)Also if I perform any action on screen say pressed enter this code will be executed only when i have put in values in all the MANDATORY fields.So will have to put in a dummy value first since its a mandatory field and then this code will be executed which doesn't serve my purpose..

My feeling is that, when you press enter, the check for mandatory field is performed first. Unless all mandatory fields are filled, it will not perform any thing else, including your logic to fill up the customer name field.

Thanks

Pranati..

Read only

Former Member
0 Likes
709

&----


*& Report ZASH_SCREEN *

*& *

&----


*& *

*& *

&----


REPORT zash_screen .

PARAMETERS: kunnr LIKE kna1-kunnr.

PARAMETERS: name1 LIKE kna1-name1.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF kunnr IS NOT INITIAL.

SELECT SINGLE name1 INTO name1

FROM kna1

WHERE kunnr = kunnr.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

Hope it helps.

Shreekant

Read only

0 Likes
709

Hi Shreekant,

Thanks for the reply..

But I suppose at selection-screen output is triggered before screen is displayed...and customer number will be entered after display of selection screen..

So don't think it will solve the problem...

Thanks so much,

Swati

Read only

0 Likes
709

Swati,

It dosednt matter if it triggers. It will be triggered even after data is entered.

Since the first time kunnr will be blank and hence the if condition wont be satisfied.

Also check the code Rich has specified. It does some checks as well.

Shreekant.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
709

Try this example, this will also automatically update the NAME1 field when user does F4 help on the customer number.



data: dynfields type table of dynpread with header line.
data: return type table of ddshretval with header line.

parameters: p_kunnr type kna1-kunnr,
            p_name1 type kna1-name1,
            p_kdgrp type knvv-kdgrp.


at selection-screen.

  if not p_kunnr is initial.
    select single name1 into p_name1 from kna1
              where kunnr = p_kunnr.
  endif.

* Now do checks
  if p_kdgrp is initial.
    message e001(00) with 'Customer group is not valid'.
  endif.


at selection-screen on value-request for p_kunnr.

  data: xkna1 type kna1.
  data: xkunnr type kna1-kunnr.
  clear dynfields . refresh dynfields .
  clear return.     refresh return.
  call function 'F4IF_FIELD_VALUE_REQUEST'
       exporting
            tabname           = 'KNA1'
            fieldname         = 'KUNNR'
            dynpprog          = sy-cprog
            dynpnr            = sy-dynnr
            dynprofield       = 'P_KUNNR'
       tables
            return_tab        = return
       exceptions
            field_not_found   = 1
            no_help_for_field = 2
            inconsistent_help = 3
            no_values_found   = 4
            others            = 5.

  read table return with key fieldname = 'P_KUNNR'.

* Add it back to the dynpro.
  dynfields-fieldname = return-retfield.
  dynfields-fieldvalue =  return-fieldval.
  append dynfields.

  call function 'CONVERSION_EXIT_ALPHA_INPUT'
       exporting
            input  = return-fieldval
       importing
            output = xkunnr.

  clear xkna1.
  select single * into xkna1
         from kna1
        where kunnr = xkunnr.

  dynfields-fieldname = 'P_NAME1'.
  dynfields-fieldvalue = xkna1-name1.
  append dynfields.

* Update the dynpro values.
  call function 'DYNP_VALUES_UPDATE'
       exporting
            dyname     = sy-cprog
            dynumb     = sy-dynnr
       tables
            dynpfields = dynfields
       exceptions
            others     = 8.

start-of-selection.

Regards,

RIch Heilman