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

finding the length of a variable record in cobol


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
subramanyamg5

New User


Joined: 13 Jun 2006
Posts: 5

PostPosted: Fri Jun 16, 2006 1:46 pm
Reply with quote

How to find the length of a variable record in cobol file.
Back to top
View user's profile Send private message
subramanyamg5

New User


Joined: 13 Jun 2006
Posts: 5

PostPosted: Fri Jun 16, 2006 2:12 pm
Reply with quote

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
View user's profile Send private message
prasadvrk

Active User


Joined: 31 May 2006
Posts: 200
Location: Netherlands

PostPosted: Fri Jun 16, 2006 2:53 pm
Reply with quote

You must have a layout for the record where you will find the length
Back to top
View user's profile Send private message
subramanyamg5

New User


Joined: 13 Jun 2006
Posts: 5

PostPosted: Fri Jun 16, 2006 4:22 pm
Reply with quote

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
View user's profile Send private message
aroraranjan22

New User


Joined: 16 Oct 2006
Posts: 3

PostPosted: Fri Oct 20, 2006 11:25 am
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Oct 21, 2006 4:41 am
Reply with quote

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
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 -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Finding and researching jobs All Other Mainframe Topics 0
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
Search our Forums:

Back to Top