A bit Complicate Script Required...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A bit Complicate Script Required...
# 1  
Old 07-06-2007
Java A bit Complicate Script Required...

I have A very complex requirement

Dont know if it Possible by scripting....

I have do some parsing and replacement in COBOL Programs

It has Statements like

SORT FSORT ASCENDING KEY FS-KEY1
FS-KEY2
INPUT PROCEDURE INPUT-PROC

the Bold Ones are the Key Feilds..

If the Key feilds are in GROUP level then replace the Individulval variables Instead if Group Name...

The Lay out look like...

01 FS-REC1.
05 FS-KEY1.
10 FS-SOCT1 PIC 9(3) COMP-3.
10 FS-GER71 PIC 9(7) COMP-3.
05 FS-KEY2.
10 FS-TIER1 PIC 9(7) COMP-3.
05 AS-CLI1 PIC X(10).
05 BS-CLI1 PIC X(10).


Here FS-KEY1 and FS-KEY2 are Group feilds so
want the SORT FSORT ASCENDING KEY FS-KEY1
FS-KEY2

to become

SORT FSORT ASCENDING KEY FS-SOCT1
FS-GER71
FS-TIER1
INPUT PROCEDURE INPUT-PROC

The Key Feild can End with eithe INPUT or OUPUT or USING....

I have attached a sample Input file with Differenent Cases..

I would be great help if we can do this via a script..
# 2  
Old 07-06-2007
Code:
#! /opt/third-party/bin/perl

my %justHash = ();

open(FILE, "<", "inp") || die "Unable to open file inp <$!>\n";

while (<FILE>) {
  chomp;
  if( /sort/i ) {
    s/.*(\d+)/\1/;
    print "SORT FSORT ASCENDING KEY ";
    my @sub_arr = split(/\|/, $justHash{$_});
    foreach(@sub_arr) {
      print "$_\n";
    }
  }
  print "$_\n";
  next if( /key(\d+)/i || /rec/i );
  if ( /FS-/ ) {
    s/PIC.*$//;
    s/^.* (\d\d)//;
    s/ //g;
    my $val = $_;
    s/.*(\d+)/\1/;
    $justHash{$_} = $justHash{$_} . "|" . $val;
  }
}

close(FILE);

exit 0

try this ! Smilie
# 3  
Old 07-06-2007
Dear Madhan

Its Fine for the Input i gave....(except that is put a number 1 2 3 after every replacement)

but And when i try this on the real COBOL Program(around 4000 lines) is jams the File...

there are some lines like

SELECT FSORT ASSIGN SORTWK1.
SELECT F60UH2 ASSIGN F60UH2E.
SELECT F60U4 ASSIGN F60U4S.


* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *


which i hope are corrupting the files....

Any word with SORT in it is doing some thing....

I have no clue of perl... I am very sorry ... not able to tell u what is the problem....

But to give u more information
the SORT FSORT ASCENDING KEY FS-SOCT1 is always constant...
then the key fields end with either INPUT or OUTPUT or USING...
and the KEY LAYouts.. group variables are always in 05 level ending with .

Last edited by pbsrinivas; 07-06-2007 at 08:03 AM..
# 4  
Old 07-06-2007
Sorry, I couldn't generalize the script with your input.

But made sure its working for the input provided.

Will it be possible to provide a snippet of the input where the script is actually corrupting the files, so that I could revisit the script ? Smilie
# 5  
Old 07-06-2007
Quote:
Originally Posted by matrixmadhan
Sorry, I couldn't generalize the script with your input.

But made sure its working for the input provided.

Will it be possible to provide a snippet of the input where the script is actually corrupting the files, so that I could revisit the script ? Smilie


If u could just add these inlines to the input file...

SELECT FSORT ASSIGN SORTWK1.

* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *


that should give u some clue..

I cant post the whole code online....

I will give u the code which is getting changed....



SELECT FSORT ASSIGN SORTWK1.
* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0.
88 FINFSORT VALUE 1.
77 CTR-FSORT-LUS PIC 9(9) COMP-3 VALUE ZERO.
77 CTR-FSORT-ECR PIC 9(9) VALUE ZERO.
* SORT PROCEDURE *
SORT FSORT ASCENDING KEY FS-KEY
IF SORT-RETURN NOT = ZERO
MOVE 'FSORT' TO FICH
ADD 1 TO CTR-FSORT-ECR.
ADD 1 TO CTR-FSORT-ECR
RETURN FSORT
MOVE 1 TO FIN-FSORT.
PERFORM LECT-FSORT
THRU LECT-FSORT-EXIT.
UNTIL FINF60UH2 AND FINFSORT.
PERFORM LECT-FSORT
THRU LECT-FSORT-EXIT.
LECT-FSORT.
MOVE 1 TO FIN-FSORT
PERFORM CUMUL-FSORT
THRU CUMUL-FSORT-EXIT
LECT-FSORT-EXIT.
* CUMUL-FSORT *
CUMUL-FSORT.
ADD 1 TO CTR-FSORT-LUS.
RETURN FSORT
CUMUL-FSORT-EXIT.



I if can just append these lines to input.... U shoule be able to see...
# 6  
Old 07-06-2007
>cat inputfile
Code:
SELECT FSORT ASSIGN SORTWK1.

* FICHIER SORT *
SD FSORT
77 FIN-FSORT PIC 9(1) COMP-3 VALUE 0. 88 FINFSORT VALUE 1.
* SORT PROCEDURE *

AAAAAA       01  FS-REC1.
BBBBBB           05  FS-KEY1.
                     10  FS-SOCT1               PIC 9(3) COMP-3.
D50180*              10  FS-GERA1               PIC 9(3) COMP-3.
D50180               10  FS-GER71               PIC 9(7) COMP-3.
                     10  FS-TIER1               PIC 9(7) COMP-3.
                 05  AS-CLI1                      PIC X(10).
                 05  BS-CLI1                      PIC X(10).



AAAAAA       01  FS-REC2.
BBBBBB           05  FS-KEY2.
                     10  FS-SOCT2              PIC 9(3) COMP-3.
D50180*              10  FS-GERA2               PIC 9(3) COMP-3.
                     10  FS-TIER2               PIC 9(7) COMP-3.
                 05  AS-CLI2                      PIC X(10).
                 05  BS-CLI2                      PIC X(10).


AAAAAA       01  FS-REC3.
BBBBBB           05  FS-KEY3.
D50180*              10  FS-GERA3               PIC 9(3). 
                     10  FS-TIER3               PIC 9(7). 
                 05  AS-CLI2                      PIC X(10).
                 05  BS-CLI2                      PIC X(10).

SORT FSORT ASCENDING KEY FS-KEY1
                         BS-CLI1
          INPUT PROCEDURE INPUT-PROC


SORT FSORT ASCENDING KEY FS-KEY2
                         BS-CLI2
           OUTPUT PROCEDURE OUTPUT-PROC.


SORT FSORT ASCENDING KEY FS-KEY3
            USING PROCEDURE OUTPUT-PROC.
            OUTPUT PROCEDURE OUTPUT-PROC.

And now execute the script I had provided and that doesn't really seem to affect the output anyway.

If you think that the script is screwing up the output, then just paste that of the input alone in CODE tags which would be quite easier to view and the output you are expecting out of the input !

Smilie
# 7  
Old 07-07-2007
Dear madhan i am attaching the new inp file and out file geneted by running ur perl script

input file --- inp
Output file-- out



I have run ur script in the following manner...

I saved my file in file name "inp" and run ur script as

tmp.prl > out

thats right na...???

I am posting both on now...
Login or Register to Ask a Question

Previous Thread | Next Thread

4 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

Which version of Windows Vista to install with a product key? 32-bit or 64-bit?

Hello everyone. I bought a dell laptop (XPS M1330) online which came without a hard drive. There is a Windows Vista Ultimate OEMAct sticker with product key at the bottom case. I checked dell website (here) for this model and it says this model supports both 32 and 64-bit version of Windows... (4 Replies)
Discussion started by: milhan
4 Replies

2. Shell Programming and Scripting

How to handle 64 bit arithmetic operation at 32 bit compiled perl interpreter?H

Hi, Here is the issue. From the program snippet I have Base: 0x1800000000, Size: 0x3FFE7FFFFFFFF which are of 40 and 56 bits. SO I used use bignum to do the math but summing them up I always failed having correct result. perl interpreter info, perl, v5.8.8 built for... (0 Replies)
Discussion started by: rrd1986
0 Replies

3. Red Hat

boot the 32 bit kernel on a 64 bit PPC Linux machine?

Hi all, I'm looking to cover a corner case for an upcoming test cycle. Is there a way to boot a RedHat Advanced Server 4 (update 3) installed on a Power PC machine to use a 32 bit kernel? This would be similar to what is done here -> https://www.unix.com/aix/26204-aix-platform.html I've done... (0 Replies)
Discussion started by: philrau
0 Replies

4. Programming

copying or concatinating string from 1st bit, leaving 0th bit

Hello, If i have 2 strings str1 and str2, i would like to copy/concatenate str2 to str1, from 1st bit leaving the 0th bit. How do i do it? (2 Replies)
Discussion started by: jazz
2 Replies
Login or Register to Ask a Question