Page 1 of 1

Convert from lower case to Upper case in COBOL.

Posted: Mon Dec 21, 2015 4:20 pm
by Ankit Gautam
Hi,

Can we convert from lower case to Upper case in COBOL?

I was not sure and I said yes.

Then the interviewer said, well, then how do you code a COBOL program to do this?
  1. Without using any Functions?
  2. And with using built-in functions or Intrinsic functions?
I have searched on it but this question sounds tough. Can someone please share his experience on this.

Re: Convert from lower case to Upper case in COBOL.

Posted: Mon Dec 21, 2015 5:55 pm
by William Collins
To do it without a function, you can look at INSPECT ... CONVERTING ...

Re: Convert from lower case to Upper case in COBOL.

Posted: Mon Dec 21, 2015 6:32 pm
by Robert Sample
I have searched on it but this question sounds tough
Where did you search? The Enterprise COBOL Language Reference manual provides a chapter with every intrinsic function and how to use it, so I wouldn't think it would be too tough to look up FUNCTION UPPER-CASE. The link to the various COBOL releases is http://www-01.ibm.com/support/docview.w ... wg27036733 so you can start learning.

Re: Convert from lower case to Upper case in COBOL.

Posted: Mon Dec 28, 2015 2:44 pm
by Ankit Gautam
Thanks for the answers. I even find a link stating the use of FUCNTION UPPER-CASE in an interesting way:
UPPER-CASE & LOWER-CASE FUNCTIONS:

If you want to compare two fields and you are not sure of what case the fields contain, you can look at the upper case version of both fields or the lower case version of both fields so that you are comparing like configurations.

IF FUNCTION UPPER-CASE(FLD1) = FUNCTION UPPER-CASE(FLD2)
> PERFORM B-300-MATCH-ROUT.

IF FUNCTION LOWER-CASE(FLD1) = FUNCTION LOWER-CASE(FLD2)
PERFORM B-300-MATCH-ROUT.

If you are concerned that a user might enter data incorrectly at the screen, you can covert it using this function.

MOVE FUNCTION UPPER-CASE(STATE-IN) TO STATE-FOR-FILE.

LENGTH FUNCTION:

The length function gets the length of non-numeric fields so that you can find out the length of the field.

COMPUTE LEN1 = FUNCTION LENGTH(FLD-IN).