ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

MOVE and /FREE

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MOVE and /FREE

    Everyone asks what to do since in /FREE there is no MOVE, and that has me coding a workaround which is rather ugly.

    We have a table on our system , which has 3 columns, A, B and C.
    A is a number with 5 digits and 0 decimals.
    B is a 15 cha string
    C is a 50 char string

    Let's say a table has the id number and name of all employees on each city where the company is.

    If we are going to look for the name of employee 100, city 1, on fixed rpg we would do something like this:

    MOVE would convert the number 100 to
    Code:
    '            100'
    , which is what we want since strings are right aligned in the table.

    But in /free, we would have to first convert 100 to a string:

    parm2=%char(empid);

    Which would produce the string

    Code:
    '100            '
    , which is not what we want.
    So this is the code we have to use:

    Code:
    if len(empid)>99;
      parm2='            '+%char(empid);
    else;
      parm2='             '+%char(empid); //one more space
    end if
    This is ugly. Is there another way, besides of course dropping /free whenever we need a MOVE operation?
    Last edited by fjleon; March 16, 2007, 12:26 PM.

  • #2
    Re: MOVE and /FREE

    I would tend to use an edit code rather than %char, that way I see in the code what I would expect to see.. %char leaves me to not know what it will be. If I use %editc I know what to expect (just my preferance). Evalr right justifies it.

    evalr parm2 = %editc(empid:'Z') // this would not matter on the number 1 to 99999
    or
    evalr parm2 = %char(empid) if you prefer
    I believe this is applicable in /free as well

    Good Luck
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

    Comment


    • #3
      Re: MOVE and /FREE

      Ok that would work, but i forgot something

      I need the leading zeros in the string if the empid's length is lower than the variable's maximum . For example:

      Let's say the empid variable can be between 1 and 9999, and it currently is 0100 since its length is 4.

      Using evalr, it would make the resulting string:
      Code:
      '            100'
      instead of
      Code:
      '          0100'
      I could have a smaller string filled with zeroes, then evalr'd the number, then evalr'd it to the size 15 char prefilled with blanks... Again, it works, but it is ugly...

      Is there a cleaner and faster way?

      Comment


      • #4
        Re: MOVE and /FREE

        fjleon,

        Just change the edit code from 'Z' to 'X'.

        HTH,
        MdnghtPgmr
        "Tis better to be thought a fool then to open one's mouth and remove all doubt." - Benjamin Franklin

        Comment


        • #5
          Re: MOVE and /FREE

          Try setting up a data structure
          PHP Code:
          D                 DS                                      
          DVALUE1                  26     30S 0 INZ
          (999)            
          DVALUE2                   1     30 
          this way you get the leading zeros and you're set to go

          Comment


          • #6
            Re: MOVE and /FREE

            midnight is correct just do like he says...(unless he tells you to bark like a dog )

            PHP Code:

            CALMMDD 
            = %dec(%SUBST(%EDITC(CALDATE:'X'):5:4):4:0); 
            PHP Code:
            d reply           s              1                                
            d status          s              4  0                             
            d display         s             10                                
                                                                              
            c                   call
            (e)   '@@@@X2'                            
            c                   eval      Status = %status()                  
            c                   eval      display = %editc(status:'X')        
            c     display       dsply                   reply                 
            c                   
            eval      *INLR = *on 
            PHP Code:
            dec6 =  %uns(%char(AZISSUED:*MDY0))   
            WorkDate6 = %editc(dec6:'X'
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: MOVE and /FREE

              Jamie,

              Are you barking mad?!

              MdnghtPgmr
              "Tis better to be thought a fool then to open one's mouth and remove all doubt." - Benjamin Franklin

              Comment


              • #8
                Re: MOVE and /FREE

                I think Ive just gone MAD!
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #9
                  Re: MOVE and /FREE

                  Hey, %editc with 'X' works great. It's the cleanest way besides MOVE.

                  Let's hope IBM brings MOVE ih v5r5

                  Comment


                  • #10
                    Re: MOVE and /FREE

                    I've been programming RPG for 6 months now (so still relatively new to all this) but I can safely say I've never felt the need for the MOVE op in /Free. Most of my coding has been in free format from the start. So I guess if you've never got used to MOVE, you're not likely to miss it as much.
                    Ben

                    Comment


                    • #11
                      Re: MOVE and /FREE

                      The only opCode I miss in /free is MOVEA. Anyone got any /free code to handle that?
                      "Time passes, but sometimes it beats the <crap> out of you as it goes."

                      Comment


                      • #12
                        Re: MOVE and /FREE

                        &#37;subarr? maybe...(without doing any deep research)
                        Bill
                        "A good friend will bail you out of jail,
                        A true friend would be sitting beside you saying,
                        'Wow, that was fun.'"

                        Comment


                        • #13
                          Re: MOVE and /FREE

                          hello,
                          i have one problem, i want to copy some records from one pf to another using cpyf command but from file i want onaly two fields data & in receving file having some data i.e 3 fields but i want it receive two fields data & 3rd as it is.

                          Comment

                          Working...
                          X