Using indexing and displacement in CA Gener/OL

Document ID : KB000009576
Last Modified Date : 14/02/2018
Show Technical Document Details
Introduction:

How is indexing and displacement handled by CA Gener/OL?

Instructions:

Indexing (a way of accessing a one-dimensional array) and Displacement (a method of accessing where the data can be in any position of the record) are implemented in CA Gener/OL through reserved words RWI1 through RWI8. These reserved words are associated with the field through the use of the Index and the Displaced phase. Please review the following examples.

    INDEX Working Storage Example:
      000001 WORK INDEX PREFIX=IN RESIDENCY=Y DESC'Sample             Index'
        000002 area 1 20 c
          000003 rec 1 2 c index rwi2
            000004 fld1 1 1 c index rwi2
              000005 fld2 2 1 c index rwi2
                000006 wrk 21 16 c . * work area take 1/2 x records 3
                  000007 * rounded to next power of 2 = 8
                    000008 * 8 records x 2 bytes = 16 bytes
                      000009 * for work area
                        000010 num 37 4 b . * the number of records in the array
                          000011 dir 41 1 c . * sorting direction ascending or descending
                            DISPLACE Working Storage Example:


                                   000001 WORK DISPLACE PREFIX=DI RESIDENCY=Y                                 DESC'Sample Displaced'

                              000002 area 1 20 c
                                000003 rec 1 2 c
                                  000004 fld1 1 1 c displaced rwi2
                                    000005 fld2 fld1+1 1 c displaced rwi2
                                      000006 wrk 21 16 c . * work area take 1/2 x records 3
                                        000007 * rounded to next power of 2 = 8
                                          000008 * 8 records x 2 bytes = 16 bytes
                                            000009 * for work area
                                              000010 num 37 4 b . * the number of records in the array
                                                000011 dir 41 1 c . * sorting direction ascending or descending



                                                  INDEX Program Example:

                                                   

                                                    000001 PROGRAM INDEX DESC='Sample Index'
                                                      000002 handleclear=stdclear,rte=stdfatal
                                                        000003 * **********************************
                                                          000004 * * *
                                                            000005 * * program : index *
                                                              000006 * * standard program layout *
                                                                000007 * * date : mm/dd/yy *
                                                                  000008 * * programmer : bruce fox *
                                                                    000009 * * analyst : bruce fox *
                                                                      000010 * * *
                                                                        000011 * *................................*
                                                                          000012 * * *
                                                                            000013 * * this program will show how *
                                                                              000014 * * to access a one-dimensional *
                                                                                000015 * * array *
                                                                                  000016 * * *
                                                                                    000017 * **********************************
                                                                                      000018 * works/records/segments go next *
                                                                                        000019 * **********************************
                                                                                          000020 work index
                                                                                            000021 * **********************************
                                                                                              000022 * * *
                                                                                                000023 * * initial *
                                                                                                  000024 * *................................*
                                                                                                    000025 * * this is the initializing *
                                                                                                      000026 * * logic routine *
                                                                                                        000027 * **********************************
                                                                                                          000028 initial.
                                                                                                            000029 move '11223344556677889900' to inarea
                                                                                                              000030 comp rwi2 = 0
                                                                                                                000031 * **********************************
                                                                                                                  000032 * * *
                                                                                                                    000033 * * mainloop *
                                                                                                                      000034 * *................................*
                                                                                                                        000035 * * this is were the main logic *
                                                                                                                          000036 * * of program resides *
                                                                                                                            000037 * **********************************
                                                                                                                              000038 main.
                                                                                                                                000039 varying rwi1 = 1 to 10
                                                                                                                                  000040 print 'INDEX FLD1 ',infld1,' INDEX FLD2 ',infld2
                                                                                                                                    000041 comp rwi2 = rwi2 + 2. * INDEX FACTOR
                                                                                                                                      000042 endvary
                                                                                                                                        000043 endjob
                                                                                                                                          000044 * **********************************
                                                                                                                                            000045 * * *
                                                                                                                                              000046 * * handle labels routines *
                                                                                                                                                000047 * *................................*
                                                                                                                                                  000048 * * this is were the handle logic *
                                                                                                                                                    000049 * * of program resides *
                                                                                                                                                      000050 * **********************************
                                                                                                                                                        000051 stdclear.
                                                                                                                                                          000052 endjob
                                                                                                                                                            000053 stdfatal.
                                                                                                                                                              000054 print rwmsg rwabend
                                                                                                                                                                000055 endjob
                                                                                                                                                                  DISPLACE Program Example:


                                                                                                                                                                         000001 PROGRAM DISPLACE DESC='Sample Displaced'

                                                                                                                                                                    000002 handleclear=stdclear,rte=stdfatal
                                                                                                                                                                      000003 * **********************************
                                                                                                                                                                        000004 * * *
                                                                                                                                                                          000005 * * program : displace *
                                                                                                                                                                            000006 * * standard program layout *
                                                                                                                                                                              000007 * * date : mm/dd/yy *
                                                                                                                                                                                000008 * * programmer : bruce fox *
                                                                                                                                                                                  000009 * * analyst : bruce fox *
                                                                                                                                                                                    000010 * * *
                                                                                                                                                                                      000011 * *................................*
                                                                                                                                                                                        000012 * * *
                                                                                                                                                                                          000013 * * this program will show how *
                                                                                                                                                                                            000014 * * to access a one-demensional *
                                                                                                                                                                                              000015 * * array *
                                                                                                                                                                                                000016 * * *
                                                                                                                                                                                                  000017 * **********************************
                                                                                                                                                                                                    000018 * works/records/segments go next *
                                                                                                                                                                                                      000019 * **********************************
                                                                                                                                                                                                        000020 work displace
                                                                                                                                                                                                          000021 * **********************************
                                                                                                                                                                                                            000022 * * *
                                                                                                                                                                                                              000023 * * initial *
                                                                                                                                                                                                                000024 * *................................*
                                                                                                                                                                                                                  000025 * * this is the initializing *
                                                                                                                                                                                                                    000026 * * logic routine *
                                                                                                                                                                                                                      000027 * **********************************
                                                                                                                                                                                                                        000028 initial.
                                                                                                                                                                                                                          000029 move '11223344556677889900' to diarea
                                                                                                                                                                                                                            000030 move 2 to rwrow
                                                                                                                                                                                                                              000031 * **********************************
                                                                                                                                                                                                                                000032 * * *
                                                                                                                                                                                                                                  000033 * * mainloop *
                                                                                                                                                                                                                                    000034 * *................................*
                                                                                                                                                                                                                                      000035 * * this is were the main logic *
                                                                                                                                                                                                                                        000036 * * of program resides *
                                                                                                                                                                                                                                          000037 * **********************************
                                                                                                                                                                                                                                            000038 varying rwi1 = 1 to 10
                                                                                                                                                                                                                                              000039 comp rwi2 = rwrow * (rwi1-1). * DISPLACED FACTOR IN ARRAY
                                                                                                                                                                                                                                                000040 print 'DISPLACED FLD1 ',difld1, +
                                                                                                                                                                                                                                                  000041 ' DISPLACED FLD2 ',difld2. * CONTINUED LINE
                                                                                                                                                                                                                                                    000042 endvary
                                                                                                                                                                                                                                                      000043 endjob
                                                                                                                                                                                                                                                        000044 * **********************************
                                                                                                                                                                                                                                                          000045 * * *
                                                                                                                                                                                                                                                            000046 * * handle labels routines *
                                                                                                                                                                                                                                                              000047 * *................................*
                                                                                                                                                                                                                                                                000048 * * this is were the handle logic *
                                                                                                                                                                                                                                                                  000049 * * of program resides *
                                                                                                                                                                                                                                                                    000050 * **********************************
                                                                                                                                                                                                                                                                      000051 stdclear.
                                                                                                                                                                                                                                                                        000052 endjob
                                                                                                                                                                                                                                                                          000053 stdfatal.
                                                                                                                                                                                                                                                                            000054 print rwmsg rwabend
                                                                                                                                                                                                                                                                              000055 endjob

                                                                                                                                                                                                                                                                               

                                                                                                                                                                                                                                                                              Additional Information:

                                                                                                                                                                                                                                                                              See the CA Gener/OL Reference Guide for detailed information regarding using CA Gener/OL