Go4AS400-Image

The Web Ask Go4AS400
Share  
Homepage
See Sitemap
as400_FAQ
See Videos here
Contact me



Ü  DATA STRUCTURE 

 

§  Data structure in general means a structure of different data type.

§  Data structure is specified in the Input Specification of an RPG 3 Program whereas in RPG 1V we specify it in 'D' specification.

§  Data Structure is used-

1. To break fields into subfields

2. To Group fields

3. To change the format of the field

4. To Group non-contiguous data into contiguous format

5.To convert data.

 

Example

 

1.      Using a data structure to break fields

 

In the below example we are breaking CURTIMDATE into different subfields CURRYEAR, CURRMONTH & CURRDAY.

 

Columns . . . :    6  80                  Browse                          AMITCC/QRPGLESRC

SEU==>                                                                              TIMEDS

FMT *   *. 1 ...+... 2 ...+... 3 ...+... 4 ...+... 5 ...+... 6 ...+... 7 ...+... 8

*************** Beginning of data ****************************************************

0001.00

0002.00 DCURTIMSTP        DS

0003.00 DCURTIMDATE               1      8S 0

0004.00 DCURRYEAR                 1      4S 0

0005.00 DCURRMONTH                5      6S 0

0006.00 DCURRDAY                  7      8S 0

0007.00 DCURRHRS                  9     10S 0

0008.00 DCURRMINS                11     12S 0

0009.00 DCURRSECS                13     16S 0

0010.00

0011.00 Dtime_is          S               z

0012.00 Dtime_isO         S             20

0013.00

0014.00  * CALCULATE THE TIME FOR THE CURRENT SYSTEM DATE

0015.00 C                   EVAL      TIME_IS=%TIMESTAMP()

0016.00 C                   EVAL      TIME_ISO=%char(TIME_IS:*iso0)

0017.00 C                   EVAL      CURRYEAR=%dec(%SUBST(TIMe_ISo:1:4):4:0)

0018.00 C                   EVAL      CURRMONTH=%dec(%SUBST(TIMe_ISo:5:2):2:0)

0019.00 C                   EVAL      CURRDAY=%dec(%SUBST(TIMe_ISo:7:2):2:0)

0020.00 C                   EVAL      CURRHRS=%dec(%SUBST(TIMe_ISo:9:2):2:0)

0021.00 C                   EVAL      CURRMINS=%dec(%SUBST(TIMe_ISo:11:2):2:0)

0022.00 C                   EVAL      CURRSECS=%dec(%SUBST(TIMe_ISo:13:4):4:0)

0023.00 C     CURTIMSTP     DSPLY

0024.00 C     CURTIMDATE    DSPLY

0025.00 C     CURRYEAR      DSPLY

0026.00 C     CURRMONTH     DSPLY

0027.00 C     CURRDAY       DSPLY

0028.00 C     CURRHRS       DSPLY

0029.00 C     CURRMINS      DSPLY

0030.00 C     CURRSECS      DSPLY

0031.00 C                   SETON                                        LR

****************** End of data *******************************************************

 

OUTPUT

 

   

2003405802      

20              

2013                  

 1                    

21                     

 3                    

40                    

5802 

 

 

 

(2) Using a data structure to group fields

In the example below fields YY, FILLER1, MM, FILLER2, DD have been used  to make a single field OPN.

Columns . . . :    6 100                Browse                            IROBO1/QRPGLESRC

SEU==>                                                                            DS_GROUP

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords++++++++++++++++++++Comments+++++++++

*************** Beginning of data ****************************************************

0001.00 DOPN              DS

0002.00 DYY                              4A

0003.00 DFILLER1                         1A   INZ('-')

0004.00 DMM                              2A

0005.00 DFILLER2                         1A   INZ('-')

0006.00 DDD                              2A

0007.00 C                   EVAL      YY=%CHAR(2012)

0008.00 C                   EVAL      MM=%CHAR(10)

0009.00 C                   EVAL      DD=%CHAR(15)

0010.00 C     OPN           DSPLY

0011.00 C                   SETON                                        LR

****************** End of data *******************************************************

 

OUTPUT

 

2012-10-15

 

   

 

 

 

 

 

Ü Types of data structures in as/400:

 

        I.            program described data structure

      II.            EXTERNALLY DESCRIBED DATASTRUCTURE

   III.            MULTIPLE OCCURENCE DATASTRUCTURE

    IV.            INDICATOR DATA STRUCTURE

       V.            DATA AREA DATA STRUCTURE (SPECIFIED IN 'U')

    VI.            PROGRAMME STATUS DATASTRUCTURE (SPECIFIED IN 'S')

  VII.            FILE INFORMATION DATASTRUCTURE

 

 

I.              Externally described data structure

In externally described data structure the structure of the data structure is decided by the external definition used in the program. e.g. In the program below file CUST has been used as a referenced external definition for the data structure DS1. Also the data structure has further been modified with the prefix ‘P’.

Physical file used in the program = CUST

Columns . . . :    1  80               Browse                               AMIT/QRPGLESRC

                                                                                        CUST

FMT PF .....A..........T.Name++++++RLen++TDpB......Functions+++++++++++++++++++++++++++

*************** Beginning of data *********************************************************

0001.00

0002.00      A          R CUSTR

0003.00      A            CSNBR          6A

0004.00      A            CSNAME        10A

0005.00      A            CS#OPN         5P 0

0006.00      A            CS$OPN        10P 2

****************** End of data ************************************************************

                                                           

                                                                       

                                                                                                                                    

 

Columns . . . :    6  80              Edit                                   AMITCC/QRPGLESRC

SEU==>                                                                               PREFIXDS

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ****************************************************

0001.00 DDS1            E DS                  EXTNAME(CUST)

0002.00 D                                     PREFIX(P_)

0003.00 C                   EVAL      P_CSNBR='100001'

0004.00 C                   EVAL      P_CSNAME='AMINEM'

0005.00 C                   EVAL      P_CS#OPN=1001

0006.00 C                   EVAL      P_CS$OPN=1000001.11

0007.00 C     DS1           DSPLY

0008.00 C                   SETON                                        LR

****************** End of data *******************************************************

 

 

Below is the compiler source listing of the above program. The data structure used in the program has got its subfield converted into the structure shown below.

 

 

                                  S o u r c e   L i s t i n g

DDS1            E DS                  EXTNAME(CUST)

D                                     PREFIX(P_)

*--------------------------------------------------------------------------------------------*

* Data structure . . . . . . :  DS1                                                          *

* Prefix . . . . . . . . . . :  P_ :    0                                                    *

* External format  . . . . . :  CUSTR : AMIT/CUST                                            *

*--------------------------------------------------------------------------------------------*

D P_CSNBR                        6A   EXTFLD (CSNBR)     >>>>>>>>>>>>>>>>>

D P_CSNAME                      10A   EXTFLD (CSNAME)    >>>>>>>>>>>>>>>>>

D P_CS#OPN                       5P 0 EXTFLD (CS#OPN)    >>>>>>>>>>>>>>>>>

D P_CS$OPN                      10P 2 EXTFLD (CS$OPN)    >>>>>>>>>>>>>>>>>

C                   EVAL      P_CSNBR='100001'

C                   EVAL      P_CSNAME='AMINEM'

C                   EVAL      P_CS#OPN=1001

C                   EVAL      P_CS$OPN=1000001.11

C     DS1           DSPLY

C                   SETON                                        LR----

* * * * *   E N D   O F   S O U R C E   * * * * *

 

 

 

 

 

The above program can also be coded like below to give the same structure to DS1 data structure.

 

 

Columns . . . :    6  8                Edit                                 AMITCC/QRPGLESRC

SEU==>                                                                              PREFIXDS

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ****************************************************

0001.00 DDS1            E DS                  EXTNAME(CUST)

0002.00 DR_CSNBR        E                     EXTFLD(CSNBR)

0003.00 DS_CSNAME       E                     EXTFLD(CSNAME)

0004.00 DT_CS#OPN       E                     EXTFLD(CS#OPN)

0005.00 DU_CS$OPN       E                     EXTFLD(CS$OPN)

0006.00 C                   EVAL      R_CSNBR='100001'

0007.00 C                   EVAL      S_CSNAME='AMINEM'

0008.00 C                   EVAL      T_CS#OPN=1001

0009.00 C                   EVAL      U_CS$OPN=1000001.11

0010.00 C     DS1           DSPLY

0011.00 C     T_CS#OPN      DSPLY

0012.00 C                   SETON                                        LR

****************** End of data *******************************************************

 

 

 

OUTPUT

 

100001                          

AMINEM                         

1001                              

1000001.11                       

 

 

II.              Multiple occurrence data structure

 

Columns . . . :    6  80                 Browse                              AMITCC/QRPGLESRC

SEU==>                                                                                 MULTDS

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ****************************************************

0001.00 D DS1             DS                  OCCURS(10)                                130118

0002.00 D FLD01                   1      5                                              130130

0003.00 D FLD02                   6     10                                              130130

0004.00 DX                S              2  0 INZ(1)                                    130118

0005.00 DN                S              2  0 INZ(1)                                    130130

0006.00                                                                                 130118

0007.00 C     X             DO        5                                                 130130

0008.00 C     X             OCCUR     DS1           N                                   130130

0009.00 C                   EVAL      FLD01=%char(X)                                    130130

0010.00 C                   EVAL      FLD02=%char(X)                                    130130

0011.00 C                   EVAL      X=X+1                                             130118

0012.00 C     DS1           DSPLY                                                       130118

0013.00 C     N             DSPLY                                                       130130

0014.00 C                   ENDDO                                                       130118

0015.00 C                   SETON                                        LR             130118

****************** End of data *******************************************************

                                                                                                                                                                                                                                                                       OUTPUT                                                                                                                                                   

DSPLY  1    1        

DSPLY   1             

DSPLY  2    2         

DSPLY   2             

DSPLY  3    3            

DSPLY   3                

DSPLY  4    4            

DSPLY   4                

DSPLY  5    5            

DSPLY   5 

 

 

III.              Data area data structure

If the data structure subfield is based on data area then that type of data structure is called data area data structure.

We create a data area DTA1. Below is the entry for the data area DTA1.

                               Display Data Area                          

                                                             System:   PUB1

 Data area . . . . . . . :   DTA1                                         

   Library . . . . . . . :     QGPL                                       

 Type  . . . . . . . . . :   *CHAR                                         

 Length  . . . . . . . . :   50                                           

 Text  . . . . . . . . . :                                                

                                                                           

            Value                                                         

 Offset      *...+....1....+....2....+....3....+....4....+....5           

     0      ' THIS IS SAMPLE DATA STRUCTUR                     ' 

 

 

 

        

 

 

Program

 

Columns . . . :    6  80            Browse                                AMITCC/QRPGLESRC

SEU==>                                                                              DTARPG

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ****************************************************

0001.00 DDADS1           UDS                  DTAARA('DTA1')

0002.00 DFLD1                     1      4

0003.00 DFLD2                     6      7

0004.00 DFLD3                     9     14

0005.00 DFLD4                    16     19

0006.00 DFLD5                    21     30

0007.00 C                   IN        DADS1          >>>>>> Data area READ operation

0008.00 C     FLD1          DSPLY

0009.00 C     FLD2          DSPLY

0010.00 C     FLD3          DSPLY

0011.00 C     FLD4          DSPLY

0012.00 C     FLD5          DSPLY

0013.00 C                   OUT       DADS1          >>>>>> Data area WRITE operation

0014.00 C                   SETON                                        LR

****************** End of data *******************************************************

 

OUTPUT

THIS                            

IS                              

SAMPLE                          

DATA                            

STRUCTURE                       

 

 

***Note:

If there is no name of data area data structure then that is nothing but local data area(*LDA) data structure.

In this case there is no need DTAARA (*LDA) keyword also we don’t need to handle input/output operation for the data area.

 

Columns . . . :    6  80                Browse                                  AMIT/QRPGLESRC

SEU==>                                                                                DTA_LDA

*************** Beginning of data ****************************************************

0002.00 D                UDS

0003.00 DFLD001                   1     50A

0004.00

0005.01 C     FLD001        DSPLY

0007.00 C                   SETON                                        LR

****************** End of data *******************************************************

                                                                                                                                   

 

OUTPUT

 

DSPLY  01   - Generic Demonstration Company QPRINT    QGPL  

 

 

 

Other way to declare Local dataarea data structure is as below:

 

Columns . . . :    6  80                 Browse                                 AMIT/QRPGLESRC

SEU==>                                                                                DTA_LDA

*************** Beginning of data ****************************************************

0002.00 D DS1            UDS                  DTAARA(*LDA)

0003.00 DFLD001                   1     50A

0004.00

0005.00 C                   IN        DS1

0005.01 C     FLD001        DSPLY

0006.00 C                   OUT       DS1

0007.00 C                   SETON                                        LR

****************** End of data *******************************************************

                                                                                                                                    

                                                                                                                                   

OUTPUT

 

DSPLY  01   - Generic Demonstration Company QPRINT    QGPL  

 

 

 

 

 

 

Ø  Explicitly control the data area LOCK/UNLOCK by removing 'U' during declaration

Columns . . . :    6  80           Browse                                    AMITCC/QRPGLESRC

SEU==>                                                                                 DTARPG

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ****************************************************

0001.00 DDADS1            DS                  DTAARA('DTA1')

0002.00 DFLD1                     1      4

0003.00 DFLD2                     6      7

0004.00 DFLD3                     9     14

0005.00 DFLD4                    16     19

0006.00 DFLD5                    21     30

0007.00 C     *LOCK         IN        DADS1

0008.00 C     FLD1          DSPLY

0009.00 C     FLD2          DSPLY

0010.00 C     FLD3          DSPLY

0011.00 C     FLD4          DSPLY

0012.00 C     FLD5          DSPLY

0013.00 C                   OUT       DADS1

0014.00 C                   UNLOCK    DADS1

0015.00 C                   SETON                                        LR

****************** End of data *****************************************************

 

 

 

 

IV.             Indicator data structure

The indicator data structure is used to rename the indicators used in our program with the name that is more meaningful and understanding.

If we want to use indicator data structure in our program then INDARA is a mandatory keyword in the display file used.

 

Columns . . . :    1  80                        Browse                    AMITCC/QRPGLESRC

SEU==>                                                                           RECDSPIND

FMT DP .....AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions+++++++++++++++++++++++++++

*************** Beginning of data ********************************************************

0001.00      A                                      INDARA          >>>> Mandatory keyword

0002.00      A                                      DSPSIZ(24 80 *DS3)

0003.00      A                                      CA03(03)

0004.00      A          R RECSFL                    SFL

0005.00      A            S_FLD01        5S 0B  7 20

0006.00      A          R RECCTL                    SFLCTL(RECSFL)

0007.00      A  42                                  SFLDSPCTL

0008.00      A  41                                  SFLDSP

0009.00      A  40                                  SFLCLR

0010.00      A  45                                  SFLEND(*MORE)

0011.00      A                                      SFLSIZ(9999)

0012.00      A                                      SFLPAG(0010)

0013.00      A            RCDNBR         4S 0H      SFLRCDNBR(CURSOR)

0014.00      A                                  1 25'TEST TO CHECK THE BUFFER'

0015.00      A                                  5 20'FLD01'

****************** End of data ***********************************************************

                                                                                                                                   

                                                                                                                                    

                                                                                                                                   

 

In the below program below is the alternate name that we have available for the indicators used in the program;

 

03 = KEY_EXIT                     

40 = SFL_CLEAR                    

41 = SFL_DSP                      

42 = SFL_DSPCTL                   

 

Hence, we can give any meaningful name to the indicators by using this data structure.

 

 

Columns . . . :    6  80                Browse                           AMITCC/QRPGLESRC

SEU==>                                                                         REC1100IND

FMT FX FFilename++IPEASF.....L.....A.Device+.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ******************************************************

0001.00 FRECDSPIND CF   E             WORKSTN SFILE(RECSFL:RRN)  INDDS(INDDS1)

0002.00 D P_INDDS1        s               *   inz(%addr(*in))

0003.00 D INDDS1          ds                  based(P_INDDS1)

0004.00 D  KEY_EXIT                      1N   overlay(INDDS1:03)

0005.00 D  SFL_CLEAR                     1N   overlay(INDDS1:40)

0006.00 D  SFL_DSP                       1N   overlay(INDDS1:41)

0007.00 D  SFL_DSPCTL                    1N   overlay(INDDS1:42)

0008.00 DI                S              5  0

0009.00 DRRN              S              5  0

0010.00 C                   EVAL      RCDNBR=9900

0011.00 C                   DOW       KEY_EXIT=*OFF

0012.00 C                   IF        KEY_EXIT=*ON

0013.00 C                   LEAVE

0014.00 C                   ENDIF

0015.00 C                   EXSR      CLRSFL

0016.00 C                   EXSR      FILSFL

0017.00 C                   EXSR      DSPSFL

0018.00 C                   ENDDO

0019.00 C                   SETON                                        LR

0020.00  *

0021.00 C     CLRSFL        BEGSR

0022.00 C                   EVAL      SFL_CLEAR=*ON

0023.00 C                   WRITE     RECCTL

0024.00 C                   EVAL      SFL_CLEAR=*OFF

0025.00 C                   ENDSR

0026.00  *

0027.00 C     FILSFL        BEGSR

0028.00 C                   FOR       I=0001 BY 1 TO 9900

0029.00 C                   EVAL      RRN=RRN+1

0030.00 C                   IF        RRN>9999

0031.00 C                   LEAVE

0032.00 C                   ENDIF

0033.00 C                   EVAL      S_FLD01=I

0034.00 C                   WRITE     RECSFL

0035.00 C                   ENDFOR

0036.00 C                   ENDSR

0037.00  *

0038.00 C     DSPSFL        BEGSR

0039.00 C                   EVAL      SFL_DSP=*ON

0040.00 C                   EVAL      SFL_DSPCTL=*ON

0041.00 C                   IF        RRN<=0

0042.00 C                   EVAL      SFL_DSP=*OFF

0043.00 C                   ENDIF

0044.00 C                   EXFMT     RECCTL

0045.00 C                   EVAL      SFL_DSP=*OFF

0046.00 C                   EVAL      SFL_DSPCTL=*OFF

0047.00 C                   ENDSR

****************** End of data *********************************************************

                                                                                                                                   

                                                                                                                                    

                   

OUTPUT

 

                        TEST TO CHECK THE BUFFER                               

                                                                                

                                                                               

                                                                               

                   FLD01                                                        

                                                                               

                    9891                                                       

                    9892                                                        

                    9893                                                       

                    9894                                                       

                    9895                                                        

                    9896                                                       

                    9897                                                       

                    9898                                                        

                    9899                                                       

                    9900                                                       

                                                                        More...

                                                                                

                                                                               

                                                                               

                                                                                

                                                                               

                                                                               

 

 

 

V.             QUALIFIED data structures

By using qualified data structures we can define same field in different data structures.

We refer to a subfield name by name of the data structure, then a period, and then the subfield name.

 

Columns . . . :    6  80               Browse                                AMITCC/QRPGLESRC

SEU==>                                                                                DS_QUAL

FMT D  DName+++++++++++ETDsFrom+++To/L+++IDc.Keywords+++++++++++++++++++++++++++++

*************** Beginning of data ****************************************************

0001.00 DPERSONAL_DETAIL  DS                  QUALIFIED                                 130225

0002.00 DNAME                           10A                                             130225

0003.00 DSEX                            10A                                             130225

0004.00 DADDR                           10A                                             130225

0005.00 DEMPLOYEE_DETAIL  DS                  QUALIFIED                                 130225

0006.00 DEMPID                          10A                                             130225

0007.00 DPERSONAL_INFO                        LIKEDS(PERSONAL_DETAIL)                   130225

0008.00                                                                                 130225

0009.00  /free                                                                          130225

0010.00           PERSONAL_DETAIL.NAME='AMINEM';                                        130225

0011.00           EMPLOYEE_DETAIL.PERSONAL_INFO.NAME='IROBO';                           130225

0012.00           DSPLY   PERSONAL_DETAIL.NAME;                                         130225

0013.00           DSPLY   EMPLOYEE_DETAIL.PERSONAL_INFO.NAME;                           130225

0014.00  /end-free                                                                      130225

0015.00 C                   SETON                                        LR             130225

****************** End of data *******************************************************