Optional parameter in an Operation | Uniface Development | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

—  Results per page  —








— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters
For a group of consecutive words like 'end of support' use Match phrase

sp_Feed Topic RSS sp_TopicIcon
Optional parameter in an Operation
09 Nov 2017
6:48 pm
Avatar
hugogarcia
Member
Forum Posts: 5
Member Since:
29 Sep 2017
sp_UserOfflineSmall Offline

Hello,

Is it possible to create an optional parameter for an Operation? Where I could or not send the value for the parameter.

For example:

public operation unifaceOperation

  params

    string OptionalParam : IN  ;an optional parameter with some default value

  endparams

end

10 Nov 2017
7:36 am
Avatar
ulrich-merkel
Frankfurt/Germany
Member
Forum Posts: 1703
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

Hi Hugo,

uniface doesn’t have a concept for optional parameters.

To build some mechanism which comes next to optional parameters,
uniface experts use a single list as a parameter which may have items, but there’s no need to add them.

You can query if a list has a specific key to detect if optional parameters have been included:
if $item(“OptionalParam”,inList) != “”) … ; optional parameter available

Greetings from Frankfurt/Germany,
Uli

10 Nov 2017
9:08 am
Avatar
ulrich-merkel
Frankfurt/Germany
Member
Forum Posts: 1703
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

This is an example based on 9.6.04

 

entry do_p_start ; put YOUR code here
; if you need input or output, there is the editbox X_AFIELD already
call OptionalParams(X_AFIELD)
end ; do_p_start

entry FILL_X_AFIELD
X_AFIELD = “Mandatory=Mandat·;Optional=Option”
end ; entry FILL_X_AFIELD

entry OptionalParams ; using a list to support optional parameters
params
string vInList : IN ; list of parameters
endparams
call add_PROTOCOL(“call OptionalParams(%%vInList%%%)”)
if ($item(“Mandatory”,vInList) = “”)
call add_PROTOCOL(“ERROR: Parameter Mandatory is missing (or empty)”)
endif
if ($item(“Optional”,vInList) = “”)
call add_PROTOCOL(“Info: Parameter Optional is missing (or empty)”)
else
call add_PROTOCOL(“Info: Parameter Optional found as %%$item(“Optional”,vInList)%%%”)
endif
end ; entry OptionalParams

 

 

 
10 Nov 2017
12:32 pm
Avatar
hugogarcia
Member
Forum Posts: 5
Member Since:
29 Sep 2017
sp_UserOfflineSmall Offline

ulrich-merkel said
This is an example based on 9.6.04

 

entry do_p_start ; put YOUR code here
; if you need input or output, there is the editbox X_AFIELD already
call OptionalParams(X_AFIELD)
end ; do_p_start

entry FILL_X_AFIELD
X_AFIELD = “Mandatory=Mandat·;Optional=Option”
end ; entry FILL_X_AFIELD

entry OptionalParams ; using a list to support optional parameters
params
string vInList : IN ; list of parameters
endparams
call add_PROTOCOL(“call OptionalParams(%%vInList%%%)”)
if ($item(“Mandatory”,vInList) = “”)
call add_PROTOCOL(“ERROR: Parameter Mandatory is missing (or empty)”)
endif
if ($item(“Optional”,vInList) = “”)
call add_PROTOCOL(“Info: Parameter Optional is missing (or empty)”)
else
call add_PROTOCOL(“Info: Parameter Optional found as %%$item(“Optional”,vInList)%%%”)
endif
end ; entry OptionalParams

 

 

 

  

Thanks for your help!!

10 Nov 2017
7:25 pm
Avatar
ulrich-merkel
Frankfurt/Germany
Member
Forum Posts: 1703
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

In case we have to handle even “empty” parameters as valid, it just takes a little helper function (9.6.04):

 

entry isKeyInList ; helper function when representation is empty
returns boolean
params
string p_key : IN
string p_list : IN
endparams
variables
string v_void
endvariables
getitem/id v_void, p_list, p_key
return($status > 0)
end ; entry isKeyInList

entry do_p_start ; put YOUR code here
; if you need input or output, there is the editbox X_AFIELD already
call OptionalParams(X_AFIELD)
end ; do_p_start

entry FILL_X_AFIELD
X_AFIELD = “Mandatory=·;Optional=Option”
end ; entry FILL_X_AFIELD

entry OptionalParams ; using a list to support optional parameters
params
string vInList : IN ; list of parameters
endparams
call <C4C_prefix>add_PROTOCOL(“call OptionalParams(%%vInList%%%)”)
if (!isKeyInList(“Mandatory”,vInList))
call <C4C_prefix>add_PROTOCOL(“ERROR: Parameter Mandatory is missing”)
endif
if (!isKeyInList(“Optional”,vInList))
call <C4C_prefix>add_PROTOCOL(“Info: Parameter Optional is missing”)
else
call <C4C_prefix>add_PROTOCOL(“Info: Parameter Optional found as %%$item(“Optional”,vInList)%%%”)
endif
end ; entry OptionalParams

Forum Timezone: Europe/Amsterdam

Most Users Ever Online: 131

Currently Online:
10 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

ulrich-merkel: 1703

Iain Sharp: 618

Theo Neeskens: 339

gianni: 260

rogerw: 232

istiller: 199

lalitpct: 197

Knut: 176

-GHAN-: 171

sochaz: 167

Member Stats:

Guest Posters: 3

Members: 6721

Moderators: 0

Admins: 8

Forum Stats:

Groups: 1

Forums: 62

Topics: 2049

Posts: 8810

Newest Members:

Mihaeleml, JosephGag, Uhqwwrl, RobertFus, Dibeiquife, Valentiatum, ThomasSib, Arthurmer, AlisaReem, Qtmawbs

Administrators: admin: 23, Adrian Gosbell: 283, diseli: 829, Bob Maier: 3, Nico Peereboom: 65, Michael Rabone: 4, richiet: 406, JanCees: 28