What is the difference between dow and dou commands?

0 pts.
Tags:
RPG
Linda wrote in with this question recently: "What is the difference between dow and dou commands? Does anyone have a sample subfile program that explains how subfiles work?" Do you know? Linda could really use your help. -- Debra Tart, associate editor, Search400.com
ASKED: December 15, 2005  8:23 AM
UPDATED: November 11, 2010  8:53 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

<ol>
<b>dow tests the condition at the start of the loop – at the dow statement.

dou tests the condition at the enddo statement.</b>

=================================================

DOW — Do While — does the statements in the DO-group <i>while</i> the condition is true. The logical test for the condition happens at the DOW statement, i.e., at the beginning. This implies that the statements won’t be executed at all if the condition is false at the time the DOW statement is executed.

DOU — Do Until — does the statements in the DO-group <i>until</i> the condition is true. The logical test for the condition happens at the ENDDO statement. This implies that the statements will always be executed at least once when the DO-group is reached.<pre>READ MyFile
DOW NOT %eof(MyFile)
…process records…
READ MyFile
ENDDO</pre>
Using a DOW for a READ-loop requires a “priming” READ outside of the loop in case the %EOF() condition is true on the first READ. Note that the condition uses a “NOT” operator.<pre>DOU %eof(MyFile)
READ MyFile
IF NOT %eof(MyFile)
…process records…
ENDIF
ENDDO</pre>A DOU READ loop does not require a “priming” READ, but then an IF-statement needs to be inside the loop to separate what happens when %EOF() happens from when it doesn’t.

Tom</ol>

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • astradyne
    The difference between DOW (Do While) and DOU (Do Until) is the point at which the test is made. The DOW performs the test at the start of the loop, so it is possible for a DOW loop not to to be performed at all. The DOU, on the other hand, tests at the end of the loop so the loop will be performed at least once. For example: C Eval *IN01 = *ON C DoW *IN01 = *OFF C ... C ... C EndDo will not perform the loop at all, whereas: C Eval *IN01 = *ON C DoU *IN01 = *ON C ... C ... C EndDo will perform the loop once. For subfile handling programs there are numerous resources available with examples of how to code them. The AS/400 Programmer's Handbook from MC Press has a number of examples for the different subfile handling techniques and is well worth the investment. Doing a Google search on the words "subfile program" (omit the quotes) returns numerous examples too. All the best Jonathan
    370 pointsBadges:
    report
  • Dawn8160
    My understanding of the two is a DOU loops around until the criteria is met and then leaves the loop, this is the same for a DOW but the difference is the dou will process the last record whereas the dow doesn't. This is the way it was explained to me by a colleague so I always use a DOU. Hope this helps Dawn
    0 pointsBadges:
    report
  • astradyne
    Hi Dawn I'm afraid your colleague is leading you astray slightly, both DOW and DOU loops will process the last "record" - it all depends on how you code the condition that's being tested for. For example, if you want to repeat the loop 10 times, you could code the DOU as: C Eval Index = 0 C DoU Index >= 10 C Eval Index = Index + 1 C Dsply Index C EndDo and that will give you the numbers 1 to 10. Similarly to achieve the same result with the DOW you could code: C Eval Index = 0 C DoW Index =10 and DOW Index
    370 pointsBadges:
    report
  • DebraTart
    ** This is what one Search400.com member sent in. ** Sample RPG IV subfile program with display file DDS included. *PARMS USRPRF(*OWNER) *==============================================================* * Plant Reporting System * *==============================================================* * * * Program Name: . . . . . . PR1108 * * * * Program Function: . Scheduling - MTS/INQ for Setup times. * * Pass a 'c' or an 'M' parm to get the * * maint mode. All else results in the * * inquiry mode. * * * * There are 3 subfiles along with a msg * * popup window. Two of the subfiles are * * contained in popup windows. * * SF01 - the main one - Setup times * * SF02 - select a diam/type. * * SF03 - select a wc. * * * * A logical is used over the physical to * * provide an accpth with just the wc. * * Recs still arrive in the desired order. * * This LF is used to fill SF01, and it * * allows for setll to work properly. * * * * Changes to key fields are not allowed. * * The records must be deleted and rekeyed.* * This is easily accomplished since there * * is prompting available for both WCs and * * pipe diam/types via the F4 key. The * * code determines whether to display the * * WC listing or the Diam/type listing * * based upon where the cursor is. If the * * sflcsrrrn for SF01 is 0, then it is ass-* * umed that the WC list should be display-* * ed. * * * * When a change is made to the WC fld * * in SF01 control record, *in43 is set on.* * This signals to the pgm to validate the * * new value and to fill SF01 again and re-* * display it. * * * * When the selection subfiles (SF02, SF03)* * are displayed, the user need only move * * the cursor to the row desired and press * * Enter. * * * * Deletions are done from SF01 by the row * * of the cursor also, which is determined * * by the value of sf01csrrrn field. * * * * In order to be able to know what the rrn* * is of the first blank row in SF01 for * * the additions record, an array is filled* * with the diam/type when SF01 is filled. * * Each array element corresonds with a row* * in SF01. Later, when selecting a diam/ * * type from a list (SF02), we can find the* * empty row using lookup vs having to read* * through the SF01 again. Another feature* * that uses the array is the filling of * * the list of diam/types. Only the ones * * not already used in SF01 are presented * * for possible selection. Using an array * * in this fashion for this function is * * only practical for small - med sized * * subfiles since it takes memory. * * * * * * by Rick Smith - Nov/Dec 2005 * * * *==============================================================* H DEBUG *==============================================================* * F i l e D e s c r i p t i o n s * *==============================================================* fpr1108df cf e workstn sfile(sf01dta:sf01rrn) f sfile(sf02dta:sf02rrn) f sfile(sf03dta:sf03rrn) fprsetupf uf a e k disk fprsetu01 if e k disk f rename(prseturf:setupbywc) fprpdiapf if e k disk fprwctrpf if e k disk *==============================================================* // to prototype for calling QCMDEXC per pg166 of "the book." d qcmdexc pr extpgm('QCMDEXC') d commandstring 512 options(*varsize) d const d cmdlength 15p 5 const // to prototype for calling the error program. d errorprogram pr extpgm('GP9000CL') d compcode s n d alldone s n d sf01loaded s n d sf01processed s n d sf02loaded s n d keyederrors s n inz(*off) d deletepressed s n inz(*off) d selectpressed s n inz(*off) d refreshpressed s n inz(*off) d badwckeyed s n inz(*on) d diamcode s like(sudiamcode) inz(*blanks) d typecode s like(sutypecode) inz(*blanks) d mode s 1 d addlines s 2 0 d commandstring s 512 d cmdlength s 15p 5 d response s 1 d sf01diamtype s 4 dim(200) d arrayelement s 3 0 d firstemptyelem s 3 0 d arraykey s 4 *==============================================================* *>>>>>> M a i n l i n e R o u t i n e = firstemptyelem; arraykey = $udiamcode + $utypecode; arrayelement = %lookup(arraykey:sf01diamtype); if arrayelement 0; @winmsg1 = 'This diameter/type is already in the list.'; exfmt msgwin1; keyederrors = *on; *in61 = *on; // RI diam field *in62 = *on; // RI type field *in69 = *off; // unprotect the diam and type fields. chain sf01rrn sf01dta; update sf01dta; *in69 = *on; // protect the diam and type fields. *in61 = *off; // don't RI diam field *in62 = *off; // don't RI type field leavesr; endif; endif; If $usetuhour > 0; susetuhour = $usetuhour; *in63 = *off; // don't RI hours field update sf01dta; else; @winmsg1 = 'Hours must be a positive number.'; exfmt msgwin1; keyederrors = *on; *in63 = *on; // RI hours field update sf01dta; *in63 = *off; // don't RI hours field leavesr; endif; chain(en) ($utypecode:$udiamcode) prpdiarf; if %found(prpdiapf); susetuhour = $usetuhour; *in61 = *off; // don't RI diam field *in62 = *off; // don't RI type field chain sf01rrn sf01dta; update sf01dta; else; @winmsg1 = 'Diameter/Type not found in PRS master files.'; exfmt msgwin1; keyederrors = *on; *in61 = *on; // RI diam field *in62 = *on; // RI type field *in69 = *off; // unprotect the diam and type fields. chain sf01rrn sf01dta; update sf01dta; *in69 = *on; // protect the diam and type fields. *in61 = *off; // don't RI diam field *in62 = *off; // don't RI type field leavesr; endif; chain(e) ($@wc:$udiamcode:$utypecode) prsetupf; susetuhour = $usetuhour; if not %error and %found(prsetupf); update prseturf %fields(susetuhour); else; suwc = $@wc; sudiamcode = $udiamcode; sutypecode = $utypecode; write prseturf; endif; readc sf01dta; enddo; endsr; /end-free //============================================================= /free begsr processsfl02; sf02rrn = 1; chain sf02csrrrn sf02dta; // get diam/type from sf02 if dicode = *blanks and ditype = *blanks OR sf02csrrrn = 0; leavesr; endif; // find first empty sf rec in sf01: arraykey = *blanks; sf01rrn = %lookup(arraykey:sf01diamtype); chain sf01rrn sf01dta; // position to 1st empty rec in sf01. $udiamcode = dicode; $utypecode = ditype; *in46 = *on; // sf next changed. *in63 = *on; // position cursor. update sf01dta; *in63 = *off; // position cursor off. *in46 = *off; // sf next changed. *in41 = *on; // display sf01 endsr; /end-free //============================================================= /free begsr processsfl03; sf03rrn = 1; chain sf03csrrrn sf03dta; // get wc from sf03 if wcwc# = 0 OR sf03csrrrn = 0; leavesr; endif; $@wc = wcwc#; endsr; /end-free //============================================================= /free begsr startup; /end-free c *entry plist c parm mode c wcdiamtype klist c kfld $@wc c kfld sudiamcode c kfld sutypecode c typediam klist c kfld typecode c kfld diamcode /free if mode = 'c' OR mode = 'm' OR mode = 'M'; mode = 'C'; // change to uppercase C. endif; if mode = 'C'; $1mode = ' Change'; else; $1mode = ' Inquiry'; *in36 = *on; // protect from keying. *in68 = *on; // protect from keying. endif; endsr; /end-free //============================================================= /free begsr goback; *inlr = *on; return; endsr; /end-free //============================================================= /free begsr os400exec; callp(e) qcmdexc(%trim(commandstring):%len(%trim(commandstring))); endsr; /end-free //============================================================= /free begsr *pssr; callp(e) errorprogram(); dump; *inlr = *on; return; endsr; /end-free //============================================================= //============================================================= //============================================================= //============================================================= A*%%TS SD 20051212 084751 RSMITH REL-V5R2M0 5722-WDS A*PARMS RSTDSP(*YES) DFRWRT(*NO) A*%%EC A DSPSIZ(24 80 *DS3) A REF(*LIBL/PRSETUPF) A PRINT A R SF01DTA SFL A*%%TS SD 20051209 090558 RSMITH REL-V5R2M0 5722-WDS A 46 SFLNXTCHG A $UDIAMCODER B 7 26REFFLD(SUDIAMCODE) A 61 DSPATR(RI) A 69 DSPATR(PR) A N69 DSPATR(UL) A 61 DSPATR(PC) A $UTYPECODER B 7 33REFFLD(SUTYPECODE) A 62 DSPATR(RI) A 69 DSPATR(PR) A N69 DSPATR(UL) A DIDESC R O 7 39REFFLD(DIDESC *LIBL/PRPDIAPF) A $USETUHOURR B 7 52REFFLD(SUSETUHOUR) A 63 DSPATR(RI) A 63 DSPATR(PC) A N36 DSPATR(UL) A 68 DSPATR(PR) A R SF01CTL SFLCTL(SF01DTA) A*%%TS SD 20051212 084751 RSMITH REL-V5R2M0 5722-WDS A SFLSIZ(0030) A SFLPAG(0012) A CA03(03) A N36 CF23(23 'Delete a record') A N36 CF04(04 'Select a diameter/type') A N37 CF05(05 'refresh') A BLINK A OVERLAY A SFLCSRRRN(&SF01CSRRRN) A 41 SFLDSP A 42 SFLDSPCTL A 40 SFLCLR A N49 SFLEND(*SCRBAR *SCRBAR) A SF01RRN 3S 0H SFLRCDNBR A SF01CSRRRN 5S 0H A 90 MSG001 78 M A 1 28' Scheduling - Setup Hours ' A DSPATR(RI) A 2 2'==================================- A ===================================- A =========' A 4 2'==================================- A ===================================- A =========' A $1MODE 10A O 3 70DSPATR(RI) A 1 3DATE A EDTCDE(Y) A 1 71TIME A 5 26'Diam' A COLOR(WHT) A DSPATR(UL) A 5 32'Type' A COLOR(WHT) A DSPATR(UL) A 5 38'Description' A COLOR(WHT) A DSPATR(UL) A 5 51'Hours' A COLOR(WHT) A DSPATR(UL) A 3 3'Workcenter: ' A $@WC R Y B 3 16REFFLD(SUWC) A EDTCDE(Z) A 45 DSPATR(PC) A CHANGE(43) A 45 DSPATR(RI) A $@WCDESC R O 3 21REFFLD(WCDESC *LIBL/PRWCTRPF) A COLOR(WHT) A R FKEYS A*%%TS SD 20051202 123244 RSMITH REL-V5R2M0 5722-WDS A 22 2'==================================- A ===================================- A =========' A 23 2'Exit - F3' A COLOR(WHT) A 23 43'Delete - F23' A COLOR(WHT) A 36 DSPATR(ND) A 23 14'Select - F4' A 36 DSPATR(ND) A COLOR(WHT) A 23 28'Refresh - F5' A 37 DSPATR(ND) A COLOR(WHT) A R MSGWIN1 A*%%TS SD 20051121 145736 RSMITH REL-V5R2M0 5722-WDS A WINDOW(15 10 5 60) A @WINMSG1 60A O 3 1 A 4 1'press Enter' A R SF02DTA SFL A*%%TS SD 20051130 080526 RSMITH REL-V5R2M0 5722-WDS A DICODE 3A O 5 15 A DITYPE 1A O 5 12 A DIDESC 8A O 5 20 A R SF02CTL SFLCTL(SF02DTA) A*%%TS SD 20051130 080526 RSMITH REL-V5R2M0 5722-WDS A CA12(12 'cancel and close window') A BLINK A SFLCSRRRN(&SF02CSRRRN) A 51 SFLDSP A 52 SFLDSPCTL A 50 SFLCLR A N59 SFLEND(*SCRBAR *SCRBAR) A SFLSIZ(0011) A SFLPAG(0010) A WINDOW(WINSF02) A SF02CSRRRN 5S 0H A SF02RRN 3S 0H SFLRCDNBR A 90 MSG002 78 M A 1 2'Move to desired row, then press En- A ter.' A COLOR(WHT) A 2 2'Cancel - F12' A COLOR(WHT) A R WINSF02 A*%%TS SD 20051202 140825 RSMITH REL-V5R2M0 5722-WDS A INZRCD A OVERLAY A WINDOW(6 30 16 40) A R SF03DTA SFL A*%%TS SD 20051202 140401 RSMITH REL-V5R2M0 5722-WDS A WCWC# 4 0O 5 5EDTCDE(Z) A DSPATR(PC) A WCDESC 25A O 5 11 A R SF03CTL SFLCTL(SF03DTA) A*%%TS SD 20051202 083158 RSMITH REL-V5R2M0 5722-WDS A CA12(12 'cancel and close window') A BLINK A SFLCSRRRN(&SF03CSRRRN) A 71 SFLDSP A 72 SFLDSPCTL A 70 SFLCLR A N79 SFLEND(*SCRBAR *SCRBAR) A SFLSIZ(0011) A SFLPAG(0010) A WINDOW(WINSF03) A SF03CSRRRN 5S 0H A SF03RRN 3S 0H SFLRCDNBR A 90 MSG003 78 M A 1 2'Move to desired row, then press En- A ter.' A COLOR(WHT) A 2 2'Cancel - F12' A COLOR(WHT) A R WINSF03 A*%%TS SD 20051202 140825 RSMITH REL-V5R2M0 5722-WDS A INZRCD A OVERLAY A WINDOW(3 10 16 40) _
    0 pointsBadges:
    report
  • Rudedog
    one is question 12 on the test and the other is quesiton 33 on the test. -Sarege :)
    950 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following