• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

In RPGIV, is there a test for uppercase values?

I am attempting to determine how much of an issue we have with a certain file and the data that is in the file.  Specifically, I need to determine how many RECORDS in the file have FIELDS that meet the criteria of having all their alpha data in uppercase.  For example, if your name is Jack P. SMITH you would NOT be counted, but if your name was JACK P. SMITH you WOULD be counted.  I want to ignore spaces and non alpha characters, simply testing all characters for uppercase and if they are, then tally that record.
Any thoughts?  
  • 2
  • 2
1 Solution
MurpheyApplication ConsultantCommented:
The deference between a Upper and a lower case character is Bit 1  (That's the second bit from the left)
All uppercase characters is this bit set to 1  and for lower case this value is 0, So you can do a TESTB operation, but the problem is that numbers 0-9 have also the uppercast bit set (and also some other characters like {,}, and \ .
So the second option is to use the Xlate opcode.

Translate everything within a variable to uppercase and compare it with the original field, if they are the same, the original field contains uppercase only.

D up              C                   'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
D lo              C                   'abcdefghijklmnopqrstuvwxyz'
   UpperField = %XLATE(lo:up:MyField);

Open in new window

wendelinaAuthor Commented:
That is a good idea.  In the interim, I already set up a program (in very little time!) that I took the field in question and did a SCAN operation 26 times setting 26 different indicators and testing each one to see if the field contained ANY lowercase characters - if not then it must be all uppercase.  But, your solution is probably more efficient.  
thank you!!
Minor variation on Murph's solution -- if the SQL Dev Kit is available. The SQL UPPER() function can be handy.


     Drc               S              4
     C/exec sql set :rc  = case when UPPER(:pTstVar)=:pTstVar
     c+                         then '*AOK'
     c+                         else '*NOK'
     c+                         end

Open in new window

MurpheyApplication ConsultantCommented:

a variation on Tom's idea, just use SQL to count your result like:

            select count(NAME) from CUSTOMER where NAME = binary upper(NAME)

This will return the number of names that is the same in upper as in stored format.
If you mean that by "determine how many RECORDS in the file have FIELDS that meet the criteria of having all their alpha data in uppercase"

(No AS/400 at home so tested on MySQL but I think this will work, otherwise I will put the right syntax here first thing in the morning)

Murph -- Yeah, I might've presented the fuller SQL solution but you'd already given the correct RPG one. And the question _was_ asked for RPG.

If SQL is used all the way through, the system catalog could be queried for tables and those tables could be queried for CHARACTER columns and those columns could be queried for UPPER()...

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Train for your Pen Testing Engineer Certification

Enroll today in this bundle of courses to gain experience in the logistics of pen testing, Linux fundamentals, vulnerability assessments, detecting live systems, and more! This series, valued at $3,000, is free for Premium members, Team Accounts, and Qualified Experts.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now