PDF='MAIN' { ATTRIBUTES='*' { LIBLOBJ='*FILES'; ROWCOLOR1='altcol1'; ROWCOLOR2='altcol2'; USEACTGROUP='1'; PLATFORM='rpgfree.txt'; ATTACHED='0'; PROJECT='36'; OBJECTNAME='AUTOINCPML'; OBJLIBRARY='XL_WEBDEMO'; TITLE='auto increment on add using record level access'; SOURCEFILE='QRPGLESRC'; SOURCELIBR='XL_WEBDEMO'; WEBPATH='http://esdi.excelsystems.com/wsdemo/'; SET='46'; VERSION='4.00'; CRTBNUM='Build 9036'; CRTTEMPLT='C:\\Program Files\\ESDI\\WebSmart\\Temp\\Page at a Time Maint.tpl'; SAVBNUM='Revision 1591'; LASTLOC='11'; VHTML='N'; LASTSAVE='26/10/2007 10:11:12'; } FILES='*' { FILE='MU_ORDHF' { LIBRARY='XL_WEBDEMO'; RCDFORMAT='RORDERH '; LEVELID='1071022162149'; RFLEVELID='4E69C242A36A9'; EXTDS='0'; } } PANELS='*' { PANEL='ListHeader' { DESC='Main List Header'; DETAILS=' auto increment on add using record level access

Example 128: Auto Increment using PML

Description:   This example shows how to have an AUTOINC field using Record Level Access. On an \'add record\' the \'Order Number\' will be automatically incremented to the HIVAL plus 1.

Order Number:
'; } PANEL='ListDetails' { DESC='Page header'; DETAILS=' '; ITERATIONS='10'; } PANEL='ListFooter' { DESC='Page footer'; DETAILS='
Action Order Number Purchase Order / Description Customer Number Order Date
Display Edit Delete
'; } PANEL='PageFooter' { DESC='Page Footer'; DETAILS='
  1. Start With a \'Page at a Time\' Template. Add the file MU_ORDHF. Accept all other defaults. Choose whatever fields you like.


  2. Add
    crtlike(tmpOHORD, OHORD, "temperary OHORD");
    above the \'runtask\'s in \'Main\'.


  3. Add
    posrcd(MU_ORDHF, "*LAST", "*GT");
    getprvrcd(MU_ORDHF, "*NOKEY", "*YES");
    tmpOHORD = OHORD+1;
    clrrcd(MU_ORDHF);
    above the \'getparmset\' which gets all of your fields from the add screen. The reason for the temperary field and the clear record is because the getprvrcd will fill in all the fields in the file specified with the last record. When we write to the file however we may only want the user to specify some of the fields while the rest are left blank which won\'t happen if we don\'t clear the records.

  4. Add
    OHORD = tmpOHORD;
    directly below the \'getparmset\' mentioned in step 3.

  5. *The program works correctly at this point. You will notice that you can input a value for the key field OHORD but it is ignored because of the automatic increment. You may wish to make the field output only or take it out alltogether.

Program Definition:   autoincpml.pdw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } PANEL='addlink' { DESC='Add Record'; DETAILS='Add Record '; } PANEL='RcdDisplay' { DESC='Display an individual record'; DETAILS=' auto increment on add using record level access

Auto Increment using PML

Description:   This example shows how to have an AUTOINC field using Record Level Access. On an \'add record\' the \'Order Number\' will be automatically incremented to the HIVAL plus 1.

Order Number:
Purchase Order / Description:
Customer Number:
Order Date:
Order Status:
Order Total:
Tax Percentage:
Warehouse Location:
Ship to Location:
Ship Date:
Invoice Number:
  1. Start With a \'Page at a Time\' Template. Add the file MU_ORDHF. Accept all other defaults. Choose whatever fields you like.


  2. Add
    crtlike(tmpOHORD, OHORD, "temperary OHORD");
    above the \'runtask\'s in \'Main\'.


  3. Add
    posrcd(MU_ORDHF, "*LAST", "*GT");
    getprvrcd(MU_ORDHF, "*NOKEY", "*YES");
    tmpOHORD = OHORD+1;
    clrrcd(MU_ORDHF);
    above the \'getparmset\' which gets all of your fields from the add screen. The reason for the temperary field and the clear record is because the getprvrcd will fill in all the fields in the file specified with the last record. When we write to the file however we may only want the user to specify some of the fields while the rest are left blank which won\'t happen if we don\'t clear the records.

  4. Add
    OHORD = tmpOHORD;
    directly below the \'getparmset\' mentioned in step 3.

  5. *The program works correctly at this point. You will notice that you can input a value for the key field OHORD but it is ignored because of the automatic increment. You may wish to make the field output only or take it out alltogether.

Program Definition:   autoincpml.pdw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } PANEL='DelChoice' { DESC='Confirm a delete'; DETAILS='

Are you SURE you want to delete this record?

Yes    No '; } PANEL='RtnToList' { DESC='Return to List'; DETAILS='
'; } PANEL='ListPrev' { DESC='Link to previous page'; DETAILS='
Previous '; } PANEL='ListNext' { DESC='Link to next page'; DETAILS='
Next '; } PANEL='RcdManage' { DESC='Add or Change An Individual Record'; DETAILS=' auto increment on add using record level access

Auto Increment using PML

Description:   This example shows how to have an AUTOINC field using Record Level Access. On an \'add record\' the \'Order Number\' will be automatically incremented to the HIVAL plus 1.

Purchase Order / Description:
Customer Number: ">
Order Date: ">
Order Status:
Order Total: ">
Tax Percentage: ">
Warehouse Location:
Ship to Location: ">
Ship Date: ">
Invoice Number: ">
  1. Start With a \'Page at a Time\' Template. Add the file MU_ORDHF. Accept all other defaults. Choose whatever fields you like.


  2. Add
    crtlike(tmpOHORD, OHORD, "temperary OHORD");
    above the \'runtask\'s in \'Main\'.


  3. Add
    posrcd(MU_ORDHF, "*LAST", "*GT");
    getprvrcd(MU_ORDHF, "*NOKEY", "*YES");
    tmpOHORD = OHORD+1;
    clrrcd(MU_ORDHF);
    above the \'getparmset\' which gets all of your fields from the add screen. The reason for the temperary field and the clear record is because the getprvrcd will fill in all the fields in the file specified with the last record. When we write to the file however we may only want the user to specify some of the fields while the rest are left blank which won\'t happen if we don\'t clear the records.

  4. Add
    OHORD = tmpOHORD;
    directly below the \'getparmset\' mentioned in step 3.

  5. *The program works correctly at this point. You will notice that you can input a value for the key field OHORD but it is ignored because of the automatic increment. You may wish to make the field output only or take it out alltogether.

Program Definition:   autoincpml.pdw

Rate This Example

Did this knowledge base article help you to achieve your goal?  Yes  No  Don\'t Know

Enter additional comments below.   If you want to hear back from us, include your contact information.

'; } } PREVIEWS='*' { DEFAULT='Main List'; PREVIEW='Main List' { SEG='ListHeader'; SEG='ListDetails' { REPEAT='10'; } SEG='ListFooter'; SEG='ListPrev'; SEG='ListNext'; SEG='PageFooter'; SEG='addlink'; } PREVIEW='Display' { SEG='RcdDisplay'; } PREVIEW='Manage' { SEG='RcdManage'; } } ACTIONS='func Main() { // Program Name: AUTOINCPML // Program Title: auto increment on add using record level access // Created by: TEH // Template family: Examples // Template name: Page at a time maintenance // Purpose: Maintain a database file. Supports options for add, change, delete and display. // Program Modifications: // Determine which library list will be used setlibl("*FILES"); // Open all files openfile("*ALL"); //declare fields for rating the page crtfld(RPNUM, 5, "N", 0, "Number"); crtfld(RPTYPE, 1, "A", 0, "Page Type"); crtfld(RPSOPR, 1, "A", 0, "Solve Problem?"); crtfld(RPCOMM, 4000, "A", 0, "Comment"); crtfld(wsnum, 5, "N", 0, "Example number from exlist app"); crtfld(rtncod, 1, "A", 0, "valid smurf return code"); wsnum = getparm("wsnum"); skipsmurfchk(); // Instead do our own check rtncod = isvalidsmurf(); if(rtncod == "1") { gensmurfid("*IFNONE", "*DAY",1, "*YES", "*YES", "*YES"); //set cookie params for use in ws example rate this page feature setsmurf("wsnumb", wsnum); } else { wsnum = getsmurf("wsnumb"); } // append to URLs to make them unique crtfld(rnd,6,"A",0); rnd = numtoalpha(pgmf_curtime); // Starting and ending relative record numbers are used to control Next/Previous page of records crtfld(StartRRN, 9,"N",0,"Starting RRN"); crtfld(EndRRN, 9,"N",0,"Ending RRN"); // Record counter to determine how many records have been output to the list crtfld(rcdcnt, 5,"N",0,"Number of records written to list "); // Page size determines the maximum number of records (rows) contained in the list crtfld(listsize, 5,"N",0,"Page size of list-max records"); // Generic relative rcd number work field crtfld(rrn, 9, "N", 0, "Relative Record Number"); // get the saved relative record number to position the list crtfld(SavedRrn, 9, "A", 0, "Saved rrn"); crtlike(tmpOHORD, OHORD, "temperary OHORD"); // Set maximum list size to 20 for this program listsize=20; crtklist(PfKlist, OHORD); // Get rrn from URL to determine if a starting value was specified StartRRN = getparm("rrn"); // Tasks to control record list (default task is to display the list) runtask("DEFAULT", displist); runtask("prev", prev); // Task for the record display option runtask("disp", disprcd); // Tasks controlling record deletion runtask("delconf", delconf); runtask("del", deletercd); // Tasks controlling record management runtask("beginmanage", beginmanage); runtask("endmanage", endmanage); runtask("ajaxupdate",ajaxupdate); } func displist() { OHORD = getparm("OHORD"); if(OHORD == 0) { OHORD = 200082; } // Output header wrtseg(ListHeader); rcdcnt=0; // if we have a starting rrn, use that as the // starting point, else use keys if (StartRRN > 0) { MU_ORDHF.rrn = StartRRN; getrcd(MU_ORDHF, "*RRN", "*NO"); } posrcd(MU_ORDHF,PfKlist); getnxtrcd(MU_ORDHF); // if the key entered is past the end of the file then display the last record in the file if (MU_ORDHF.status <> RecordRetrieved) { posrcd(MU_ORDHF,"*LAST"); getnxtrcd(MU_ORDHF); } while ((MU_ORDHF.status == RecordRetrieved) and (rcdcnt < listsize)) { // assign the relative record number for use in page rrn = MU_ORDHF.rrn; // If it\'s the first time through, output the list header if (rcdcnt == 0) { // Save key value of last first record in list StartRRN = MU_ORDHF.rrn; } // output the list detail wrtseg(ListDetails, TRUE); // Save rrn value of last record in list EndRRN = MU_ORDHF.rrn; // get the next record rcdcnt = rcdcnt + 1; getnxtrcd(MU_ORDHF); } // close off the table wrtseg(ListFooter); // write the PREV link if necessary MU_ORDHF.rrn = StartRRN; getrcd(MU_ORDHF, "*RRN", "*NO"); posrcd(MU_ORDHF, pfklist); getprvrcd(MU_ORDHF); if (MU_ORDHF.status == RecordRetrieved) { wrtseg(ListPrev); } // write the Add Link wrtseg(AddLink); // write the NEXT link if necessary if (rcdcnt == listsize) { MU_ORDHF.rrn = EndRRN; getrcd(MU_ORDHF, "*RRN", "*NO"); posrcd(MU_ORDHF, pfklist,"*GT"); getnxtrcd(MU_ORDHF); if (MU_ORDHF.status == RecordRetrieved) { EndRRN = MU_ORDHF.rrn; wrtseg(ListNext); } } // close the page wrtseg(PageFooter); } // If TASK=PREV position file pointer at 1st record of previous list and read previous until // BOF or list size is reached. Then using save new starting key values and load list func prev() { MU_ORDHF.rrn = StartRRN; getrcd(MU_ORDHF, "*RRN", "*NO"); posrcd(MU_ORDHF,PfKlist); getprvrcd(MU_ORDHF); rcdcnt = 1; while ((MU_ORDHF.status == RecordRetrieved) and (rcdcnt < listsize)) { rcdcnt = rcdcnt + 1; getprvrcd(MU_ORDHF); } // Save key values as current list start location and display new list StartRRN = MU_ORDHF.rrn; displist(); } // Display details for selected record: func disprcd() { // get the relative record number parm rrn = getparm("rrn", "*MAND"); // get saved relative record number parm SavedRrn = getparm("FirstRowRRN"); // get the record from the file MU_ORDHF.rrn = rrn; getrcd(MU_ORDHF, "*RRN"); wrtseg(RcdDisplay, TRUE); } func delconf() { // get the relative record number parm rrn = getparm("rrn", "*MAND"); // get saved relative record number parm SavedRrn = getparm("FirstRowRRN"); // get the record from the file MU_ORDHF.rrn = rrn; getrcd(MU_ORDHF, "*RRN"); wrtseg(RcdDisplay, TRUE); } func deletercd() { // get the relative record number parm rrn = getparm("rrn", "*MAND"); // get saved relative record number parm SavedRrn = getparm("FirstRowRRN"); // get the record from the file MU_ORDHF.rrn = rrn; getrcd(MU_ORDHF, "*RRN"); // if the record to be deleted is the first record in the list, retrieve the previous // record and use that as the first record when the list is redisplayed if (rrn == alphatonum(savedrrn)) { // position by key posrcd(MU_ORDHF, pfklist); getprvrcd(MU_ORDHF); // set the list starting point savedrrn = numtoalpha(MU_ORDHF.rrn); // re-retrieve the record to be deleted MU_ORDHF.rrn = rrn; getrcd(MU_ORDHF, "*RRN"); } dltrcd(MU_ORDHF); // redirect back to the mainlist redirect("?rrn=" + SavedRrn); } // Present panel to prepare to Add or Change new record: func beginmanage() { // get the relative record number parm rrn = getparm("rrn", "*MAND"); // get saved relative record number parm SavedRrn = getparm("FirstRowRRN"); // get the record from the file MU_ORDHF.rrn = rrn; getrcd(MU_ORDHF, "*RRN"); // output the segment wrtseg(RcdManage, FALSE); } // Accept user input and pass to add or change record. func endmanage() { // create a field to capture the requested action crtfld(mode, 15,"A",0,"add or change?"); mode = getparm("mode"); // get saved relative record number parm SavedRrn = getparm("FirstRowRRN"); if(mode == "Add") { // get the parms posrcd(MU_ORDHF, "*LAST", "*GT"); getprvrcd(MU_ORDHF, "*NOKEY", "*YES"); tmpOHORD = OHORD+1; clrrcd(MU_ORDHF); getparmset(OHDESC, OHCUST, OHORDT, OHSTAT, OHOTOT, OHTAX, OHWHSE, OHCUSH, OHSHPDT, OHINV); OHORD = tmpOHORD; // do any validation // write the record wrtrcd(MU_ORDHF); } if(mode == "Change") { // get the relative record number parm rrn = getparm("rrn", "*MAND"); // get the record from the file MU_ORDHF.rrn = rrn; getrcd(MU_ORDHF, "*RRN"); // get the parms getparmset(OHDESC, OHCUST, OHORDT, OHSTAT, OHOTOT, OHTAX, OHWHSE, OHCUSH, OHSHPDT, OHINV); updrcd(MU_ORDHF); } // redirect back to the mainlist redirect("?rrn=" + SavedRrn, "*SAME", "rand"); } func ajaxupdate (){ //get \'rate this page\' form values getparmset(RPNUM,RPTYPE,RPSOPR,RPCOMM); //redirect to non-cgi to write to ratepg file call("RATEPAGE","W_WEBPUB",RPNUM,RPTYPE,RPSOPR,RPCOMM); //output acknowledgment wrthtml("

Rate This Example

Thank you for your feedback!

"); } '; }