Processing unnamed optional include file parameters in Progress

94 Views Asked by At

I'm trying to add a simple IF statement to my include .i-file to handle optional unnamed parameters:

message.i:

/*
    - {1}: Message.
    - {2}: OPTIONAL Sender name
*/
&IF DEFINED({2}) <> 0 &THEN
    {2} = "Unknown sender".
&ENDIF.
MESSAGE "{2}" + ": " + "{1}" VIEW-AS ALERT-BOX.

test.p:

{message.i "hello world" }
// Should output "Unknown sender: hello world".
// Does not compile.

{message.i "hello world" "Michael" }
// Should output "Michael: hello world".

In this version, the message.i will throw error if the second parameter is missing.

I want to use unnamed parameters and avoid the parameter naming.

How I can fix the code to make it work?

2

There are 2 best solutions below

1
Tom On BEST ANSWER

You could check if the second parameter is empty :

message.i

&IF "{2}" <> "" &THEN
    MESSAGE "{2}" + ": " + "{1}" VIEW-AS ALERT-BOX.
&ELSE
    MESSAGE "Unknown sender" + ": " + "{1}" VIEW-AS ALERT-BOX.
&ENDIF.

AblDojo example

1
Stefan Drissen On

As an alternative, you can use an intermediate preprocessor to grab the unnamed parameter:

&if '{2}' > '' &then
   &scoped sender {2}
&else
   &scoped sender Unknown sender
&endif

message '{&sender}: {1}' view-as alert-box.

Watch it run at… drat, ABLDojo share and copy to clipboard does not work on an iPad.