Efficient way to write deliimiter into a file?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Efficient way to write deliimiter into a file?

Postby fornanthakumar » Thu Sep 08, 2011 2:16 pm

Hi,

Greetings.

OBJECTIVE : I have to retrieve information from diffrent files and DB2 tables then write those values into single output file with delimiters (like $, #). I have a copy book for a output file. Assume 50 fields will be there in output file and 49 delimiters are required. For the delimiter fileds , I have defined variables like FIL1,FIL2..FIL49 in copybook and in the program i have move '$' to individual field. Which requires me to write 49 move statements.. I would like do it in a simple and efficient way.

Solution & Problem :
1. I planned to implement filler clause as filler clause values remains same even if you initialize it. The problem is when i write those file records, all the values is gone immediately.

Please suggest some better way of doing or implement this..
Regards,
Nanthu.Y.
fornanthakumar
 
Posts: 69
Joined: Fri Oct 22, 2010 1:58 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Efficient way to write deliimiter into a file?

Postby BillyBoyo » Thu Sep 08, 2011 3:06 pm

If you need to write lines of code, then that should not worry you, because at the end of the day that is a major part of your job.

You don't need 49 MOVE statements. You can do it with one MOVE with 49 receiving fields.

For either of the above, the editor makes your task hardly noticeable.

I suggest you check on your understanding of what happens with initialise if, as you say, your delimeters are disappearing. It isn't magic, it is something that you have done, even if you are not aware of it. For the moment, forget what you think you know and check it out thoroughly in the manual.

If you have initial values in your copybook (for everthing) you can do this sort of thing:

move the-01-of-the-copybook to another-01-of-the same-size

you do that up where you are setting-up the program.

Then, to initiliase whenever you need to:

move another-01-of-the same-size to the-01-of-the-copybook

You can ensure that the 01-levels are the same length using LENGTH OF (although it does not matter for correct processing, just for human clarity, if the second is longer, it does (can) matter if the second is shorter).
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Efficient way to write deliimiter into a file?

Postby fornanthakumar » Thu Sep 08, 2011 3:31 pm

Hi Billy,

Thats exactly fine. I just proceed with the the-01-of-the-copybook and don't want to go for another with the same size as i do not do any intermediate process. Just move from other source.
Regards,
Nanthu.Y.
fornanthakumar
 
Posts: 69
Joined: Fri Oct 22, 2010 1:58 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Efficient way to write deliimiter into a file?

Postby BillyBoyo » Thu Sep 08, 2011 3:42 pm

OK.... it's just not completely clear to me that you are happy now. Do you have a solution that works and you are happy with?

I've given you two options with one MOVE statement only. To do it with no MOVEs, you have to use VALUEs and not trash the values, through initialise or any other means.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Efficient way to write deliimiter into a file?

Postby Ed Goodman » Thu Sep 08, 2011 10:23 pm

If I get what you're doing, you have 50 move statements already, one for each field. If that's ALWAYS true, then you can do this:
MOVE ALL '$' TO GTL030FB-REC


Which will fill the entire record with the '$' character. Then your individual moves will remove them as you fill the fields with data, leaving the dollar signs in place.

You could also use a single STRING command, if your source fields are the same sizes/pictures of your output fields. You would mix the fields with '$' constants.
Ed Goodman
 
Posts: 341
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: Efficient way to write deliimiter into a file?

Postby fornanthakumar » Fri Sep 09, 2011 5:44 pm

Okay, Then will i will post with an example clearly,

FD Division..
File description
01 FILE REC.
05 FILED1 PIC X(10).
05 DELI-1 PIC X.
05 FILED2 PIC X(10).
05 DELI-2 PIC X.
.....
.....
05 FILED49 PIC X(10).
05 DELI-49 PIC X.
05 FILED50 PIC X(10).
05 DELI-50 PIC X.

I want move '$' to all the delimeters. So if i use filler clause and initialize it.. then $ will remain there. But once i write these records into file then these values will go off and blank remains.

I can do create working storage group for this file rec and do the same with out all 50 MOVE statements or 1 move to all 50 delimeter fields individually required.

I just want to know the effcient way,

Is there any way to do the same thing without working storage group and also i do not want to move '$' to the individual 50 fields in 50 lines.
Regards,
Nanthu.Y.
fornanthakumar
 
Posts: 69
Joined: Fri Oct 22, 2010 1:58 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Efficient way to write deliimiter into a file?

Postby BillyBoyo » Fri Sep 09, 2011 6:12 pm

If your layout is in the file section, the values on the fillers are not going to be much use (don't you get any diagnostic messages from the compiler?).

I'm not sure what you mean by "efficient". Ed's "MOVE ALL "$"..." would leave the delimiters behind after filling in all the other fields in the record. You wouldn't have to do any other typing. You could put the copybook in working-storage and use WRITE FROM, but you'd have to test the file-status, so that would be more coding.

I don't think you're going to get less coding than with Ed's suggestion, it is after all, only one line.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Efficient way to write deliimiter into a file?

Postby Ed Goodman » Fri Sep 09, 2011 7:32 pm

I don't think you can use a value clause on a field that's in an FD anyway. I know it gets treated as comments by my compiler.

Are you looking for a specific answer to match something you already think? Like you have a running debate with a co-worker and are trying to prove something?

Do you always move each of the 50 data fields? That's important.

Is it beyond your desire to code the write statement as "WRITE FILE-REC FROM WS-FILE-REC" where the WS-FILE-REC is in working storage? If not then you can use the value clause.
Ed Goodman
 
Posts: 341
Joined: Thu Feb 24, 2011 12:05 am
Has thanked: 3 times
Been thanked: 17 times

Re: Efficient way to write deliimiter into a file?

Postby dick scherrer » Fri Sep 09, 2011 9:42 pm

Hello,

Do you always move each of the 50 data fields? That's important.
If each of the fields is NOT being moved, the data written to the output file is gong to be unpredictable. . .

I too would favor writing from WS and have no need to deal with the "filler" fields. . .
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post