29
CL programming (with Display Files) Updated Winter 2007

CL programming (with Display Files)

  • Upload
    anevay

  • View
    52

  • Download
    0

Embed Size (px)

DESCRIPTION

CL programming (with Display Files). Updated Winter 2007. Agenda. Assignment 1 Review Display Files CL Programming Use of Indicators CL Program Examples. Review Display Files. Constants Input/Output fields Attributes Activating Function keys. How do we use the Display File?. - PowerPoint PPT Presentation

Citation preview

Page 1: CL programming (with Display Files)

CL programming (with Display Files)

Updated Winter 2007

Page 2: CL programming (with Display Files)

Agenda

• Assignment 1• Review Display Files• CL Programming• Use of Indicators• CL Program Examples

Page 3: CL programming (with Display Files)

Review Display Files

• Constants

• Input/Output fields

• Attributes

• Activating Function keys

Page 4: CL programming (with Display Files)

How do we use the Display File?

• They are included in programs.

• The programs use them to communicate with the user( i.e. information is passed back and forth between the program and the user via the display file.)

Page 5: CL programming (with Display Files)

Program Flow

Display the Screen

While not F3

Process Data

Display the Screen

Exit

Page 6: CL programming (with Display Files)

CL Programming Restrictions

• Only five *FILE per program– Display file or Database File

• Can’t update Database Files• Can’t create reports

Page 7: CL programming (with Display Files)

CL Variables• Datatypes = *CHAR , *DEC , *LGL, *INT, *UINT • Variable names start with an ‘&’ e.g. &IN03,

&CTR, &USER, &DATE, &MARK1, etc.• DCL VAR(&varname) TYPE(*CHAR) LEN(8)

variables must be declared before you can use them)

• variables from a display file will automatically be available to program. (passed in)

• CHGVAR VAR(&varname) VALUE(value)

Page 8: CL programming (with Display Files)

Examples

DCL VAR(&TOTAL) TYPE(*DEC) LEN(7,2)

DCL VAR(&GRADE) TYPE(*CHAR) LEN(1)

CHGVAR VAR(&GRADE) VALUE (‘A’)

CHGVAR VAR(&TOTAL) VALUE(&TOTAL + 1)

Page 9: CL programming (with Display Files)

Some File Commands• DCLF - Declares a File

(files must be declared before you can use them)e.g. DCLF FILE(MARKSDF)

• SNDRCVF - Sends a record to a screen and waits for the user to enter input, then reads it (only for Display Files) - used with input/output screens

e.g. SNDRCVF(MARKSDF)

Page 10: CL programming (with Display Files)

Selection and Iteration

• IF (condition) THEN (command) ELSEfor conditions, *AND, *OR, *NOT, *LT, *GT, *EQ, *NL, *NG, etc

• DO and ENDDO - used when you need to execute several commands in an IF statement

• GOTO and labels

Page 11: CL programming (with Display Files)

IF, THEN, ELSE example

IF COND(&TIME *LE 120000) + THEN ( SNDMSG MSG('Good Morning') TOUSR(DC233A40) ) ELSE + CMD( SNDMSG MSG('Good Afternoon') TOUSR(DC233A40 ) )

Page 12: CL programming (with Display Files)

DO, ENDDO example

IF (&CHOICE = 'O' *OR &CHOICE = 'o') + DO CHGCURLIB IBC233LIB WRKOBJPDM IBC233LIB ENDDO ELSE (GOTO END)

END: ENDPGM

Page 13: CL programming (with Display Files)

Select Group

SELECTWHEN COND(&TYPE *EQ *CMD) THEN(DO)

(group of CL commands)ENDDOWHEN COND(&TYPE = *PGM) THEN(DO)

(group of CL commands)ENDDOOTHERWISE CMD(CHGVAR &BADTYPE ‘1’)

ENDSELECT

Page 14: CL programming (with Display Files)

DOWHILE Loop

SNDRCVF DOWHILE(&IN03 *NE ‘1’)

IF (&IN05 *EQ ‘1’) + DO

CHGVAR VAR(&MARK1) VALUE(0) CHGVAR VAR(&MARK2) VALUE(0)

ENDDO

SNDRCVF ENDDO WRKOBJPDM This bit of code sends the display file to the screen and reads it back. If F3 is pressed, the loop exits and WRKOBJPDM is done. If not, It then checks to see if the user has pressed F5. If so, it initializes the 2 fields MARK1 and MARK2 and redisplays the screen.

Page 15: CL programming (with Display Files)

DOUNTIL Loop

SNDRCVF DOUNTIL(&IN03) /* the contents of loop is */

IF (&IN05) + /* always processed once */ DO

CHGVAR VAR(&MARK1) VALUE(0) CHGVAR VAR(&MARK2) VALUE(0)

ENDDO

SNDRCVF ENDDO WRKOBJPDM This bit of code sends the display file to the screen and reads it back. If F3 is pressed, the loop exits and WRKOBJPDM is done. If not, It then checks to see if the user has pressed F5. If so, it initializes the 2 fields MARK1 and MARK2 and redisplays the screen.

Page 16: CL programming (with Display Files)

DOFOR Loop

DCL &LOOPCTL TYPE(*INT) LEN(4)

DCL &LOOPLMT TYPE(*INT) LEN(4)

DOFOR VAR(&LOOPCTL) FROM(1) TO(&LOOPLMT) BY(1)

(group of commands run 0 or more times)

ENDDO

Page 17: CL programming (with Display Files)

Resulting Indicators

• Indicators are on/off switches used by programs. 2 possible values: 1 or 0– Response indicators: set by functions keys, used

by programs to determine the appropriate response e.g. exit when F3 is pressed

– Option indicators: set by programs, used to control when/how info is displayed e.g. an indicator is set to on when an error is detected causing an data field to be displayed in red.

Page 18: CL programming (with Display Files)

Program Flow using Screens and Indicators

SNDRCVF

Check response indicators DOWHILE (&IN03 *NE ‘1’)

Edit input, set option indictorsIf (&name = ‘ ‘) chgvar IN30 ‘1’SNDRCVF

Exit

Page 19: CL programming (with Display Files)

Examples of Response Indicator use

If (&in03 *eq ‘1’) +goto cmdlbl(exit)

If (&in05 * eq ‘1’) + do

chgvar var(&assign1) value ( 0 )chgvar var(&assign2) value ( 0 )

goto cmdlbl(read) enddo

Page 20: CL programming (with Display Files)

Examples of Option Indicator Use

IF (&ASSIGN1 *LT 0 *OR &ASSIGN1 *GT 5) +CHGVAR VAR( &IN30) VALUE (‘1’)

IF (&ASSIGN2 *LT 0 *OR &ASSIGN2 *GT 10) +CHGVAR VAR (&IN31) VALUE (‘1’)

IF (&IN30 *OR &IN31) +GOTO CMDLBL(SEND) /* REDISPLAY SCREEN */

Page 21: CL programming (with Display Files)

/* sample */

DCLF FILE(ORDERDF)

SNDRCVF DOWHILE (&IN03 *NE ‘1’)

IF (&ORDERNO *LE 0) + CHGVAR VAR (&IN40 ) VALUE ( ‘1’ )IF (&ORDDESC *EQ ‘ ‘) +

CHGVAR VAR (&IN41 ) VALUE ( ‘1’)IF ( &IN40 *OR &IN41 ) +

GOTO CMDLBL(NEXT)CALL CBLPGM ( &ORDERNO &ORDDESC )

NEXT: SNDRCVFENDDO ENDPGM

Page 22: CL programming (with Display Files)

Fix MarksCL

Page 23: CL programming (with Display Files)

Exercise:• Write a CL program which uses the following screen (HAPPYDF

in IBC233LIB). The userid must not be spaces. It is controlled by indicator 55. When the userid is valid, send a happy birthday message to the userid entered. If the user presses F3, end the program

Dd/dd/dd Happy Birthday tt/tt/tt

userid: BBBBBBBBBB Must not be blank

F3=exit

Page 24: CL programming (with Display Files)

Resulting indicators and attributes0000.20 A*%%EC 0000.30 A DSPSIZ(24 80 *DS3) 0000.40 A INDARA 0000.50 A CF03(03) 0000.60 A CF05(05) 0000.70 A CF12(12) 0000.80 A R TSTREC 0000.90 A*%%TS SD 20010306 204121 ABERNS REL-V4R4M0 5769-PW1

0004.00 A FLD003 1Y 0B 9 45 0004.10 A 45 DSPATR(HI) 0004.20 A 45 COLOR(RED) 0004.30 A RANGE(1 4)0004.40 A EDTWRD(' ') 0004.50 A 45 DSPATR(PC) 0004.60 A CHECK(ME) ****************** End of data **************************************

Key response result

option result

Page 25: CL programming (with Display Files)

Preparation and setting

0040.00 /* Check for Invalid Option */ 0041.00 0042.00 IF COND((&OPTION *NE '1 ') *AND (&OPTION *NE '2 + 0043.00 ') *AND (&OPTION *NE ' 1') *AND (&OPTION + 0044.00 *NE ' 2') *AND (&OPTION *NE '01') *AND + 0045.00 (&OPTION *NE '02')) THEN(DO) 0046.00 CHGVAR VAR(&IN99) VALUE('1') 0047.00 GOTO CMDLBL(READ) 0048.00 ENDDO 0049.00

0020.00 /* Start of iteration (Processing Loop) */ 0021.00 READ: SNDRCVF /* Program displays the screen and */ 0022.00 /* waits here for a response from */ 0023.00 /* the keyboard */ 0024.00 0025.00 /* Initialize Error Checking Indicators before */ 0026.00 /* validating input */ 0027.00 CHGVAR VAR(&IN99) VALUE('0') 0028.00

0014.00 PGM /* Field and File Declaration Section */ 0015.00 DCLF FILE(CHAP11) RCDFMT(SCRNR) 0016.00 0017.00 /* Field Initialization Section */ 0018.00 CHGVAR VAR(&IN99) VALUE('0') 0019.00

Page 26: CL programming (with Display Files)

Debugging CL Programs

Use start interactive source debug

STRISDB

Make sure the compile includes the SRCDBG option

Page 27: CL programming (with Display Files)

Compile with debug option set(figure it out for WDSc)

• Create CL Program (CRTCLPGM) • • Type choices, press Enter. • • Program . . . . . . . . . . . . > MARKSCLMST Name • Library . . . . . . . . . . . > ABIBC20071 Name, *CURLIB • Source file . . . . . . . . . . > QCLLESRC Name • Library . . . . . . . . . . . > ABIBC20071 Name, *LIBL, *CURLIB • Source member . . . . . . . . . > MARKSCLMST Name, *PGM • Text 'description' . . . . . . . *SRCMBRTXT • • • Additional Parameters • • Source listing options . . . . . > *SRCDBG *SOURCE, *NOSOURCE, *SRC... • + for more values *source • Generation options . . . . . . . > *LIST *NOLIST, *LIST, *NOXREF... • + for more values • User profile . . . . . . . . . . *USER *USER, *OWNER • Log commands . . . . . . . . . . *JOB *JOB, *YES, *NO • More...

!! How do we get to see these??

Page 28: CL programming (with Display Files)

MessagesInteractive Batch

SNDMSG SNDMSG

DSPMSG RCVMSG from a queue

SNDPGMMSG to a queue

WRKMSG

MONMSG

SNDBRKMSG

Message Description files i.e. QCPFMSGDSPMSGD CPF0797 What are these messages?DSPMSGD CPF0881

Page 29: CL programming (with Display Files)

To Do(s):

• Work on this lab and THE Assignment 1