How to get the actual storage of a cobol varibale

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
srinivas
Member
Posts: 9
Joined: Wed Feb 08, 2006 2:58 pm
Location: Bangalore

How to get the actual storage of a cobol varibale

Post by srinivas » Wed Feb 08, 2006 3:54 pm

Hi,

Im new to this group.
I have a scenario like, one varibale whose length is X(16).
Suppose if the variable has value 'IBM' means I want to get the value as 3.
Suppose if the variable has value 'MAINFRAMES' means 10 and so on......

Can anyone Pls help me regarding this.

User avatar
prasad
Member
Posts: 7
Joined: Mon Feb 06, 2006 12:04 am

Post by prasad » Thu Feb 09, 2006 8:52 am

Hi Srinivas,

Actually there are many ways we can do this, one way is as follows.

Use REVERSE function to reverse the string then use the INSPECT tallying
to count the number of spaces at the begining of the reversed string.
Now substring length = actual length of variable - number of spaces.

Code: Select all

    MOVE 0 TO Count
    INSPECT FUNCTION REVERSE(Str) TALLYING Count
        FOR LEADING SPACES

    String-length =  16 - count.

    Here 16 is Str declaration length.



Thanks,
Prasad

ahkumar

How to get the actual storage of a cobol varibale

Post by ahkumar » Thu Feb 09, 2006 10:48 am

Try this thru perform, which is pretty simple and you can get the correct size even if there are any spaces in your field.

PERFORM VARYING WS-SIZE FROM 16 BY -1
UNTIL WS-COBOL-FLD-NM(WS-INDEX:1) > SPACE

COMPUTE WS-INDEX = ( WS-INDEX - 1 )
END-PERFORM

WS-SIZE gives you the size of WS-COBOL-FLD-NM

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others