Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
String function

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
sriraj1122

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Wed Feb 23, 2011 5:08 pm    Post subject: String function
Reply with quote

Hi ,

I need a small help regarding string function in Cobol

Code:
01 TEMP-VAR                       PIC X(50)         
                                    VALUE     SPACE.       
01 SOURCE-CD                                         
                        PIC X(2)                           
                        VALUE SPACES.                     
01 FULL-DESC           PIC X(55)             
                          VALUE     SPACE.                 
PROCEDURE DIVISION.                                       
    MOVE 'FAIR CREDIT REPORTING ACT NOTICE/CL'             
    TO   TEMP-VAR.                                   
    MOVE 'CS' TO SOURCE-CD.                         
          STRING TEMP-VAR  DELIMITED BY SIZE         
                 '/' SOURCE-CD DELIMITED BY SIZE     
                 INTO FULL-DESC             
          END-STRING.                                     
        DISPLAY FULL-DESC.     


In the final output FULL-DESC i should get the out as below

FAIR CREDIT REPORTING ACT NOTICE/CL/CS

But with the above code im getting like below
FAIR CREDIT REPORTING ACT NOTICE/CL

Pls help me
Back to top
View user's profile Send private message

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10326
Location: italy

PostPosted: Wed Feb 23, 2011 5:32 pm    Post subject: Reply to: String functoin
Reply with quote

do not double post
people hanging on the other forum are mostly the same who answer here

topic locked, will be deleted shortly!
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Feb 23, 2011 5:41 pm    Post subject:
Reply with quote

1. learn to use bbcode.

Code:

01 TEMP-VAR           PIC X(50)    VALUE SPACE.
01 SOURCE-CD          PIC X(2)     VALUE SPACES.
01 FULL-DESC          PIC X(55)    VALUE SPACE.

PROCEDURE DIVISION.

MOVE 'FAIR CREDIT REPORTING ACT NOTICE/CL' TO TEMP-VAR.
MOVE 'CS'                                  TO SOURCE-CD.

STRING TEMP-VAR
        DELIMITED BY SIZE
       '/'
       SOURCE-CD 
         DELIMITED BY SIZE
  INTO FULL-DESC
END-STRING.

DISPLAY FULL-DESC.


will build this:
Code:

FAIR CREDIT REPORTING ACT NOTICE/CL               /CS


if you wanted this:
Code:
FAIR CREDIT REPORTING ACT NOTICE/CL/CS


you should have coded:
Code:

STRING TEMP-VAR
        DELIMITED BY '  '
       '/'
         DELIMITED BY SIZE
       SOURCE-CD 
         DELIMITED BY SIZE
  INTO FULL-DESC
END-STRING.


I changed the delimiter on temp-var from size (?why did you do that????)
to 2 (that is TWO) spaces

not that it is needed
(maybe the last is applied to every subsequent until a new delimiter is found)
but I added DELIMITED BY SIZE for the literal '/'.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10326
Location: italy

PostPosted: Wed Feb 23, 2011 6:02 pm    Post subject: Reply to: String function
Reply with quote

since Dick provided a very good explanation I unlocked the topic,
but only reasonable/intelligent replies, please icon_cool.gif
Back to top
View user's profile Send private message
sriraj1122

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Wed Feb 23, 2011 6:26 pm    Post subject:
Reply with quote

Thnx dbzTHEdinosauer,

I got it ..
But can u tell me what is significance of DELIMITED BY SIZE ?
And why the result would be as below
FAIR CREDIT REPORTING ACT NOTICE/CL /CS
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Wed Feb 23, 2011 6:46 pm    Post subject:
Reply with quote

DELIMITED BY SIZE means exactly what it says -- transfer the entire variable. COBOL does not have the concept of strings such as C or Basic (that is, where the length of the variable changes at run time). COBOL variables have fixed sizes and that size is fixed at compile time. So when you say STRING TEMP-VAR DELIMITED BY SIZE and TEMP-VAR is defined as 50 bytes, all 50 bytes are going to be transferred. If the last 15 (or 20 or 45) are spaces, they will STILL be transferred.
Back to top
View user's profile Send private message
sriraj1122

New User


Joined: 18 Dec 2008
Posts: 15
Location: Hyderabad

PostPosted: Wed Feb 23, 2011 11:46 pm    Post subject:
Reply with quote

Thnx a lot !!
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts line 52: Name or string > 250 char... Ashishpanpaliya CLIST & REXX 5 Sat Oct 14, 2017 2:29 am
No new posts Search for a string in many PDS KARTHIGADEVI CLIST & REXX 5 Fri Sep 08, 2017 2:32 pm
No new posts How to change a string containing the... chong.zhou TSO/ISPF 6 Tue Aug 29, 2017 4:54 pm
No new posts String after '.' (period) is not copy... balaji81_k SYNCSORT 6 Wed Aug 23, 2017 9:35 pm
No new posts change string before sertan string anatol DFSORT/ICETOOL 8 Tue Aug 15, 2017 5:43 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us