05-30-2011 9:01 AM
Hi,
I have written one common validation method for all select-options in selection-screen.
Which will be called for every select option validation.
I will pass s_vkorg, s_vtweg, s_abgru etc.. for each of the validations.
In the method i have created structrure & table type for the im_sel_scr_field.
This zsel_field structure is created with sign(char1), option(char2), low(45), high(45) field values.
zsel_field_tt (Table type for zsel_field structure).
Now when i am calling validation method as below, i am getting 'type compatible' error.
If i can create i.table of above structure: zsel_field i can pass the sel-opt value to i.table to avoid this error.
But i need to do this for each select option.
Z_Meth
Method
EXPORTING
im_sel_scr_field = s_vkorg[]/s_abgru[] etc...
Note: I don't want to create structure/table type for each select option.
I want to make s_vkorg[], s_abgru[] etc... passed without type-compatibale error.
Can anyone provide input for resolving this issue!
Thanks in advance.
Thanks,
Kumar.
05-30-2011 9:08 AM
Hi,
The structure of Sel option is as:
SIGN C(1)
OPTION C(2)
LOW C(10)
HIGH C(10)
Use the same in your method.
05-30-2011 9:13 AM
Hi,
Thanks for your reply.
I will get same error message 'Not Type compatible' as LOW/HIGH are Char(10) but s_vkorg will have Char4 & s_abgru will have char2.
I want to make it work for all different lengths of select options.
Thanks,
Kumar.
05-30-2011 9:18 AM
Hi,
All of them are select options at database level.It shouldnt be a problem.Please paste teh code where you are calling the method and passing the same.Also please show the method definition.
05-30-2011 9:25 AM
Hello Sap_Wiz,
May be you didn't notice Marcin's "wiz"adry
Cheers,
Suhas
05-30-2011 10:17 AM
Hi,
Thanks for your replies.
I am calling my validation code in below way currently:
DATA: gt_sel_field TYPE TABLE OF z_sel_field,
gt_sel_field[] = s_vkorg[].
CALL METHOD zcl_validation=>z_sel_scr_validation
EXPORTING
* im_param = ''
im_sel_field = gt_sel_field[]
* im_sel_field = s_vkorg[].
z_sel_field is a structure with fields: sign(char1), option(char2), low(char45), high(char45).
My method (z_sel_scr_validation) in class created with below parameters:
IM_PARAM TYPE string. (optional)
IM_sel_field TYPE z_sel_field_tt, (optional)
z_sel_field_tt refers to z_sel_field structure.
In method i will validate select option (or) parameter based on user input (Have all the logic to validate against check table etc..).
In above method call i am using gt_sel_field[] but i want to use s_vkorg[], s_abgru[] etc... but they are not type compatiable
with table type (or) structure of z_sel_field. If i use gt_sel_field[] i need to declare it every time validation happens for each field.
How can i acheive this!
Thanks in advance.
Thanks,
Kumar.
05-30-2011 9:17 AM
As each of your select options are of different type (LOW and HIGH fields) you will keep raising this error. I don't think you can statically address parameter type which would be common to all your select options. Try then working with it dynamically by passing only reference to it
"definition
METHOD z_meth IMPORTING ref_sel_opt TYPE REF TO DATA.
"implementation
METHOD z_meth.
field-symbols: <sel> type any table, <field> type any.
assign ref_sel_opt->* to <sel>.
if sy-subrc = 0.
"validate the structure
ASSIGN COMPONENT 'SIGN' of structure <sel> to <field>.
if sy-subrc ne 0.
"wrong structure raise some error
endif.
ASSIGN COMPONENT 'OPTION' of structure <sel> to <field>.
if sy-subrc ne 0.
"wrong structure raise some error
endif.
ASSIGN COMPONENT 'LOW' of structure <sel> to <field>.
if sy-subrc ne 0.
"wrong structure raise some error
endif.
ASSIGN COMPONENT 'HIGH' of structure <sel> to <field>.
if sy-subrc ne 0.
"wrong structure raise some error
endif.
endif.
"now work with <sel> as the structure is correct
ENDMETHOD.
"client
data ref_sel type ref to data.
get reference of s_opt1[] into ref_sel.
CALL METHOD ...z_meth EXPORTING ref_sel.
get reference of s_opt2[] into ref_sel.
CALL METHOD ...z_meth EXPORTING ref_sel.
get reference of s_opt3[] into ref_sel.
CALL METHOD ...z_meth EXPORTING ref_sel.
Regards
Marcin
05-30-2011 10:45 AM
Hi,
Try with below code...
select-options:
s_var1 for im_sel_scr_field,
s_var2 for im_sel_scr_field,
s_var3 for im_sel_scr_field,
s_var4 for im_sel_scr_field.
because you are maintining all select opt fields are characters. so according to that based on 'im_sel_scr_field' attribute data type we can follow to assign type to select options.
Now you can pass select option values to the respective method as well.
Ram.