MOD Function



Unicenter CA-Easytrieve Plus Report Generator: CA's information retrieval and data management tool

MOD Function

Postby usuario24 » Tue Oct 26, 2010 2:31 pm

Hi everyone!!

Could anyone tell me how to use de MOD function in EASYTRIEVE?

I need to use it to calc bis years.

Thanks a lot.
usuario24
 
Posts: 9
Joined: Thu Jul 08, 2010 3:22 pm
Has thanked: 0 time
Been thanked: 0 time

Re: MOD Function

Postby dick scherrer » Tue Oct 26, 2010 11:01 pm

Hello,

Where did you see a "MOD function" in Easytrieve?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: MOD Function

Postby usuario24 » Wed Oct 27, 2010 1:00 pm

I dont know if there is anything in Easytrieve like MOD function in other programming languages.

I'll try to do it using another supported function.

Thanks a lot!!!
usuario24
 
Posts: 9
Joined: Thu Jul 08, 2010 3:22 pm
Has thanked: 0 time
Been thanked: 0 time

Re: MOD Function

Postby dick scherrer » Thu Oct 28, 2010 12:55 am

Hello,

Most systems have callable routines that support date functions. Suggest you ask your seniors or technical support if something is already available to do what you want.

fwiw - i know of no MOD function in cobol or assembler (or several more specific languages). . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: MOD Function

Postby marta.doural » Thu Oct 28, 2010 3:25 pm

Hi all,

I've found a solution that works. My problem was a file with a date field with the following format: YYYYMMDD. But the DD part was missing, so I've had to fill it in. For QA reasons, I could't touch the cobol that generates the file, so I've developed the following in Easytrieve:

**********************************************************************
FILE FICIN
TOTAL1       1    197 A
I1CAB        1    184 A
I1CAMPO    185      5 A
I1AAAA     190      4 N
I1MM       194      2 A
I1DD       196      2 A
*
FILE FICOK
TOTAL2       1    197 A
I2CAB        1    181 A
I2CAMPO    182      5 A
I2FIL2     187      3 A
I2AAAA     190      4 N
I2MM       194      2 A
I2DD       196      2 A
*
* working area
*
W-MOD400       W      4 N
W-MOD4         W      4 N
W-MOD100       W      4 N
*
**********************************************************************
* PROGRAM CODE AREA
**********************************************************************
JOB INPUT FICIN
*
* - first, calculate all MOD operations
*
* I1AAAA MOD 400
*
  W-MOD400 = I1AAAA
  DO WHILE W-MOD400 >= 400
    W-MOD400 = W-MOD400 - 400
  END-DO
*
* I1AAAA MOD 4
*
  W-MOD4 = I1AAAA
  DO WHILE W-MOD4 >= 4
    W-MOD4 = W-MOD4 - 4
  END-DO
*
* I1AAAA MOD 100
*
  W-MOD100 = I1AAAA
  DO WHILE W-MOD100 >= 100
    W-MOD100 = W-MOD100 - 100
  END-DO
*
* write the correspondent day of end of month - leap-years
*
  IF I1MM = '02'
   IF W-MOD400 = 0
     I2DD = '29'
   ELSE
     IF W-MOD4 = 0 AND W-MOD100 ¬= 0
        I2DD = '29'
     ELSE
        I2DD = '28'
     END-IF
   END-IF
  ELSE
    IF I1MM = '04' OR I1MM = '06' OR I1MM = '09' OR I1MM = '11'
     I2DD = '30'
    ELSE
     I2DD = '31'
    END-IF
  END-IF

  I2CAB   = I1CAB
  I2AAAA  = I1AAAA
  I2MM    = I1MM
  I2CAMPO = I1CAMPO
  I2FIL2  = '   '
  PUT FICOK
*
**********************************************************************

Thank you all!!
marta.doural
 
Posts: 3
Joined: Tue Oct 26, 2010 2:55 pm
Has thanked: 0 time
Been thanked: 0 time

Re: MOD Function

Postby marta.doural » Thu Oct 28, 2010 3:49 pm

Hi all,
I'm sorry, I forgot... if you need both the integer part and the remainder part of the division, the algorithm would be as follows:

W-DIV400 = 0
W-MOD400 = I1AAAA
DO WHILE W-MOD400 >= 400
    W-MOD400 = W-MOD400 - 400
    W-DIV400 = W-DIV400 + 1
END-DO


Sorry for the mess on the previous post.
Hope this helps,
Marta.
marta.doural
 
Posts: 3
Joined: Tue Oct 26, 2010 2:55 pm
Has thanked: 0 time
Been thanked: 0 time

Re: MOD Function

Postby dick scherrer » Fri Oct 29, 2010 12:25 am

Sorry for the mess on the previous post.
Not to worry. It has now been "Code'd" :)

Thanks for posting your solution,

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: MOD Function

Postby Zio69 » Tue Feb 22, 2011 8:08 pm

In my salad days I implemented a macro to get that done....

MACRO 3 DIVIDEND DIVISOR MODULO QUOTIENT 'MACRO_DIVISION_QUOTIENT'
PUSH
LIST OFF
* Returns the modulo of the division of the
* first operand by the second; optionally it also returns quotient
*---------- START MACRO ----------------------------------
DEFINE  MACRO_DIVISION_QUOTIENT   W 10 P 0
&QUOTIENT = ( &DIVIDEND ) / ( &DIVISOR )
&MODULO = &DIVIDEND - (&QUOTIENT * ( &DIVISOR ))
POP
MEND


Save it in your MACRODD with the name you prefer - original name was MOD

example:

%MOD variable1 variable2 module
(in case you named it differently, code % followed by the name you gave the macro)
Zio69
 
Posts: 31
Joined: Wed Feb 16, 2011 7:08 pm
Has thanked: 0 time
Been thanked: 0 time

Re: MOD Function

Postby dick scherrer » Wed Feb 23, 2011 1:00 am

Hello,

How does this "solution" help if the requirement is Easytrieve?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: MOD Function

Postby BillyBoyo » Wed Feb 23, 2011 6:22 am

dick scherrer wrote:w does this "solution" help if the requirement is Easytrieve?


It is an Easytrieve Plus macro.

%MOD whole-number base-to-divide-by(also whole number) remainder (also whole number, so actually modulus) QUOTIENT what-the-quotient-was

This is if you named it "MOD" when putting it in the macro library.

It has three positional parameters and one keyword parameter. With a keyword parameter, you can specify a default on the macro definition.

The macro can be used at more than one location in the code, despite the fact that it DEFINEs some storage (outside of the "library" part of the program). The first physical occurence of the MACRO in the source is the one where the definition of the storage actually takes place (check on the DMAP, if requested on the PARM).

You don't have to be in a MACRO to DEFINE storage, by the way, but obviously outside a MACRO it should be used with some care, as it may not be apparent to the person stuck with maintaining the program where the field is...

Of course, you could screw it up if you give it decimal numbers with non-zero decimal parts, but that would just be abusing the whole concept (modulus would only mean modulus in whole-number arithmetic). Thus, some argument for "bullet-proofing" in the macro, so you could check for non-zero decimal part... and then what, well, abend if you wanted to I suppose. I think the macro is fine like this as long as its use is documented, which would be enough CYA.

Nice, Zio69.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Next

Return to CA-Easytrieve