Padding a character parameter when calling a program - Support

Padding a character parameter when calling a program

From Support

Jump to: navigation, search

Discussion of the Issue

The most common error when calling programs from a command line is that additional garbage appears in a character parameter. This excerpt from the help text for the PARM parameter of the CALL command explains this, but might need some further explication:

Character string constants of 32 bytes or less are always passed with a length of 32 bytes (padded on the right with blanks). If a character constant is longer than 32 bytes, the whole length of the constant is passed. If the parameter is defined to contain more than 32 bytes, the calling program must pass a constant that contains exactly that number of bytes. Constants longer than 32 characters are not padded to the length expected by the receiving program.

The last sentence is the key here – if the parameter is declared to be longer than 32 and you pass it a constant that is shorter than the length declared, that parameter will get whatever is in memory after the last character of the constant. That is why the above sentence says to pass a constant that is as long as the declared length of the parameter.

There is a possible error with numbers, as well. A numeric constant is assumed by the system to be a packed decimal with precision of 15 and scale of 5 – that is, 15 digits and 5 of them are after the decimal point.

This behavior also occurs when submitting jobs with the SBMJOB command and using the CMD parameter to submit a CALL.

Possible Solutions

There are two possible solutions for this issue.

  • 1. Make sure that you are passing the exact number of characters that your parameter is expecting. This means that if your parameter is 100 characters and the value you are passing is on 30 characters, you need to be padding the last 70 characters with spaces to avoid allowing the rest of the parameter to be filled with garbage.
  • 2. (RJS recommended) An easy way around this issue is to build a command interface for your program. You simply setup the command parameters to match the program parameter sizes and call the command instead of your program.

For example, if your program has one 100 character parameter, you would write a command that would accept that pass one 100 character value to the program.

IBM commands have an inherent ability to automatically pad out values that are being passed into a program.

Reference

The below IBM and Midrange Guru articles help detail the problem a bit more and offer some solutions.

IBM

Midrange Guru



This article has been proofread by Jordan as of 14:18, 27 February 2008 (Central Standard Time)

garbage GARBAGE Garbage padding PADDING Padding Literal literal literals LITERAL LITERALS character CHARACTER CONSTANT constant characters CHARACTERS extra EXTRA program PROGRAM

Personal tools