Skip to main content


Showing posts from April, 2021

Return Number of Parameters (%PARMS) and Parameter Number (%PARMNUM) - IBM i

Return Number of Parameters (%PARMS) Built-In Function %PARMS returns the number of parameters passed to the procedure where %PARMS is run.  This BIF is useful when the procedure contains multiple optional parameters and if the procedure is called from different places with different number of parameters to identify the number of parameters passed.  This is most commonly used to to handle the procedure logic based on the parameters passed only.  Value returned by %PARMS is same as *PARMS in Program Status Data Structure if used in the main procedure.  Let's have a look at the simple example to see how this works.  In the above example,  Lines - 5 to 9: Prototype declaration of the Sub procedure with one mandatory parameter, two optional parameters and one return value. We will see the code of procedure in a bit.  Line - 18, 22 & 26: Calling the sub procedure with one mandatory parameter, two parameters and three parameters respectively.  Let's have a look at the code for Su

String method zfill() in Python

String Method - zfill() While working with numeric values in a string format, it becomes essential to have the data for a specific length as required i.e., filling the leading blanks with zeros.  E.g.: If we have number 470 and need to mention this in 5 digits in character format, two leading zeros to be added to make it 5 digits.  470 --> 00470 String method 'zfill()' is very useful to achieve this.  Syntax: str.zfill(width) Method zfill accepts one argument 'width' which defines the minimum number of digits (width) the return string should be. This method doesn't amend the original string.  Before we see an example, Below are the few points to consider.  zfill is a string method and cannot be directly used with int or float or other data types.  Width passed as an argument is the minimum number of digits is by considering the period (.) and any prefix (+/-).  If the original string has more width than the width passed in the argument, return string would be sam

Retrieve list of Open files for a Job from SQL - IBM i

Retrieve List of Open Files The list of open files for a job can be seen by using the command WRKJOB (Work with Job) or DSPJOB (Display Job) and then by taking option '14'. Or, by using the API 'QDMLOPNF' (List Open Files).  One other easier way to do this is from SQL by using the table function OPEN_FILES.  This function accepts a single parameter 'Job Name'. Job Name (JOB_NAME) - Name of the job (qualified) for which the list of open files are to be retrieved. If current job, '*' can be passed instead of the job name.  One thing to note here is 'Job Control (*JOBCTL)' authority is required to retrieve the list of files opened by other user's jobs. And, no special authority is required to retrieve our own jobs.  One advantage of having SQL table function to retrieve the the list of open files based on the specific condition as required.  E.g.:  Retrieve the list of open physical files.           Retrieve the list of files opened in OUTPUT m

Usage of map() function in Python

Usage of map() function in Python - Explained Python map() function is very helpful when we need to call a specific function for each element in an iterable and return the result as an iterable of type map object.  In other words, map() function would call another function for each element in an iterable (range, list, tuple...) and returns an iterable. Syntax map(function, iterable1, iterable2,...) map() accepts a minimum of two parameters. A function (to be called) An iterable (function to be executed for each element in an iterable) And, can have multiple iterables as required by the function passed in the first parameter. If the function requires two parameters then two iterables to be passed in parameters for map function.  Let's have a look at an example to calculate the square of each number in the range of 0 to 5. Without using map() In the above example,  Line - 3: Create empty list to hold square of numbers.  Line - 6: for loop over range of 0 and 5.  Line - 7: pass number