Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Tips and Techniques: '00208' Is Possible in Free-Format

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

  • Tips and Techniques: '00208' Is Possible in Free-Format

    ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
    This is a discussion about Tips and Techniques: '00208' Is Possible in Free-Format.

    Click here for the article.


  • #2
    Tips and Techniques: '00208' Is Possible in Free-Format

    ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
    Here is a technique I also use: D Number s 7p 2 inz(-150.00) D AlphaNum s 10 alphaNum = %editw(Number : '0 . -'); alphaNum = %trim(AlphaNum); //I use this to reverse the sign if needed //after the above statement runs: alphaNum = %subst(alphaNum : %len(%trim(alphaNum)) : 1) + %subst(alphaNum : 1 : %len(%trim(alphanum))-1 ); Again nice tip Bob, keep em coming. Gus

    Comment


    • #3
      Tips and Techniques: '00208' Is Possible in Free-Format

      ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
      see code below. imho, much better and no costly cpu cycles trimming no offence bob! ;-)
      Code

      Comment


      • #4
        Tips and Techniques: '00208' Is Possible in Free-Format

        ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
        At the risk of opening the floodgates on this discussion AGAIN it is amazing how many articles and discussions revolve around the lack of a "move" op-code equivalent in free format RPG. We have been using the Move op-code to convert num->char and char->num forever. From reading the articles and posts, there are ways around it and yes we can create our own procedure in a service program to try and make it as easy as the Move op-code was but it just seems silly that this functionality was removed and isn't coming back apparently. But each method of "getting around it" has its problems or is cumbersome or not immediately obvious to the developer reading the code; at least not as obvious as the Move op-code is. On the other hand the move op-code "hides" the fact that a data-type change is being made. It may actually be beneficial for the developer to know this. I'm not sure what my point is (you're probably not either), but it appears that the existing Move op-code functionality for going from numeric to character is pretty much duplicated by the %editc example Bob provides. The rest of the example solves a problem not handled by the current Move op-code anyway. There is no "native" way of converting character to numeric however and this is a stumbling block. Garrett

        Comment


        • #5
          Tips and Techniques: '00208' Is Possible in Free-Format

          ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
          I have used the %EditW() Function and works great. You also have to put it inside a %Trim() to get it to work correctly.
          Code

          Comment


          • #6
            Tips and Techniques: '00208' Is Possible in Free-Format

            ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
            jgutierrez, Bob wanted the field to be left justified with a left minus sign. good luck doing that with EditW!!! and with EditW, you have to manually put (hard code) exactly the same number of spaces as the length of the field

            Comment


            • #7
              Tips and Techniques: '00208' Is Possible in Free-Format

              ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
              Here's my solution: Chris
              Code

              Comment


              • #8
                Tips and Techniques: '00208' Is Possible in Free-Format

                ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                I always have to wonder why people are so attached to MOVE. Compared to other RPG functions, this one is pretty low-level. Looking back to the days when RPG had just zoned decimal variables, most variations of MOVE could be implemented by a single MVC instruction (move characters). (Ever wonder why old RPG had a 256 byte limit on char vars? That's all MVC supported!) In other words, all MOVE did (at least before packed and binary decimal) was move bytes. The reason MOVE seemed to do conversion between char and decimal was that zoned decimal format used EBCDIC characters for the digits. If you want to simulate the behavior of MOVE by using EVAL, the closest you'll get is by using overlapping data structure subfields. Simply map the same few bytes of storage with a character subfield and a zoned decimal subfield of the same length. Then, write to the char subfield and read from the zoned subfield. Voila! MOVE functionality without having to use any advanced built-in functions. It should also be noted that MOVE does some wonky things when the source and target fields are not the same length. If the target is shorter, then you get truncation. If the target is longer, the left-most characters (or digits) are unchanged. EVAL always does a complete replacement of the target value, and so you always know what you get. Oh yeah, one other thing. Don't forget that converting character to numeric using MOVE is a bit strange when you want to deal with negative numbers. If you have a leading (or trailing) sign, MOVE won't do what you want - you'll need something like %DEC(). OK, so maybe the new BIFs aren't what RPG programmers are used to. But that's good, since they're much more powerful. And most of the time, they do the right thing. Cheers! Hans

                Comment


                • #9
                  Tips and Techniques: '00208' Is Possible in Free-Format

                  ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                  You need the minus sign on the left-side for some Excel data and other database's to recognize it. Whether that's EDI, Oracle, or elsewhere. Using %EditW is too ridged a solution. I find many "better" solutions that are offered, often don't work in anything except the once specific context in which they are illustrated. I prefer to write code that will "always work" regardless of the situation. A good piece of feedback would be "Hey, Bob, this is good, but in this situation is need to be tweeked a bit, like this..." Not "I already do that this way". Heck use MOVE if you want a ridged solution.

                  Comment


                  • #10
                    Tips and Techniques: '00208' Is Possible in Free-Format

                    ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                    I think as time passes it was a good decision to NOT port MOVE/MOVEL to expressions. But what is missing is the benefit that we see in the %char() built-in function. With EVAL it would be nice to have much more forgiving auto-conversion between data types when no error would occur. For example, why can't I concatenate a date with a character string without using %Char? Why can't I simply EVAL CharVar = DecVar and have it work? Oh, I don't mind eval charvar= %char(decvar) buy you see my point? If we use multiple variables in an expression and various variable names, using a DS to map the data is just a complex as al lthose embedded %this or %that built-ins. How about a function that copies data from one format to another? eval %Map(CharVar : DecVar ) eval %Map(decVal : CharValue ) And have it just work the way we think it should. That way, the programmer has requested the action, it wasn't implied by EVAL.

                    Comment


                    • #11
                      Tips and Techniques: '00208' Is Possible in Free-Format

                      ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                      You can use edit codes other than 'X' to get the format you want

                      Comment


                      • #12
                        Tips and Techniques: '00208' Is Possible in Free-Format

                        ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                        I always have to wonder why people are so attached to MOVE. That's because you're not an RPG programmer, Hans. Alright, I'm going to keep this short. OK, so maybe the new BIFs aren't what RPG programmers are used to. But that's good, since they're much more powerful. And most of the time, they do the right thing. That's really not your call, Hans. What is right is what we as progammers need, not what you want us to do. As a compiler writer you have absolutely no business--none, zero, nada, zilch--trying to dictate what we do. This argument has gone on forever, but I think it can be summed up this way: The number one reason people don't switch to /free is that they don't want to have to deal with fixing all those MOVE instructions. If your goal in demanding there be no MOVE was to make less people use /free, then you've succeeded admirably. Joe

                        Comment


                        • #13
                          Tips and Techniques: '00208' Is Possible in Free-Format

                          ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                          Joe Pluta opined: The number one reason people don't switch to /free is that they don't want to have to deal with fixing all those MOVE instructions. Naaaaah. The number one reason not to move to /free, is because if they did, they would also have to work with the COBOL programmers on the big machine in the back. :-) Dave

                          Comment


                          • #14
                            Tips and Techniques: '00208' Is Possible in Free-Format

                            ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                            Bob wrote: "Why can't I simply EVAL CharVar = DecVar and have it work?" First, I'd like to point out that, in general, like many other popular and useful programming languages, RPG is a strongly typed language. That is, it's strongly typed in all opcodes except for two weird ones: MOVE and MOVEL. You can debate the merits of strong typing if you want, but generally it's considered a good thing. Almost all of the time, assigning a char value to a numeric variable is a programming error. Second, how should "EVAL CharVar = DecVar" work? Should it work the way MOVE or MOVEL work? Should it work like %CHAR? Or like some particular edit word? If so, which edit word? Would all RPG programmers have the same opinion of how it should work? Would even the same RPG programmer have the same opinion from one application to the next? Cheers! Hans

                            Comment


                            • #15
                              Tips and Techniques: '00208' Is Possible in Free-Format

                              ** This thread discusses the article: Tips and Techniques: '00208' Is Possible in Free-Format **
                              Joe: You know, I can predict with almost 100% accuracy when writing a posting to a public forum that you will reply! And this time, again, you did not disappoint. You're right, I'm not an RPG programmer. The only RPG programs I wrote were a couple thousand testcases written to test various specific RPG functions. The languages I currently use actively are PL/X (at work), and Python, C, and Perl (at home). I've also used at different times various other programming languages like Pascal, C++, Java, Lisp, REXX, Object REXX, Smalltalk, GPSS, BCPL, PL/I, Modula-2 (Yucch!), COBOL, Basic, and various assemblers. I know there are lots of other languages I've left out. What's my point? One thing I've observed is that programming is pretty much the same process no matter which programming language you use. Is there something magical or special about RPG? In my opinion, no. It has some nice features, and it's sorely lacking in some others. You can say the same about pretty much any other language out there. Some are good for certain things, and not so good for others. But programming is programming is programming, and that's true for any language and any environment. Likewise, the needs of programmers are pretty much the same everywhere. Some particular programmers may have their own specific wants and desires. Which brings me to my second point: As you are well aware, when designing new features in a product, you can't please everyone. You do the best you can: You listen to suggestions and negotiate changes with your peers, and you hope that doesn't get you fired from your job. Regarding MOVE in free-form (how did that come up?), that decision wasn't my doing. In my original design for free-form calcs, I included all opcodes. However, some internal approvers didn't want that, and were quite adamant about it. In retrospect, though, I think they were right. Overall, without all opcodes, it made for a much cleaner design. Will that slow adoption of free-form calcs? Perhaps. But I think there are a lot of other excuses programmers will use. Cheers! Hans

                              Comment

                              Working...
                              X