View previous topic :: View next topic |
Author |
Message |
sajinpattath Beginner
Joined: 27 Aug 2006 Posts: 1 Topics: 1 Location: india
|
Posted: Sun Aug 27, 2006 1:42 am Post subject: Is there any variable of dynamic size in cobol |
|
|
I want to remove the unwanted space of a variable which is declared with size x(20) and put a pipe delimiter at the end while writing to a PS file.
For example.
Input copy book
Name pic X(20)
Address pic x(20)
Output copy book
Name max length pic X(20)
Filler pic X(1) value '|'
Address max length pic X(20)
Filler pic X(1) value '|'
Suppose Name contains - 'sajin pattath s' which occupies only 15 bytes.
and Address contains-'company,India' which occupies only 13 bytes.
When we write to the out put PS file of variable length record
The output file should contain
sajin pattath s|company,India|
instead of
sajin pattath s'5spaces'|company,india'7spaces'|
Is there any variable of dynamic size in cobol to do this so that i can give it in the output copy book?
I dont want to use
'unstring delimited by spaces' as it is prone to alot of bugs in my case.
Could any one specify a method to do this.  _________________ Thanks,
Sajin Pattath. |
|
Back to top |
|
 |
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Sun Aug 27, 2006 1:55 am Post subject: |
|
|
There is no variable. You will have to do it yourself, using UNSTRING or INSPECT TALLYING.
O.
________
Mercury Topaz picture
Last edited by ofer71 on Sat Feb 05, 2011 11:43 am; edited 1 time in total |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Tue Aug 29, 2006 9:50 am Post subject: |
|
|
sajinpattath,
Try this
[code:1:0b0b1f33b2]
WORKING-STORAGE SECTION.
01 NAME PIC X(20).
01 CUST-ADDR PIC X(20).
01 WS-OUT-SUB PIC S9(04) COMP VALUE 1.
01 WS-OUT-STRING PIC X(80) VALUE SPACES.
01 WS-TEMP-VAR.
05 WS-STRING PIC X(20) VALUE SPACES.
05 WS-LENGTH PIC S9(04) COMP.
05 WS-TALLY PIC S9(04) COMP.
PROCEDURE DIVISION.
INITIALIZE WS-TEMP-VAR
MOVE 'SAJIN PATTATH S' TO NAME
MOVE NAME TO WS-STRING
PERFORM 0500-FORMAT-DATA
INITIALIZE WS-TEMP-VAR
MOVE 'COMPANY,INDIA' TO CUST-ADDR
MOVE CUST-ADDR TO WS-STRING
PERFORM 0500-FORMAT-DATA
DISPLAY 'OUT-STRING : ' WS-OUT-STRING
GOBACK
.
0500-FORMAT-DATA.
PERFORM 1000-GET-EXACT-LENGTH
PERFORM 1500-MOVE-TO-OUTPUT
PERFORM 2000-MOVE-DELIMITER
.
1000-GET-EXACT-LENGTH.
INSPECT FUNCTION REVERSE(WS-STRING) TALLYING WS-TALLY
FOR LEADING SPACES
COMPUTE WS-LENGTH = LENGTH OF WS-STRING - WS-TALLY
.
1500-MOVE-TO-OUTPUT.
MOVE WS-STRING(1: WS-LENGTH) TO
WS-OUT-STRING(WS-OUT-SUB : WS-LENGTH)
COMPUTE WS-OUT-SUB = WS-OUT-SUB + WS-LENGTH
.
2000-MOVE-DELIMITER.
MOVE ' _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
|
|