Time for action—customizing the hello world file with arguments and parameters

Let's create a more flexible version of the job you did in the previous section.

  1. Create a new transformation.
  2. Press Ctrl+T to bring up the Transformation properties window.
  3. Select the Parameters tab.
  4. Add a named parameter HELLOFOLDER. Insert chapter10 as the default value.
  5. Click on OK.
  6. Drag a Get System Info step to the canvas .
  7. Double-click the step.
  8. Add a field named yourname. Select command line argument 1 as the Type.
  9. Click on OK.
  10. Now add a Formula step located in the Scripting category of steps.
  11. Use the step to add a String field named message. As Formula, type"Hello, " & [yourname] & "!".
  12. Finally, add a Text file output step.
  13. Use the step to send the message data to a file. Enter ${LABSOUTPUT}/${HELLOFOLDER}/hello as the name of the file.
  14. Save the transformation in the transformations folder you created in the previous tutorial, under the name hello_world_param.ktr.
  15. Open the hello_world.kjb job you created in the previous tutorial and save it under a new job named hello_world_param.kjb.
  16. Press Ctrl+J to open the Job properties window.
  17. Select the Parameters tab.
  18. Add the same named parameter you added in the transformation.
    Time for action—customizing the hello world file with arguments and parameters
  19. Click on OK.
  20. Double-click the Create a folder entry.
  21. Change the Folder name textbox content to ${LABSOUTPUT}/${HELLOFOLDER}.
  22. Double-click the Transformation entry.
  23. Change the transformation filename textbox to point to the new transformation: ${Internal.Job.Filename.Directory}/transformations/hello_world_param.ktr.
  24. Click on OK.
  25. Save the job and run it.
  26. Fill the dialog window with a value for the named parameter and a value for the command-line argument.
    Time for action—customizing the hello world file with arguments and parameters
  27. Click on Launch.
  28. When the execution finishes, check the output folder. The folder named my_folder, which you initially specified as a named parameter, should be created.
  29. Inside that folder there should be a file named hello.txt. This time the content of the file has been customized with the name you provided:
    Hello, pdi student!
    

What just happened?

You created a transformation that generated a hello.txt file in a folder given as the named parameter. The content of the file is a customized "Hello" message that gets the name of the reader from the command line.

In the main job you also defined a named parameter, the same that you defined in the transformation. The job needs the parameter to create the folder.

When you run the job, you provided both the command-line argument and the named parameter in the job dialog window that shows up when you launch the execution. Then a folder was created with the name you gave, and a file was generated with the name you typed as argument.

Using named parameters in jobs

You can use named parameters in jobs in the same way you do in transformations. You define them in the Job properties window. You provide names and default values, and then you use them just as regular variables. The places where you can use variables, just as in a transformation, are identified with a dollar sign to the right of the textboxes. In the tutorial, you used a named parameter in the Create a folder job entry. In this particular example, you used the same named parameter both in the main job and in the transformation called by the job. So, you defined the named parameter HELLOFOLDER in two places—in the Job settings window and in the Transformation properties window.

Note

If a named parameter is used only in the transformation, you don't need to define it in the job that calls the transformation.

Have a go hero—backing up your work

Suppose you want to back up your output files regularly, that is, the files in your ${LABSOUTPUT} directory. Build a job that creates a ZIP file with all your output files. For the name and location of the ZIP file, use two named parameters.

Tip

Use the Zip file job entry located in the File management category.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.103.27