Some correct examples of VC_USING commands follow.

Example 1: Accumulate real fields TOT01 -> TOT05 into virtual field TOTAL:

     C*
    C* VC_USING FIELDS(TOT01 TOT02 TOT03 TOT04 TOT05 TOTAL)
    C*
    C                     Z-ADDTOT01     TOTAL
    C                     ADD  TOT02     TOTAL
    C                     ADD  TOT03     TOTAL
    C                     ADD  TOT04     TOTAL
    C                     ADD  TOT05     TOTAL

Some points to note about this example are:

  • The VC_USING command details all fields in the code section that come from the file definition. The command is included into the source code as a comment so as not to upset the RPG syntax checker when editing and begins in column 9.
  • None of the fields are declared (i.e. type and length specified). LANSA automatically declares all real and virtual file fields in a data structure.

If this example virtual field code section was actually compiled into the file I/O module it would look something like this:

     * FIELD REPLACEMENT VALUES USED FOR THIS SECTION OF USER CODE
  *
  *  Field name as     Field name as in   Internal field name
  *in file definition  user RPG code      used as replacement
  *------------------  ----------------   ------------------
 *     TOT01              TOT01              @F0001
 *     TOT02              TOT02              @F0002
  *     TOT03              TOT03              @F0003
  *     TOT04              TOT04              @F0004
  *     TOT05              TOT05              @F0005
  *     TOTAL              TOTAL              @F0006
  *
 C                     Z-ADD@F0001    @F0006
 C                     ADD  @F0002    @F0006
 C                     ADD  @F0003    @F0006
 C                     ADD  @F0004    @F0006
 C                     ADD  @F0005    @F0006

Note how the VC_USING command has been replaced by a series of comments that detail exactly what effect it has on the following code. Also, note how all fields listed in the VC_USING command have been replaced by their "internal" names in the actual code section.

Example 2: Accumulate real fields TOT01 -> TOT05 into virtual field FULLTOTAL:

     C*
   C* VC_USING FIELDS(TOT01 TOT02 TOT03 
   C*                 TOT04 TOT05 (FULLTOTAL FFFFFF))
   C*
   C                     Z-ADDTOT01     FFFFFF
   C                     ADD  TOT02     FFFFFF
  C                     ADD  TOT03     FFFFFF
   C                     ADD  TOT04     FFFFFF
   C                     ADD  TOT05     FFFFFF

Some points to note about this example are:

  • The VC_USING command has been continued over 2 source lines by use of the "+" continuation character. In addition, it indicates that file field "FULLTOTAL" is actually referenced by name "FFFFFF" in the following code. This was done because field name FULLTOTAL is more than 6 characters long.
  • The name FFFFFF has been used in place of name FULLTOTAL in all RPG code lines.

If this example virtual field code section was actually compiled into the file I/O module it would look something like this:

     FIELD REPLACEMENT VALUES USED FOR THIS SECTION OF USER CODE
  *
  *  Field name as     Field name as in   Internal field name
  *in file definition  user RPG code      used as replacement
  *------------------  ----------------   -------------------
  *       TOT01              TOT01              @F0001
  *       TOT02              TOT02              @F0002
  *       TOT03              TOT03              @F0003
  *       TOT04              TOT04              @F0004
  *       TOT05              TOT05              @F0005
  *       FULLTOTAL          FFFFFF             @F0006
  *
 C                     Z-ADD@F0001    @F0006
 C                     ADD  @F0002    @F0006
 C                     ADD  @F0003    @F0006
 C                     ADD  @F0004    @F0006
 C                     ADD  @F0005    @F0006

Again the VC_USING command has been replaced by a series of comments that detail exactly what effect it has had on the following code. Also note how all fields listed in the VC_USING command have been replaced by their "internal" names, particularly the name "FFFFFF".

  • No labels