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

COBOL VS SORT Utility for file formatting


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Pradeepv

New User


Joined: 15 Nov 2020
Posts: 1
Location: India

PostPosted: Sun Nov 15, 2020 11:05 pm
Reply with quote

I have a requirement to re-format records if a PS file. I know that building a sort card is the easiest way. But, I do not want to create 500+ Sort cards for each file that I had to reformat. When I do not have to sort a file, but only re-format fields in a record where each record can have 3000+ fields, which one is effective? A COBOL PGM OR A SORT CARD?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1650

PostPosted: Mon Nov 16, 2020 4:01 am
Reply with quote

Generally, the total amount of code to be created for SORT utility should be seriously less than verbose COBOL code.

1. Need to create the “record description” as SYMNAMES member for SORT. It is functionally equivalent to COBOL copybook for the same record. If copybooks already do exist, it’s not a big deal to create a REXX script converting them from COBOL format to SYMNAMES format.
Code:
* SYMNAMES COPYBOOK FOR XXXXXXX_RECORD
$RDWLEN,BI,*,2    record length if RECFM=VB
$RDWFLAG,BI,*,2     flag field if RECFM=VB
FIELDaaa,CH,*,30 from PIC X(30)
FIELDbbb,PD,*,5 from PIC S9(7)V99 COMP-3
FIELDccc,FI,*,2 from PIC S9(4) COMP-1
FIELDddd,ZD,*,9 from PIC S9(7)V99
. . . etc . . .


2. Need to use required conversion in any of BUILD parameters of SORT control statements
Code:
 INREC BUILD=($RDWLEN,$RDWFLAG,
          FIELDaaa,      no conversion
          FIELDbbb,CH,EDIT=(STTTTTTT.TT),SIGNS=(,-),   
          FIELDccc,CH,EDIT=(TTTTT), unpack binary
          FIELDddd,CH,EDIT=(STTTTTTT.TT),SIGNS=(,-),
 . . . . . etc . . . . .
Back to top
View user's profile Send private message
Garry Carroll

Senior Member


Joined: 08 May 2006
Posts: 1176
Location: Dublin, Ireland

PostPosted: Mon Nov 16, 2020 1:54 pm
Reply with quote

Quote:
If copybooks already do exist, it’s not a big deal to create a REXX script converting them from COBOL format to SYMNAMES format.


See: ibmmainframes.com/about49973.html

Garry
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 1650

PostPosted: Tue Nov 17, 2020 1:34 am
Reply with quote

While not using any tool daily a lot of syntax tricks are missing from my mind.

The correct syntax must be
1.
Code:
* SYMNAMES COPYBOOK FOR XXXXXXX_RECORD
$RDWLEN,*,2,BI   record length if RECFM=VB
$RDWFLAG,*,2,BI    flag field if RECFM=VB
FIELDaaa,*,30,CH   from PIC X(30)
FIELDbbb,*,5,PD   from PIC S9(7)V99 COMP-3
FIELDccc,*,2,FI     from PIC S9(4) COMP-1
FIELDddd,*,9,ZD    from PIC S9(7)V99
. . . etc . . .


2.
Code:
 INREC BUILD=($RDWLEN,$RDWFLAG,
          FIELDaaa,      no conversion
          FIELDbbb,PD,EDIT=(STTTTTTT.TT),SIGNS=(,-),     
          FIELDccc,FI,EDIT=(TTTTT), unpack binary
          FIELDddd,ZD,EDIT=(STTTTTTT.TT),SIGNS=(,-),
 . . . . . etc . . . . .


Sorry for mistakes
Back to top
View user's profile Send private message
Rohit Umarjikar

Global Moderator


Joined: 21 Sep 2010
Posts: 2963
Location: NYC,USA

PostPosted: Tue Nov 17, 2020 6:41 pm
Reply with quote

Pradeepv wrote:
I have a requirement to re-format records if a PS file. I know that building a sort card is the easiest way. But, I do not want to create 500+ Sort cards for each file that I had to reformat. When I do not have to sort a file, but only re-format fields in a record where each record can have 3000+ fields, which one is effective? A COBOL PGM OR A SORT CARD?

How do you intend to write one program fits all 500+ formats ? It’s a less efforts if you do by SORT., use option copy if you don’t want to sort, that’s okay.
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1291
Location: Vilnius, Lithuania

PostPosted: Tue Nov 17, 2020 7:03 pm
Reply with quote

Two COBOL copybooks, one MOVE CORRESPONDING. How short do you want it?
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1036
Location: Richmond, Virginia

PostPosted: Wed Nov 18, 2020 3:42 am
Reply with quote

MOVE CORRESPONDING does not handle OCCURS's.
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Mon Nov 29, 2021 1:04 am
Reply with quote

Short answer: I recommend using sort with SYMNAMES.

Long winded answer:
Several years ago a wrote a COBOL program to do this. It was before SYMNAMES were a thing. It wasn't a trivial program to create. But it works well. Since SYMNAMES didn't exist, I also wrote a program to convert copybooks to basically a metadata file that performs the same function as symnames only for COBOL.

The way it works is you must either have a one of these meta data files for each file layout and pass the metadata information into the COBOL program so it knows the layout of the input and output files.

The field names in the metadata file need to be the same on the input and output layouts.

You need to code a conversion paragraph for each combination of input and output field formats. I coded it so that if a new combination was encountered it abended so you could create the new paragraph. After about a month we had all of the combinations we deal with.

It's pretty trivial from there because all you need to do is create the metadata file if you get a new layout.

To the question of "how do you create a cobol program that handles all of those layouts?". Combination of some kind of logic that can detect if it's new and abend so you can add logic for the new layout, and using REC EQUALS 0. By the way you can use REC EQUALS 0 for the output, too, but you have to allow linking after return code = 8. For this reason I have a version that write out an lrecl that's longer than needed.

Since I already have that process, I prefer to use it most of the time. However, if SYMNAMES existed at the time, I would have used them. And I recommend people use SYMNAMES now.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts File Aid Batch IBM Tools 7
No new posts Can EATTR be coded in an IMS COBOL pgm? IMS DB/DC 1
No new posts Cobol transactions in SYSVIEW COBOL Programming 0
No new posts To replace jobname in a file with ano... SYNCSORT 12
No new posts executing XCTL command in COBOL witho... CICS 4
Search our Forums:

Back to Top