View previous topic :: View next topic
|
Author |
Message |
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi All,
Below post is on forum regarding truncating leading zeros in easytrieve
www.ibmmainframes.com/viewtopic.php?t=60517
With reference to above post and with great help from Bill Woodger below is the Easytrieve - Cobol combination to remove leading zeros in easytrieve
Easytrieve Program - EZTTEST
Code: |
PARM LINK (EZTTEST, R) +
DEBUG (CLIST, DMAP, FLDCHK, +
FLOW, FLOWSIZ (100), STATE, XREF(SHORT)) +
ENVIRONMENT(COBOL)
FILE EDITFILE FB (4)
WS-IN-MAIN 1 4 B.
FILE EDITOUT1 PRINTER EXIT(TSTEZT, +
USING (WS-OUT))
FILE EDITOUT2 FB (09)
EDIT-OUT-REC 1 09 A.
DEFINE WS-IN W 09 N MASK 'ZZZZZZZ99'.
DEFINE WS-OUT W 100 A.
DEFINE WS-REC-LEN W 2 B VALUE 0.
JOB INPUT EDITFILE FINISH SHOW-TOTALS
WS-IN = WS-IN-MAIN
DISPLAY 'WS-IN: ' WS-IN
DISPLAY EDITOUT1 WS-IN X'FF'
DISPLAY 'WS-OUT: ' WS-OUT
EDIT-OUT-REC = WS-OUT
PUT EDITOUT2.
SHOW-TOTALS. PROC
DISPLAY 'PROCESSING COMPLETED'
END-PROC |
This program will call another cobol program TSTEZT from every display statement performed on EDITOUT
Cobol Program - TSTEZT
Code: |
WORKING-STORAGE SECTION.
01 WS-FILLER-1 PIC X(16) VALUE
' WORKING-STORAGE'.
01 W-WHEN-COMPILED PIC X(8)BX(8).
01 WS-SWITCH PIC X VALUE "Y".
88 W-FIRST-TIME-IN-PROGRAM VALUE "Y".
88 W-FIRST-TIME-IN-PROGRAM-FALSE VALUE "N".
77 WS-TSTEZT PIC X(08) VALUE 'TSTEZT'.
LINKAGE SECTION.
01 L-PARM-OF-CALL BINARY PIC 9(8).
88 L-PARM-IS-CLOSE-DOWN VALUE 8.
01 WS-IN.
05 WS-IN-CARRIAGE-CONTROL PIC X.
05 WS-IN-ACTUAL PIC X(100).
01 WS-OUT PIC X(100).
PROCEDURE DIVISION USING WS-IN
L-PARM-OF-CALL
WS-OUT.
0000-MAILINE.
IF W-FIRST-TIME-IN-PROGRAM
PERFORM 10-SAY-WHO-WE-ARE
END-IF
IF NOT L-PARM-IS-CLOSE-DOWN
UNSTRING WS-IN-ACTUAL DELIMITED BY X'FF'
INTO WS-OUT
DISPLAY 'WS-IN IN COBOL :' WS-IN
DISPLAY 'WS-IN-ACTUAL :' WS-IN-ACTUAL
DISPLAY 'WS-OUT IN COBOL : ' WS-OUT
END-IF
GOBACK
.
10-SAY-WHO-WE-ARE.
MOVE WHEN-COMPILED TO W-WHEN-COMPILED
DISPLAY "BBEZEDF THIS PROGRAM COMPILED ON "
W-WHEN-COMPILED
SET W-FIRST-TIME-IN-PROGRAM-FALSE
TO TRUE. |
Output Display's -Easytreive
Code: |
WS-IN: 1234567
WS-OUT: 1234567
WS-IN: 1234
WS-OUT: 1234
WS-IN: 567
WS-OUT: 567
WS-IN: 5679
WS-OUT: 5679 |
Output Display - Cobol
Code: |
BBEZEDF THIS PROGRAM COMPILED ON 03/15/13 01.23.59
WS-IN IN COBOL :1 1234567
WS-IN-ACTUAL : 1234567
WS-OUT IN COBOL : 1234567
WS-IN IN COBOL : 1234
WS-IN-ACTUAL : 1234
WS-OUT IN COBOL : 1234
WS-IN IN COBOL : 567
WS-IN-ACTUAL : 567
WS-OUT IN COBOL : 567
WS-IN IN COBOL : 5679
WS-IN-ACTUAL : 5679
WS-OUT IN COBOL : 5679 |
Thanks Bill for your help and kindly add if I am missing anything
Regards,
Chandan |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No problem Chandan.
Just a little bit about what this is.
If you look at the FILE statement, you'll see EXIT. The Cobol program is then used for the actual processing of that file, Easytrieve just calls the Cobol program and imagines that "writing" occurs. The EXIT details the program to be called, and any extra parameters - this needs an output area, so that is where it is defined.
Easytrieve does its "normal" processing of DISPLAY, which includes respecting the edit MASK, and immediately appending the X'FF, then passes on the record to the Cobol program.
The Cobol program simply UNSTRING's on the X'FF' (which is not otherwise going to appear in the editing of a field) and puts the real edited input value in the 100-byte output field.
(we did try using the RECORD-LENGTH instead of the X'FF', but Easytrieve wouldn't co-operate)
This will work for any Easytrieve MASK. If you need "formatted" data on an output file, then it can be done like this.
This is a very simple FILE EXIT, but can be used as a basis for many things (standard headers/footers in fixed positions, whilst the REPORT has "SPREAD", routing-information, editing for multiple currency symbols, producing CVS, etc).
Thanks for the work Chandan. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
It's my pleasure Bill.. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
Thanks Chandan and Bill. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It is a good idea to "wrap" the Easytrieve code in MACROs, something like this (for "instream" macros, once working they go in the macro library).
Code: |
MSTART DOEDPR
MACRO 2 IN OUT PRINTER EDITOUT1 LIST OFF
POP
LIST &LIST
* This macro causes Easytrieve Plus to use an Edit Mask
DEFINE DOEDIT-IN-VALUE S 100 A
DISPLAY &PRINTER &IN X'FF'
&OUT = DOEDIT-IN-VALUE
PUSH
MEND
MSTART DOEDFI
MACRO 0 OUT DOEDIT-IN-VALUE PRINTER EDITOUT1 EXIT TSTEZT LIST OFF
POP
LIST &LIST
FILE &PRINTER PRINTER EXIT(&EXIT, +
USING (&OUT))
PUSH
MEND
|
Put these two at the start of your source, before the first statement, including PARM if present.
Then replace the FILE statement that we have for the EXIT with:
Code:
%DOEDFI LIST ON
Then replace the DISPLAY statement that we have for the EXIT with:
Code:
%DOEDPR WS-IN EDIT-OUT-REC LIST ON
The "LIST ON" bit will list out the contents of the MACRO in the source, by default (in my definition) it is "OFF", so that the code is not listed, makes the output listing "cleaner" once happy that everything is working.
Note that the FILE name and the EXIT program are paramaterised in preparation for multiple use: this can also be extended, macros embedded and all types of interesting things like that :-)
I have added links or new posts to several topics where this has come up before, hopefully new questioners will find the answers without having to ask again :-) |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Im not sure if all this is necessary. If the output file is a print file, zero suppressing is done automatically by Easytrev. |
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi Peter,
Agree if its a print file..This is done for such requests where we need output in normal sequential file. In such cases this code will help..
Regards,
Chandan |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The intention, Peter, as Chandan says, is to be able to "use the MASK" for an output file other than a PRINTER. A MASK is only respected when using PRINT or DISPLAY.
With this simple example there is no need to use it for REPORT output, but I've used the technique to add "floating Currency Codes" to values for REPORT output. |
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
As far as i know, a print file is a normal sequential file. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
But you can't define any fields on it, and your maximum length is limited by compiler option, which would affect all PRINTER output, and "records" could only be fixed-length. It would require "redefinition" (thus allowing room for the introduction of error) to get binary or packed-decimal onto the "file".
Therefore, unless your required output actually fitted within these constraints, a PRINTER file itself is too limited to be considered a "normal sequential file" in a general-purpose sense.
Code: |
FILE INFILE
INFILE-PD 1 5 P 2 MASK ('ZZZZZZ9.99-')
FILE OUTFILE
OUTFILE-READABLE 1 11 A
JOB INPUT INFILE
DISPLAY EDITOUT1 INFILE-PD X'FF'
OUTFILE-READABLE = WS-OUT
PUT OUTFILE |
|
|
Back to top |
|
|
|