RPG/400: Maximum and minimum values

140 pts.
Tags:
MaxField
MinField
RPG
RPG/400
Please advice how to find out maximum and minimum values in particular filed using rpg/400.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi,

If you’re allowed to use embedded SQL on your machine :-

C* Get Maximum value.
C/EXEC SQL
C+ SELECT MAX(Field_Name) INTO :MAXVAL
C+ FROM YourFile
C/END-EXEC

C* Get Minimum value.
C/EXEC SQL
C+ SELECT MIN(Field_Name) INTO :MINVAL
C+ FROM YourFile
C/END-EXEC

I’ve kept the following in RPG/400 format, so it should work with non-ILE as well.

Replace FieldName with your database field and YourFile with your file name, define MAXVAL and MINVAL in your RPG to be the same as your FieldName.

Otherwise it depends on how your file is keyed. If the field you’re checking is the key you can do the following :-

C *LOVAL SETLL YourFile
C READ YourFile
>>>> Now you should have the minimum value.

C *HIVAL SETGT YourFile
C READP Yourfile
>>>>> Now you should have the maximum value.

If your file is not keyed with your field, you may need to read the whole file :-

C *LOVAL SETLL YourFile
C READ YourFile 99 (End of file)
C *IN99 DOWEQ *OFF
C YourField IFGT MaxField
C MOVE YourField MaxField
C ENDIF
C YourField IFLT MinField
C MOVE YourField MinField
C ENDIF
C READ YourFile 99 (End of file)
C ENDDO

You should end up with MaxField being filled with your maximum value and MinField with your minimum value. You’ll need to declare MaxField and MinField to be the same as YourField (database field).

Regards,

Martin Gilbert.

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following