View previous topic :: View next topic
|
Author |
Message |
sriraj1122
New User
Joined: 18 Dec 2008 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
since Dick provided a very good explanation I unlocked the topic,
but only reasonable/intelligent replies, please |
|
Back to top |
|
|
sriraj1122
New User
Joined: 18 Dec 2008 Posts: 15 Location: Hyderabad
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
sriraj1122
New User
Joined: 18 Dec 2008 Posts: 15 Location: Hyderabad
|
|
|
|
Thnx a lot !! |
|
Back to top |
|
|
|