COBOL读取/存储在表中 [英] COBOL read/store in table

查看:134
本文介绍了COBOL读取/存储在表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此练习的目标是将输入文件读取并存储到表中,然后验证输入中的某些字段并输出任何错误记录。我需要读取和存储每个策略组,以便一次只在表中存储5条记录,而不是整个文件。

The goal of this exercise is to read and store an input file into a table then validate certain fields within the input and output any error records. I need to read and store each policy group so that there are just 5 records stored in the table at a time instead of the entire file.

因此,我需要读取一个包含5条记录的策略组,进行处理,然后读取接下来的5条记录,依此类推,直到文件结尾。 / p>

So I need to read in a policy group which is 5 records, do the processing, then read the next 5 records, etc until the end of the file..

This is the input file.
10A 011111          2005062520060625                                    
20A 011111000861038                                                     
32A 011111                            79372                             
60A 0111112020                                             6          4 
94A 011111     080 1                                                    
10A 02222          2005082520060825                                    
20A 022221000187062                                                     
32A 022221                            05038                             
60A 0222212003                                             6          4 
94A 022221     090 1                                                    
....

通过使我的表发生5次,我能够将前5条记录加载到表中,但是我不知道该如何继续。我的代码如下。 (我写它只是为了查看它是否正常工作,但是它用前4条记录而不是前5条记录打印标题行)
01 TABLES。

I was able to load the first 5 records into a table by having my table OCCUR 5 TIMES but I don't know how I would continue that. My code is below. (I wrote it just to see if it was working correctly, but it prints the header line with the first 4 records, instead of just the first 5) 01 TABLES.

05  T1-RECORD-TABLE.                                
    10  T1-ENTRY                OCCURS 5 TIMES      
                                INDEXED BY T1-INDEX.

        15  RECORD-TYPE-10      PIC X(80).          
        15  RECORD-TYPE-20      PIC X(80).          
        15  RECORD-TYPE-32      PIC X(80).          
        15  RECORD-TYPE-60      PIC X(80).          
        15  RECORD-TYPE-94      PIC X(80).          

 copy trnrec10.
 COPY TRNREC20.
 COPY TRNREC32.
 COPY TRNREC60.
 COPY TRNREC94.
.....

Z200-READ-FILES.                               
    READ DISK-IN INTO T1-ENTRY(T1-INDEX)       
        AT END MOVE 'YES' TO END-OF-FILE-SW.   

    WRITE PRINT-RECORD FROM T1-ENTRY(T1-INDEX).

我不希望逐步进行此操作(尽管那样很好:P)公元前我知道我需要做什么我只是不知道该怎么做。公元前我的教科书和课程笔记对我没有用。我已经坚持了一段时间,但没有任何尝试。

I don't want a step by step for this (though that'd be nice :P) bc I know WHAT I need to do I just don't know HOW to do it bc my textbook and course note are useless to me. I've been stuck on this for a while and nothing I try works.

推荐答案

您有教科书,课程笔记和手册,编辑器,JCL和计算机。

You have textbook, course notes, a manual, an editor, JCL and a computer.

所有这些都将对您有用,但您还必须让自己像应该编程的程序那样思考。

All of those are going to be of use to you, but you've also got to get yourself thinking like your should program.

您的任务是读取文件,将五个记录加载到表中,对它们进行处理,然后将其写出。

Your task is to read a file, load five records into a table, do something with them, then write them out.

您将执行许多任务,其中需要读取文件,执行某些操作并写入文件。

You will have many tasks where you read a file, do something, and write a file.

那么首先如何处理文件处理呢?

So how about getting the file processing down pat first?

使用文件状态定义文件

PERFORM OPEN-INPUT-POLICY-MASTER
PERFORM OPEN-OUTPUT-NEW-POLICY-MASTER

在这些段落中(或部分,具体取决于您的站点标准)打开文件,检查文件状态,如果不是 00,则退出。

In those paragraphs (or SECTIONs, depending on your site standards) OPEN the files, check the file status, abend if not "00".

您将需要一个READ段落。读入那里,检查文件状态,注意 10是有效的并且它指示文件结束(因此您不需要AT END和END-READ)。计算所有已读取的记录(文件状态为 00)。

You will need a READ paragraph. READ in there, check the file status, being aware that "10" is valid and that it indicates end-of-file (so you don't need AT END and END-READ). Count all records read (file status "00").

您将需要一个WRITE段落。检查文件状态。仅 00有效。计算记录的记录。

You will need a WRITE paragraph. Check the file status. Only "00" is valid. Count the records written.

PERFORM PRIMING-READ-OF-POLICY-MASTER

该段所需要做的就是执行READ段。将其放在自己的段落中是一种记录其功能的方式。告诉下一个人。

All that paragraph needs to do is PERFORM the READ paragraph. Putting it in a paragraph of its own is a way of documenting what it does. Telling the next person along.

它是做什么的?读取或尝试读取第一条记录。如果文件为空,则文件状态为 10。如果文件不应该为空,则中止。现在,您已经处理了一个空文件,而又不影响您的处理逻辑。

What does it do? Reads, or attempts to read, the first record. If the file is empty, you will get file status "10". If the file should not be empty, abend. You've now dealt with an empty file without affecting your processing logic.

PERFORM PROCESS-POLICY-MASTER UNTIL END-OF-POLICY-MASTER

PERFORM UNTIL END-OF-POLICY-MASTER
    ....
END-PERFORM

我喜欢第一个,以避免主要逻辑扩散,但是如果您喜欢/适合您的课程,那么从第二个开始就可以了。

I prefer the first, to avoid the main logic "spreading", but it's fine to start with the second if you prefer/it fits in with your course.

该段中或结束执行之前的最后一件事是您执行的读取。

The last thing in the paragraph or before the END-PERFORM is a PERFORM of your READ.

然后您可以执行CLOSE-INPUT-

You can then PERFORM CLOSE-INPUT-POLICY-MASTER, and similar for the output file.

然后检查计数是否相等。如果没有,请弯曲。在此示例中,这是微不足道的,但是随着您的逻辑变得越来越复杂,事情可能会出错。

Then check that the counts are equal. If not, abend. This is trivial in this example, but as your logic gets more complicated, things can go wrong.

总是提供计数以使您的输入与输出保持一致,计数增加和删除。分别计算更新以获取信息。获取您的程序以检查其功能。如果更新多于输入记录,请识别并中止。让您的程序进行尽可能多的验证。

Always provide counts to reconcile your input to output, count additions, deletions. Count updates separately for information. Get your program to check what it can. If you have more updates than input records, identify that and abend. Have your program do as much verification as possible.

您现在将拥有一个简单的程序,该程序可以读取文件,写入文件,进行尽可能多的检查,并且只是缺少处理逻辑。

You will now have a simple program which reads a file, writes a file, checks as much as it can, and is just lacking processing logic.

您可以使用该程序作为读取一个文件并写入另一个文件的所有任务的基础。

You can use that program as a base for all your tasks reading one file and writing another.

所有这些东西都将在您的新程序中运行,而无需执行任何操作。

All that stuff will work in your new program, without you having to do anything.

您现在需要的逻辑是将数据存储在表中。

The logic you need for now is to store data in a table.

好的,正如吉尔伯特(Gilbert)正确显示的那样,在您的实际情况下将表存储在表中是没有意义的。但是,这是必需的。您还需要精通表。

OK, as Gilbert has rightly shown, storing in a table doesn't make sense in your actual case. But, it is the requirement. You need to get good at tables as well.

您的表定义不正确。试试这个:

Your table is not defined correctly. Try this:

01  T1-RECORD-TABLE.                                
    05  T1-ENTRY                OCCURS 5 TIMES      
                                INDEXED BY T1-INDEX.

        10  POLICY-RECORD.
            15  POLICY-RECORD-TYPE PIC XX.
            15  POLICY-RECORD-DATA PIC X(78).

为每个记录类型在POLICY-RECORD-TYPE下方放置一个88。用88来描述业务功能,而不仅仅是说 RECORD-IS-TYPE-10。

Put an 88 underneath POLICY-RECORD-TYPE for each of your record-types. Make the 88 descriptive of the business function, don't just say "RECORD-IS-TYPE-10".

您正在使用索引来引用表中的项目。在将第一个条目放入表之前,必须将索引设置为1。要访问下一个条目,必须将索引设置为UP BY 1。

You are using an index to reference items in the table. Before putting the first entry in the table you have to SET the index to 1. To access the next entry, you have to SET the index UP BY 1.

已将您的商品存储在表格中,您需要再次获取它们。再次将索引设置为1,您可以引用第一个条目。依次将索引设置为UP BY 1以访问其他条目。

Once you have stored your items in the table, you need to get at them again. SET the index to 1 again and you can reference the first entry. SET the index UP BY 1 serially to access the other entries.

在开始处理之前,将索引设置为1。将零移动到表条目计数。进入文件处理循环。

SET index TO 1 before you start the processing. MOVE zero to a count of table entries. Get into your file processing loop.

在那里,对存储的内容进行计数,每当表项计数达到5时,执行一段输出记录并设置您的记录索引为1。如果计数不为5,则将索引设置为1。

There, count what you store, every time that your count of table entries reaches five, PERFORM a paragraph to output your records and SET your index to 1. If the count is not five, SET your index UP BY 1.

在您的段落中输出记录,请使用PERFORM VARYING FROM FROM BY 1 BY 1直到超过5。在PERFORM中,使用当前表条目作为记录源,执行WRITE段落。

In your paragraph to output the records, use PERFORM VARYING your index FROM 1 BY 1 UNTIL GREATER THAN 5. In the PERFORM, PERFORM your WRITE paragraph with the current table entry as the source for the record.

您现在将拥有两个程序,这两个程序读取输入文件并生成相同的输出文件。

You will now have two programs, both of which read an input file and produce an identical output file.

然后您可以执行验证逻辑。

Then you can do your verification logic.

如果您将所有内容分解,分开,简单,命名,您将开始编写除特定业务逻辑之外相同的COBOL程序。所有标准的东西,所有无聊的东西,如果您愿意,所有基本结构都保持不变。您编写的新代码仅是下一个任务的细节。

If you break everything down, keep things separate, keep things simple, name them well, you'll start to write COBOL programs that are the same except for the specific business logic. All the standard stuff, all the boring stuff, if you like, all the basic structure stays the same. The new code you write is just the specifics of the next task.

是的,您将可以读取更多文件,这些文件可以用作参考文件,也可以用作多个输入。您将有多个输出。但是,您可以以完全相同的方式构建所有这些基础。然后,您将获得更多示例,作为将来程序的基础。

Yes, you'll get to read more files, either as reference files, or as multiple inputs. You'll have multiple outputs. But you can build the basics of all those in exactly the same manner. Then you'll have more examples to base your future programs on.

掌握了基本知识之后,就无需再编写代码了。您只需复制并申请。

Once you've got the basic stuff, you never need to code it again. You just copy and apply.

使用好名字,您的程序将告诉他们它们在做什么。

With good names, your programs will tell what they are doing.

您实际编写的代码将是有趣的东西,而不是您每次所做的东西。

The code that you actually write will be the "interesting" stuff, not the stuff you do "every time".

我刚刚为您设计了此代码。这不是唯一可行的设计。我就是这样做的,并且已经做了一段时间了。您还应该设计处理的每个部分。在编写代码之前,您应该知道它在做什么。

I've just "designed" this for you. It is not the only workable design. It is how I do it, and have done for some time. You should also design every part of your processing. You should know what it is doing before you write the code.

以一个简单的循环为例。想象一下如何测试它。如果表中的条目为零,会发生什么?与一个?用一个中间数字?比最大值少一?最大值?比最大值多一?比最大值多10个?然后编写代码,知道您需要知道如何处理这些情况。

As an example, take a simple loop. Imagine how you will test it. With zero entries in the table, what happens? With one? With an intermediate number? One less than the maximum? The maximum? One more than the maximum? 10 more than the maximum? Then write the code knowing that you need to know how to deal with those cases.

在不久的时间内,您将考虑低级设计,同时您编码。在更多的时间里,您也将以这种方式进行高级设计。在足够的时间内,您将只设计以前不需要处理的事情,其余的您已经知道。

In time, not too long, you'll think about the low-level design while you code. In more time, you'll do the high-level design that way as well. In enough time you'll only design things you've not had to deal with before, the rest you'll already know.

您有教科书,课程笔记,手册,编辑器,JCL和计算机。我给你一些想法。看看它们是否对您有用。我想您现在有些沮丧。编写一些基本程序,然后将其应用于您的任务。

You have textbook, course notes, a manual, an editor, JCL and a computer. I've given you some ideas. How about seeing if taken all together they are useful to you. I think you have some frustrations now. Write some basic programs, then apply them to your tasks.

这篇关于COBOL读取/存储在表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆