sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Find the last day of the month

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

  • Find the last day of the month

    Here is a simple way to find the last day of the month. You do not have to worry about which month has 30 or 31 days, or leap years.

    1. Set your date to the first day of the month. Move '01' to the day portion of the date.
    2. Using COBOL Intrinsic Functions (I assume RPG works the same way) to add 1 month to the date.
    3. Using COBOL Intrinsic Functions, subtract 1 day from the date.

    This assumes you date is within the month you want the last day. I've written a detail article if you are interested.

    http://www.iseries-cobol.com/blog/20...-of-the-month/
    iSeriesCOBOL
    www.iseries-cobol.com

  • #2
    Re: Find the last day of the month

    We are really missing out still coding in OPM Cobol here, but that isn't up to me. I also don't know enough about it (potential downfalls) to suggest it to my boss. I originally thought, well, if we all just write our programs to run in same activation group, we'll be OK. But don't think so.......

    Anyway, I saw this somewhere (maybe your blog?), and I think I could substitute calls to other pgms we have in house. To accomplish a lot of date manipulation functions (add a month, etc.)., we call another routine, passing parameters. But that's a lot of code......lol

    Comment


    • #3
      Re: Find the last day of the month

      I don't know much about COBOL, but ...
      The iSeries can compile ILE programs into a "Default Activation Group". This makes the programs run the same way they did in OPM, but allows the new syntax and many of the new features. It used in shops (like mine) where we have have lots of OPM programs that we can't convert, mixed in with ILE programs.
      I would suggest taking a new or "safe" program and using the ILE on this pgm.

      Comment


      • #4
        Re: Find the last day of the month

        Most shops think they are ILE, when in fact they are only using the ILE create commands. They are not using Activation Groups, Service Programs, Modules, or Binding Directories.

        Missy, I would suggest you only use the ILE create options, which will give you the Intrinsic Functions.
        iSeriesCOBOL
        www.iseries-cobol.com

        Comment


        • #5
          Re: Find the last day of the month

          Well, if you want to be technical ....
          If you are running V3R1 or higher, you ARE running ILE. It's just that you are running everything in this "Default Activation Group" that doesn't behave like an activation group.

          Comment


          • #6
            Re: Find the last day of the month

            So as long as I create a program specifying default activation group, I'm essentially creating an OPM program? I'll bring it up........

            Oh, we're running V5R4. That's what got me thinking about it-so many enhancements to ILE Cobol!

            Comment


            • #7
              Re: Find the last day of the month

              That is only true for CRTBNDCL. CRTBNDCBL and CRTSQLCBLI defaults to the QILE activation group, which is ILE. However, if everything is in the same QILE activation group, nobody will be able to tell the difference between OPM and ILE. Also, OPM uses an activation group; although different from ILE, but it is still an activation group.
              iSeriesCOBOL
              www.iseries-cobol.com

              Comment


              • #8
                Re: Find the last day of the month

                Hi,

                if you are already on release V5R4 there is even an easier method to calculate the end of month. SQL provides the scalar function LAST_DAY that can be used with embedded SQL in either ILE and OPM programs.

                PHP Code:
                EXEC SQL  Set :MyLastDay Last_Day(:MyDate)
                END-EXEC 
                Birgitta

                Comment


                • #9
                  Re: Find the last day of the month

                  Hi Birgitta,

                  That is awesome! We're not on V5R4 yet, but that is good to know.
                  iSeriesCOBOL
                  www.iseries-cobol.com

                  Comment


                  • #10
                    Re: Find the last day of the month

                    iseriescobol, what exactly did you mean? We routinely make calls to other programs that do little routines. So, if I refrain from using one of these other programs, and compile using CRTBNDCBL (not option 15 from PDM) that would mean "everything is the same"? Sorry for being so dense.....Things have pretty much been done the same way here for years, and changing isn't something I see as going over really big. So I don't want to argue for permission to stop coding in OPM just to mess everything up!

                    when you said "However, if everything is in the same QILE activation group, nobody will be able to tell the difference between OPM and ILE.

                    Melissa

                    Comment


                    • #11
                      Re: Find the last day of the month

                      Be careful here. QILE is the IBM-supplied activation group. However, its NOT the same as "Default Activation Group". You can't just switch to QILE. Normal activation groups require scoping on things like OVRDBF. If you just switch to QILE, you will find that some overrides don't appear to work, and you could have a mess.
                      But, OTOH, the CRTBNDxxx commands create a single module, then bind it into a program. It defaults to "Default Activation Group". So, you are correct - using this allows you to use the new syntax/commands, but the program behaves as OPM.
                      The only gotcha I found in going to RPGIV with this method is that program-to-program calls with numeric parms MUST be packed fields. Most of mine were anyway, but I got caught on a couple that weren't. There are easy workarounds for this.

                      Comment


                      • #12
                        Re: Find the last day of the month

                        CRTBNDRPG does default to the Default Activation Group. However, this is not true for CRTBNDCBL. Here is the link to the CRTBNDCBL command. The activation group defaults to QILE.

                        http://publib.boulder.ibm.com/infoce...TBNDCBL.ACTGRP

                        You will have to watch OVRDBF and scoping. Either change the scoping or compile with ACTGRP(*CALLER). Both will solve the problem.
                        iSeriesCOBOL
                        www.iseries-cobol.com

                        Comment


                        • #13
                          Re: Find the last day of the month

                          Hmm. I was just going to play around with coding, but I get syntax errors just trying to enter. SEU doesn't like word "function"???

                          Message . . . . : ANS COBOL reserved word FUNCTION will be accepted as a
                          nonreserved word.

                          Cause . . . . . : FUNCTION is a reserved word in the 1985 ANSI COBOL
                          standard (revised 1989), but it is not a COBOL/400* reserved word.
                          Recovery . . . : Do not use ANS (American National Standard) COBOL reserved
                          words that are not COBOL/400 reserved words.

                          Comment


                          • #14
                            Re: Find the last day of the month

                            Originally posted by missymssy View Post
                            Hmm. I was just going to play around with coding, but I get syntax errors just trying to enter. SEU doesn't like word "function"???

                            Message . . . . : ANS COBOL reserved word FUNCTION will be accepted as a
                            nonreserved word.

                            Cause . . . . . : FUNCTION is a reserved word in the 1985 ANSI COBOL
                            standard (revised 1989), but it is not a COBOL/400* reserved word.
                            Recovery . . . : Do not use ANS (American National Standard) COBOL reserved
                            words that are not COBOL/400 reserved words.
                            Are you using "function" as a variable name -or- are you trying to use an intrinsic function call? If your using an intrinsic function your source type must be CBLLE. I believe you'll receive an error message in OPM for using "function" as a variable since OPM Cobol does not support intrinsic functions (TTBOMK).

                            Terry

                            Comment


                            • #15
                              Re: Find the last day of the month

                              Terry,
                              how do I make sure of the source type?

                              Comment

                              sponsored links

                              Collapse

                              Working...
                              X