×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

MF COBOL - Convert index value to numeric

MF COBOL - Convert index value to numeric

MF COBOL - Convert index value to numeric

(OP)
IBM Mainframe COBOL:
I've got a 300-character work area where I insert an alphanumeric string and then determine the beginning and ending non-space characters of the string so I can determine the number of characters in the string.  I've got the 300-character work area indexed to speed the lookup of the first non-space character and the final non-space character, but once I've got the beginning and ending index values, how can I determine the overall length of the non-space portion of the character string?  I can't use the index values to perform the math needed.

In other words, how do I convert an index value into a "normal" numeric value?

Rich (in Minn.)

RE: MF COBOL - Convert index value to numeric

Cant you just move the index name to a standard numeric
variable?

RE: MF COBOL - Convert index value to numeric

You can't MOVE an INDEX, but you can use the SET statement.  Define a numeric field (it can be zoned decimal or packed). Use the SET statement this way:

  SET num-field TO index-field

This will convert the index value to a numeric value.

RE: MF COBOL - Convert index value to numeric

You might also run a timing test using reference modification without using an array . . .

RE: MF COBOL - Convert index value to numeric

I alway use reference modification (substring notation) to do this sort of thing.

RE: MF COBOL - Convert index value to numeric

Are you trying to find the length of a string? If so, would this be easier?

CODE

      *SCAN********************************************************
      *  CALCULATE THE NUMBER OF KEY STROKES FOR A GIVEN STRING.  *
      *       WS-FIELD-LENGTH: SIZE OF WS-STRING                  *
      *       WS-LENGTH: NUMBER OF KEYSTROKES IN WS-STRING        *
      *       WS-SPACES: NUMBER OF TRAILING SPACES                *
      *       WS-STRING: STRING TO BE TESTED                      *
      *************************************************************
       CALCULATE-KEYSTROKES.                                        
           INITIALIZE WS-SPACES, WS-LENGTH.                         
           INSPECT FUNCTION REVERSE(WS-STRING)                      
                   TALLYING WS-SPACES FOR LEADING SPACES.           
           COMPUTE WS-LENGTH = WS-FIELD-LENGTH - WS-SPACES.         
                                                                    

RE: MF COBOL - Convert index value to numeric

Please re-read the original request. The "calculate-keystrokes" routine only does part of the requirement.

RE: MF COBOL - Convert index value to numeric

weberm, your code assumes no leading spaces.  You must also inspect the unreversed WS-STRING for leading spaces.  This is a common analysis error by beginning programmers.

RE: MF COBOL - Convert index value to numeric

(OP)
Here's the code that I ended up using:  (WORK-FIELD is used for inspecting a number of different-length fields, ranging from 20 to 300 bytes.  The length of field to inspect is contained in MAX-LEN.  If, for example, MAX-LEN has a value of 20, only the first 20 bytes of WORK-FIELD need to be inspected for the actual string length.  The string can have leading and/or trailing spaces, which need to be removed, and the length of the remaining string calculated (WORK-LENGTH).  

IF WORK-FIELD(1:MAX-LEN) NOT = SPACES                      
  IF WORK-FIELD(MAX-LEN:1) = SPACE                      
***  AT LEAST 1 TRAILING SPACE SO GET COUNT  
    INSPECT FUNCTION REVERSE(WORK-FIELD(1:MAX-LEN))    
            TALLYING END-SPACE-COUNT                   
            FOR LEADING SPACES                         
  ELSE                                                   
    MOVE 0 TO END-SPACE-COUNT                          
  END-IF                                                 
  IF WORK-FIELD(1:1) = SPACE                             
***  AT LEAST 1 LEADING SPACE SO GET COUNT          
    INSPECT WORK-FIELD(1:MAX-LEN)                      
            TALLYING BEG-SPACE-COUNT                   
            FOR LEADING SPACES
  ELSE                                                  
    MOVE 0 TO BEG-SPACE-COUNT                          
  END-IF                                                 
  COMPUTE WORK-LENGTH                                    
          = MAX-LEN - (BEG-SPACE-COUNT + END-SPACE-COUNT)
  ELSE                                                       
      MOVE 0 TO BEG-SPACE-COUNT                   
                      END-SPACE-COUNT                   
                      WORK-LENGTH.

MOVE WORK-FIELD(BEG-SPACE-COUNT + 1,WORK-LENGTH)
        TO OUTPUT-FIELD.


Rich (in Minn.)           

RE: MF COBOL - Convert index value to numeric

How about something like the following?

It doesn't look like you really need to know how long the field is because when you move a shorter field to a longer one it pads the receiving field with spaces.  How about if we first left justify the WORK-FIELD to get rid of leading spaces?  Doesn't really matter how many leading spaces there are if we get rid of them.

Then move that field for the maximum possible length (MAX-LEN) to the output.  

IF WORK-FIELD(1:MAX-LEN) NOT = SPACES
   PERFORM
     UNTIL WORK-FIELD(1:1)NOT = SPACE
     MOVE WORK-FIELD (2: MAX-LEN - 1)
             TO WORK-FIELD (1:MAX-LEN)
   END-PERFORM
END-IF                      

MOVE WORK-FIELD(1:MAX-LEN)
        TO OUTPUT-FIELD.
 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close