IBMiAccess




Results 1 to 7 of 7

Thread: Renaming a field in a RPG program

  1. #1
    Code400 Newbie
    Join Date
    Apr 2007
    Location
    bhubaneswar
    Posts
    42
    Rep Power
    604

    Renaming a field in a RPG program

    Hi All

    I am using two files in a RPG Program. In the two files some of the fields have same name. But In my program I want to rename the fields of one of the file. Is it possible to rename the fields of the Physical file in a RPG Program.

    Thanks
    Mohan

  2. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

  3. #2
    Programmer Mercury's Avatar
    Join Date
    Feb 2007
    Location
    Paris, France
    Posts
    1,831
    Rep Power
    5435

    Re: Renaming a field in a RPG program

    Define an externally described data structure and rename fields inside that data structure.
    F.E.
    PHP Code:
    D Wrk_Rcd       E DS                  EXTNAME(MyFile)    
    D  Wrk_Field1   E                     EXTFLD(Field1)     
    D  Wrk_Field2   E                     EXTFLD(Field2
    In this example Field1 and Field2 are respectively renamed Wrk_Field1 and Wrk_Field2. Other fields are unaltered.

    However I think that you'd be better off using the PREFIX keyword instead to get rid of that EXTFLD so RPGIII style.

    F.E.
    PHP Code:
    D Wrk_Rcd       E DS                  EXTNAME(MyFile
    D                                     PREFIX(Wrk_)       
      /
    free                                                 
        Read MyFile Wrk_Rcd

    Last edited by Mercury; November 13th, 2007 at 08:25 AM.
    Philippe

  4. #3
    SubAdmin Billw's Avatar
    Join Date
    Sep 2005
    Location
    Ontario, Canada
    Age
    82
    Posts
    861
    Rep Power
    3295

    Re: Renaming a field in a RPG program

    PHP Code:
    FFileName  IF   E           K DISK                  
    f                                                   PREFIX
    (P_
    This will prefix all fields for this file with "P_"

    Good Luck
    Bill
    Last edited by Billw; November 13th, 2007 at 08:20 AM.
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

  5. #4
    Analyst
    Join Date
    Aug 2007
    Location
    Belvidere, IL
    Posts
    163
    Rep Power
    733

    Re: Renaming a field in a RPG program

    PREFIX(prefix{:nbr_of_char_replaced})
    The PREFIX keyword is used to partially rename the fields in an externally
    described file. The character string or character literal specified is prefixed to the
    names of all fields defined in all records of the file specified in positions 7-16. In
    addition, you can optionally specify a numeric value to indicate the number of
    characters, if any, in the existing name to be replaced. If the nbr_of_char_replaced
    is not specified, then the string is attached to the beginning of the name.
    If the nbr_of_char_replaced is specified, it must be a numeric constant containing
    a value between 0 and 9 with no decimal places. For example, the specification
    PREFIX(YE:3) would change the field name YTDTOTAL to YETOTAL.
    Specifying a value of zero is the same as not specifying nbr_of_char_replaced at
    all.
    Rules:
    v You can explicitly rename a field on an input specification, even when the
    PREFIX keyword is specified for a file. The compiler will recognize (and require)
    the name which is first USED in your program. For example, if you specify the
    prefixed name on an input specification to associate the field with an indicator,
    and you then try to rename the field referencing the unprefixed name, you will
    get an error. Conversely, if you first rename the field to something other than the
    prefixed name, and you then use the prefixed name on a specification, you will
    get an error at compile-time.
    v The total length of the name after applying the prefix must not exceed the
    maximum length of an RPG field name.
    v The number of characters in the name to be prefixed must not be less than or
    equal to the value represented by the nbr_of_char_replaced parameter. That is,
    after applying the prefix, the resulting name must not be the same as the prefix
    string.
    v If the prefix is a character literal, it can end in a period.
    v If the prefix is a character literal, it must be uppercase. In this case, the field
    names must all be subfields of the same qualified data structure.

  6. #5
    Code400 Newbie
    Join Date
    Apr 2007
    Location
    bhubaneswar
    Posts
    42
    Rep Power
    604

    Re: Renaming a field in a RPG program

    Thanks Mercury for the quick response. But I am Using RPGIII. So is there any way out to do that in RPGIII.


    Quote Originally Posted by Mercury View Post
    Define an externally described data structure and rename fields inside that data structure.
    F.E.
    PHP Code:
    D Wrk_Rcd       E DS                  EXTNAME(MyFile)    
    D  Wrk_Field1   E                     EXTFLD(Field1)     
    D  Wrk_Field2   E                     EXTFLD(Field2
    In this example Field1 and Field2 are respectively renamed Wrk_Field1 and Wrk_Field2. Other fields are unaltered.

    However I think that you'd be better off using the PREFIX keyword instead to get rid of that EXTFLD so RPGIII style.

    F.E.
    PHP Code:
    D Wrk_Rcd       E DS                  EXTNAME(MyFile
    D                                     PREFIX(Wrk_)       
      /
    free                                                 
        Read MyFile Wrk_Rcd


  7. #6
    SubAdmin Billw's Avatar
    Join Date
    Sep 2005
    Location
    Ontario, Canada
    Age
    82
    Posts
    861
    Rep Power
    3295

    Re: Renaming a field in a RPG program

    Yoiu have to use "I" specs to rename each individual field for the file.

    PHP Code:
    IRecFormat                                                 
    I
    *                                                        
    IRENAME FIELDS FOR TRANSACTION LINE DESCRIPTION 
    I
    * -------------------                                    
    I              CURFLD                          NEWFLD 
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

  8. #7
    Code400 Newbie
    Join Date
    Apr 2007
    Location
    bhubaneswar
    Posts
    42
    Rep Power
    604

    Re: Renaming a field in a RPG program

    Thanks Bill

  9. # 666
    Circuit advertisement
    Join Date
    Aug 1965
    Location
    Yakutsk, Russia
    Posts
    1,000,000
     

Facebook Comments


Similar Threads

  1. Regarding Journaling
    By Sandeep D in forum RPG/RPGLE
    Replies: 3
    Last Post: November 16th, 2009, 07:37 AM
  2. Program Modification Notation
    By dcutaia in forum /Free format
    Replies: 6
    Last Post: April 30th, 2007, 03:46 AM
  3. Service Program
    By yogeshgupta26 in forum RPG/RPGLE
    Replies: 3
    Last Post: December 28th, 2006, 06:34 AM
  4. rpgle
    By mohans in forum RPG/RPGLE
    Replies: 4
    Last Post: May 21st, 2005, 11:50 PM
  5. Null Values and SQL Fetch
    By pjk in forum SQL
    Replies: 1
    Last Post: February 22nd, 2005, 11:31 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •