« Quick check on a case | Main | Reloading an Unload »
Tuesday
Sep162008

Using VARPUT function in a called procedure

A generic procedure called UPDATE_VAR was created to update the value of a variable as defined in parameter 1 to a value defined in parameter 2.

OLD REC IS ……….
. COMPUTE X=VARPUT( '<1>',<2>)
END REC

We wanted to call the member either by entering a variable name in parameter 1 or by extracting the variable name held as the value of another variable.

. CALL UPDATE_vAR(HCREL00,3)
. CALL UPDATE_VAR(VARGET(VARNAME), RELOPPS(3))

These calls were not working correctly as the quotes surrounding <1> in the called procedure meant that in the second call above the variable name was assumed to be VARGET(VARNAME). The value in parameter 2 (i.e. the value to update the variable to) is required to be a text value in the VARPUT command. This worked well when a specific figure was included in the CALL command (as in the first call statement above) but when an integer variable was included the VARPUT statement in the called procedure did not work correctly.

The solution was to amend the procedure UPDATE_VAR to include a statement to assign the value of parameter 1 to a new variable VARTOUPD and to apply the format function to the value to update to (parameter 2).

COMPUTE VARTOUPD=<1>
OLD REC IS ……….
. COMPUTE X=VARPUT(VARTOUPD, format(<2>))
END REC

The CALL commands now need to be in the following forms; the name of the variable to be updated should be entered either as text enclosed in quotes or the name of the variable containing the name of the variable to be updated.

. CALL UPDATE_VAR("HCREL00",3)
. CALL UPDATE_VAR(VARNAME,RELOPPS(3))

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>