Smart/400开发上手5: Cobol开发标准

 

ENVIRONMENT DIVISION.

CONFIGURATION SECTION.SOURCE-COMPUTER. IBM-AS400.
OBJECT-COMPUTER. IBM-AS400.

 这个没什么说的。

Data Division : Working Storage


· Use the prefix WSAA- for fields for any user defined working variables. You should group
together data which forms a logical group, e.g. subscripts.

使用WSAA-作为用户定义字段前缀;


· Use asterisks (*) to separate logical groups of data and to make the working storage easier
to browse.

使用星号*分隔数据逻辑组,使代码易读;


· Two fields must be set up at the beginning of working storage containing the program name
and its version number. Whenever the program is totally revised, the version number is
incremented by 1.
01 WSAA-PROG PIC X(05) VALUE(annnn).
01 WSAA-VERSION PIC X(02) VALUE(nn).

在working storage开头必须定义两个字段:程序名称和版本号,每次修改版本号增加1;


· All files which are used by the program, including subsystem specific logical files, must be
defined under an 01 level of:
01 FORMATS.
   03 aaaaREC PIC X(10) VALUE ('aaaaREC').
 03 bbbbbbbREC PIC X(10) VALUE ('bbbbbbbREC').

所有用到的逻辑文件(LF文件、子系统、表),都定义在01级;


· All tables used by the program must be defined under an 01 level of:
01 TABLES.
   03 Tnnnn PIC X(05) VALUE ('Tnnnn').
所有的表也定义在01级,表也要在01 FORMATS.定义,格式是:TnnnnREC

例子:

       01  FORMATS.
           03  BMSGREC                 PIC X(10) VALUE 'BMSGREC'.
           03  BPRDREC                 PIC X(10) VALUE 'BPRDREC'.
           03  BSPRREC                 PIC X(10) VALUE 'BSPRREC'.
           03  BSSCREC                 PIC X(10) VALUE 'BSSCREC'.
           03  BUPAREC                 PIC X(10) VALUE 'BUPAREC'.
           03  DESCREC                 PIC X(10) VALUE 'DESCREC'.
           03  AE52DATREC              PIC X(10) VALUE 'AE52DATREC'.
           03  GR04DATREC              PIC X(10) VALUE 'GR04DATREC'.
           03  AA01REC                 PIC X(10) VALUE 'AA01REC'.
           03  ITEMREC                 PIC X(10) VALUE 'ITEMREC'.
           03  TT832REC                PIC X(10) VALUE 'TT832REC'.


· All errors used by the program must be defined under an 01 level of:
01 ERRORS.
  03 annn PIC X(04) VALUE ('annn').

错误必须定义在01级。


· All PICs must start in column 40.

PIC必须起始在40列;


· Always use indentation and line up the levels. Ideally, 4 characters of indentation should be
used:
01 WSAA-GROUP-NAME
    03 WSAA-DATA-NAME-1
    03 WSAA-SUB-GROUP-NAME
        05 WSAA-DATA-NAME-2

一般使用4个字符的缩进;

 

Procedure Division


· Each section must begin on a new page.

所有的节必须开始在新页;


· All sections must be prefixed by a number. These should be incremented sequentially to
simplify locating them within the program.

所有的节开始于一个递增的数字前缀;


· Paragraphs within a section should all increment from the section header number in steps of
at least 10.

数字前缀至少递增10,比如1000-INITIALISE,后面的第一个节必须是1010-,第二个是1020-,也可以跳增,比如第二个也可以1080-;


· Section headers should be underlined by a row of asterisks (*). Above each section there
must be a brief description of the functions, enclosed in asterisks.
· Asterisks (to indicate comment lines) must be used to separate logical blocks of statements
and to improve readability.

使用星号*分隔块;


· Use 4 characters of indentation for IF, PERFORM statements etc.

IF、PERFORM也是4个字符缩进;


· Always complete IF, PERFORM statements with END-IF, END-PERFORM etc.
· All statements must have their right hand portion aligned to column 48.

所有的声明,必须在右侧对齐于48列,包括了TO,=, USING, OF......


· The exit paragraph for each section will be called nnnn-EXIT, where n has the same first
digit as the section header.

退出段以nnnn-EXIT定义,其中nnnn是起始数字;


· All CALLs to subroutines and subprograms must be explicit, not dynamic, i.e. a working
storage variable should NOT be used to hold the name of the subroutine / program to be
called. The only exception to this is for table driven subroutine calls.

不能使用子程序的变量名称定义;


· STOP RUN must not be used.

不能使用STOP RUN;


· On-line mainline programs should never explicitly issue an EXIT PROGRAM, but should
allow MAINF/MAING to do this.
· For on-line screen programs, the procedure division will be using two linkage areas, both in
copybooks. The first area is WSSPCOMN and the second depends on the area you are
working in, as follows:

  • SMART - WSSPSMART
  • LIFE - WSSPLIFE
  • POLISY - WSSPFANG
  • FSU - WSSPFSU
  • Window Program - WSSPWINDOW

· The GO TO command should only be used with a very good reason. Its use should be
restricted to jumping past a block of code that is not required, and even then it is preferable
to PERFORM a section instead.

谨慎使用GO TO;

· When validating an item against a table, read the ITEM or the ITDM file first and then the
DESC file if you want the description. The DESC file is read using a specific language
code, and if the description is not present in the language of operation, it will appear that
the item does not exist.

当验证一个表对应的一个项,先读ITDM或ITDM文件,如果需要描述说明则读DESC描述文件。

读DESC文件使用特定的语言代码,如果描述不存在于操作语言中,它会提示该项目不存在;


· Use the literal from working storage instead of a character string for such things as MRNF,
READR, T1690 in the procedure division, i.e.

使用原词而不是引用字符定义MRNF, READR, T1690之类的东西;

  • MOVE T1690 TO... 正确
  • MOVE ‘T1690’ TO...错误
  • MOVE READR  TO AA01-FUNCTION... 正确
  • MOVE ‘READR’  TO AA01-FUNCTION... 错误


· When setting up a key comprised of multiple fields, set the fields up in the order that they
appear in the key, since this is easier to read and to check.

· After all I/O calls, check for the abend conditions first.

在I/O调用之后,首先要检查退出条件(非常重要);


· If there is an abend condition, move the PARAMS to SYSR-PARAMS as well as the
STATUZ to SYSR-STATUZ.

在退出条件内部,以下两项需要赋值,SYSR-STATUZ、SYSR-PARAMS :

           IF AE52DAT-STATUZ        NOT = O-K AND ENDP

  •               MOVE AE52DAT-STATUZ      TO SYSR-STATUZ
  •               MOVE AE52DAT-PARAMS      TO SYSR-PARAMS
  •               PERFORM 600-FATAL-ERROR

           END-IF.


· All subroutines should be called with a FUNCTION. The subroutine should check that the
function passed is held in its working storage, and, if it is not, should return a status of
FUNC to the calling program.
· All subroutines should pass back a STATUZ to the calling program. This should always be
'****' if the subroutine did not encounter an error condition. The calling program must
always check for a STATUZ of O-K on return from the call. A returned STATUZ other
than O-K is passed to SYSR-STATUZ and the abort processing is performed, or the
returned STATUZ is placed in the XXXX-ERR field as an error code.

 

Batch Program Sections Standards


All batch programs must include a copybook called MAINB as the first statement of the
procedure division. This copybook controls the overall logic flow of the program and will
perform the following, if required:
· Open, update and close a batch audit group during processing
· Remove all softlocks except those with an error status or held status
· Maintain a count of all records read, records not processed and records in error
· Restarting logic.
MAINB performs the following sections in the appropriate place:
0900-RESTART
Please refer to the Restart Logic section below.
1000-INITIALISE

  • Read any tables etc. applicable to the whole process,
  • Open files, set up report headings,
  • OPEN SQL cursors, etc.
  • Test for valid restart method 1 (re-run), 2 (continue) or 3 (skip completed cycles).

2000-PRIMARY-READ

  • Read primary file record
  • Call I/O module
  • SQL FETCH
  • COBOL READ etc.)
  • At end, set WSSP-EDTERROR to ENDP.

2500-EDIT

  • If applicable, perform any checking/validation to ensure the record read really requires
  • if not required, set WSSP-EDTERROR to spaces, (验证不需要的记录)
  • if error, move an error code to WSSP-EDTERROR,(错误发生)
  • else move OK to WSSP-EDTERROR.(验证正确的数据)
  • IF WSSP-EDTERROR = O-K Soft lock the entity, if applicable. (如果需要修改记录,则Soft lock)
  • If entity already locked, move spaces to WSSP-EDTERROR.(如果已上锁)

3000-UPDATE
Perform all the processing related to the primary record read, writing of details to a report etc.

执行所有与主记录相关的处理


3500-COMMIT
Please refer to the Restart Logic section below.
3600-ROLLBACK

 

Batch Program Development Checklist

Listed below is a summary of the steps required when building and maintaining batchprograms. Before starting, ensure that you have the following:
· The design of any reports required.
· The new subsystem specification or updated current manual.
To develop a new program or modify an existing one:
1. Build any new data sets required and modify any existing ones if required (CB ... *PF).
2. Generate any new or modified access methods required and their I/O modules (CB ... *LF).
3. If required, generate a new, or modify the existing, parameter prompt program (CB ...
*PARM).
4. Build or modify any printer files required (ED and CB ... *PRTF).
5. Create or modify the Batch Cobol program (ED Bnnnn). The standard batch skeleton
*CBL in PAXUS/XGENSKEL is for a report program.
6. For a new program, add the coding required in the standard section (ED ...).
7. Compile the program (CB ... *CBL).
8. If a CL program is required, for new programs, copy the standard CL skeleton program in
PAXUS/XGENSKEL (ED Cnnnn *CLP).
9. Compile the CL program (CB ... *CLP).
10.Ensure that the batch schedule details, batch extract details (T1697), control total details
(T1671) and reconciliation rules (T1672) are set up as required.
11.Test the programs.
While testing the program, you should ensure that:
1. All standards have been adhered to, especially that all error numbers, tables, record formats,
etc. are included in the appropriate places in working storage. (This information is required
by the Data Dictionary).
2. All control totals are accumulated correctly.
3. The program will run successfully even if the primary input file is empty or no processing is
required.
4. All database maintenance is performed correctly, including updates to the schedule
submissions file.
5. The program successfully traps any database or system errors which could occur.
6. The program will restart correctly if it is cancelled prior to successful completion.
7. On completion of a new mainline program, the program is registered to the correct
subsystem in the Data Dictionary.

 

Restart Logic

posted @ 2016-09-13 11:26  昕友软件开发  阅读(2440)  评论(0编辑  收藏  举报
欢迎访问我的开源项目:xyIM企业即时通讯