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.
How to get the actual storage of a cobol varibale
Moderators: dbzTHEdinosauer, Moderator Group
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.
Thanks,
Prasad
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
How to get the actual storage of a cobol varibale
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
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
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
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page