sponsored links

Collapse

Announcement

Collapse
No announcement yet.

Check for ds subfield

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

  • Check for ds subfield

    Hi,
    I have a stream file with different type of record inside.

    I thought to copy all the record into a generic file with a CPYFROMIMPF, whihc define only the header of the record, then with an RPGLE program I read all the record, and through the header i move the record into a DS with all the specific field for this type of record, but I've a problem with the subfield, because the documentation in same numeric field I found some blanks, How do can I check the validity of the subfield?

    Many thanks.
    Bye

  • #2
    Hi,

    I found this solution, probably there are better...

    Tell me what do you think.

    Code:
    
    Dcl-Proc CheckSubField;
      Dcl-Pi CheckSubField Int(5);
        DsToTest     Char(10) const; 
      End-Pi CheckSubField;
      Dcl-s StartPos          Int(10);
      Dcl-s Data_Type         Char(10);
      Dcl-s FieldLength       Int(10);
      Dcl-s Numeric_Scale     Int(10);
      Dcl-s Null_Ind          Int(5);
      Dcl-s TestNumber        Zoned(40 :20);
      // ____________________________________________
    
      StartPos  = 0;
    
      Exec Sql 
        Declare CheckField Cursor for 
          Select Data_Type, Length, Numeric_Scale
            From Syscolumns
            Where Table_Name = :DsToTest
            Order By Ordinal_Position;
      Exec Sql 
        Open CheckField;
      If SqlState = '02000';
        Log(ERRORE :'Errore: Check Field per DS' + DsToTest + '. Non gestito verificare.');
        Return -1;
      EndIf;
    
      Dow SqlState <> '02000';
    
        Exec Sql 
          Fetch next from CheckField 
            Into :Data_Type, :FieldLength, :Numeric_Scale :Null_Ind;
        If SqlState = '02000';
          Leave;
        EndIf;
    
    
        If Data_Type <> 'NUMERIC';
          // Registro l'offset del campo
          StartPos = StartPos + FieldLength;
          Iter;
        EndIf;
    
        Monitor;
          TestNumber = %Dec(%SubSt(DsAfuRcv :StartPos +1: FieldLength) :40 :20);
        On-Error;
          %SubSt(DsAfuRcv :StartPos +1: FieldLength) = *Zeros;
        EndMon;
    
        // Registro l'offset del campo
        StartPos = StartPos + FieldLength;
    
      EndDo;
    
      Exec Sql 
        Close CheckField;
    
      Return 0;
    
    End-Proc CheckSubField;

    Comment

    Working...
    X