One READ, several identical files

I have 12 (monthly) identical files that I need to read based on the current month.

They look like this:

01 FILE01 VIEW OF ACCT01
02 ACCOUNT-NUMBER (N13)
*
*
01 FILE12 VIEW OF ACCT12
02 ACCOUNT-NUMBER (N13)

Dynamic code is not an option since I need the object in production.
First idea was to have a driver that wiould decide on 12 CALLNATs based on the current month from *DATX.
Now I am thinking about using COPYCODE as follows:

  • MAIN CODE
  • Get Month from *DATX
    INCLUDE READCOP #MONTH
    END

COPYCODE:

READ FILE&#MONTH& BY ACCOUNT-NUMBER
*

  • VALIDATIONS

WRITE WORK FILE 01 FILE&#MONTH&
END-READ

Any thoughts?

Thanks

Hi Carlos,
As far I can see you idea won’t work :frowning:

Natural needs to be able to determine the values at compiletime !
So a rewritten version could be possible with dynamic programming if you were allowed to use that.

I can’t quite see how you can avoid having a decide- statement or similar
like below.
regards Finn

DECIDE ON FIRST VALUE OF #MONTH
VALUE 1
INCLUDE TESTC ‘ACCT01’
VALUE 2
INCLUDE TESTC ‘ACCT02’

I don’t have access to NATURAL now, but like your idea.
Will try tomorrow and post the results.

Thanks,

Carlos

The copybook is working, but I can’t get it to work with LABELs as below:

Main module

DECIDE ON FIRST #MONTH

VALUE 1
INCLUDE TESTBOOK ‘ACCTG1’ ‘ACCTG1-UPDATE’

VALUE 2
INCLUDE TESTBOOK ‘ACCTG2’ ‘ACCTG2-UPDATE’

Copybook

READ-&1&.
READ &1& BY ACCT-KEY

  • VALIDATIONS

GET-&1&.
GET &2& #ISN
UPDATE (GET-&1&.)

Am I missing something or it is like this by default? If the later, I believe that it should allow the LABELs as way of a clean logic.

From the documentation

Note:
Because &n& is a valid part of an identifier, this notation may not be used as a copy code parameter substitution in other positions described above (i.e. abc&1& or &1&abc&2&). In other words, a string may only come after copy code parameters, not before or between.

In other words, it is legal to have something like:

&1&-read.
READ &1& BY ACCT-KEY

  • VALIDATIONS

But not, as you have it, read-&1&.

steve

Why not use USR2005N in SYSEXT to change the TF definitions dependent on the month?

For that matter, why not add MONTH as a field on your file and combine all of the files into one.

That works!

Do you have a working sample?
I checked that module in SYSEXT but still could not understand how to setup the parms and make it work…

Thanks,

Carlos

We ate talking about 12 files that have each around 20M records and lots of keys. They were created over 20 years ago and still have some updates done by direct calls. An effort to consolidate all of them in one file would means changes on almost 50% of the application, as I have been told… :cry: