ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Using a field from a data structure

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

  • Using a field from a data structure

    Hi all,

    I have a data structure defined like so:
    Code:
    D DSNXLD        E DS                  EXTNAME(LZLDN) 
    D  W8NXLD                11     64                   
    
    
    C                   MOVE      *ZEROS        W8NWLD            6 0
    one of the field name is LDNXLD, numeric length 6.
    my program has this line

    Code:
    IF %STATUS(ZPAL01)<>ALLOCFAIL; 
       W8ZPAC = 100;               
       IF S_ZPAL01=1;              
          W8NXLD = W06DATA;        
          W8NWLD = LDNXLD;         //DATA DECIMAL ERROR
    I get a data decimal error on the last line. In debug, the value of W8NWLD is 000000 and LDNXLD is 6 blank spaces.

    I read somewhere that when a user uses a field from a DS, it comes out as blanks, and that is the reason for the data decimal error. how can I solve this problem?
    I tried to initiallize the LDNXLD to *ZERO, and that did not work. Fairly new to RPG world. Please help!

  • #2
    Before I forget - two quick comments. 1) You have code in free-form - don't mix it with the old fixed format - that was replaced _17_ years ago!

    2) Don't use MOVE it was deprecated at the same time.
    W8NWLD = *Zeros; Or W8NWLD = 0; Is preferred.

    3) Same applies to the DS. Don't use fixed from/to notation. Use Overlay or Pos and define the field the way you want it.

    To your question - without seeing the layout of the DS it is difficult to tell - but are you sure that you are not overlaying all or part of LDNXLD with your W8NXLD definition? W8NXLD is an alpha field since you only defined from/to and did not specify the data type. If it overlaps LDNXLD then your move of character zeros to it could well screw it up. We'd need to see the full layout of the DS to know.

    Comment


    • #3
      Code the INZ keyword on the data structure definition to get all the subfields initialized.
      Code:
      D DSNXLD E DS EXTNAME(LZLDN) [COLOR=#FF0000][B]INZ[/B][/COLOR]
      D W8NXLD 11 64

      Comment

      Working...
      X