nicowi
nicowi

Reputation: 472

ILE RPG MOVEL in FREE FORMAT FREE RPG

Can anyone show me how this Line is coded in FREE RPG?

C                   MOVEL     TEST          TESTFELD 

Upvotes: 1

Views: 14578

Answers (5)

Nifriz
Nifriz

Reputation: 1235

You can use the powerful EVAL. (Eval in FREE is implicit)

TESTFIELD = Test ;

Remember EVAL clear the field and then move the new value.

Upvotes: 6

lou wilkinson
lou wilkinson

Reputation: 19

to extend on some answers above you can:

%SUBST(TESTFIELD: 1: %len(TEST) ) = TEST;

if they're both character fields. or if TEST is numeric

%SUBST(TESTFIELD: 1: %len(%char(TEST)) ) = TEST;

Upvotes: 2

Christoff Erasmus
Christoff Erasmus

Reputation: 975

Refer to The Essential Guid To Free-Format RPG by Bryan Meyers.

The this article describes the issues involved in converted the Move, MoveL and MoveA opcodes to free-format.

With the enhancements to the Compiler, removing the requirement for /free the C-Spec statement is not intrusive.

My recomendation:

Keep old existing MOVE opcodes, but new code should be written in free-form.

Final Thought:

Have a look at "UPGRPGSRC - Upgrade and Modernize RPG Source to RPGLE /Free" available from http://www.projex.com/ for FREEEE. They also have other useful tools for IBMi.

Please note that at the time of posting this answer ProjeX website was down. https://web.archive.org/web/20160320171335/http://www.projex.com/

Upvotes: 1

user2338816
user2338816

Reputation: 2163

Use this form:

%SUBST(TESTFELD: 1: len ) = TEST ;

Set the "len" variable to the length of the value that you want replaced with TEST, or simply hard-code the length.

Upvotes: 1

CRPence
CRPence

Reputation: 1259

The given statement, apparently means to suggest the following RPGIV syntax:

 C                   MOVEL     TEST          TESTFELD 

As I understand, with a newer iteration of free-form rules, the [IBM i 7.2 ILE RPG] compiler no longer requires the /free specification /free and /end-free are ignored, thus the fixed-form statement can appear exactly as shown; i.e. there is no need to find an alternate OpCode or define a new block of code to replace whatever MOVEL provides in the current context.

Prior to that enhancement to the compiler, just precede the fixed-format line of code with the /end-free compiler directive, and then follow that fixed-format line of code with the /free compiler directive to reestablish free-form; again, no reason to rewrite the statement with free-form:

  /end-free
 C                   MOVEL     TEST          TESTFELD 
  /free

Note that any single assignment as an alternate to the MOVEL is likely to require much more significant capabilities than that one Op-Code can effect alone. That is because the MOVEL acts with implicit casting, whereas other operation codes likely will not provide the full support capabilities [nor possibly even the same results] of the old fixed-form op-code. The documentation suggests there are many possible replacements for the MOVEL (Move Left)

Oddly the %SUBST is not one of the mentioned replacements, but for the simplest scenarios with fixed-length character string variables, the receiving variable in a %SUBST as shown by user2338816 is quite possibly all that is required. Refer to %SUBST built-in function as result

An alternative to leaving the fixed-format opCode inline, is to move the work into a procedure, where effectively the same code is performed, even using that same opCode. This could be an imperative choice, if converting code, while intending also eliminate all fixed-form specifications inline to that converted code; having the fixed-format opCode in the procedure may not be desirable, but to ensure absolutely the same effect from the complex opCode, that is often the safest rather than trying to code for all the nuances. And although arguably another alternative, because a /COPY or a /INCLUDE is no prettier than the fixed-format [appearing conspicuously or at least seemingly out of place, inline to free-form calculation specifications], neither of those compiler directives is likely to be preferable to just leaving the old opCode inline.

Upvotes: 3

Related Questions