Skip to main content

Posts

Showing posts from March, 2021

Check locks on IFS Objects from SQL - IBM i

IFS Object Locks Identifying locks or references on IFS Objects become essential at times. This can be done by calling API QP0LROR (Retrieve Object References).  The same information can be retrieved from SQL by using table function IFS_OBJECT_LOCK_INFO.  This function accepts two parameters (Path name and Ignore errors).  Path Name (PATH_NAME) - Path name for which the locks or references are to be retrieved. This could be a directory or stream file. This is a mandatory parameters.  Ignore Errors (IGNORE_ERRORS) - YES or NO to be passed to determine what needs to be done when an error is encountered. This is an optional parameter and YES would be considered if no value passed.  YES (Default) - A warning is returned and no row would be returned incase of an error.   NO - An error is returned. This function can be called to check the locks on a directory Or, by passing a stream file.  Optionally we can pass Ignore errors 'NO' if the error is to be returned in case of any error

Dictionary Merge & Update Operators in Python

Dictionaries Dictionaries (dict) are used to store the data based on a key value. Unlike  Lists  and  Tuples , data in the dictionaries isn't stored based on the index. And, data in the dictionaries are specified using curly brackets with the key and it's corresponding value ({key1 : value1, key2 : value2,...}. Click Here to see more about dictionaries.  In this post, we will see more about the dictionary merge and update operators introduced in Python 3.9 along with the equivalent methods to do the same before 3.9.   Merge (|) Operator Merge operator would merge the elements from both the dictionaries into a new dictionary. This wouldn't update either of these dictionaries.  If there are any common keys between both the dictionaries only one would be present in the resulting dictionary as no duplicate keys are allowed in dictionaries. In the above example,  Line - 5: merge (|) operator merges the elements from both the dictionaries (first_dictionary and second_dictionary)

Check Journaled Objects from SQL - IBM i

Journaled Objects Journals play very important role on IBM i and are helpful to identify who has updated the data and/or to retrieve the data before the update or delete from the tables and so on.  Journaled objects can be seen by using WRKJRNA (Work with Journal Attributes) CL command or by using API QjoRetrieveJournalInformation (Retrieve Journal Information).  One other easier way to check the list of journaled objects is by using SQL view JOURNALED_OBJECTS. This view is present in QSYS2 and system name JRN_OBJS. We can use this view to retrieve the objects attached to a particular journal or identify the journal associated with the particular object and so on.  E.g.:  Retrieve the objects attached to a journal.  In the above query,  Line - 1: SELECT statement on JOURNALED_OBJECTS view.  Line - 2: Where condition on column JOURNAL_LIBRARY to select the records with the journal library passed.  Line - 3: condition on column JOURNAL_NAME to select the records with the journal name pa

Tuple Unpacking in Python

Tuple Unpacking Tuple is a collections of data (of different data types) and are created by specifying the data (or variables) inside round brackets. We can also call this as Tuple packing. See more about working with tuples . So, what is tuple unpacking? As the name suggests unpacking the data from a tuple into variables is called tuple unpacking. Let's have a quick look at the creation of a tuple (packing) and unpacking of a tuple.  In the above example,  Line - 2: Creating variable num_one to store a number (1). Line - 4: Creating variable char_one to store a string (ONE).  Line - 8: Creating a tuple by mentioning the variables created inside round brackets (num_one, char_one). This can also be done by directly providing the data inside round brackets (1, "ONE"). Line - 11: Unpacking the tuple, unpacking the data in a tuple into different variables. First element in the tuple would be assigned to the first variable and second element in the tuple would be assigned to t

Split the string in SQL - IBM i

Split String Substring from a string can be extracted using %SUBST BIF in RPG, %SST in CL and SUBSTRING in SQL by passing from position and the numbers of characters to be extracted.  But, if we need to split the string based on a specific delimiter and if we don't know the positions? One way to do this is by retrieving the position of a delimiter in the string using %SCAN BIF. This would require more logic to be written if the string needs to be split into multiple substrings.  This has been made easier with the use of SPLIT  table function in SQL. This function is present in SYSTOOLS library. SPLIT table function accepts three parameters.  INPUT_LIST (Input List) - String(s) that needs to be split. DELIMITER (Delimiter) - String or character that needs to be considered as separator. Both Input List and Delimiter are mandatory parameters.   ESCAPE (Escape) - A character string of length '1' that is to be used as escape character. Delimiter followed by escape character w

Using if-else statements in List Comprehension

List Comprehension List comprehension is one of the ways of creating list. List would be created as a result of some operation on a range, set or list based on some condition (optional).   Click Here to see more about list comprehension.  In this post, we will see how to use if - else statements in list comprehension.  Let's have a quick look at using if statement alone before we see if - else statements.  E.g.:  Create a list of odd numbers less than 10.  odd_numbers = [ number for number in range ( 10 ) if number % 2 != 0 ] In the above example, We are using if statement towards the end for identifying the odd numbers.  We are only considering the odd numbers using the if statement and leaving the others. But if we have to to a different operation for even numbers and different operation for odd numbers, we should be using if-else statements.  if-else statements in List Comprehension So, How do we use else statement in list comprehension? Is it just adding else statement aft

Retrieve System Values from SQL - IBM i

System Values System values contain the control information related to the IBM i OS or parts of OS.  System values are used to control or define the way working environment is setup on the system. For example, setting up time zone, default system library list, number of jobs allowed and so on... System values can be accessed either from IBM Navigator for i or by using DSPSYSVAL (Display System Value) command. And, the same can be accessed from a program either by using RTVSYSVAL (Retrieve System Value) CL command or QWCRSVAL (Retrieve System Values) API.  One other way of accessing this information from SQL is by using view 'SYSTEM_VALUE_INFO' present in QSYS2 library (System name for this view is SYSVALINFO). SYSTEM_VALUE_INFO view has got the below three columns. SYSTEM_VALUE_NAME - Name of the system value CURRENT_NUMERIC_VALUE - System value, if numeric. if not, contains NULL.  CURRENT_CHARACTER_VALUE - System value, if character. if not, contains NULL. We can use these

If Condition in Python

If Condition Conditions are nothing but statements used to check if a specific action is True or False.  In this post, we will see how If condition works in Python and how to use if, elif (Else-If) and else statements.  Syntax: if some_condition:     // code to be executed elif another_condition:     // code to be executed elif another_condition_2:     // code to be executed . . . else:     // code to be executed Let's breakdown the syntax of into three statements and see each of the statement in detail along with few examples. if elif else if statement If statement is used to verify if a specific condition is True and the block of code under the if statement would only be executed if the condition is True.  if some_condition:     // code to be executed 'some_condition' here needs to be replaced with the actual condition to be used in the program and 'code to be executed' needs to be replaced with what needs to be executed when the condition is satisfied.  If the co

Retrieve Active Jobs info from SQL - IBM i

Work with Active Jobs Work with Active Jobs (WRKACTJOB) is one most used and helpful commands on IBM i. This would help us to see what are the jobs running, status of the jobs, CPU percentage used and many more details.  We can retrieve the same information from SQL by using table function ACTIVE_JOB_INFO. We can either retrieve information for all the jobs or retrieve a set of jobs by using optional parameters.  With no parameters passed, ACTIVE_JOB_INFO returns all the active jobs running on the system.  SELECT * FROM TABLE(ACTIVE_JOB_INFO()) ;  We can make of the parameters to filter the jobs. Let's have a look at the jobs running for a specific user.  In the above example, we are only selecting few columns and there are many other columns that we can get using this table function. Line - 1: Column ' JOB_NAME ' returns the job name (job_number/user_name/job_name).  Line - 2: Column ' SUBSYSTEM ' returns the name of subsystem the job is running in.  Line - 3: Colu