Problem solve Get help with specific problems with your technologies, process and projects.

Data extractor for a flat record

This subprocedure extracts data from a flat record (no dds), tab delimited, comma delimited, etc.

This subprocedure extracts data from a flat record (no dds), tab
delimited, comma delimited, etc. It uses the field delimiting character
and the positional number in the record to identify the desired
data. So if I wanted to get the data from the ninth field of and
EDI document, I would use an asterisk as the field ending
character and ask for the ninth field (see my example below).

It is no longer necessary to code additional routines to extract
specific data from flat records. This method can be used to
quickly and efficiently to convert uploaded data to DB2 files.

 

É*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
      É* FillField              KHN  02/04 
 manipulate string data      *
      É*                                             
                   *
      É* Fill field  from a flat record.  Pass in the
 record,           *
      É* the end of field character, and the field #
 to be filled.      *                                
   *
      É*  The program will loop until it gets to the
 filed to yank out. *
     

É*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
      D FillField       PR           500    Varying
      É*
      D    StringIn                  500    VALUE 
 Varying
      D    EndofFld                    1    VALUE
      D    FieldsNo                    3u 0 VALUE
 
 
É*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
      É* FillFields procedure   KHN   2/04 
 manipulate string data      *
       É*                                             
                   *
      É* Fill field  from a flat record.  Pass in the
 record,           *  
      É*  the end of field character, and the field #
 to be extracted   *
      É*  The program will loop until it gets to the
 field to yank out. *
     
 
É*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*
      P FillField       B
      D FillField       PI           500    Varying
      D    StringIn                  500    VALUE 
 Varying
      D    EndofFld                    1    VALUE
      D    FieldNo                     3u 0 VALUE
      D Done            S               n    
 Inz('0')
      D ThisField       S            500      Varying
      D Pos             S              5u 0   Inz(1)
      D Fields          S              5u 0   Inz(0)
      D StrLeng         S              5u 0   Inz(1)
 
       /Free
 
            Done = *off;
 
            StringIn = %Triml(StringIn);
 
            Dou  Done;
               StrLeng = %len(StringIn);
               Pos = %Scan(EndofFld : StringIn : 1);
               If Pos > 0;
                  Fields += 1;
                  ThisField = %Trim(%Subst(StringIn :
 1 : Pos - 1 ));
 
                  If Fields = FieldNo;
                     Done = *on;
                     Iter;
                  Else;
                     StringIn =
 %Triml(%Subst(StringIn:Pos + 1));
                  Endif;
               Else;
                  If Pos = 0 and StrLeng > 0;
                     ThisField =
 %Triml(%Subst(StringIn:1));
                  Endif;
                  Done = *on;
               Endif;
 
          Enddo;
 
          RETURN  ThisField;
 
       /End-Free
 
      P FillField       E
 
 

For Example, I use this to check to see what company an edi transaction is for, as we have two companies on our iSeries box. The code for that look up using the subprocedure is:

 
  /Free                                              
                         
 ISA09 = FILLFIELD (FTPREC : '*' : 9);     
  
     /End-free    
 
 or if I just wanted to make a decision: 
 
 /Free
 IF FILLFIELD(FTPREC : '*' : 9) = 'MWCT'; 
 Cmpy = 'MCT';
 /End-Free 

We also use it for insurance applications. From the flat-file up load we can fill our numeric fields by using it. This way, we get an amount from an alphameric no decimal field:
/Free
F10 = %int(FILLFIELD(RECORD : '@' : 10)) * 100;
/End-Free

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close