What are we talking about?
Show us the code. Well, ok.
Is this what usage could look like?
DISCLAIMER
The COBOL might be a bit rusty (1987) and the perl
is definitely a little speculative :-) so if I made mistaeks please correct them, but do not bother to check matching ({[< and the like - I didn't - the code is not meant to be run yet. It is meant to illustrate the questions and comments below the code.
#!/usr/bin/perl -w
# ModuleWithAcceptableNameThatReflectsThePurpose Q1
use COBOLstorage;
$datafile="somepathtothedata.coboldata";
$COBOLrecord = <<'FD1'; # C1
* paymenttrack-file
01 Payment.
03 Rec-id pic X(6) value "PAY001".
03 Date pic X(10) value spaces.
03 EEEE-MM-DD Redefines Date.
05 EEEE pic 9999.
05 FILLER pic X.
05 MM pic 99.
05 FILLER pic X.
05 DD pic 99.
03 Amount pic 9(12)V99 comp-3 value zeroes.
03 Currency-code pic XXX value spaces.
03 Description.
05 Desc-line occurs 4 pic X(50) value spaces.
03 Originator.
05 Ident-type-code pic x value spaces.
* 'P' Natural person
* 'B' Business
* 'N' National/Local Gov Agency
* 'S' Supranational Agency
05 Ident.
07 Accountnumber pic 9(10) comp-3 value zeroes.
07 N-Name.
09 Familyname pic X(36) value spaces.
09 Title pic X(6) value spaces.
09 Initials pic X(6) value spaces.
09 FILLER pic X(10) value spaces.
07 O-Name redefines N-Name.
09 OrganisationName pic X(48).
09 Contact-nick pic X(10).
07 Address.
09 Street pic X(48) value spaces.
09 Nr pic X(8) value spaces.
09 Postal-code pic X(7) value spaces.
09 Country-code pic XX value spaces.
03 Beneficiary.
05 Ident-type-code pic x value spaces.
* 'P' Natural person
* 'B' Business
* 'N' National/Local Gov Agency
* 'S' Supranational Agency
05 Ident.
07 Accountnumber pic 9(10) comp-3 value zeroes.
07 N-Name.
09 Familyname pic X(36) value spaces.
09 Title pic X(6) value spaces.
09 Initials pic X(6) value spaces.
09 FILLER pic X(10) value spaces.
07 O-Name redefines N-Name.
09 OrganisationName pic X(48).
09 Contact-nick pic X(10).
07 Address.
09 Street pic X(48) value spaces.
09 Nr pic X(8) value spaces.
09 Postal-code pic X(7) value spaces.
09 Country-code pic XX value spaces.
FD1
open(IN,$datafile);
associate($blurk,$COBOLrecord); # Q2;
my $total = 0;
while(<IN>) {
$blurk = $_;
#========== this is where the module magic should take effect:
# we can now use the COBOL data-item in perl.
if ( $Description =~ /(?:salary|gage)/i ) {
if ($Beneficiary.ident-type-code ne 'P') { # Q3
print << "WARNING"; # C2
Check this! Salary paid to organisation?:
On $Date $Originator.Accountnumber paid $Beneficiary.A
+ccountnumber
$Currency-code $Amount BENY: $Beneficiary.Organisation
+Name $Beneficiary.Contact-nick
\"$Description\"\n"
WARNING
}
else {
$total{$Currency-code} += $Amount;
}
}
}
print "Total salaries / gages in USD $total{"USD"} \n";
So here is the preliminary list of questions:
- Q1: What should the name be - preferrably something
more fitting than "COBOLstorage" used here.
- C1: In actual practice this would come from a copylibrary or dictonary.
I put it here in the code to open it up for critique / amendments.
- Q2: What should be the ways to associate (both lvalues and rvalues, where appropriate) data with a specific COBOL-FD or WS entry, the COBOL way of structuring? I used "associate" here, but I think that may be to generic.
"tie" comes to mind, but "tie" is richer than what I imagine this
module should do, because "tie" also takes care of really
reading and storing the data if necessary. The module however should (IMO) limit itself to parsing and composing COBOLdata.
- Q3: Is this going to be the perl 6 way of qualifying data?
$Bigstructure.partofbigstructure.iteminpart
If so, let's go for that.
- C2: This syntax is hopefully going to be ok in perl 6.
The example leaves a lot of questions unanswered:
- - What abouts arrays ?
- - occurs depending on, how? (should it be @Description in the example print-statement?)
- - 66, 88 levels
- - initialising, writing COBOL-data
- - machine dependencies
- - locale dependencies
... we can only start at one place at a time. Maybe you could reflect on this, or on your vision of how you would name / use this module.
HTH,
Danny | [reply] [d/l] |
This would be useful, the idea being that "I've got a copylib member, I've got a data file, I just want to process it in Perl". I have done this quite a bit in the past, but always make up my own data storage, parsing code, etc.
Q1: maybe IO::COBOL ???
Q2: Not sure if I agree with your assumptions, here. My own take on such a module would be the ability to do something like
IO::COBOL::ReadData($FILEHANDL, $COBOLRecord);
IO::COBOL::WriteData($OUTFILEHANDL, $COBOLRecord);
Q3: Omygod, I'm not ready for Perl6
Other:
Why not just add subscripts to the (target) data variables for an OCCURS statement?
88 levels are just Static symbols.
I would assume that all data has already been translated to ASCII encoding in order to use this.
Are you working on something? I can work on it if you don't have anything yet (although I've never written a CPAN module before).
... HH
| [reply] [d/l] |