STRING in cobol

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
Jairam_baju
Member
Posts: 10
Joined: Thu Jul 30, 2009 8:11 pm
Location: Bangalore

STRING in cobol

Post by Jairam_baju » Thu Aug 06, 2009 5:02 pm

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.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

COBOL INSPECT STRING

Post by Natarajan » Thu Aug 06, 2009 5:28 pm

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.
Natarajan
Chennai

Jairam_baju
Member
Posts: 10
Joined: Thu Jul 30, 2009 8:11 pm
Location: Bangalore

Post by Jairam_baju » Thu Aug 06, 2009 5:37 pm

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.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

COBOL - USING INSPECT FUNCTION REVERSE STRING verbs

Post by Natarajan » Thu Aug 06, 2009 6:34 pm

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.

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

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Thu Aug 06, 2009 7:58 pm

WTF????
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.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

STRING delimited by....

Post by Natarajan » Thu Aug 06, 2009 8:53 pm

dbzTHEdinosauer wrote: WTF????
???

what is that word...... :evil:
different people gives different solutions.... does not required to be
use words like WTF????
Natarajan
Chennai

chandana
Member
Posts: 6
Joined: Mon Jun 21, 2010 2:50 pm

Post by chandana » Fri Dec 03, 2010 2:42 pm

Hi ..
When REVERSE FUNCTION used with INSPECT TALLYING its working fine..
But there is a compilation error when used with INSPECT REPLACING..

Is there any way to replace trailing spaces by zeroes using INSPECT?

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Dec 03, 2010 4:58 pm

WTF??? why the foolishness? (don't get your undies in a bundle!!!)
But there is a compilation error when used with INSPECT REPLACING..
Useless comment. What compiler error?
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.

chandana
Member
Posts: 6
Joined: Mon Jun 21, 2010 2:50 pm

Post by chandana » Fri Dec 03, 2010 5:30 pm

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...

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Dec 03, 2010 6:28 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.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

chandana
Member
Posts: 6
Joined: Mon Jun 21, 2010 2:50 pm

Post by chandana » Mon Dec 06, 2010 11:24 am

yes, i started my thread with eliminating trailing spaces.. but my question was how to replace the trailing spaces by zeroes...

Anyways,thank you for the answer..
but better watch ur language.. its disgusting.. and gets bad impression on the site

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Mon Dec 06, 2010 1:15 pm

Cool....

It is always good to start a new thread instead of replying to existing thread even there is a similartiy.
Natarajan
Chennai

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