ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Moving entry parameter values to Data Structure in RPGLE

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

  • Moving entry parameter values to Data Structure in RPGLE

    Hi All, Sorry if this looks too silly, but been having tough time to figure this out.

    I am passing FIELD1 from CL to RPGLE with value as 11100 (Its a 5 character field and each character has some significance - such as if library1 is found for a file, then character1 will be 1, else 0. Similarly, 5 characters for 5 libraries). So, 11100 indicates that the file is found in libraries1,2,3 and not found in libraries4,5

    In RPGLE, i have to build a logic to display the libraries in which the file is found. I can manually do substring of each character and check if it is on/off, but that doesnt look good from programming perspective. So, i am holding a DS as below

    D DS INZ
    D LIBFND 1 5
    D DIM(5)
    D LIBFND1 1 1
    D LIBFND2 2 2
    D LIBFND3 3 3
    D LIBFND4 4 4
    D LIBFND5 5 5

    My plan is to move the input FIELD value to LIBFND so that i can later run a for loop to check if value is set as on/off for that particular library.

    So, i try to perform "MOVE FIELD1 LIBFND"

    But, when i check value of LIBFND, its not 11100, rather 11111. Can you point out the mistake i am making here? How better i can handle this?

  • #2
    You are moving a field into an array, so it is moving that field into each element of the array. Give the data structure a name (such as LIBFNDDS) and move the field to the data structure name.

    Comment


    • #3
      You haven''t used the code tags around your RPG so it is really hard to read but I _think_ this is a far easier way to create your array.

      P.S. Don;'t use from-to notation - that was deprecated 25+ years ago just use field lengths.

      Code:
              // Old fixed form version - use the DS name as the target for the FIELD1 data.
           d  LibFndAll      Ds
           d    LibFnd                      1a   Dim(5)
      
              // I prefer the current free-form version         
             Dcl-ds  LibFndAll;
                LibFnd  Char(1)  Dim(5);
             End-Ds;
      
               //  Use this - NOT MOVE - MOVE is effectively deprecated
      
             LibFndAll = Field1;
      
               //  Now just loop through the =LibFnd array

      Comment


      • #4
        Originally posted by Brian Rusch View Post
        You are moving a field into an array, so it is moving that field into each element of the array. Give the data structure a name (such as LIBFNDDS) and move the field to the data structure name.
        Another very good reason not to use the obsolete MOVE op-code - it often doesn't do what you thought it would!

        Comment


        • #5
          Hi Brian Rusch,

          Thanks for your comment. Yes, it was a very silly mistake from my end, and was really scratching my head too hard about it.

          Hi JonBoy,

          Thanks for your comment. What you provided is a straightforward and easy solution. And sorry for not aligning the code properly. And got your point about MOVE opcode as well.

          Comment

          Working...
          X