cancel
Showing results for 
Search instead for 
Did you mean: 

User exit to check user variable values

Former Member
0 Kudos

Hi All,

We have a user exit variable based on CALYEAR (to have the last year as default value).

Therefor, the user could choose another value (year) but not values later than 2 last years.

For instance, in 2010, the default value is 2010, and the user could choose 2009 or both 2010 and 2009.

How can we check the user variable entries, and how can we prevent the user to do this.

In other words, could you please give us the step number when we have put this checking (1, 2 or 3), and

If itu2019s possible the ABAP programme to do this.

Thank you in advance.

Radjech.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi Radjech

you can reach that with the i_step = 3.

The step 3 is used for validation. This step checks the variable value keyed in by the user to see if you allow him to proceed the query.

Here is an example.

This code it to be included after the i_step = 1 where you give the default value of the year.

Anyway the I_step = 3 is called only once.

The case endcase is declared for the whole coding in the user exit. So for example you have

Case i_vnam

if i_step = 1.

your treatment for default value.

Endif.

Then you give in the below coding.

if i_step = 3.

read table i_var_range into s_var_range with key vnam = zvar_calyear. " here I assume you have defined your simple and unique variable with the same technical name.

if sy-subrc = 0.

l_queriedyear = l_s_var_range-low(4) " here you retrieve the value of the variable in a local variable.

endif.

l_currrentyear =sy-datum(4). " here you take the current date and put it in a variable.

if l_currrentyear - l_queriedyear > 2. " here you make the comparison of the current system date and the year of the variable. if it is > to 2 then raise the validation

raise wrong_value. " here you can use a raise wrong value

Endif.

Endif.

Or you can combine a message with a raise like follows

therefore example should be

if i_step = 3.

read table i_t_var_range into l_s_var_range with key vnam = zvar_calyear.

if sy-subrc = 0.

l_queriedyear = l_s_var_range-low(4)

endif.

l_currrentyear =sy-datum(4).

if l_currrentyear - l_queriedyear > 2.

Call functinn 'RRMS_MESSAGE_HANDLING'

Exporting

I_class = 'RSBBS'

I_TYPE = 'I'

I_number = '000'

I_MSGV1 = 'Year value to big'.

Raise wrong_value.

Endif.

Endif.

eNDCASE.

Boujema

Former Member
0 Kudos

Hi Boujema,

Thank you for answer.

I tried your ABAP code, but I didn't have the ERROR message when I put the prohibitted value (PLA) in the variable.

Could you have a look, on the code below please.

For your information, whand debugging, the ABAP code don't read the i_step3.

I replaced the message MF by "Message 'ERROR' Type 'C'." because I don't know the whole syntaxe to ut the error msg.

Could you give meit please.

WHEN 'RD_PLANT'.
     IF i_step = 1.
   CLEAR l_s_range.
      l_s_range-low = 'PLA'.
      l_s_range-sign = 'I'.
      l_s_range-opt = 'EQ'.
      APPEND l_s_range TO e_t_range.
    ENDIF.

  IF i_step = 3.
      READ TABLE i_t_var_range INTO LOC_VAR_RANGE WITH KEY vnam = 'MA_PLANT'.
        IF sy-subrc EQ 0.
               IN_PLANT = LOC_VAR_RANGE-LOW.
       ENDIF.
               OUT_PLANT = 'PLA'.
          If IN_PLANT EQ OUT_PLANT.
Message 'ERROR' Type 'C'.

          ENDIF.

ENDIF.

Former Member
0 Kudos

hi

try the following.

if you can't go in debug post the coding before CASE i_vnam or after the ENDCASE.

Then position your coding. Here are the ways you could handle an error message.

IF i_step = 3.

READ TABLE i_t_var_range INTO LOC_VAR_RANGE WITH KEY vnam = 'MA_PLANT'.

IF sy-subrc EQ 0.

IN_PLANT = LOC_VAR_RANGE-LOW.

ENDIF.

OUT_PLANT = 'PLA'.

If IN_PLANT EQ OUT_PLANT.

CALL FUNCTION 'RRMS_MESSAGE_HANDLING'

EXPORTING

I_CLASS = 'RSBBS'

I_TYPE = 'I'

I_NUMBER = '000'

I_MSGV1 = 'Plant not allowed'.

RAISE no_replacement.

ENDIF.

if the system warns you about no_replacement is not defined as exception in function module, ignore the warning Save and Activate.

or try

IF i_step = 3.

READ TABLE i_t_var_range INTO LOC_VAR_RANGE WITH KEY vnam = 'MA_PLANT'.

IF sy-subrc EQ 0.

IN_PLANT = LOC_VAR_RANGE-LOW.

ENDIF.

OUT_PLANT = 'PLA'.

If IN_PLANT EQ OUT_PLANT.

raise wrong_value.

ENDIF.

Again if the system warns you about wrong_value is not defined as exception in function module, ignore the warning Save and Activate.

Hope this could help you solving your issue. For the syntaxe of the raise let it as written. If you want more details about the function 'RRMS_MESSAGE_HANDLING' go to the function as look at the parameters for instance for message type you have

E Error

A Termination

I Information

W Warning

S Success message

in the domain MSGTY_CO.

Boujema

Boujema

Former Member
0 Kudos

Thank you a lot Boujema.

It works fine.

Therefor, I have another question, could we update the characteristic values of the variable, before user choosing.

For instance, if my characteristic "0CALYEAR" contain years values since 2001 (2001, 2002, 2003 ....2010), could we to show to the user only values of the 2 last years (2009, 2010).

For information, my variable is "ready for input".

Thks in advance.

Radjech.

Edited by: monsdn on Aug 25, 2010 10:55 AM

Answers (1)

Answers (1)

former_member189638
Active Contributor
0 Kudos

Yes, Create a customer exit variable and write the ABAP Code in I_STEP =3. This is used for validation. You can raise the message here if the user enters wrong value.

Refer the following thread if you need any help on the coding part.

Former Member
0 Kudos

Thank you a lot for the answer.

.

But could you please explain me where I have to put this ABAP code.

Is there between the "CASE i_vnam" and "ENDCAS" ? OR after the instruction "ENDCASE '.

Another question, the I_STEP 3 is related to a variable or no ? have we put the code after "When "Variable name" or put it directly without the instrucion "When "Variable name".

Thx in advance.

Radj.

former_member189638
Active Contributor
0 Kudos

i_step = 3 is vey much related to the variable. You have to put it after the endcase. and you need to use the instruction in i_step = 3. Without instruction i_step will not work.

Following weblog by Mansi will give you a clear picture..

/people/mansi.dandavate/blog/2009/12/16/using-combination-of-istep-2-and-istep-3-to-meet-a-typical-requirement