Saturday, February 18, 2023

*OMIT vs *NOPASS: Understanding the Key Differences - IBM i

*OMIT v/s *NOPASS

In RPGLE, *OMIT and *NOPASS are the two options used to specify the optional parameters for the procedures. It is essential to understand the difference between *OMIT and *NOPASS because knowing which keyword to use for the specific case helps in writing the clean code. 

Before we jump on to the key differences, let's have a look at the use of each of the keywords.

*OMIT

By using the *OMIT on the parameter while declaring a procedure, we can make this parameter an optional parameter. 

We could either pass the data to this parameter or simply pass '*OMIT' to while calling the procedure. 

Dcl-PR SampleProcedure;                              

  MandatoryParameter1 Char(1);                       

  OptionalParameterWithOmit Char(1) Options(*Omit);  

  MandatoryParameter2 Packed(1);                     

End-PR;                                              

                                                     

Dcl-Proc SampleProcedure Export;                     

  Dcl-PI SampleProcedure;                            

    MandatoryParameter1 Char(1);                     

    OptionalParameterWithOmit Char(1) Options(*Omit);

    MandatoryParameter2 Packed(1);                   

  End-PI;                                            

                              

  // Code to be run in the procedure         

                                        

End-Proc;                               


This procedure can be called in one of the two ways,
  • Either by passing the data for the optional parameter. 
  • Or by passing '*OMIT' to avoid passing this parameter. 

// Passing the data

SampleProcedure('A' : 'B' : 1);                      


// Passing *Omit

SampleProcedure('A' : *Omit : 1);


*NOPASS

By using the *NOPASS on the parameter while declaring a procedure, we can make this parameter an optional parameter. 

We could either pass the data to this parameter or not pass this parameter at all while calling the procedure. 

Dcl-PR SampleProcedure;                                  

  MandatoryParameter1 Char(1);                           

  MandatoryParameter2 Packed(1);                         

  OptionalParameterWithNoPass Char(1) Options(*NoPass);  

End-PR;                                                  

                                                         

Dcl-Proc SampleProcedure Export;                         

  Dcl-PI SampleProcedure;                                

    MandatoryParameter1 Char(1);                         

    MandatoryParameter2 Packed(1);                       

    OptionalParameterWithNoPass Char(1) Options(*NoPass);

  End-PI;                                                

                                                         

  // Code to be run in the procedure;                  

                                                         

End-Proc;                                                


This procedure can be called in one of the two ways,
  • Either by passing the data for the optional parameter. 
  • Or by not passing the parameter at all.

// Passing the data

SampleProcedure('A' : 1 : 'B');                      


// Not passing the optional parameter

SampleProcedure('A' : 1);


The Difference

There are couple of main differences between using *OMIT and *NOPASS. 
  • *OMIT can be used on any parameter, whereas *NOPASS can only be used on the last parameter(s) i.e., no mandatory parameter can be declared after *NOPASS is specified. 
  • *OMIT needs to passed to avoid passing the parameter declared with *OMIT, whereas no parameter needs to be passed when specified using *NOPASS (considering it is the last parameter). 

I hope this post has help in understanding what is the use of *OMIT, *NOPASS and the difference. 


If you have any Suggestions or Feedback, Please leave a comment below or use Contact Form.

No comments:

Post a Comment

Different Ways of Sorting Data in a List - Python

Sorting Data in a List List is a collection of data (of different data types), much like an array. Like any data structure or data set, dat...