ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Pointers...

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

  • Pointers...

    As I can know the address of a variable, when the name of the variable that is required to know this as data within a table ...

    S.S.

  • #2
    Re: Pointers...

    WHAT??? is there a question in there somewhere?
    I'm not anti-social, I just don't like people -Tommy Holden

    Comment


    • #3
      Re: Pointers...

      Not sure to clearly understand what you mean so yes, can you clarify your requirement please ?
      Philippe

      Comment


      • #4
        Re: Pointers...

        I think what he's saying is ... if the variable name is kept in a Table.Field address, is there a way to get the pointer to the field that the value of Table.Field points to.

        I could be wrong... Have been before.

        Comment


        • #5
          Re: Pointers...

          which (correct me if i'm wrong) would simply be a use for %ADDR built-in function?
          the smoking gnu

          Comment


          • #6
            Re: Pointers...

            It could be online Jeopardy ?

            "What does the %ADDR built-in function do?"
            Greg Craill: "Life's hard - Get a helmet !!"

            Comment


            • #7
              Re: Pointers...

              It sounds like the OP is trying to store variable names within variables. You could simulate this with pointers using the %addr function. But I hope by "table" he means something like a program array, and not a file. Varable pointers will change every time the program is activated, and any stored pointer address in a file will no longer be pointing where you want them to once the program activation is removed from the activation group. In other words, you will not be able to set up a permenent cross reference file between variables and their pointers, this info will have to be rebuilt upon every program activation.
              Michael Catalani
              IS Director, eCommerce & Web Development
              Acceptance Insurance Corporation
              www.AcceptanceInsurance.com
              www.ProvatoSys.com

              Comment


              • #8
                Re: Pointers...

                i have this code:

                DSP
                PHP Code:
                     A            FIELD1        10   B  3 29DSPATR(&@FIELD1)    
                     
                A            FIELD2        10   B  3 70DSPATR(&@FIELD2)    
                     
                A            FIELD3        10   B  6 55DSPATR(&@FIELD3)    
                     
                A            FIELD4        10   B  7 56DSPATR(&@FIELD4)    
                     
                A            FIELD5        10   B  8 55DSPATR(&@FIELD5)    
                     
                A            FIELD6        10   B  9 56DSPATR(&@FIELD6)    
                     
                A            FIELD7        10   B 10 55DSPATR(&@FIELD7)    
                     
                A            FIELD8        10   B 11 55DSPATR(&@FIELD8)    
                      *                                                         
                     
                A            @FIELD1        1A  P                          
                     A            
                @FIELD2        1A  P                          
                     A            
                @FIELD3        1A  P                          
                     A            
                @FIELD4        1A  P                          
                     A            
                @FIELD5        1A  P                          
                     A            
                @FIELD6        1A  P                          
                     A            
                @FIELD7        1A  P                          
                     A            
                @FIELD8        1A  P 
                Table of Parameters Fields

                Field Protected
                Code:
                FIELD1	Y
                FIELD2	N
                FIELD3	Y
                FIELD4	Y
                FIELD5	Y
                FIELD6	Y
                FIELD7	N
                FIELD8	N
                I need to initialize the attribute of the field with the constant X'A0' depending on the parameter for the field.

                Thanks for your help

                S.S.

                Comment


                • #9
                  Re: Pointers...

                  Overlay both sets of fields with their own array.

                  Then read thru the array for the attribute fields in a loop. If the attribute field in that array element meets the criteria, then set the corresponding array element for the fields to x'0A'.
                  Michael Catalani
                  IS Director, eCommerce & Web Development
                  Acceptance Insurance Corporation
                  www.AcceptanceInsurance.com
                  www.ProvatoSys.com

                  Comment


                  • #10
                    Re: Pointers...

                    I wanted to do something like this..
                    PHP Code:
                     FTabField  if   e             disk                           
                     FDspField  cf   e             WorkStn                        
                      
                    *                                                           
                     
                    D Field_Ptr       S               *                          
                      *                                                           
                     
                    D Field_Cmp       Ds                  Based(Field_Ptr)       
                      *                                                           
                     
                    D TxtField        S             15A                          
                      
                    *                                                           
                      /
                    FREE                                                       
                       Read TabFieldR
                    ;                                            
                       
                    Dow not %Eof ;                                             
                         
                    TxtField '@'+trim(Field);                              
                         
                    Field_Ptr = %Addr(TxtField);                             
                         if Protected = 
                    'Y';                                      
                            
                    Field_Cmp '0A';                                     
                         else;                                                    
                            
                    Field_Cmp '  ';                                     
                         endif;                                                   
                         
                    Read TabFieldR;                                          
                       
                    EndDo ;                                                    
                                                                                  
                       
                    exfmt Rdto
                    :

                    Comment


                    • #11
                      Re: Pointers...

                      that will just give you the pointer address to the TxtField not the field value of @+%trim(Field)
                      I'm not anti-social, I just don't like people -Tommy Holden

                      Comment


                      • #12
                        Re: Pointers...

                        ok, this is true, is there any way to know the memory address of a variable what your name is value in another variable ... that is the question ...

                        Comment


                        • #13
                          Re: Pointers...

                          Originally posted by scsr01 View Post
                          ok, this is true, is there any way to know the memory address of a variable what your name is value in another variable ... that is the question ...
                          absolutely not
                          I'm not anti-social, I just don't like people -Tommy Holden

                          Comment


                          • #14
                            Re: Pointers...

                            Originally posted by scsr01 View Post
                            ok, this is true, is there any way to know the memory address of a variable what your name is value in another variable ... that is the question ...
                            Definitely not! RPG isn't able to access the value of a variable whose name is the value of another variable.

                            There may be a solution (I have not checked) thru Debug APIs (AFAIK, Debug APIs are able to access variables by name). But it's not an easy way.

                            To achieve your goal, MichaelCatalani give you what I think is the best answer

                            Overlay both sets of fields with their own array.

                            Then read thru the array for the attribute fields in a loop. If the attribute field in that array element meets the criteria, then set the corresponding array element for the fields to x'0A'.
                            PS: IMHO, you should avoid special characters for fields names (@#...) as they are CCSID sensitive
                            Jean-Michel

                            Comment


                            • #15
                              Re: Pointers...

                              Thanks, I have learn ...

                              Comment

                              Working...
                              X