Title: Can I define one or more data items based on the definition of another one?

It is possible to define a single or group data item based on the definition of one defined previously. Use this to make sure that data items with a similar purpose have the same structure.

The SAME AS clause is what makes this possible.

Consider the following example of working-storage data items to store names. The second and third use the SAME AS clause so that all three names are the same size and type.

    77 customer-name        pic x(50).
    77 sales-executive-name same as customer-name.
    77 supervisor-name      same as customer-name.

You can then move up to 50 characters to each of those data items as follows.

     move "Adam Smith"         to customer-name
     move "Alessandra Vivaldi" to sales-executive-name
     move "Juan Ramirez"       to supervisor-name

You can also use the SAME AS clause for group items. Consider the case when you define a date data item with a detailed structure and you want other date items to have the same structure. You can define them as in the following example, with the birth-date using the SAME AS clause:

    01 contract-date.
        05 dt-yy  pic 9(4).
        05 filler pic x value "-".
        05 dt-mm  pic 9(2).
        05 filler pic x value "-".
        05 dt-dd  pic 9(2).

    01 birth-date same as contract-date.

And then you can assign values to the child items of each group item as follows:

    move 2021 to dt-yy of contract-date
    move   05 to dt-mm of contract-date
    move   30 to dt-dd of contract-date

    move 1990 to dt-yy of birth-date
    move   10 to dt-mm of birth-date
    move   17 to dt-dd of birth-date

So, if you display the contract-date and birth-date you would see the following:

    contract date: 2021-05-30
    birth    date: 1990-10-17

Authored by: Veryant Support on Fri, Jun 18th, 2021 at 7:00 PM
This question has been viewed 649 times so far.
Online URL: http://support.veryant.com/support/phpkb/question.php?ID=321

Powered by PHPKB Knowledge Base Software