STRING in cobol
Moderators: dbzTHEdinosauer, Moderator Group
-
- Member
- Posts: 10
- Joined: Thu Jul 30, 2009 8:11 pm
- Location: Bangalore
STRING in cobol
hi, i have a req it says that,
Var1 to var 14 : each 6 character length. each one i will read from the array.
ex: Var1 = 'bala ', var2 = 'ji '
when i do, STRING VAR1 ',' VAR2 ','..........
i will get 'bala ,ji ' but i dont want that. i want 'bala,ji'. basically the spaces after the acharacter sholud be truncated and i could do this for 14 variables.
please suggest methe option.
Var1 to var 14 : each 6 character length. each one i will read from the array.
ex: Var1 = 'bala ', var2 = 'ji '
when i do, STRING VAR1 ',' VAR2 ','..........
i will get 'bala ,ji ' but i dont want that. i want 'bala,ji'. basically the spaces after the acharacter sholud be truncated and i could do this for 14 variables.
please suggest methe option.
COBOL INSPECT STRING
You need to remove the spaces for the data in 14 variables.
You can do that using INSPECT COBOL verb.
Try that, if you dont get.. let me know.
You can do that using INSPECT COBOL verb.
Try that, if you dont get.. let me know.
Natarajan
Chennai
Chennai
-
- Member
- Posts: 10
- Joined: Thu Jul 30, 2009 8:11 pm
- Location: Bangalore
NO my concern is different.
first time i am moving the var1 to temp.
var1 has ' bala' but the length is 60.
second time i am doing string of var2 and temp into temp.
third time i am doing string of var3 and temp into temp.
like this its going on for 14 times.
so every time temp will get somee value and the next var will get concat to it.
temp var length is 850.
first tim its working fine. but the second time temp itself has a pic clause of 850. so the string option is not working.The data inside the temp is 10 to 20 charaters only.
problem is when its doing the second loop it sld take only the content length only not the var length.
first time i am moving the var1 to temp.
var1 has ' bala' but the length is 60.
second time i am doing string of var2 and temp into temp.
third time i am doing string of var3 and temp into temp.
like this its going on for 14 times.
so every time temp will get somee value and the next var will get concat to it.
temp var length is 850.
first tim its working fine. but the second time temp itself has a pic clause of 850. so the string option is not working.The data inside the temp is 10 to 20 charaters only.
problem is when its doing the second loop it sld take only the content length only not the var length.
COBOL - USING INSPECT FUNCTION REVERSE STRING verbs
Yes, in this situation INSPECT verb will work.
Use following code... following cobol code will find the the length of the actual chatacter before space.
I hope above solution will work out..
You need to repeat above solution for 14 variables , before using COBOL STRING verb.
Use following code... following cobol code will find the the length of the actual chatacter before space.
Code: Select all
INSPECT FUNCTION REVERSE(VAR1)
TALLYING WS-CNT FOR LEADING SPACES
COMPUTE WS-INSPECT-OFFSET-1 = 60 - WS-CNT
....
....
STRING VAR1(1:WS-INSPECT-OFFSET-1) , VAR2(1:WS-INSPECT-OFFSET-2)....
I hope above solution will work out..
You need to repeat above solution for 14 variables , before using COBOL STRING verb.
Last edited by Natarajan on Thu Aug 06, 2009 9:13 pm, edited 1 time in total.
Natarajan
Chennai
Chennai
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
WTF????
a simple string with each variable delimited by space is all that is necessary:
a simple string with each variable delimited by space is all that is necessary:
Code: Select all
string var1 delimited by spaces
var2 delimited by spaces
...
var14 delimited by spaces
into whatever
end-string.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
STRING delimited by....
???dbzTHEdinosauer wrote: WTF????
what is that word......
different people gives different solutions.... does not required to be
use words like WTF????
Natarajan
Chennai
Chennai
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
WTF??? why the foolishness? (don't get your undies in a bundle!!!)
what is your statement?
the following compiles fine:
here is the ouptut:
Useless comment. What compiler error?But there is a compilation error when used with INSPECT REPLACING..
what is your statement?
the following compiles fine:
Code: Select all
01 SOURCE-GROUP.
05 WS-FIELD-01 PIC X(10) VALUE 'ABC'.
05 WS-FIELD-02 PIC X(10) VALUE 'DEF'.
- - - - - - - - - - - - - 10 Line(s) not Dis
DISPLAY SOURCE-GROUP
INSPECT SOURCE-GROUP REPLACING ALL SPACE BY ZERO.
DISPLAY SOURCE-GROUP
here is the ouptut:
Code: Select all
ABC DEF
ABC0000000DEF0000000
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
Am talking about FUNCTIOBN REVERSE with INSPECT REPLACING ..
U r talking about INSPECT REPLACING
Code:
INSPECT FUNCTION REVERSE(WS-LOB-CLASS-CODE) REPLACING
LEADING SPACES BY ZEROES.
The compilation error:
"ALPHANUMERIC FUNCTION REVERSE" was specified as the subject of "INSPECT", but a "CONVERTING" or "REPLACING"
phrase was found. The statement was discarded.
Please mind your words... and read full question before REPLYING...
U r talking about INSPECT REPLACING
Code:
INSPECT FUNCTION REVERSE(WS-LOB-CLASS-CODE) REPLACING
LEADING SPACES BY ZEROES.
The compilation error:
"ALPHANUMERIC FUNCTION REVERSE" was specified as the subject of "INSPECT", but a "CONVERTING" or "REPLACING"
phrase was found. The statement was discarded.
Please mind your words... and read full question before REPLYING...
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
Chandana,
you also need to relax and think.
there is an interm data area presented to the INSPECT statement by FUNCTION reverse.
what would be a replacing phrase for an interm data area accomplish?
why are you FUNCTION REVERSing?
you started this thread wanting to eliminate trailing spaces, before stringing variable contents.
now you want to what, replace them with zeroes?
get your head out of your butt,
and describe exactly what it is that you want to do.
you also need to relax and think.
there is an interm data area presented to the INSPECT statement by FUNCTION reverse.
what would be a replacing phrase for an interm data area accomplish?
why are you FUNCTION REVERSing?
you started this thread wanting to eliminate trailing spaces, before stringing variable contents.
now you want to what, replace them with zeroes?
get your head out of your butt,
and describe exactly what it is that you want to do.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
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