IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

String function


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Feb 23, 2011 5:32 pm
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: 6966
Location: porcelain throne

PostPosted: Wed Feb 23, 2011 5:41 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Wed Feb 23, 2011 6:02 pm
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
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: 8696
Location: Dubuque, Iowa, USA

PostPosted: Wed Feb 23, 2011 6:46 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 2
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Calling an Open C library function in... CICS 1
No new posts DATE2 function SYNCSORT 15
Search our Forums:

Back to Top