• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • How To Replace MOVE And MOVEL With Subprocedures

    September 27, 2016 Ted Holt

    Note: The code accompanying this article is available for download here.

    Google “what shall we do about” and you’ll find a lot of issues that people are concerned about. Now that RPG has gone fully free-form, the question of concern for RPG programmers is “what shall we do about MOVE and MOVEL?” Faithful reader Mark sent me a solution he used in his shop and gave me permission to pass it along in case it may be of help to you.

    I can think of two ways to replace MOVE and MOVEL with free-form code. The first is to string together math expressions and/or built-in functions within EVAL statements. Bryan Meyers has thoughtfully provided a thorough and concise guide to this approach at http://enskill.com/faqs/free-format-alternatives-to-move/.

    I can illustrate this approach with a common task from my experience. Suppose a customer number is an eight-digit value, which consists of a two-digit company number followed by a six-digit account number within that company. Users perceive the customer number as a single eight-digit value, but in the database, company and account are separate fields. A common task is to split an eight-digit number into company and account. (An equally common task is to combine company and account into one eight-digit number.)

    With fixed-form RPG, this process is efficiently handled using MOVE and MOVEL.

    C                   MOVEL     CUSNO         COMPNY
    C                   MOVE      CUSNO         ACCT
    

    The following code shows two ways to extract company and account from the customer number.

       COMPNY = CUSNO * 0.000001;
       ACCT   = CUSNO - (COMPNY * 1000000);
    
       COMPNY = %uns(%subst(%editc(CUSNO:'X'):1:2));
       ACCT   = %uns(%subst(%editc(CUSNO:'X'):3));
    

    I won’t say that is ideal, but it does seem to me to be the best available method. It’s a labor-intensive method, requiring a programmer to examine each operation, decide how it works, write a free-form equivalent, and test the new code.

    The other approach is to replace each MOVE and MOVEL with a call to a subprocedure that accomplishes the same task. The effort required for this approach is less than the first method, requiring nothing more than determining the proper parameter values to pass to the subprocedures.

    Mark chose the second approach. He wrote a service program with five exported subprocedures.

    Name

    Description

    TRUNKHI

    Resize a
    number (high-order truncation)

    MV_A2A

    Move Alpha
    to Alpha

    MV_N2A

    Move
    Number to Alpha

    MV_N2N

    Move
    Number to Number

    MV_A2N

    Move Alpha
    to Number

    Let’s see the same task using Mark’s routines.

    COMPNY = mv_n2n ('L': CUSNO : COMPNY: 8.0: 2.0);
    ACCT   = mv_n2n ('R': CUSNO : ACCT:   8.0: 6.0);
    

    The following table explains the parameters:

    Parameter

    Description

    1

    L = MOVEL,
    R = MOVE (right)

    2

    Factor 2

    3

    The result
    field

    4

    Factor 2
    definition

    5

    Result
    field definition

    Field definitions are expressed as real numbers, where the whole number portion is the total field length and the decimal portion is the number of decimal positions. This is an easy way to pass two pieces of information through one value.

    It’s not necessary to hardcode field definitions. The compiler can calculate the lengths for variables.

    COMPNY = mv_n2n ('L': CUSNO : COMPNY:
                     %len(CUSNO)  + 0.1 * %decpos(CUSNO):
                     %len(COMPNY) + 0.1 * %decpos(COMPNY));
    ACCT   = mv_n2n ('R': CUSNO : ACCT:
                     %len(CUSNO)  + 0.1 * %decpos(CUSNO):
                     %len(ACCT)   + 0.1 * %decpos(ACCT));
    

    Notice that the result field is expressed twice–as the third parameter and as the target of the assignment.

    Let me end with a few more comments.

    • Besides the move equivalents, Mark also wrote a routine that performs high-order truncation. He used it mainly to convert date-conversion multiplications.
    • The maximum size of a numeric variable is 35 digits. The maximum number of decimal places is 9.
    • These routines have no support for MOVEA.
    • These routines have no support for dates.
    • My example used variables. Mark’s routines also handle literals.
    • Using subprocedure calls lends itself to automation. Mark wrote other routines that automated much of the code replacement. As a result, what was originally estimated to be a four-year project was completed in a little over a year.

    There you have two ways to convert MOVE and MOVEL to free-form RPG. Which is better? That’s easy. The better one is the one that more easily enables you to raise prices and/or decrease costs.

    Ted Holt welcomes your comments and questions. Email him through the IT Jungle Contacts page.

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Sponsored Links

    System i Developer:  RPG & DB2 Summit - October 4-6 2016 in Chicago. Register now!
    BCD:  Webinar: What's Possible with PHP on IBM i. Tues., Sept. 27 at 1pm ET. Sign up now!
    Manta Technologies Inc.:  The Leader in IBM i Education! Download catalog and take sample sessions!

    IBM Preaches Cognitive, Cloud, And IT Consumption PowerHA Implementations No Picnic; Help On The Way

    Leave a Reply Cancel reply

Volume 16, Number 21 -- September 27, 2016
THIS ISSUE SPONSORED BY:

WorksRight Software
T.L. Ashford
COMMON

Table of Contents

  • RPG Talks To Watson
  • A Brief Introduction To The SQL Procedures Language
  • How To Replace MOVE And MOVEL With Subprocedures

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24
  • Big Blue Raises IBM i License Transfer Fees, Other Prices
  • Keep The IBM i Youth Movement Going With More Training, Better Tools
  • Remain Begins Migrating DevOps Tools To VS Code
  • IBM Readies LTO-10 Tape Drives And Libraries
  • IBM i PTF Guide, Volume 27, Number 23

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle