Embedded SQL Example è Scroll cursor to fetch records from BOTTOM to
TOP 2nd method
Physical
file used in the program: PARTYD
PNAME PNUM PADDR OPNDD OPNMM OPNYY OPNSTS
IROBO P00000000001 CHENNAI 1 1 2,010 2
IROBO P00000000002 EMPHAL 2 10 2,012 2
SHMANT P00000000003 CHENNAI 3 5 2,011 2
AFTAB P00000000007 HOMEIIEA 13 1 2,010 2
AMI P00000000008 HELLY CORN 12 12 2,012 2
JPY P00000000009 JEKINSAN 11 11 2,011 2
SHANN P00000000010 KUPUNUS 24 1 2,012 2
HAPART P00000000011 KOLINSA 16 1 2,010 2
******** End of data ********
Display
file used in the program: EMBED_DSP2
Columns . . . : 1 80 Browse AMIT/QRPGLESRC
SEU==> EMBED_DSP2
FMT DP .....AAN01N02N03T.Name++++++RLen++TDpBLinPosFunctions+++++++++++++++++++++++++++
*************** Beginning of data *********************************************************
0001.00 A DSPSIZ(24 80 *DS3)
0002.00 A CA03(03 'EXIT')
0003.00 A R EMBED_SFL SFL
0004.00 A S_PNUM 12A O 7 13
0005.00 A S_PNAME 12A O 7 35
0006.00 A S_PADDR 10A O 7 53
0007.00 A R EMBED_CTL SFLCTL(EMBED_SFL)
0008.00 A OVERLAY
0009.00 A 42 SFLDSP
0010.00 A 41 SFLDSPCTL
0011.00 A 40 SFLCLR
0012.00 A 45 SFLEND(*MORE)
0013.00 A SFLSIZ(0011)
0014.00 A SFLPAG(0010)
0015.00 A FIRSTRRN 4S 0H SFLRCDNBR(CURSOR)
0016.00 A 1 28'PARTY BASIC INFORMATION'
0017.00 A 1 73DATE
0018.00 A EDTCDE(Y)
0019.00 A 2 73TIME
0020.00 A 6 13'PARTY NUMBER'
0021.00 A DSPATR(HI)
0022.00 A 6 36'PARTY NAME'
0023.00 A DSPATR(HI)
0024.00 A 6 52'PARTY ADDRESS'
0025.00 A DSPATR(HI)
0026.00 A R FOOTER
0027.00 A 24 3'F3 = EXIT'
****************** End of data ***********************************************************
PROGRAM
*************** Beginning of data **********************************************
HDEBUG(*YES)
HOPTION(*NODEBUGIO)
FEMBED_DSP2CF E WORKSTN
F SFILE(EMBED_SFL:RRN)
F INFDS(infds)
*
Dinfds DS
DRECNO 378 379I 0
*
C *IN03 DOWEQ *OFF
C 03 LEAVE
C EXSR DSPSFL
C ENDDO
C SETON LR
C*
C*_________________________________________________
C*_______________CLEAR SUBFILE_____________________
C*_________________________________________________
C CLRSFL BEGSR
C EVAL RRN=0
C SETON 40
C WRITE EMBED_CTL
C SETOFF 40
C ENDSR
C*_________________________________________________
C*_______________FIRST FUBROUTINE__________________
C*_________________________________________________
C*
C *INZSR BEGSR
C SETOFF 404142
C SETOFF 45
C Z-ADD *ZEROS RRN 4 0
C EVAL FIRSTRRN=1
C EXSR CLRSFL
C EXSR FILSFL
C EXSR DSPSFL
C ENDSR
C*_________________________________________________
C*_______________FILL SUBFILE__________________
C*_________________________________________________
C*
C FILSFL BEGSR
C
C EVAL RRN=0
*
C/EXEC SQL
C+ DECLARE C1 SCROLL CURSOR FOR
C+ select PNAME, PNUM,PADDR from AMIT/PARTYD
C+ order by PNUM
C/END-EXEC
*
*
C/EXEC SQL
C+ OPEN C1
C/END-EXEC
*
C/EXEC SQL
C+ FETCH LAST FROM C1 INTO :S_PNUM, :S_PNAME,:S_PADDR
C/END-EXEC
*
C DOW SQLCOD=0
C EVAL RRN=RRN+1
C IF RRN>9999
C LEAVE
C ENDIF
C WRITE EMBED_SFL
C/EXEC SQL
C+ FETCH PRIOR FROM C1 INTO :S_PNUM, :S_PNAME,:S_PADDR
C/END-EXEC
C IF SQLCOD<0
C LEAVE
C ENDIF
C IF SQLCOD=100
C SETON 45
C LEAVE
C ENDIF
C ENDDO
*
*
C/EXEC SQL
C+ CLOSE C1
C/END-EXEC
*
C ENDSR
C*_________________________________________________
C*
C DSPSFL BEGSR
*
C SETON 4142
*
C IF RRN<=0
C SETOFF 42
C ENDIF
*
C WRITE FOOTER
C EXFMT EMBED_CTL
C EVAL FIRSTRRN=RECNO
C SETOFF 4142
C ENDSR
****************** End of data *************************************************
OUTPUT
PARTY BASIC INFORMATION 2/21/13
07:48:49
PARTY NUMBER PARTY NAME PARTY ADDRESS
HAPART P00000000011 KOLINSA
SHANN P00000000010 KUPUNUS
JPY P00000000009 JEKINSAN
AMI P00000000008 HELLY CORN
AFTAB P00000000007 HOMEIIEA
SHMANT P00000000003 CHENNAI
IROBO P00000000002 EMPHAL
IROBO P00000000001 CHENNAI
Bottom
F3 = EXIT