ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Load same data into multiple fields in one line of code

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

  • Load same data into multiple fields in one line of code

    Hello and thank you in advance for the help

    Program has multiple files
    F FileA uf a e k disk prefix(a_)
    F FileB uf a e k disk prefix(b_)
    F FileC uf a e k disk prefix(c_)
    F FileD uf a e k disk prefix(d_)
    F FileE uf a e k disk prefix(e_)

    Several fields in these files have the same file name
    FieldName 15 TEXT('Field Name')

    I wish to populate FieldName in all the files at once

    Currently it's obviously like this
    /free
    a_FieldName = data;
    b_FieldName = data;
    c_FieldName = data;
    d_FieldName = data;
    e_FieldName = data;
    /end-free

  • #2
    You asked this elsewhere and I responded. When I final solution is arrived at please post the answer here too.

    The simple answer as I said to to remove the prefix option - but that may have other impacts.

    Comment


    • #3
      You would have to create a data structure for each file with the pertinent subfields, where each subfield is in the same order and have the same attributes. From there there's several things you can do. For example, point them all to one location:

      Code:
      FFileA     if   e             disk    prefix(a_)          
      FFileB     if   e             disk    prefix(b_)          
      FFileC     if   e             disk    prefix(c_)          
                                                                
      d fileADsP        s               *   inz(%addr(fileADs))
      d fileADs         ds                                      
      d  a_FIELD1                                              
      d  a_FIELD2                                              
                                                                
      d fileBDs         ds                  based(fileADsP)    
      d  b_FIELD1                                              
      d  b_FIELD2                                              
                                                                
      d fileCDs         ds                  based(fileADsP)    
      d  c_FIELD1                                              
      d  c_FIELD2                                                ​                                            ​


      However, this "glues" the data structures together so keep in mind that any change in one data structure will result in the same change in the other data structures.

      If this "glue" is not desirable then remove the pointer stuff and just assign each data structure (fileBDs = fileADs, fileCDs = fileADs, etc.). That's a lot faster than assigning each field.

      Mike

      Comment

      Working...
      X