That is an interesting idea Brad.
I'll have to ponder and see if I can come up with a use case to try it out somewhere.
As for some simple prototype samples, here are a couple that I've had good results from.
So far I've used overloading a couple of times.
I've had the best results when using updatable parameters.
Once you try to make too much stuff Constant then you run into mapping issues where the compiler does not know how to choose between "Packed(5) Const" and "Packed(10) Const".
In one instance it was a way to load default values to fields by name.
I used overload to load a field by a constant name.
This make it easier to move the default value retrieval into a service program and still have it generic enough to allow for new fields to be added later without a lot of issues. I'd only need to add more procedures if the data type changed.
POS00P_Dft_GetValue( 'NAME' : xxNAME );
POS00P_Dft_GetValue( 'CODE' : xxCODE );
// --------------------------------------------------
// Procedure name: POS00P_Dft_GetValue
// Purpose: Return the Default value for the POS Field.
// Returns: Default Value in Value Parameter
// Parameter: Field
// Parameter: Value => Destination Field for default value
// --------------------------------------------------
Dcl-pr POS00P_Dft_GetValue
OVERLOAD(
POS00P_Dft_GetValueChar
:POS00P_Dft_GetValue3P0
:POS00P_Dft_GetValue5P0
:POS00P_Dft_GetValue5P2
:POS00P_Dft_GetValue7P2
:POS00P_Dft_GetValue15P0
);
// Use Procedure POS00P_Dft_GetValue
Dcl-Pr POS00P_Dft_GetValueChar OPDESC;
Field Char(10) Const;
Value Char(1000) OPTIONS(*VARSIZE);
End-pr;
// Use Procedure POS00P_Dft_GetValue
Dcl-Pr POS00P_Dft_GetValue3P0;
Field Char(10) Const;
Value Packed(3:0);
End-pr;
// Use Procedure POS00P_Dft_GetValue
Dcl-Pr POS00P_Dft_GetValue5P0;
Field Char(10) Const;
Value Packed(5:0);
End-pr;
// Use Procedure POS00P_Dft_GetValue
Dcl-Pr POS00P_Dft_GetValue5P2;
Field Char(10) Const;
Value Packed(5:2);
End-pr;
// Use Procedure POS00P_Dft_GetValue
Dcl-Pr POS00P_Dft_GetValue7P2;
Field Char(10) Const;
Value Packed(7:2);
End-pr;
// Use Procedure POS00P_Dft_GetValue
Dcl-Pr POS00P_Dft_GetValue15P0;
Field Char(10) Const;
Value Packed(15);
End-pr
In another example, I've used Overload to allow looking something up by a different set of keys.
Here I can get the Environment data structure by numeric ID key and by character NAME.
// --------------------------------------------------
// Procedure name: PosJ_GetEnvironment
// Purpose: Get Environment Record
// Returns: n/a
// Parameter: Environment Id --OR-- Environment Name
// Parameter: Environment Record (output)
// Parameter: Log Handle
// --------------------------------------------------
Dcl-Pr PosJ_GetEnvironment Overload(
PosJ_GetEnvironment_EnvironmentId
: PosJ_GetEnvironment_EnvironmentName
);
// --------------------------------------------------
// Procedure name: PosJ_GetEnvironment_EnvironmentId
// OVERLOADED TO: PosJ_GetEnvironment
// --------------------------------------------------
Dcl-Pr PosJ_GetEnvironment_EnvironmentId;
EnvironmentId Like(POSJ_Environment_t.EnvironmentId) Const;
EnvironmentRecord Likeds(POSJ_Environment_t);
Logger Like(Pos00j_ref.LogHandle) Options(*Nopass) Const;
End-pr;
// --------------------------------------------------
// Procedure name: PosJ_GetEnvironment_EnvironmentName
// OVERLOADED TO: PosJ_GetEnvironment
// --------------------------------------------------
Dcl-Pr PosJ_GetEnvironment_EnvironmentName;
EnvironmentName Like(POSJ_Environment_t.EnvironmentName) Const;
EnvironmentRecord Likeds(POSJ_Environment_t);
Logger Like(Pos00j_ref.LogHandle) Options(*Nopass) Const;
End-pr;
--
Chris Hiebert
Senior Programmer/Analyst
Disclaimer: Any views or opinions presented are solely those of the author and do not necessarily represent those of the company.
From: RPG400-L <rpg400-l-bounces@xxxxxxxxxxxxxxxxxx> On Behalf Of Brad Stone
Sent: Sunday, January 14, 2024 3:11 PM
To: RPG programming on the IBM i (AS/400 and iSeries) <rpg400-l@xxxxxxxxxxxxxxxxxx>
Subject: Overloading RPG Subprocedures
So, I decided to start digging into this. It looks pretty cool. Thanks for
the examples online (Scott!)
I have yet to find any examples with more than one parameter, so here is my
question....
Can you overload with multiple parameters where one or two are different?
Like this to retrieve an invoice or PO:
dcl-pr getInvoice int(10);
In_ID char(128) const;
Out_Invoice likeds(invoiceDS) options(*exact);
end-pr;
dcl-pr getPO int(10);
In_ID char(128) const;
Out_PO likeds(poDS) options(*exact);
end-pr;
dcl-pr getData int(10) Overload(getInvoice:getPO);
So you could do something like:
dcl-ds thisInvoiceDS like(invoiceDS) end-ds;
dcl-ds thisPODS like(poDS) end-ds;
dcl-s rc int(10);
rc = getData('10':thisInvoiceDS);
rc = getData('10':thisPurchaseOrderDS);
From what I'm reading this should work.
Blizzards are fun. Downtime = exploring time. :)
Bradley V. Stone
As an Amazon Associate we earn from qualifying purchases.