ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Deleting single record from subfile,how???

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Re: Deleting single record from subfile,how???

    I cranked this out real quick, so there might be some dumb stuff inside:

    Display File - SubFileD

    Code:
     
         A*%%TS  SD  20110310  104809  QPGMR       REL-V6R1M0  5761-WDS       
         A*%%EC                                                               
         A                                      DSPSIZ(24 80 *DS3)            
         A                                      CF03(03)                      
         A                                      CF05(05)                      
         A                                      INDARA                        
         A          R SFLA                      SFL                           
         A*%%TS  SD  20110310  104809  QPGMR       REL-V6R1M0  5761-WDS       
         A            OPTION         1Y 0B  6  4COLOR(WHT)                    
         A                                      EDTCDE(Z)                     
         A            DAYNUMBER      1  0O  6  8                              
         A            DAYNAME       10   O  6 12                              
         A          R SFLB                      SFLCTL(SFLA)                  
         A*%%TS  SD  20110310  104809  QPGMR       REL-V6R1M0  5761-WDS       
         A                                      SFLSIZ(0010)                  
         A                                      SFLPAG(0009)                  
         A N92                                  ROLLUP                        
         A                                      OVERLAY                       
         A  90                                  SFLDSP                           
         A                                      SFLDSPCTL                        
         A  91                                  SFLCLR                           
         A  92                                  SFLEND(*MORE)                    
         A            PGRRN          4S 0H      SFLRCDNBR                        
         A                                  5  2'Opt'                            
         A                                      COLOR(PNK)                       
         A                                      DSPATR(UL)                       
         A                                  1 22'Jamies Subfile Delete Program'  
         A                                      COLOR(WHT)                       
         A                                  5  6'Day#'                           
         A                                      COLOR(PNK)                       
         A                                      DSPATR(UL)                       
         A                                  5 12'Day Name  '                     
         A                                      COLOR(PNK)                       
         A                                      DSPATR(UL)                       
         A                                  4  4'Option 4 - Delete'              
         A                                      COLOR(WHT)                       
         A          R FOOTER                                                     
         A*%%TS  SD  20110310  102702  QPGMR       REL-V6R1M0  5761-WDS          
         A                                 23  2'F3-Exit'                    
         A                                      COLOR(WHT)                   
         A          R ASSUME                                                 
         A*%%TS  SD  20100814  163357  QPGMR       REL-V6R1M0  5761-WDS      
         A                                  1  3' '
    Program - SubFile

    Code:
     **************************************************************************          
     *                                                                                   
     *  Program - S U B F I L E                                                          
     *            Jaime's Delete Subfile Record Program                                  
     *                                                                                   
     *  Copyright (c) 1996,2010  Michael Catalani                                        
     *                           901.581.8791 cell phone                                 
     *                           901.672.7572 home phone                                 
     *                                                                                   
     *  Description - Program shows how to delete a sngle subfile record                 
     *                using data structures                                              
     *                                                                                   
     *                Using option 4 next to an subfile record will                      
     *                cause it to be removed frmo the subfile                            
     *                                                                                   
     *************************************************************************           
     
    h DftActGrp( *No )                                                                   
     
    fSubfileD  cf   e             Workstn                                       
    f                                     SFILE( SflA : PgRRN )                 
    f                                     IndDS( DisplayDS )                    
     
     *** Program Variables ***                                                  
    d PgRRN           s              4s 0                                       
     
     *** Display File Indicators Data Structure ***                             
    d DisplayDS       ds                                                        
    d  ExitKeyPressed...                                                        
    d                         3      3n                                         
    d  DisplaySubfile...                                                        
    d                        90     90n                                         
    d  DeleteSubfile         91     91n                                         
    d  EndOfSubfile          92     92n                                         
     
     *** Program DataStructures ***                                             
    d SubfileDS       ds                  LikeRec( SflA : *All )                
     
     *** ProtoTypes ***                                                         
    d ClearSubFile    pr                                                                   
     
    d DisplayScreen   pr                                                                   
     
    d LoadSubFile     pr                                                                   
     
    d SetSubFileStatus...                                                                  
    d                 pr                                                                   
     
    d RemoveDeletedSubfileRecords...                                                       
    d                 pr                                                                   
     
     **********************************************                                        
     * Main Procedure                                                                      
     **********************************************                                        
     /free                                                                                 
     
      LoadSubfile();                                                                       
     
      dow NOT ExitKeyPressed;                                                              
    d ClearSubFile    pr                                                                   
     
    d DisplayScreen   pr                                                                   
     
    d LoadSubFile     pr                                                                   
     
    d SetSubFileStatus...                                                                  
    d                 pr                                                                   
     
    d RemoveDeletedSubfileRecords...                                                       
    d                 pr                                                                   
     
     **********************************************                                        
     * Main Procedure                                                                      
     **********************************************                                        
     /free                                                                                 
     
      LoadSubfile();                                                                       
     
      dow NOT ExitKeyPressed;                                                              
          when Option = 4;                                                
          // put delete code here                                         
      //  for LoadIndex = 1 to PgRRN;                                     
      //    SubFileSave( LoadIndex ) = SubfileDS;                         
      //  ClearSubfile;                                                   
      //  leave;                                                          
        endsl;                                                            
     
        Option = 0;                                                       
         update SflA;                                                     
        readc(e) SflA;                                                    
      enddo;                                                              
     
      write Footer;                                                       
      exfmt SflB;                                                         
     /end-free                                                            
    p                 e                                                   
     
     **********************************************                       
     * ClearSubfile Subprocedure                                          
     **********************************************                    
    p ClearSubFile    b                                                
    d                 pi                                               
     /free                                                             
      DeleteSubfile = *on;                                             
      write SflB;                                                      
      DeleteSubfile = *off;                                            
      EndOfSubfile = *off;                                             
      PgRRN = 0;                                                       
     /end-free                                                         
    p                 e                                                
     
     **********************************************                    
     *  LoadSubfile SubProcedure                                       
     **********************************************                    
    p LoadSubFile     b                                                
    d                 pi                                               
     
    d                 ds                                               
    d  Day                          70a   Inz('Monday    +             
    d                                          Tuesday   +               
    d                                          Wednesday +               
    d                                          Thursday  +               
    d                                          Friday    +               
    d                                          Saturday  +               
    d                                          Sunday   ')               
    d  DayArray                     10a   overlay(Day) dim(7)            
    d  DayNumber      s              1s 0                                
     
     /free                                                               
     
      for PgRRN = 1 to 7;                                                
        SubFileDS.DayNumber = PgRRN;                                     
        SubFileDS.DayName = DayArray( PgRRN );                           
        SubFileDS.Option = 0;                                            
     
        write SflA SubFileDS;                                            
      endfor;                                                            
     
      SetSubfileStatus();                                                
     
      return;                                             
     
     /end-free                                            
    p                 e                                   
     
     **********************************************       
     *  SetSubfileStatus Subprocedure                     
     **********************************************       
    p SetSubfileStatus...                                 
    p                 b                                   
    d                 pi                                  
     
     /free                                                
     
      EndOfSubfile = *on;                                 
     
      if PgRRN > 0;                                       
        DisplaySubfile = *on;                             
        PgRRN = 1;                           
      else;                                                                   
        DisplaySubfile = *off;                                                
      endif;                                                                  
     
      return;                                                                 
     
     /end-free                                                                
    p                 e                                                       
     
     
     **********************************************                           
     *  RemoveDeletedSubfileRecords Subprocedure                              
     **********************************************                           
    p RemoveDeletedSubfileRecords...                                          
    p                 b                                                       
    d                 pi                                                      
     
    d SubFileSaveDS   ds                  LikeDS( SubFileDS ) Dim( 9999 )     
     
    d SaveIndex       s             10i 0                                     
    d Index           s             10i 0                          
     
     /free                                                         
     
      SaveIndex = 1;                                               
      chain SaveIndex Sfla SubFileDS;                              
      dow %found( SubfileD );                                      
        eval-corr SubFileSaveDS( SaveIndex ) = SubFileDS;          
        SaveIndex +=1;                                             
        chain SaveIndex Sfla SubFileDS;                            
      enddo;                                                       
     
      ClearSubfile();                                              
     
      for Index = 1 to SaveIndex - 1;                              
        if SubFileSaveDS( Index ).Option <> 4;                     
          PgRRN +=1;                                               
          write Sfla SubfileSaveDS( Index );                       
        endif;                                                     
      endfor;                                                      
     
      SetSubfileStatus();                   
     
      return;                               
     
     /end-free                              
    p                 e
    Last edited by MichaelCatalani; March 10, 2011, 11:34 AM.
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

    Comment


    • #17
      Re: Deleting single record from subfile,how???

      Code:
       **********************************************                         
       *  RemoveDeletedSubfileRecords Subprocedure                            
       **********************************************                         
      p RemoveDeletedSubfileRecords...                                        
      p                 b                                                     
      d                 pi                                                    
                                                                              
      d SubFileSaveDS   ds                  LikeDS( SubFileDS ) Dim( 9999 )   
                                                                              
      d SaveIndex       s             10i 0                                   
      d Index           s             10i 0                                   
                                                                              
       /free                                                                  
                                                                              
        SaveIndex = 1;                                                        
        chain SaveIndex Sfla SubFileDS;                                       
        dow %found( SubfileD );                                               
          eval-corr SubFileSaveDS( SaveIndex ) = SubFileDS;                   
          SaveIndex +=1;                                                      
          chain SaveIndex Sfla SubFileDS;                                     
        enddo;                                               
                                                             
        ClearSubfile();                                      
                                                             
        for Index = 1 to SaveIndex - 1;                      
          if SubFileSaveDS( Index ).Option <> 4;             
            PgRRN +=1;                                       
            write Sfla SubfileSaveDS( Index );               
          endif;                                             
        endfor;                                              
                                                             
        SetSubfileStatus();                                  
                                                             
        return;                                              
                                                             
       /end-free                                             
      p                 e

      This subprocedure is the heart of the subfile delete code. These are the steps this subprocedure is performing:

      1) Reading Every Subfile Record & Loading Into A Save Data Structure
      2) Clearing The Subfile
      3) Load The Records From The Save Data Structure Back Into The Subfile If They Werent Flagged For Deletion
      Michael Catalani
      IS Director, eCommerce & Web Development
      Acceptance Insurance Corporation
      www.AcceptanceInsurance.com
      www.ProvatoSys.com

      Comment


      • #18
        Re: Deleting single record from subfile,how???

        First I have to say Thanks Michael, then I need to apologize..
        I took your example and beat the snot outta it with an ugly stick..

        (you do write some purtty code )

        anyway I needed to take an existing subfile and allow users to duplicate
        a specfic record. I allowed them to place cursor on line, press < F2 > and
        then duplicate the line changing some fields..

        THis is just a proof of concept prior to implementation, but it does
        stand on its own as an example. I'm still on V5R4 so I had to use both
        the *INPUT & *OUTPUT instead of *ALL.

        DDS
        PHP Code:
             A*%%TS  SD  20110310  095110  FLANARY     REL-V5R4M0  5722-WDS                                 
             A
        *%%EC                                                                                         
             A                                      DSPSIZ
        (24 80 *DS3)                                      
             
        A                                      REF(*LIBL/LBAFREF)                                      
             
        A                                      PRINT                                                   
             
        A                                      INDARA                                                  
             A                                      CF01                                                    
             A                                      CF02                                                    
             A                                      CF03                                                    
             A                                      CF04                                                    
             A                                      CF05                                                    
             A                                      CF06                                                    
             A                                      CF07                                                    
             A                                      CF08                                                    
             A                                      CF09                                                    
             A                                      CF10                                                    
             A                                      CF11                                                    
             A                                      CF12                                                    
             A                                      CF13                                                    
             A                                      CF14                                                    
             A                                      CF15                                                    
             A                                      CF16                                                    
             A                                      CF17                                                    
             A                                      CF18                                                    
             A                                      CF19                                                    
             A                                      CF20                                                    
             A                                      CF21                                                    
             A                                      CF22                                                    
             A                                      CF23                                                    
             A                                      CF24                                                    
             A                                      PAGEDOWN                                                
             A                                      PAGEUP                                                  
             A
        **************************************************************************                    
             
        A          R SUB01                     SFL                                                     
             A
        *%%TS  SD  20110310  094247  FLANARY     REL-V5R4M0  5722-WDS                                 
             A            S1OPT          1A  B  9  7                                                        
             A            S1NOTE        14A  B  9 10                                                        
             A            S1QTY          4Y 0B  9 25EDTCDE
        (Z)                                               
             
        A            S1WEIGHT       5Y 0B  9 30EDTCDE(Z)                                               
             
        A**************************************************************************                    
             
        A          R SUB01CTL                  SFLCTL(SUB01)                                           
             
        A*%%TS  SD  20110310  093029  FLANARY     REL-V5R4M0  5722-WDS                                 
             A                                      SFLSIZ
        (0014)                                            
             
        A                                      SFLPAG(0005)                                            
             
        A                                      RTNCSRLOC(&#REC &#FLD &#POS)                            
             
        A  99                                  ALARM                                                   
             A                                      OVERLAY                                                 
             A                                      SFLCSRRRN
        (&WHERE)                                       
             
        A  31                                  SFLDSP                                                  
             A  32                                  SFLDSPCTL                                               
             A  30                                  SFLCLR                                                  
             A  33                                  SFLEND
        (*MORE)                                           
             
        A            SCRRN          4S 0H      SFLRCDNBR                                               
             A                                  1  2DATE                                                    
             A                                      EDTCDE
        (Y)                                               
             
        A                                  1 12TIME                                                    
             A            C1COMPANY     30A  O  1 26DSPATR
        (HI)                                              
             
        A            C1TITLE       40A  O  2 21DSPATR(HI)                                              
             
        A                                  5  4'Type options, press Enter'                             
             
        A                                      COLOR(BLU)                                              
             
        A            HDPROGRAM     10A  O  1 71                                                        
             A            
        #REC          10A  H                                                              
             
        A            #FLD          10A  H                                                              
             
        A            #POS           4S 0H                                                              
             
        A            WHERE          5S 0H                                                              
             A                                  6  6
        '2=Edit'                                                
             
        A                                      COLOR(BLU)                                              
             
        A                                  6 14'3=Copy'                                                
             
        A                                      COLOR(BLU)                                              
             
        A                                  6 23'5=Display'                                             
             
        A                                      COLOR(BLU)                                              
             
        A                                  8 12'Some data'                                             
             
        A                                      DSPATR(HI)                                              
             
        A                                      DSPATR(UL)                                              
             
        A                                  8  6'Opt'                                                   
             
        A                                      DSPATR(HI)                                              
             
        A                                      DSPATR(UL)                                              
             
        A**************************************************************************                    
             
        A          R FKEY01                                                                            
             A
        *%%TS  SD  20110310  093851  FLANARY     REL-V5R4M0  5722-WDS                                 
             A                                 23 14
        'F3=Exit'                                               
             
        A                                      COLOR(BLU)                                              
             
        A                                 23  4'F2=Break'                                              
             
        A                                      COLOR(BLU)                                              
             
        A          R DUMMY                                                                             
             A
        *%%TS  SD  20110310  095110  FLANARY     REL-V5R4M0  5722-WDS                                 
             A                                      ASSUME                                                  
             A                                  1  3
        ' '                                                     
             
        A          R WINDOW                                                                            
             A
        *%%TS  SD  20110310  095110  FLANARY     REL-V5R4M0  5722-WDS                                 
             A                                      WINDOW
        (5 12 7 38 *NOMSGLIN *NORSTCS-                    
             
        A                                      R)                                                      
             
        A                                  1  1'Break line#'                                           
             
        A            W1LINE#        4Y 0O  1 13EDTCDE(Z)                                               
             
        A                                  3  3'Bundles:'                                              
             
        A            W1BUNDLES      2Y 0B  3 12EDTCDE(Z)                                               
             
        A                                  4  4'Adjust Quantities:'                                    
             
        A            W1ADJUST       1   B  4 23                                                        
             A                                  4 26
        'N=No, Y=Yes'                                           
             
        A                                      DSPATR(HI)                                              
             
        A                                  3 16'(1-99)'                                                
             
        A                                      DSPATR(HI)                                              
             
        A                                  7  2'F3=Exit'                                               
             
        A                                      COLOR(BLU)                                              
             
        A                                  1 24'Quantity'                                              
             
        A            W1QUANTITY     4Y 0O  1 33EDTCDE(Z
        RPG

        PHP Code:
              //---------------------------------------------------                                         
              // Program -                                                                                  
              // Purpose -                                                                                  
              // Written - xx/xx/xx                                                                         
              // Author  - xxxxxxxxxxxxxxxxxxxx                                                             
              //                                                                                            
              // INPUT PARAMETERS                                                                           
              //   Description        Type  Size    How Used                                                
              //   -----------        ----  ----    --------                                                
              //                                                                                            
              // INDICATOR USAGE                                                                            
              //   03 - leave                                                                               
              //---------------------------------------------------                                         
             
        fDROP2AD   cf   e             workstn INFDS(INFDS)                                             
             
        f                                     SFILE(SUB01:RRN1)                                        
                                                                                                            
             
        d sub01DS         ds                  LIKEREC(SUB01 : *input)                                  
             
        d sub01OutDS      ds                  LIKEREC(SUB01 : *output)                                 
                                                                                                            
             
        d AllSubRec       s                   Like(Sub01DS)                                            
             
        d                                     Dim(9999Ascend                                         
                                                                                                            
              
        // Data Structures                                                                            
             
        d Infds           ds                                                       INFDS data structure
             d Choice                369    369                                                             
             d Currec                378    379B 0                                                          
                                                                                                            
              
        // Command Keys                                                                               
                                                                                                            
             
        d Cmd01           c                   const(x'31')                         Cmd-1               
             d BreakLine       c                   
        const(x'32')                         Cmd-2               
             d LeaveProgram    c                   
        const(x'33')                         Cmd-3               
             d Cmd04           c                   
        const(x'34')                         Cmd-4               
             d Cmd05           c                   
        const(x'35')                         Cmd-5               
             d Cmd06           c                   
        const(x'36')                         Cmd-6               
             d Cmd07           c                   
        const(x'37')                         Cmd-7               
             d Cmd08           c                   
        const(x'38')                         Cmd-8               
             d Cmd09           c                   
        const(x'39')                         Cmd-9               
             d Cmd10           c                   
        const(x'3A')                         Cmd-10              
             d Cmd11           c                   
        const(x'3B')                         Cmd-11              
             d Cmd12           c                   
        const(x'3C')                         Cmd-12              
             d Cmd13           c                   
        const(x'B1')                         Cmd-13              
             d Cmd14           c                   
        const(x'B2')                         Cmd-14              
             d Cmd15           c                   
        const(x'B3')                         Cmd-15              
             d Cmd16           c                   
        const(x'B4')                         Cmd-16              
             d Cmd17           c                   
        const(x'B5')                         Cmd-17              
             d Cmd18           c                   
        const(x'B6')                         Cmd-18              
             d Cmd19           c                   
        const(x'B7')                         Cmd-19              
             d Cmd20           c                   
        const(x'B8')                         Cmd-20              
             d Cmd21           c                   
        const(x'B9')                         Cmd-21              
             d Cmd22           c                   
        const(x'BA')                         Cmd-22              
             d Cmd23           c                   
        const(x'BB')                         Cmd-23              
             d Cmd24           c                   
        const(x'BC')                         Cmd-24              
             d EnterKey        c                   
        const(x'F1')                                             
             
        d RollUp          c                   const(x'F5')                         Roll Up             
             d RollDown        c                   
        const(x'F4')                         Roll Down           
                                                                                                            
                                                                                                            
              
        //                                                                                            
              // Program Info                                                                               
              //                                                                                            
             
        d                SDS                                                                           
             d  
        @PGM                 001    010                                                             
             d  
        @PARMS               037    039  0                                                          
             d  
        @MSGDTA               91    170                                                             
             d  
        @MSGID               171    174                                                             
             d  
        @JOB                 244    253                                                             
             d  
        @USER                254    263                                                             
             d  
        @JOB#                264    269  0                                                          
              //                                                                                            
              // Variables                                                                                  
              //                                                                                            
                                                                                                            
             
        d count           s              4  0                                                          
             d count2          s              4  0                                                          
             d ds
        #             s              3  0                                                          
             
        d EndScreen1      s              1    inz('N')                                                 
             
        d removerrn       s                   like(SCRRN)                                              
             
        d RRN1            s                   like(SCRRN)                                              
             
        d Savrrn          s                   like(SCRRN)                                              
             
        d ScreenError     s              1    inz('N')                                                 
              
        //                                                                                            
              // Break apart the time stamp                                                                 
              //                                                                                            
              //---------------------------------------------------                                         
              //       C a l c u l a t i o n  S p e c s                                                     
              //---------------------------------------------------                                         
              
        /free                                                                                         
                                                                                                            
                 exsr $Screen1
        ;                                                                             
                 *
        inlr = *on;                                                                               
                                                                                                            
               
        //===========================================                                                
               //  $Screen1 - Display all parts allow for                                                   
               //             Search.                                                                       
               //===========================================                                                
                                                                                                            
                 
        begsr $Screen1;                                                                            
                   
        //                                                                                       
                   
        reset EndScreen1;                                                                        
                   
        dow EndScreen1 'N';                                                                    
                                                                                                            
                     
        write FKEY01;                                                                          
                     
        exfmt SUB01CTL;                                                                        
                                                                                                            
                     if 
        Currec <> *Zeros;                                                                   
                       
        RRN1    =  Currec;                                                                   
                       
        SCRRN   =  Currec;                                                                   
                     endif;                                                                                 
                                                                                                            
                     
        reset ScreenError;                                                                     
                                                                                                            
                     
        select;                                                                                
                       
        // F2 pressed break the line                                                         
                      
        when  Choice BreakLine;                                                             
                       
        exsr $breakline;                                                                     
                                                                                                            
                       
        // F3 pressed end the program F3 = LeaveProgram                                      
                      
        when  Choice LeaveProgram;                                                          
                       
        EndScreen1 'Y';                                                                    
                                                                                                            
                      
        when  Choice Rollup;                                                                
                                                                                                            
                      
        other;                                                                                
                       
        exsr $process;                                                                       
                     
        endsl;                                                                                 
                    
        enddo;                                                                                  
                                                                                                            
               
        endsr;                                                                                       
                                                                                                            
               
        //===========================================                                                
               // $Process - Process the subfile(1)                                                         
               //===========================================                                                
               
        begsr $Process;                                                                              
                                                                                                            
               
        endsr;                                                                                       
                                                                                                            
               
        //===========================================                                                
               // $BreakLine - Break the subfile line                                                       
               //===========================================                                                
               
        begsr $BreakLine;                                                                            
                                                                                                            
                
        // identify the line to break                                                               
                
        if where > *zeros;                                                                          
                 
        removerrn where;                                                                         
                 
        chain where sub01;                                                                         
                 if %
        found(DROP2AD);                                                                        
                  
        w1quantity s1qty;                                                                       
                  
        w1line# = where;                                                                          
                  
        clear w1bundles;                                                                          
                  
        w1adjust 'N';                                                                           
                  
        exfmt window;                                                                             
                 endif;                                                                                     
                endif;                                                                                      
                                                                                                            
                
        // clear the array that holds subfile data                                                  
                
        clear allsubrec;                                                                            
                
        clear ds#;                                                                                  
                                                                                                            
                // Load all records from subfile into datastructure                                         
                
        for count 1 to savrrn;                                                                    
                 
        chain count SUB01  sub01ds;                                                                
                 if %
        found(DROP2AD);                                                                        
                  
        ds# +=1;                                                                                  
                  
        allsubrec(ds#) = sub01ds;                                                                 
                 
        endif;                                                                                     
                endfor;                                                                                     
                                                                                                            
                
        // clear subfile & rewrite with additional records                                          
                
        exsr $clearsfl;                                                                             
                                                                                                            
                for 
        count 1 to ds#;                                                                       
                  
        if count <> removerrn;                                                                    
                   
        rrn1 +=1;                                                                                
                   
        scrrn RRN1;                                                                            
                   
        sub01OUTds allsubrec(count);                                                           
                   
        write SUB01 sub01OUTds;                                                                  
                  else;                                                                                     
                   
        sub01OUTds allsubrec(count);  // original subfile line                                 
                   
        for count2 1 to  w1bundles;                                                            
                    
        savrrn +=1;     // increment the original subfile record count                          
                    
        rrn1 +=1;                                                                               
                    
        scrrn RRN1;                                                                           
                    
        write SUB01 sub01OUTds;                                                                 
                   endfor;                                                                                  
                  endif;                                                                                    
                endfor;                                                                                     
                                                                                                            
               
        endsr;                                                                                       
               
        //===========================================                                                
               //  $ClearSFL- Clear the route error sub                                                     
               //===========================================                                                
               
        begsr $clearsfl;                                                                             
                                                                                                            
                 *
        in31  = *Off;                                                                             
                 *
        in32  = *Off;                                                                             
                 *
        in30  = *On;                                                                              
                                                                                                            
                 
        write SUB01CTL;                                                                            
                                                                                                            
                 *
        in31  = *On;                                                                              
                 *
        in32  = *On;                                                                              
                 *
        in30  = *Off;                                                                             
                                                                                                            
                 
        clear RRN1;                                                                                
                 
        clear SCRRN;                                                                               
                 
        clear SavRrn;                                                                              
                                                                                                            
                 *
        in33 = *off;                                                                              
               
        endsr;                                                                                       
                                                                                                            
               
        //===========================================                                                
               //  $LoadSfl  - Load up the route errors                                                     
               //===========================================                                                
                
        begsr $loadsfl;                                                                             
                                                                                                            
                 if 
        SavRrn  > *Zeros;                                                                       
                  
        rrn1  savrrn;                                                                           
                  
        scrrn savrrn;                                                                           
                 endif;                                                                                     
                 
        //                                                                                         
                       
        for count 1 to 5;                                                                  
                        
        RRN1  +=1;                                                                          
                        
        SCRRN  RRN1;                                                                      
                        
        S1note 'ABRF23A' + %char(rrn1);                                                   
                        
        s1Qty count rrn1;                                                               
                        
        s1weight 12.34 s1qty;                                                           
                        
        write SUB01;                                                                        
                       endfor;                                                                              
                                                                                                            
                 
        //                                                                                         
                 
        savrrn scrrn;                                                                            
                                                                                                            
                 
        //                                                                                         
                 //  If no records in subfile then do not disply the subfile.                               
                 //                                                                                         
                                                                                                            
                 
        if SavRrn  = *zeros;                                                                       
                   *
        in31 = *off;                                                                            
                 endif;                                                                                     
                                                                                                            
                 
        //                                                                                         
               
        endsr;                                                                                       
                                                                                                            
               
        //=================================================                                          
               //  *inzsr - One time run processing                                                         
               //=================================================                                          
               
        begsr *inzsr;                                                                                
                                                                                                            
                 
        exsr $clearsfl;                                                                            
                 
        exsr $loadsfl;                                                                             
                                                                                                            
               
        endsr;                                                                                       
                                                                                                            
              /
        end-free 
        Attached Files
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #19
          Re: Deleting single record from subfile,how???

          Okay ---

          changes the AllSubRec stand alone field should have been a DS which forces the Like(SUb01DS) to LikeDS(Sub01DS)


          PHP Code:
              d AllSubRec       ds                  LikeDs(Sub01DS)                                          
               
          d                                     Dim(9999
          This is really important bacause you need eval-corr to skip the indicators
          that are capture with the *output datastructure..


          What this means in English is the *output ds pulls in more fields than the *input ds..
          so if you do a straight move/eval the data gets WRECKED!

          You wont see this in this example, but if you add a position cursor then trouble comes following.


          dds
          PHP Code:
               A*%%TS  SD  20110311  091937  FLANARY     REL-V5R4M0  5722-WDS                                 
               A
          *%%EC                                                                                         
               A                                      DSPSIZ
          (24 80 *DS3)                                      
               
          A                                      REF(*LIBL/LBAFREF)                                      
               
          A                                      PRINT                                                   
               
          A                                      INDARA                                                  
               A                                      CF01                                                    
               A                                      CF02                                                    
               A                                      CF03                                                    
               A                                      CF04                                                    
               A                                      CF05                                                    
               A                                      CF06                                                    
               A                                      CF07                                                    
               A                                      CF08                                                    
               A                                      CF09                                                    
               A                                      CF10                                                    
               A                                      CF11                                                    
               A                                      CF12                                                    
               A                                      CF13                                                    
               A                                      CF14                                                    
               A                                      CF15                                                    
               A                                      CF16                                                    
               A                                      CF17                                                    
               A                                      CF18                                                    
               A                                      CF19                                                    
               A                                      CF20                                                    
               A                                      CF21                                                    
               A                                      CF22                                                    
               A                                      CF23                                                    
               A                                      CF24                                                    
               A N41N45                               PAGEDOWN                                                
               A                                      PAGEUP                                                  
               A
          **************************************************************************                    
               
          A          R SUB01                     SFL                                                     
               A
          *%%TS  SD  20110310  094247  FLANARY     REL-V5R4M0  5722-WDS                                 
               A            S1OPT          1A  B  9  7                                                        
               A            S1NOTE        14A  B  9 10                                                        
               A            S1QTY          4Y 0B  9 25EDTCDE
          (Z)                                               
               
          A            S1WEIGHT       5Y 0B  9 30EDTCDE(Z)                                               
               
          A**************************************************************************                    
               
          A          R SUB01CTL                  SFLCTL(SUB01)                                           
               
          A*%%TS  SD  20110310  144931  FLANARY     REL-V5R4M0  5722-WDS                                 
               A                                      RTNCSRLOC
          (&#REC &#FLD &#POS)                            
               
          A  99                                  ALARM                                                   
               A                                      OVERLAY                                                 
               A                                      SFLCSRRRN
          (&WHERE)                                       
               
          A  31                                  SFLDSP                                                  
               A  32                                  SFLDSPCTL                                               
               A  30                                  SFLCLR                                                  
               A  33                                  SFLEND
          (*MORE)                                           
               
          A                                      SFLSIZ(0014)                                            
               
          A                                      SFLPAG(0012)                                            
               
          A            SCRRN          4S 0H      SFLRCDNBR                                               
               A                                  1  2DATE                                                    
               A                                      EDTCDE
          (Y)                                               
               
          A                                  1 12TIME                                                    
               A            C1COMPANY     30A  O  1 26DSPATR
          (HI)                                              
               
          A            C1TITLE       40A  O  2 21DSPATR(HI)                                              
               
          A                                  5  4'Type options, press Enter'                             
               
          A                                      COLOR(BLU)                                              
               
          A            HDPROGRAM     10A  O  1 71                                                        
               A            
          #REC          10A  H                                                              
               
          A            #FLD          10A  H                                                              
               
          A            #POS           4S 0H                                                              
               
          A            WHERE          5S 0H                                                              
               A                                  6  6
          '2=Edit'                                                
               
          A                                      COLOR(BLU)                                              
               
          A                                  6 14'3=Copy'                                                
               
          A                                      COLOR(BLU)                                              
               
          A                                  6 23'5=Display'                                             
               
          A                                      COLOR(BLU)                                              
               
          A                                  8 12'Some data'                                             
               
          A                                      DSPATR(HI)                                              
               
          A                                      DSPATR(UL)                                              
               
          A                                  8  6'Opt'                                                   
               
          A                                      DSPATR(HI)                                              
               
          A                                      DSPATR(UL)                                              
               
          A**************************************************************************                    
               
          A          R FKEY01                                                                            
               A
          *%%TS  SD  20110310  093851  FLANARY     REL-V5R4M0  5722-WDS                                 
               A                                 23 14
          'F3=Exit'                                               
               
          A                                      COLOR(BLU)                                              
               
          A                                 23  4'F2=Break'                                              
               
          A                                      COLOR(BLU)                                              
               
          A          R DUMMY                                                                             
               A
          *%%TS  SD  20110310  095110  FLANARY     REL-V5R4M0  5722-WDS                                 
               A                                      ASSUME                                                  
               A                                  1  3
          ' '                                                     
               
          A          R WINDOW                                                                            
               A
          *%%TS  SD  20110311  091937  FLANARY     REL-V5R4M0  5722-WDS                                 
               A                                      WINDOW
          (9 32 7 38 *NOMSGLIN *NORSTCS-                    
               
          A                                      R)                                                      
               
          A                                  1  1'Break line#'                                           
               
          A            W1LINE#        4Y 0O  1 13EDTCDE(Z)                                               
               
          A                                  3  2'Bundles  :'                                            
               
          A            W1BUNDLES      2Y 0B  3 13EDTCDE(Z)                                               
               
          A                                  3 19'(1-99)'                                                
               
          A                                      DSPATR(HI)                                              
               
          A                                  7  2'F3=Exit'                                               
               
          A                                      COLOR(BLU)                                              
               
          A                                  1 24'Quantity'                                              
               
          A            W1QUANTITY     4Y 0O  1 33EDTCDE(Z)                                               
               
          A                                  4  2'Quantity :'                                            
               
          A            W1QTY          3Y 0B  4 13EDTCDE(Z)                                               
               
          A                                  4 19'(1-9999)'                                              
               
          A                                      DSPATR(HI

          RPG
          PHP Code:
                //---------------------------------------------------                                         
                // Program -                                                                                  
                // Purpose -                                                                                  
                // Written - xx/xx/xx                                                                         
                // Author  - xxxxxxxxxxxxxxxxxxxx                                                             
                //                                                                                            
                // INPUT PARAMETERS                                                                           
                //   Description        Type  Size    How Used                                                
                //   -----------        ----  ----    --------                                                
                //                                                                                            
                // INDICATOR USAGE                                                                            
                //   03 - leave                                                                               
                //---------------------------------------------------                                         
               
          fDROP2AD   cf   e             workstn INFDS(INFDS)                                             
               
          f                                     SFILE(SUB01:RRN1)                                        
                                                                                                              
                
          // Data Structures                                                                            
               
          d Infds           ds                                                       INFDS data structure
               d Choice                369    369                                                             
               d Currec                378    379B 0                                                          
                                                                                                              
               d sub01DS         ds                  LIKEREC
          (SUB01 : *input)                                  
               
          d sub01OutDS      ds                  LIKEREC(SUB01 : *output)                                 
                                                                                                              
               
          d AllSubRec       ds                  LikeDs(Sub01DS)                                          
               
          d                                     Dim(9999)                                                
                                                                                                              
                
          // Command Keys                                                                               
                                                                                                              
               
          d Cmd01           c                   const(x'31')                         Cmd-1               
               d BreakLine       c                   
          const(x'32')                         Cmd-2               
               d LeaveProgram    c                   
          const(x'33')                         Cmd-3               
               d Cmd04           c                   
          const(x'34')                         Cmd-4               
               d Cmd05           c                   
          const(x'35')                         Cmd-5               
               d Cmd06           c                   
          const(x'36')                         Cmd-6               
               d Cmd07           c                   
          const(x'37')                         Cmd-7               
               d Cmd08           c                   
          const(x'38')                         Cmd-8               
               d Cmd09           c                   
          const(x'39')                         Cmd-9               
               d Cmd10           c                   
          const(x'3A')                         Cmd-10              
               d Cmd11           c                   
          const(x'3B')                         Cmd-11              
               d Cmd12           c                   
          const(x'3C')                         Cmd-12              
               d Cmd13           c                   
          const(x'B1')                         Cmd-13              
               d Cmd14           c                   
          const(x'B2')                         Cmd-14              
               d Cmd15           c                   
          const(x'B3')                         Cmd-15              
               d Cmd16           c                   
          const(x'B4')                         Cmd-16              
               d Cmd17           c                   
          const(x'B5')                         Cmd-17              
               d Cmd18           c                   
          const(x'B6')                         Cmd-18              
               d Cmd19           c                   
          const(x'B7')                         Cmd-19              
               d Cmd20           c                   
          const(x'B8')                         Cmd-20              
               d Cmd21           c                   
          const(x'B9')                         Cmd-21              
               d Cmd22           c                   
          const(x'BA')                         Cmd-22              
               d Cmd23           c                   
          const(x'BB')                         Cmd-23              
               d Cmd24           c                   
          const(x'BC')                         Cmd-24              
               d EnterKey        c                   
          const(x'F1')                                             
               
          d RollUp          c                   const(x'F5')                         Roll Up             
               d RollDown        c                   
          const(x'F4')                         Roll Down           
                                                                                                              
                
          //                                                                                            
                // Program Info                                                                               
                //                                                                                            
               
          d                SDS                                                                           
               d  
          @PGM                 001    010                                                             
               d  
          @PARMS               037    039  0                                                          
               d  
          @MSGDTA               91    170                                                             
               d  
          @MSGID               171    174                                                             
               d  
          @JOB                 244    253                                                             
               d  
          @USER                254    263                                                             
               d  
          @JOB#                264    269  0                                                          
                //                                                                                            
                // Variables                                                                                  
                //                                                                                            
                                                                                                              
               
          d bundles         s              4  0                                                          
               d count           s              4  0                                                          
               d count2          s              4  0                                                          
               d count3          s              4  0                                                          
               d ds
          #             s              3  0                                                          
               
          d EndScreen1      s              1    inz('N')                                                 
               
          d Lastqty         s              4  0                                                          
               d removerrn       s                   like
          (SCRRN)                                              
               
          d RRN1            s                   like(SCRRN)                                              
               
          d Savrrn          s                   like(SCRRN)                                              
               
          d ScreenError     s              1    inz('N')                                                 
                                                                                                              
                
          //---------------------------------------------------                                         
                //       C a l c u l a t i o n  S p e c s                                                     
                //---------------------------------------------------                                         
                                                                                                              
                
          /free                                                                                         
                                                                                                              
                   exsr $Screen1
          ;                                                                             
                   *
          inlr = *on;                                                                               
                                                                                                              
                 
          //===========================================                                                
                 //  $Screen1 - Display all parts allow for                                                   
                 //             Search.                                                                       
                 //===========================================                                                
                                                                                                              
                   
          begsr $Screen1;                                                                            
                     
          //                                                                                       
                     
          reset EndScreen1;                                                                        
                     
          dow EndScreen1 'N';                                                                    
                                                                                                              
                       
          write FKEY01;                                                                          
                       
          exfmt SUB01CTL;                                                                        
                                                                                                              
                       if 
          Currec <> *Zeros;                                                                   
                         
          RRN1    =  Currec;                                                                   
                         
          SCRRN   =  Currec;                                                                   
                       endif;                                                                                 
                                                                                                              
                       
          reset ScreenError;                                                                     
                                                                                                              
                       
          select;                                                                                
                         
          // F2 pressed break the line                                                         
                        
          when  Choice BreakLine;                                                             
                         
          exsr $breakline;                                                                     
                                                                                                              
                         
          // F3 pressed end the program F3 = LeaveProgram                                      
                        
          when  Choice LeaveProgram;                                                          
                         
          EndScreen1 'Y';                                                                    
                                                                                                              
                        
          other;                                                                                
                                                                                                              
                       
          endsl;                                                                                 
                      
          enddo;                                                                                  
                                                                                                              
                 
          endsr;                                                                                       
                                                                                                              
                 
          //===========================================                                                
                 // $BreakLine - Break the subfile line                                                       
                 //===========================================                                                
                 
          begsr $BreakLine;                                                                            
                                                                                                              
                  
          // identify the line to break                                                               
                  
          if where > *zeros;                                                                          
                   
          removerrn where;                                                                         
                   
          chain where sub01;                                                                         
                   if %
          found(DROP2AD);                                                                        
                    
          w1quantity s1qty;                                                                       
                    
          w1line# = where;                                                                          
                    
          clear w1bundles;                                                                          
                    
          exfmt window;                                                                             
                   endif;                                                                                     
                  endif;                                                                                      
                                                                                                              
                  
          // clear the array that holds subfile data                                                  
                  
          clear allsubrec;                                                                            
                  
          clear ds#;                                                                                  
                                                                                                              
                  // Load all records from subfile into datastructure                                         
                  
          for count 1 to savrrn;                                                                    
                   
          chain count SUB01  sub01ds;                                                                
                   if %
          found(DROP2AD);                                                                        
                    
          ds# +=1;                                                                                  
                    
          eval-corr allsubrec(ds#) = sub01ds;                                                       
                   
          endif;                                                                                     
                  endfor;                                                                                     
                                                                                                              
                  
          // clear subfile & rewrite with additional records                                          
                  
          exsr $clearsfl;                                                                             
                                                                                                              
                  for 
          count 1 to ds#;                                                                       
                   
          if count <> removerrn;                                                                     
                    
          rrn1 +=1;                                                                                 
                    
          scrrn RRN1;                                                                             
                    
          savrrn +=1;     // increment the original subfile record count                            
                    
          eval-corr sub01OUTds allsubrec(count);                                                  
                    
          write SUB01 sub01OUTds;                                                                   
                   else;                                                                                      
                    eval-
          corr sub01OUTds allsubrec(count);  // original subfile line                        
                    
          select;                                                                                   
                     
          when w1bundles > *zeros;                                                                 
                      for 
          count2 1 to  w1bundles;                                                           
                       
          savrrn +=1;     // increment the original subfile record count                         
                       
          rrn1 +=1;                                                                              
                       
          scrrn RRN1;                                                                          
                       
          write SUB01 sub01OUTds;                                                                
                      endfor;                                                                                 
                     
          when w1qty > *zeros;   // divide total quantity by this number and print                 
                      
          bundles =  (w1quantity/w1qty)*1;                                                        
                      if %
          rem(w1quantity:w1qty) > *zeros;                                                     
                       
          lastqty w1quantity - (bundles*w1qty);                                                
                       
          bundles +=1;                                                                           
                      endif;                                                                                  
                      for 
          count3 1 to bundles;                                                              
                       
          sub01OUTds.s1qty w1qty;                                                              
                       if 
          count3 bundles;                                                                   
                        
          sub01OUTds.s1qty lastqty;                                                           
                       endif;                                                                                 
                       
          savrrn +=1;     // increment the original subfile record count                         
                       
          rrn1 +=1;                                                                              
                       
          scrrn RRN1;                                                                          
                       
          write SUB01 sub01OUTds;                                                                
                      endfor;                                                                                 
                                                                                                              
                    
          endsl;                                                                                    
                   endif;                                                                                     
                  endfor;                                                                                     
                                                                                                              
                 
          endsr;                                                                                       
                 
          //===========================================                                                
                 //  $ClearSFL- Clear the route error sub                                                     
                 //===========================================                                                
                 
          begsr $clearsfl;                                                                             
                                                                                                              
                   *
          in31  = *Off;                                                                             
                   *
          in32  = *Off;                                                                             
                   *
          in30  = *On;                                                                              
                                                                                                              
                   
          write SUB01CTL;                                                                            
                                                                                                              
                   *
          in31  = *On;                                                                              
                   *
          in32  = *On;                                                                              
                   *
          in30  = *Off;                                                                             
                                                                                                              
                   
          clear RRN1;                                                                                
                   
          clear SCRRN;                                                                               
                   
          clear SavRrn;                                                                              
                                                                                                              
                   *
          in33 = *off;                                                                              
                 
          endsr;                                                                                       
                                                                                                              
                 
          //===========================================                                                
                 //  $LoadSfl  - Load up the route errors                                                     
                 //===========================================                                                
                  
          begsr $loadsfl;                                                                             
                                                                                                              
                   if 
          SavRrn  > *Zeros;                                                                       
                    
          rrn1  savrrn;                                                                           
                    
          scrrn savrrn;                                                                           
                   endif;                                                                                     
                   
          //                                                                                         
                         
          for count 1 to 5;                                                                  
                          
          RRN1  +=1;                                                                          
                          
          SCRRN  RRN1;                                                                      
                          
          S1note 'ABRF23A' + %char(rrn1);                                                   
                          
          s1Qty count rrn1;                                                               
                          
          s1weight 12.34 s1qty;                                                           
                          
          write SUB01;                                                                        
                         endfor;                                                                              
                                                                                                              
                   
          //                                                                                         
                   
          savrrn scrrn;                                                                            
                                                                                                              
                   
          //                                                                                         
                   //  If no records in subfile then do not disply the subfile.                               
                   //                                                                                         
                                                                                                              
                   
          if SavRrn  = *zeros;                                                                       
                     *
          in31 = *off;                                                                            
                   endif;                                                                                     
                                                                                                              
                   
          //                                                                                         
                 
          endsr;                                                                                       
                                                                                                              
                 
          //=================================================                                          
                 //  *inzsr - One time run processing                                                         
                 //=================================================                                          
                 
          begsr *inzsr;                                                                                
                                                                                                              
                   
          exsr $clearsfl;                                                                            
                   
          exsr $loadsfl;                                                                             
                                                                                                              
                 
          endsr;                                                                                       
                                                                                                              
                /
          end-free 
          Attached Files
          All my answers were extracted from the "Big Dummy's Guide to the As400"
          and I take no responsibility for any of them.

          www.code400.com

          Comment


          • #20
            Re: Deleting single record from subfile,how???

            Originally posted by jamief View Post
            What this means in English is the *output ds pulls in more fields than the *input ds..
            so if you do a straight move/eval the data gets WRECKED!
            Yea, that was one of the biggest pains with not being able to specify *ALL. On some of my output fields, I had to make them input / output & protect them in order to get it to work with *INPUT and *OUTPUT. The *ALL eliviates that.
            Michael Catalani
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #21
              Re: Deleting single record from subfile,how???

              I driving down a road Ive never been Kinda fun.

              Thanks for pointing me in the right direction, Have a fantastic weekend.

              If you all want to feel sorry for me, tomorrow we are having a Justin Bieber Birthday party with
              many 9 year old girls.... NOT GOOD!


              jamie
              All my answers were extracted from the "Big Dummy's Guide to the As400"
              and I take no responsibility for any of them.

              www.code400.com

              Comment


              • #22
                Re: Deleting single record from subfile,how???

                Remember that the indicators are now within the data structure and when you reference them,
                you must do so prior to the write back to the subfile.

                PHP Code:
                rcvrrn +=1;                 
                exsr $indicators;           
                write RCVSFA RcvSfAOutDS;  
                   
                //--------------------------------------------------------            
                   // $Indicators - setup indicators on writeback                        
                   //--------------------------------------------------------            
                        
                begsr $Indicators;                                               
                                                                                         
                         
                select;                                                         
                          
                when #rec =  'RCVSFA';                                         
                           
                if rcvrrn=1;                                                  
                            
                rcvsfaoutds.in92 = *off;                                     
                           else;                                                         
                            
                rcvsfaoutds.in92 = *on;                                      
                           endif;                                                        
                                                                                         
                           if 
                idbytag# =  'Y';                                           
                            
                rcvsfaoutds.in93 = *off;                                     
                           else;                                                         
                            
                rcvsfaoutds.in93 = *on;                                      
                           endif;                                                        
                ..................................................> 
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #23
                  Re: Deleting single record from subfile,how???

                  Originally posted by jamief View Post
                  I driving down a road Ive never been Kinda fun.

                  Thanks for pointing me in the right direction, Have a fantastic weekend.

                  If you all want to feel sorry for me, tomorrow we are having a Justin Bieber Birthday party with
                  many 9 year old girls.... NOT GOOD!


                  jamie
                  i can feel your pain...except when my girls went through this it was the Jonas Brothers..ugh
                  I'm not anti-social, I just don't like people -Tommy Holden

                  Comment

                  Working...
                  X