I read multiple forums but could not come to any conclusion.
I have mainframe file (& corresponding copybook layout). This file contains combination packed and binary fields. Before sending (sftp) this file to Windows; I want to convert all packed / binary fields into display format fields.
Any idea what is the best way to do it ?
1. Do we have any converter available which converts input packed copybook layout to output display copybook layout ?
2. Any COBOL Program / Sort which takes input file & copybook and converts to output display format ?
If it’s few fields then DFSORT/SYNCSORT can be used to convert them to any EDITed Zoned Decimal format but if it’s so many fields then write a COBOL program to write in readable format.
If it’s few fields then DFSORT/SYNCSORT can be used to convert them to any EDITed Zoned Decimal format but if it’s so many fields then write a COBOL program to write in readable format.
Yes, this is correct.
Only one problem exists: writing any COBOL program just to convert field formats takes about 50-100 times more efforts (and 100-300 times more lines of code, in total - including compilation and binder steps coding, and debugging) compared to doing the same via SORT control statements.
Using COBOL makes sense only when some other processing is required (or has been already implemented) via COBOL.
Writing a new COBOL code specifically to convert field formats is a good exercise for learning COBOL, but nothing else.
The only visible problem in using SORT control statements is: its requirement to specify actual field positions within the record. In COBOL, so called COPYBOOKs are used (I hope so?) for this purpose - to refer to any field of the record by its symbolic name.
In order to simplify this process in SORT approach, especially when hundreds of different files need to be converted and transferred, I had to write (already several times in my career) quite simple REXX code, to provide conversion of COBOL copybook(s) to their equivalent SORT symbol table(s). This has simplified the conversion process dramatically.
I had to re-create similar REXX scripts every time I left one company, and joined another one, for not to "violate the signed agreements on company copyright formalities for any created code". This rarely took longer than 30 minutes.
Just recently I had to created one of those scripts again. I can demonstrate it as an example; every version of those codes usually had specific limitations depending on possible variety of used records.
In each particular case it can be enhanced, to handle more specific record variations used by a particular company.
Code:
/* REXX */
XCOBSYM: /* conversion of COBOL layout to SORT symbol table */
/* limited version; to be enchanced to handle :
- OCCURS groups, on multiple levels
- REDEFINE groups
*/
Arg FromDD ToDD .
If FromDD = '' Then
FromDD = 'COBOLIN'
If ToDD = '' Then
ToDD = 'SYMOUT'
"EXECIO * DISKR" FromDD "(FINIS"
Lines = Queued()
Parse Source . . REXXNAME .
/*
*/
LongLine = ''
StemNum = 0
StemLine. = ''
Do x = 1 By 1 To Lines
Pull . =7 TestLine =73 .
If Left( TestLine, 1 ) ¬= '*' ,
& TestLine ¬= ' ' Then Do
TestLine = Space( TestLine, 1 )
LongLine = LongLine TestLine
If Right( TestLine, 1 ) = '.' Then Do
LongLine = Left( LongLine, Length(LongLine) - 1 )
StemNum = StemNum + 1
StemLine.StemNum = LongLine
LongLine = ''
End
End
End x
StemLine.0 = StemNum
Queue "*======================================================"
Queue "* Symbolic Names Table for SORT"
Queue "* Created by" REXXNAME "on" Date() "at" Time()
Queue "* from COBOL layout definition"
Queue "*======================================================"
Occurs.0 = 0
RedefLevel = 0
Do x = 1 By 1 To StemLine.0
Parse Var StemLine.x FLevel FName FDescr
If Level = '*' ,
| Descr = '' Then Do
Iterate x
End
Call ProcessQueue FLevel FName FDescr
If RedefLevel > 0 Then Do
If Level + 0 > RedefLevel Then Do
Queue "*" Level C_Name Descr
Return 0
End
Else Do
RedefLevel = 0
/* Say "continue from:" Level C_Name Descr */
End
End
If Pos( 'REDEF', Descr ) > 0 Then Do
RedefLevel = Level + 0
Queue "*" Level C_Name Descr
End
Else Do
If Level = '88' Then Do
Return 0
End
Parse Var Descr . 'OCCURS' Array_Size .
NewLine = ''
Name = Translate( C_Name, '_', '-' )
If Left( Name, 3 ) = 'FD_' Then
Name = Substr( Name, 4 )
Parse Var Descr . 'PICTURE' PicValue LeftDescr
If PicValue = '' Then
Parse Var Descr . 'PIC' PicValue LeftDescr
If PicValue = '' Then Do
Queue "*" Level Name Descr
If Array_Size > '' Then Do /* OCCURS only - for the group */
Array_Level = Occurs.0 + 1
Occurs.Array_Level.Prefix = Level
Occurs.Array_Level.Count = Array_Size
Occurs.0 = Array_Level
If ¬ Datatype( Array_Size, 'W' ) ,
| Array_Size > 1 Then Do
Say "*" Name Descr
Say "* OCCURS clause not supported"
Say "* Program terminated. RC=8"
Exit 8
End
End
Else /* just dummy group */
Return 0
End
LongPic = ''
Do x = 1 By 1 While PicValue > ''
Parse Var PicValue PicChar +1 PicValue
If Left( PicValue, 1 ) = '(' Then Do
Parse Var PicValue '(' CharCount ')' PicValue
If ¬ Datatype( CharCount, 'W' ) Then Do
Say "*" Name Descr
Say "* bad size count:" PicChar"("CharCount")"PicValue
Say "* Program terminated. RC=12"
Exit 12
End
PicChar = Copies( PicChar, CharCount )
End
LongPic = LongPic || PicChar
End x
Do i = 1 By 1 While LongPic > ''
Parse Var LongPic Cx +1 LongPic
Select
When Cx = 'S' Then S_Count = S_Count + 1
When Cx = '9' Then D_Count = D_Count + 1
When Cx = 'V' Then V_Count = V_Count + 1
When Cx = 'X' Then X_Count = X_Count + 1
Otherwise O_Count = O_Count + 1
End /* Select */
End i
Select
When Pos( 'COMP-3', LeftDescr ) > 0 ,
| Pos( 'COMPUTATIONAL-3', LeftDescr ) > 0 Then Do
Size = (D_Count + 2) % 2
Type = "PD"
End
Writing SORT step for 70+ files with different layouts is cumbersome. As for every PD / Binary field we need to first calculate location of every field in input and output. Also manual calculation to convert size of field into target format.
I thought this is standard requirement which every one needs; why IBM has not provided any standard utility.
Rohit Umarjikar.
Personally I feel creating output copybook layout with unpacked fields; then moving input fields to output copybook is also the solution. SORT might get complex after we add additional filtering criteria or want to change fields.
sergeyken,
In mainframe if you open copybook using file manager / fileaid; it gives you starting position of every field.
Also; listing of the program should give starting position of every field. (I have not tried this.)
I strongly feel this is where mainframe is lagging. Even for standard requirement there is no library functions available. Where java is growing with lot of reusable libraries.
Personally I feel creating output copybook layout with unpacked fields; then moving input fields to output copybook is also the solution.
That is what I meant by writing a COBOL program which reusable for many datasets with different copybooks. It’s a clean way To maintain and achieve the results. Many years back we had written standard subprograms which will convert the comp and pd values to readable format, you could write that one and call it across many fields.
Joined: 31 Oct 2006 Posts: 1048 Location: Richmond, Virginia
I have done this as suggested above with an unpacked version of the copybook (easy to create).
MOVE CORRESPONDING is helpful, except as I remember does not handle OCCURS items.
Another reason to use a program as opposed to a utility is that if (when) there are errors (and when are there not?), tracing back to the source, especially by someone other than the converting person, is more straightforward.
I have mainframe file (& corresponding copybook layout). This file contains combination packed and binary fields. Before sending (sftp) this file to Windows; I want to convert all packed / binary fields into display format fields.
A_programmers wrote:
Writing SORT step for 70+ files with different layouts is cumbersome.
Your question was about ONE file, but when provided with a solution you start talking about 70+ files !
This means you have been wasting our time.
Please don't do that !
Joined: 06 Jul 2010 Posts: 765 Location: Whitby, ON, Canada
Our shop uses INSYNC, a product from Macro4 to convert files from one format to another. It’s competitors (File aid from Compuware and File Manager from IBM) likely have similar capabilities.
I also have an automated process that converts COBOL copybooks to DFSORT symbols and then generates the BUILD statement to convert the file. I tend to prefer the INSYNC approach now.
Whenever the SORT symbols table is automatically created from the COBOL copybook, then any conversion of any dataset to printable format (e.g. suitable to FTP to other platforms) becomes just a piece of cake. With new conversion features of nowadays utilities creating a new COBOL program for each dataset conversion is possible, but seems to be a sort of masochism.
In my experience a typical JCL to convert a particular file looks like this