Monday, December 22, 2008

My first REXX script


This is my first program written in REXX, it is a scripting language used first on mainframe, now have port for major platform from linux to windows and more. This is basically a Julian to Gregorian date converter. At least or form used in the bank. It took me a day to finish it, by then i spent a lot of time Procrastinating. Don't just copy it, the formating is wrong


/* REXX */
START:
  /* SAY IS TO PRINT ON SCREEN */
  SAY "PLEASE ENTER THE JULIAN DATE WITH THE SLASH"
  SAY "(DDD/YYYY)"
  /* PULL IS TO GET INPUT */
  PULL PARM
  /* PARSE IS TO GET THE VARIABLE FROM A STRING */
  /* PARM IS THE INPUT OR THE STRING. THE NEW VARIABLE IS DY AND YR */
  /* SPLIT THE PARM INTO DY AND YR, DELIMITED BY "/" */
  PARSE UPPER VAR PARM DY "/" YR
  /* CALL A FUNCTION */
  YR = CHECK_YEAR(YR)
  /* NOT EQUAL IS /= OR \= OR <> */
  IF YERR /= 1 THEN
     IF CHECK_YDAY(DY,YR) /= 1 THEN
      DO
        /* ANOTHER WAY TO CALL A SUBROUTINE */
       CALL CONVERT DY,YR
       /* || IS THE APPEND OPERATOR, APPEND STRING */ 
       SAY CDY||"/"||CMT||"/"||YR||" (DD/MM/YYYY)"
      END
     ELSE
      DO
       SAY "WRONG DAY!!!!"
      END
  ELSE
    SAY "WRONG YEAR!!!!!"
  EXIT
/* THIS IS THE BEGINNING OF THE FUNCTION */
CHECK_LEAP: PROCEDURE
  /* MEANS THE ARGUMENT IS PYR*/
  ARG PYR
  LYR = 0
  /* // IS THE MODULUS OPERATION */
  IF (PYR // 100) = 0 THEN
   DO
    IF (PYR // 400) = 0 THEN
      LYR = 1
    END
  ELSE
   DO
    IF (PYR // 4) = 0 THEN
      LYR = 1
    END
  RETURN LYR
/* ANOTHER FUNCTION */
/* EXPOSE MEANS EXPOSE A VARIABLE IN THIS CASE, YERR */ 
CHECK_YEAR: PROCEDURE EXPOSE YERR
  ARG PYR
  YERR = 1
  IF LENGTH(PYR) = 2 THEN
   DO
    IF PYR > 50 THEN
      PYR = 19||PYR
    ELSE
      PYR = 20||PYR
   YERR = 0
   END
  ELSE
   DO
    IF LENGTH(PYR) = 4 THEN
      YERR = 0
   END
  RETURN PYR
CHECK_YDAY: PROCEDURE
  ARG PDY,PYR
  VDY = 1
  IF PDY > 0 & PDY < (366 + CHECK_LEAP(PYR)) THEN
    VDY = 0
  RETURN VDY
CONVERT: PROCEDURE EXPOSE CDY CMT
  /* THE ARGUMENTS OR PARAMETER IS POSITION ORIENTED */
  ARG PDY,PYR
  /* THIS IS A COMPOUND VARIABLE, ACCESS IS BY STEM.TAIL */
  /* DATE IS STEM, TAIL IS THE NUMBER */
  DATE.1=31;DATE.2=28;DATE.3=31;DATE.4=30
  DATE.5=31;DATE.6=30;DATE.7=31;DATE.8=31
  DATE.9=30;DATE.10=31;DATE.11=30;DATE.12=31
  DATE.2=28+CHECK_LEAP(PYR)
  MONTH = 1
  TDY = PDY
  /* THE LOOP */
  /* BY THE WAY INFINITE LOOP IS "DO FOREVER" */
  DO WHILE DATE.MONTH < TDY
    /* NOTICE THE COMPOUND VARIABLE, AND HOW I USE MONTH AS A TAIL */
    TDY = TDY - DATE.MONTH
    MONTH = MONTH + 1
  END
  CDY=TDY
  CMT=MONTH
  RETURN



No comments:

Post a Comment