Can any one please let me know Difference between Global Variable and Context Variables and in what scenarios we should each of these?
The differences are very subtle and they can usually be used interchangeably in a lot of scenarios.
However, Context Variables can be set prior to a job running and outside of the job design. By that I mean, you can assign them a value after a job has been compiled. This can be done via parameter files or TAC (Talend Administration Center) configuration. Context variables are stored typed. This means that if you set up a String context variable, it will be made available as String. You can find which context variables you have available in your design at design time by typing "context." in any component parameter field and hitting CTRL+space.
The globalMap is a HashMap. You generally set these values at runtime, although you can force them to be able to be set values from a parameters file like contexts (....but this support is not built in). When retrieving your globalMap parameters you will usually need to cast them. That means you will need to know the types (or classes to be more precise).
Often context variables and globalMap variables will be used together, but it is a good idea to make some rules which suit your style of working.
A key difference in use will be when passing variables between parent and child jobs. You will need to set up context variables in your child job to receive values. BUT you can populate the those values with globalMap variables if you choose (see tRunJob).
Did you mean if we have to pass data from parent job to child join using Context Variable in that scenario we will have to declare context variable in child job too. In case we have not declared context variable in child job then we will get null value. Please confirm.
Where as there is no need to define Global Variable in Child Job. Please confirm.
If you want to pass all of your context variables without explicitly specifying values in the tRunJob, then you will need the same context variables in your child job as your parent job (well, the ones you wish to use in your child job anyway) and tick the "Transmit whole context" tick box. Otherwise you can click the green cross below the Context Param table and explicitly set the context variables you have set up in your child job. This is where you can use Context variables OR globalMap values to pass values.
globalMap variables do not need to be set in a child job, but you can use them. However you cannot receive values in the child job into globalMap. The child job can receive values into Context variables, and those values can be supplied by the parent job's Context variables AND globalMap variables. The child job cannot receive values directly into the globalMap.
The globalMap is also used internally by Talend. Unless you are a Java developer, I would go with Context variables to start with.
Another scenario where globalMap values are use is with the tFlowToIterate component. When the rows are iterated over, the column values are stored in the globalMap.
Is this also an example of Parent Job and Child Job?
Suppose we have two sub jobs in our one job. We have connected 2nd subjob with first subjob by OnSubJobOk or by OnComponentOk. In that case will 1st job be the parent job and 2nd job be the child job?
You've misunderstood a little. Take a look here (https://help.talend.com/reader/jomWd_GKqAmTZviwG_oxHQ/MtazXrCxpWSuiIwNDwqc8A). In your example, all subjobs are in the same job. There is no parent/child relationship. However the subjob processing will be carried out in order from the first to the last. To have a parent/child job relationship, you need to include a Talend job inside another.
Talend named a Leader.
Kickstart your first data integration and ETL projects.
Watch the recorded webinar!
Part 2 of a series on Context Variables
Learn how to do cool things with Context Variables
Find out how to migrate from one database to another using the Dynamic schema