I've being doing some research about this, but all the results are from a couple of years ago.
Is there a way to define an input parameter as optional when calling a Procedure or a .W file?
My program works in this way - I have an external procedure that sends email using SMTP and it needs a few input parameters (Like Subject, Send To, etc) and I need to add a new input field that will add an attachment for the email.
To not edit and compile old codes, is possible to create this new parameter as optional and if it doesn't receive any value the program consider as blank?
DEFINE INPUT PARAMETER p_tipo_alerta AS CHAR.
DEFINE INPUT PARAMETER p_grupo_email AS CHAR.
DEFINE INPUT PARAMETER p_obs AS CHAR.
DEFINE INPUT PARAMETER p_site AS CHAR.
DEFINE INPUT PARAMETER p_CodeRequest AS CHAR.
DEFINE INPUT PARAMETER p_DescRequest AS CHAR.
// New-Optional
DEFINE INPUT PARAMETER p_AttachPath AS CHAR.
Thanks!
The ABL language does not support this kind of programming. The closest you can come is using classes and have multiple overloaded methods, which then call the 'primary' method passing in whatever the default values are.
class Foo:
method public void m1(p1 as character):
define variable nullObj as Object.
define variable defaultDate as date initial today.
this-procedure:m1(p1, defaultDate, nullObj, nullObj).
end method.
method public void m1(p1 as character, p2 as date).
define variable nullObj as Object.
this-procedure:m1(p1, p2, nullObj, nullObj).
end method.
method public void m1(p1 as character, p2 as date, p3 as Object).
define variable nullObj as Object.
this-procedure:m1(p1, p2, p3, nullObj).
end method.
method public void m1(p1 as character, p2 as date, p3 as Object, p4 as Object):
// does what it does
end method.
end class.
Doing this with procedural code is more complex since (internal) procedure names cannot be overloaded, so the names needs need to be unique.
If you don't want to change the calling code, though, you may be out of luck.