ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Track change in cursor field of subfile

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

  • Track change in cursor field of subfile

    Hello Folks,

    I have a DSPF that loads a subfile. Now i want to monitor a change in one of the fields of the subfile to capture whether any change has been made to this value.

    eg: I have a subfile field Item_Code(Editable on screen) that gets populated from a program along with its associated Sub_Code(This is protected on screen). Now since Item_Code is editable, suppose this field value is changed on screen after it has been populated via the program, it should also clear the Sub_Code value. I need to monitor this field through my program for this. How can i go about it.

    Please guide.

  • #2
    Re: Track change in cursor field of subfile

    One way is to create a hidden field in the subfile (maybe called Item_Orig) and put the value of ITem_Code in both the Item_Code field and the Item_Orig field. Later, loop through the subfile and compare Item_Code <> Item_Orig. If Item_Code has changed by the user, it'll no longer have the same value as Item_Orig.

    Comment


    • #3
      Re: Track change in cursor field of subfile

      Thanks Scott. I had a similar solution in mind. Is there any other way so as to prevent using a hidden field.

      Comment


      • #4
        Re: Track change in cursor field of subfile

        I guess you could create an array the same size as the subfile and use that. Or you could play with stuff like READC/SFLNXTCHG/CHANGE keyword to detect changes, but I have found those don't work nearly as well.

        What sort of problems do hidden fields cause for you? To me, they are by far the simplest and most elegant way, with no disadvantage.

        Hopefully you understand that I mean a "hidden" field, NOT a "non-display" field. The former does not take up any space on the screen, and is not sent to/from the 5250 terminal. The latter does take up space, and is sent to the terminal. Please use the former.

        Comment


        • #5
          Re: Track change in cursor field of subfile

          Well i thought non-display was the same as hidden.Please guide how is a hidden field created under keying options?

          Comment


          • #6
            Re: Track change in cursor field of subfile

            H1WINCHES is a hidden field in this subfile -- are you using PDM or WDSC/RDP to edit source?

            PHP Code:
            A          R SUB01                     SFL                      
            A            S1FWIDTHIN     3A  B 10 13                         
            A  71                                  DSPATR
            (RI)               
            A  71                                  DSPATR(PC)               
            A                                      CHECK(RZ)                
            A  81                                  DSPATR(HI)               
            A N81N80                               DSPATR(UL)               
            A  81                                                           
            AO 80                                  DSPATR
            (PR)               
            A            S1FWIDTHFR     4A  B 10 17                         
            A  72                                  DSPATR
            (RI)               
            A  72                                  DSPATR(PC)               
            A                                      CHECK(RZ)                
            A  81                                  DSPATR(HI)               
            A N81N80                               DSPATR(UL)               
            A  81                
            AO 80                                  DSPATR
            (PR)                  
            A            S1FLENFT       2A  B 10 23                            
            A  73                                  DSPATR
            (RI)                  
            A  73                                  DSPATR(PC)                  
            A                                      CHECK(RZ)                   
            A  81                                  DSPATR(HI)                  
            A N81                                  DSPATR(UL)                  
            A  81                                  DSPATR(PR)                  
            A            S1FLENIN       3A  B 10 26                            
            A  74                                  DSPATR
            (RI)                  
            A  74                                  DSPATR(PC)                  
            A                                      CHECK(RZ)                   
            A  81                                  DSPATR(HI)                  
            A N81                                  DSPATR(UL)                  
            A  81                                  DSPATR(PR)                  
            A            S1FLENFR       4A  B 10 30                            
            A  75                                  DSPATR
            (RI)                  
            A  75                                  DSPATR(PC)                  
            A                                      CHECK(RZ)                   
            A  81                                  DSPATR(HI)                                          
            A N81                                  DSPATR(UL)                 
            A  81                                  DSPATR(PR)                 
            A            S1CIRCLE       1A  B 10 37                           
            A  76                                  DSPATR
            (RI)                 
            A  76                                  DSPATR(PC)                 
            A  81                                  DSPATR(HI)                 
            A N81                                  DSPATR(UL)                 
            A  81                                  DSPATR(PR)                 
            A            S1DECIMAL      1A  B 10 41                           
            A  77                                  DSPATR
            (RI)                 
            A  77                                  DSPATR(PC)                 
            A  81                                  DSPATR(HI)                 
            A N81                                  DSPATR(UL)                 
            A  81                                  DSPATR(PR)                 
            A            S1QTY          4Y 0B 10  8EDTCDE(Z)                  
            A                                      CHECK(RB)                  
            A  70                                  DSPATR(RI)                 
            A  70                                  DSPATR(PC)                 
            A  81                                  DSPATR(HI)                 
            A N81                                  DSPATR(UL)        
            A  81                                  DSPATR(PR)              
            A            S1WEIGHT       7Y 0B 10 44EDTCDE(Z)               
            A  98                                  DSPATR(UL)              
            A                                      DSPATR(PR)              
            A  81                                  DSPATR(HI)              
            A            H1WINCHES      9S 4H 
            RDP -- notice that the type is "H"
            Click image for larger version

Name:	Noname.jpg
Views:	1
Size:	578.7 KB
ID:	126635


            PDM -- 17 in front of source 12 in front of member then {F4}
            Click image for larger version

Name:	Noname2.jpg
Views:	1
Size:	155.1 KB
ID:	126636
            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


            • #7
              Re: Track change in cursor field of subfile

              Originally posted by techas400 View Post
              Well i thought non-display was the same as hidden.Please guide how is a hidden field created under keying options?
              LOL... I'm only allowed to use the "keying options" screen to tell you how to create the field?! Since this is a hidden field, there are no keying options for it, so that doesn't make sense. Assuming you are using SDA (I'm getting that from the reference to "keying options") then press F4 on your subfile screen, and use the "ADD" blanks next to the word "hidden" to add a hidden field.

              See Jamie's screenshot.

              Comment


              • #8
                Re: Track change in cursor field of subfile

                I would certainly use the hidden field approach rather than using SFLNXTCHG which can be rather unreliable if you need to read the SFL record again for validation.

                Do you really need to amend the subfile directly? May I suggest a different approach? I tend to have a front end selection subfile, then allow users to amend data on a standard flat format screen, pressing a command key to accept.
                www.midlifegamers.co.uk

                Comment


                • #9
                  Re: Track change in cursor field of subfile

                  ...which can be rather unreliable if you need to read the SFL record again for validation.
                  Why would it be unreliable? I've never run into an issue (and maybe I've just been lucky).

                  That is, I realize it can be triggered even if the existing value is retyped by the user so that there is no actual "change" in value, but that shouldn't be a problem for program logic. (And if a hidden field is also used, program logic becomes almost trivial for READC.)

                  Tom
                  Tom

                  There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                  Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                  Comment


                  • #10
                    Re: Track change in cursor field of subfile

                    SFLNXTCHG is completely reliable. The only problem I have with that approach is that you can no longer tell if a user has made a change (or not), since READC will return records that the user hasn't changed (because your program marked them changed with "SFLNXTCHG")

                    Of course, the hidden field makes it possible to solve that problem.. Even though READC won't tell you if a field is changed, you can do both READC and compare against the hidden field.

                    Personally, I opt to use CHAIN instead of READC/SFLNXTCHG, since I just like it better... But, READC/SFLNXTCHG are completely reliable.

                    Comment


                    • #11
                      Re: Track change in cursor field of subfile

                      Okay, I just wanted to be sure I hadn't missed something. (It has happened before!)

                      Tom
                      Tom

                      There are only two hard things in Computer Science: cache invalidation, naming things and off-by-one errors.

                      Why is it that all of the instruments seeking intelligent life in the universe are pointed away from Earth?

                      Comment


                      • #12
                        Hi. I need hide or show choices in dspf from rpgle file. how i can access specific choice? Thanks.

                        Comment


                        • #13
                          This should really be a new topic but ...


                          A 81 DSPATR(HI)
                          A N81N80 DSPATR(UL)
                          A 81
                          AO 80 DSPATR(PR)


                          This is taken from the earlier full example. in this case it is showing/hiding display characteristics like UL (underline) but the principal is the same for showing/hiding fields, literals, etc.
                          Last edited by JonBoy; July 6, 2020, 06:27 AM.

                          Comment


                          • JonBoy
                            JonBoy commented
                            Editing a comment
                            the [code] tags have stopped working and even courier font is screwed - so apologies for the squashed format,
                        Working...
                        X