Define CS

PURPOSE:  Code Segments provide users with a method of defining segments of DBL objects that can be shared by two or more objects.  Code Segments can define codes to be shared in SD’s, CM’s, PM’s, GS’s, DI’s, and ID’s.  In this way, users can share statements to help manage their development projects.  Code Segments are added to a DBL object by using the INCLUDE Statement.

Statements can be designed once, and INCLUDEd wherever needed.  There is no syntax checking when a Code Segment is DEFINEd, so a Code Segment does not have to be a “complete” frame of executable code but rather can be an annotated fragment of code.  The INCLUDEd Code Segments statements can replace the INCLUDE statement by using the COMPOSE command to aid debugging the application.

See the COMPOSE command documentation for further discussion of this feature.

A Code Segment is DEFINEd in the same way as any other ACCENT R object.  Within one, Code Segment there can be several separate segments that can be included individually.

SYNTAX

DEFINE CS name [IN DBL dbl_name]

name

is the user-assigned name of the CS being defined.

[IN DBL dbl_name]

is used to define the CS in the specified DBL.

EXAMPLE

*DEFINE CS PAY_CALC
--10  SEGMENT PAY_FIELDS
--20  AMOUNT, N, 8, 2
--30  HOURS, N, 4, 2
--40  CODE, C, 2
--SAVE
INCLUDE PAY_FIELD FROM CS PAY_CALC

Now you can use the INCLUDE statement to add statement 20 thru 40 to, say, a Schema Definition.

The INCLUDE statement is used to add lines from a Code Segment.  Also, arguments may be placed in Code Segment, and the values for those arguments specified when the segment is included.

Code Segment Structure

A Code Segment has the following general form:

SEGMENT segment_name.1

(ACCENT R statements)

SEGMENT segment_name.2

(ACCENT R statements)

Note that you can place as many different SEGMENTs as needed within one Code Segment and that each SEGMENT can be called separately.  Typically, all segments that are logically related will be placed in the same Code Segment.  The INCLUDE statement may be placed within a segment of code.

Arguments

A Code Segment can have 36 replacement arguments which are specified in the INCLUDE statement.  This lets you generalize the Code Segment so it can be used in many different situations.  Replacement arguments within the Code Segment are defined with the following statement:

$ARG_n (and) $ARG_A through $ARG_Z

n

is a digit (0 through 9) that corresponds to the sequence of the replacement arguments given in the INCLUDE statement.  A through Z may be upper or lower case ($ARG_A is equivalent to $ARG_a).

INCLUDE STATEMENT

Code Segment names are specified in the INCLUDE statement.  Within one Code Segment, there can be several different segments, which can be individually, INCLUDEd.  You place an INCLUDE statement in an object where you want the lines of that segment.  When you SAVE the object, ACCENT R will compile the lines of the segments in the compiled code.

The syntax of the INCLUDE statement is:

INCLUDE segment_name FROM CS cs_name [IN DBL dbl_name] [WITH \\argument\\]

argument

is a list of string constants which are used to replace the arguments in the INCLUDEd segment.  You can specify up to a maximum of 36 arguments.  You must specify the arguments in numerical order ($ARG_0, $ARG_1, and so on).

CODE SEGMENTS AND PM DEBUG

The INCLUDE statement is treated as one statement when you are stepping through a Process Module using PM DEBUG.  Since the statements of a Code Segment are represented by only one line number, you can only break at the beginning of a Code Segment.  If you attempt to step through the code segment, PM DEBUG executes the statements of the segment and breaks at the next Process Module statement after the INCLUDE statement.  The Code Segments contained within a Process Modules may be actually inserted with the COMPOSE command.

EXAMPLE

The Code Segment shown here, used to calculate compound interest, has two segments.  One segment is for the declared fields and the other segment is for the procedure code.  The Code Segment has arguments for the annual interest rate, the principal, and the number of days.

*DEF CS INTEREST_CALC
--I
00001  SEGMENT COMPOUND_INTEREST_DECLARE
00002 
00003  DAILY_INTEREST_L, N, 9, 5
00004  COMPOUND_RATE_L, N, 9, 5
00005 
00006  SEGMENT COMPOUND_INTEREST
00007
00008  ! $ARG_0 is annual interest rate
00009  ! $ARG_1 is principal
00010  ! $ARG_2 is the number of days
00011  ! $ARG_3 is the total interest
00012 
00013  $ARG_0 / 360. TO DAILY_INTEREST_L
00014
00015  ( 1 + DAILY_INTEREST_L ) ** $ARG_2 TO COMPOUND_RATE_L
00016
00017  $ARG_1 * ( COMPOUND_RATE_L - 1 ) TO $ARG_3
00018  END
--SAVE

The Code Segment shown above is INCLUDEd in the Process Module below.  There is an INCLUDE statement for the segment that has the locally required declared field, and an INCLUDE statement for the segment with the procedure code in the DETAIL SECTION.  The values for the arguments are specified with the name of fields that are entered by the user of the Process Module.

*DEF PM DAILY_INTEREST
--I
00001  DECLARE SECTION
00002
00003    ANNUAL_INTEREST, N, 7, 2
00004    INTEREST, N, 9, 2
00005    NO_OF_DAYS, I, MAX
00006    PRINCIPAL, N, 9, 2
00007
00008    INCLUDE COMPOUND_INTEREST_DECLARE FROM CS INTEREST_CALC
00009
00010  DETAIL SECTION
00011
00012  TYPE@CR, “This program calculates interest compounded &
            daily ”,NOCR
00013    TYPE @CR, @CR, “Enter the number of days: “, NOCR
00014    ACCEPT NO OF DAYS
00015    TYPE @CR, “Enter the amount: “, NOCR
00016    ACCEPT PRINCIPAL
00017    TYPE@CR, “Enter the annual interest (such as 13.25)",NOCR
00018    ACCEPT ANNUAL INTEREST
00019    ANNUAL_INTEREST / 100 TO ANNUAL_INTEREST
00020
00021  INCLUDE COMPOUND INTEREST FROM CS INTEREST_CALC WITH&
           ‘ANNUAL INTEREST’, ‘PRINCIPAL’, ‘NO_OF_DAYS’, ‘INTEREST’
00022  TYPE@CR, "Total compounded interest is:", INTEREST
00023  "$$$,$$$,$$$.$$"
00024  END
--SAVE

Next, the Process Module is executed.

*USE PM DAILY_INTEREST
This program calculates interest compounded daily.
Enter the number of days:  360
Enter the amount:  1000
Enter the annual interest (such as 13.25):  8
Total compounded interest is:  $83.2