Variable length fields in RPG IV

Ed is wondering, "If you don't yet use free-format RPG, is there a way to utilize variable length fields in RPG IV?" What do you think? Is it possible? -- Michelle Davidson, editor,

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yes, yes yes!!! There is full support for variable-length fields in RPGIV. Free-format does not give you anything extra; it just makes the C-specs messier, and because of the very slight differences in the way one or two operation codes are processed, it can make a program harder to fix. Anyway, don’t get me started!!!

You can read about variable-length fields and their advantages and cautions at

Be sure to read the reference carefully, because you can get unexpected results with variable-length fields, especially if you use MOVE/MOVEL with them (which I know you could not use in free-form!).


Variable-length fields are unrelated to fixed- or free-format RPG (nor even to RPG). And free-format has no connection to D-specs; free-format only affects C-specs.

Further, because free-format does not allow on-the-fly scattered variable definitions to be practically hidden all over the C-specs, the D-specs become much more organized and far less messy. All data definitions are known to be in a specific area of the program source.

D-specs are for ‘D’ata. Defining data at random in C-specs has long been a major cause of prolonged debugging for maintenance programmers by the increased difficulty in determining what data is being manipulated by the program.

Since MOVE/MOVEL have caused so much trouble for RPG programmers, they shouldn’t be used in any case. As such, there should be no unexpected results. There is no point in using MOVEL when a DS subfield clarifies exactly what is being operated upon at a glance.


Discuss This Question: 1  Reply

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Vatchy
    Define the field with the maximum length that you will want and specify "VARYING" in the control specification keyword area. D Temp60 S 60 Varying This is an example of setting the length: C EVAL %len(Temp60) = 60 This is an example of moving an array to the field: C MOVEA ar4(X) Temp60 Hope this helps.
    1,415 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.


Share this item with your network: