7 Replies Latest reply on Jun 14, 2018 4:19 AM by Danny van Lieshout

    Variable %%ODAY %%MINUS 1

    José Alfredo Rangel Sánchez

      Hello everyone I have a problem in Control M with the declaration of a variable oday.

      What I need to do is bring the date of the previous day but with a parameter DDMMYYYY

      My file is called EXP EXP _ %% ODAY. %% OMONTH. %% $ OYEAR..txt "

       

      But when calling the day before I do it with variables but when doing the "minus in ODAY if it brings it to me but in a single digit I need to show it in 06 and it only shows it to me 6.

       

      EXP _ %% A. %% REMOVE_DIA..txt "

      Variables

      REMOVE_DIA = %% OMONTH. %% $ OYEAR

      A = %% DAY %% MINUS 1

       

      Someone has gone through the same or know how to solve it,

       

      I am grateful in advance.

       

      Greetings.

        • 1. Re: Variable %%ODAY %%MINUS 1
          Jesse Richardson

          Successfully moved to the Control-M space so product experts can reply

          1 of 1 people found this helpful
          • 2. Re: Variable %%ODAY %%MINUS 1
            Danny van Lieshout

            To make it double-digit again, you can add 100 and then substr 2,2 it..

            1 of 1 people found this helpful
            • 3. Re: Variable %%ODAY %%MINUS 1
              Mark Francome

              Hi José,

               

              Do you need to do this inside a job? I had so many requests for variables to represent yesterday's date that I scripted the following (please don't laugh at my scripting, the main thing is this works!).

               

              If the following is run just before midnight (and the variables are not needed between it running and midnight) then the following will create variables for the month (both digits and alpha) and day. The variable you would want is %%yesterdy_dd

               

              This works for Unix, adapt as needed. I also have a New Year's Eve version that does the year.

               

              #!/bin/sh

              #

              #  Script:              yesterdays_setup.sh

              #  Server:              ctrlmpv9

              #  Version:             1

              #

              #  Job Name:            pdiscm075

              #  Description:         Sets the Control-M User Variables for yesterday

              #  Notes:               Add other variables to this job if required

              #  Run Time:            Must be before midnight

              #

              #  Created By:          Mark Francome

              #  Date Created:        20.MAY.2012

              #  Updates:             25.JUN.2017 - added mmm

              #

              #

              set `ctmstvar 0 "%%MONTH"`;

                if [ "$1" = "01" ]

                  then V2=01;

                elif [ "$1" = "02" ]

                  then V2=02;

                elif [ "$1" = "03" ]

                  then V2=03;

                elif [ "$1" = "04" ]

                  then V2=04;

                elif [ "$1" = "05" ]

                  then V2=05;

                elif [ "$1" = "06" ]

                  then V2=06;

                elif [ "$1" = "07" ]

                  then V2=07;

                elif [ "$1" = "08" ]

                  then V2=08;

                elif [ "$1" = "09" ]

                  then V2=09;

                elif [ "$1" = "10" ]

                  then V2=10;

                elif [ "$1" = "11" ]

                  then V2=11;

                else V2=12;

                fi;

              ctmvar -action set -var "%%#\yesterdy_mth" -varexpr $V2 -quiet

              #

              ctmvar -action list

              #

              set `ctmstvar 0 "%%DAY"`;

                if [ "$1" = "01" ]

                  then V3=01;

                elif [ "$1" = "02" ]

                  then V3=02;

                elif [ "$1" = "03" ]

                  then V3=03;

                elif [ "$1" = "04" ]

                  then V3=04;

                elif [ "$1" = "05" ]

                  then V3=05;

                elif [ "$1" = "06" ]

                  then V3=06;

                elif [ "$1" = "07" ]

                  then V3=07;

                elif [ "$1" = "08" ]

                  then V3=08;

                elif [ "$1" = "09" ]

                  then V3=09;

                elif [ "$1" = "10" ]

                  then V3=10;

                elif [ "$1" = "11" ]

                  then V3=11;

                elif [ "$1" = "12" ]

                  then V3=12;

                elif [ "$1" = "13" ]

                  then V3=13;

                elif [ "$1" = "14" ]

                  then V3=14;

                elif [ "$1" = "15" ]

                  then V3=15;

                elif [ "$1" = "16" ]

                  then V3=16;

                elif [ "$1" = "17" ]

                  then V3=17;

                elif [ "$1" = "18" ]

                  then V3=18;

                elif [ "$1" = "19" ]

                  then V3=19;

                elif [ "$1" = "20" ]

                  then V3=20;

                elif [ "$1" = "21" ]

                  then V3=21;

                elif [ "$1" = "22" ]

                  then V3=22;

                elif [ "$1" = "23" ]

                  then V3=23;

                elif [ "$1" = "24" ]

                  then V3=24;

                elif [ "$1" = "25" ]

                  then V3=25;

                elif [ "$1" = "26" ]

                  then V3=26;

                elif [ "$1" = "27" ]

                  then V3=27;

                elif [ "$1" = "28" ]

                  then V3=28;

                elif [ "$1" = "29" ]

                  then V3=29;

                elif [ "$1" = "30" ]

                  then V3=30;

                else V3=31;

                fi;

              ctmvar -action set -var "%%#\yesterdy_dd" -varexpr $V3 -quiet

              #

              ctmvar -action list

              #

              set `ctmstvar 0 "%%MONTH"`;

                if [ "$1" = "01" ]

                  then V4=Jan;

                elif [ "$1" = "02" ]

                  then V4=Feb;

                elif [ "$1" = "03" ]

                  then V4=Mar;

                elif [ "$1" = "04" ]

                  then V4=Apr;

                elif [ "$1" = "05" ]

                  then V4=May;

                elif [ "$1" = "06" ]

                  then V4=Jun;

                elif [ "$1" = "07" ]

                  then V4=Jul;

                elif [ "$1" = "08" ]

                  then V4=Aug;

                elif [ "$1" = "09" ]

                  then V4=Sep;

                elif [ "$1" = "10" ]

                  then V4=Oct;

                elif [ "$1" = "11" ]

                  then V4=Nov;

                else V4=Dec;

                fi;

              ctmvar -action set -var "%%#\yestmthmmm" -varexpr $V4 -quiet

              #

              ctmvar -action list

              #

              1 of 1 people found this helpful
              • 4. Re: Variable %%ODAY %%MINUS 1
                David Brenchley

                Why not subtract the day first, before creating the format you need?

                 

                If you do this all within the job definition it's a bit messy. Something like this:

                PREV_DATE.JPG

                However, you could do it a bit tidier if you're going to use the value in a script. In windows for instance all you would need is the first variable above and then something like:
                Set "PREV_DATE_DDMMYYYY=%PREV_DATE:~6,2%%PREV_DATE:~4,2%%PREV_DATE:~0,4%"

                in the script.

                 

                Also keep in mind that subtracting 1 from ODATE gives you the previous day the job was scheduled, which is not necessarily the previous day.

                1 of 1 people found this helpful
                • 5. Re: Variable %%ODAY %%MINUS 1
                  Paul Robins

                  I agree with David's approach. However I disagree that %%$CALCDATE will consider scheduling dates.

                  • 6. Re: Variable %%ODAY %%MINUS 1
                    José Alfredo Rangel Sánchez

                    Thank you very much, your answer was very helpful with this I was able to bring the day to two digits with the formula.

                     

                     

                    Formula

                    echo "/homes/EXP_%%DD.%%QUITAR_DIA..txt"

                     

                     

                    Variables

                    QUITAR_DIA= %%OMONTH.%%$OYEAR

                    NEWDATE= %%$ODATE %%MINUS 1

                    DD= %%SUBSTR %%NEWDATE 7 8

                    • 7. Re: Variable %%ODAY %%MINUS 1
                      Danny van Lieshout

                      NEWDATE= %%$ODATE %%MINUS 1 doesn't work on the first day of month.

                      Better to use %%$CALCDATE like in David's reply.