View previous topic :: View next topic
|
Author |
Message |
subramanyamg5
New User
Joined: 13 Jun 2006 Posts: 5
|
|
|
|
How to find the length of a variable record in cobol file. |
|
Back to top |
|
|
subramanyamg5
New User
Joined: 13 Jun 2006 Posts: 5
|
|
|
|
If the question is not clear then
how can we find the actual length of a record in a variable length file |
|
Back to top |
|
|
prasadvrk
Active User
Joined: 31 May 2006 Posts: 200 Location: Netherlands
|
|
|
|
You must have a layout for the record where you will find the length |
|
Back to top |
|
|
subramanyamg5
New User
Joined: 13 Jun 2006 Posts: 5
|
|
|
|
prasadvrk wrote: |
You must have a layout for the record where you will find the length |
Prasad i think you did not get my question.
I am asking for the actual length of a record in the case of a variable record length file.
The layout will be there but how can you get the actual length of a record.
Do not tell me to count the number of characters in the length by looking into each record. That is not the correct process
In the layout also how can you get the actual length |
|
Back to top |
|
|
aroraranjan22
New User
Joined: 16 Oct 2006 Posts: 3
|
|
|
|
Hi Subramanyam
Move your record to a variable say WS-REC1 having length as the maximum length of the variable record file say 250.
01 WS-REC1 PIC X(250).
Now define an array with occurs as the max length of the file, in this case, it will be 250.
01 WS-ARRAY.
05 WS-REC2 PIC X(1) OCCURS 250 times.
Define another variable to be used as subscript for WS-REC2.
01 ws-counter PIC 9(3) VALUE ZEROES.
Now, the logic of the code will be something like this :
Move 250 to WS-COUNTER.
Move WS-REC1 to WS-ARRAY.
Perform para 2000-check-spaces THRU 2000-EXIT.
Display 'length of the record is : ' WS-COUNTER.
STOP rUN.
2000-check-spaces.
IF WS-REC2(WS-COUNTER) NOT = SPACES
GO TO 2000-EXIT
ELSE
WS-COUNTER = WS-COUNTER - 1
GO TO 2000-CHECK-SPACES.
2000-EXIT.
EXIT.
By this logic, you will get the actual length of the record in the variable WS-COUNTER itself.
Please let me know if I'm not able to explain it clearly. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Sub,
In your FD code the following along w/whatever other clauses you want:
RECORD VARYING FROM 1 TO whatever DEPENDING ON WS-LEN-FLD
Define the field in WS as PIC 9(004).
After each read WS-LEN-FLD will contain the length of the rec just read. If you want to write a rec mo0ve the desired len to WS-LEN-FLD before the WRITE. |
|
Back to top |
|
|
|