AS/400 flat file

620 pts.
Tags:
AS/400
Flat files
I have a flatfile (flat1) and record length of flat file is 200. How to read the flat file? Would you please correct the below code?
FLAT1
000001 00001chow
000002 00002balu
000003 00013ram
000004 00014sai
000005 00024sss
****** End of report  ******

fflat1     ip   e             disk    rename(flat1:flat10)
dds1              ds
dsid                      1      4
dsname                    6     14
iflat10    aa  01
c                   read      flat10
c                   dow       not%eof(flat1)
c     sid           dsply
c     sname         dsply
c                   read      flat10
c                   enddo
c                   seton                                        lr
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

There are essentially two methods to doing this. Firstly, you can copy the flat file into a database file. Why would you want to do this ? Well, if the data is stuff that you need to sort or query, then this is by far the best route. There is a CL command to do this which is CPYFRMIMPF, which copies data from a flat file held in the IFS into a database file. The default settings for this command will copy a CSV or Comma Separated Value file from the IFS into a database file. Very handy.

The alternative is to read in a file in RPG. Now RPG does not natively handle this, but the C programming language does. You can use the C library at runtime in RPGLE by binding to it in the H specs.

Discuss This Question: 7  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • chowas400
    Could you please provide sample code for rpgle?
    Thanks in advance..
    620 pointsBadges:
    report
  • deepu9321
    Your RPGLE program could still do that. Just by moving the data of flat file to DS after READ.

    FFLAT1     IP   E             DISK    RENAME(FLAT1:FLAT10)         
    DDS1              DS                                               
    DSID                      1      5                                 
    DSNAME                    6     14                                 
    C                   READ      FLAT10                               
    C                   DOW       NOT %EOF(FLAT1)                      
    C                   EVAL      DS1 = FLAT1                          
    C     SID           DSPLY                                          
    C     SNAME         DSPLY                                          
    C                   READ      FLAT10                               
    C                   ENDDO                                          
    C                   SETON                                        LR

    Pradeep.
    4,980 pointsBadges:
    report
  • chowas400
    Thanks for reply..
    when i compile the above code , i got the below errors,please help me..

    Msg id       Sv    Number Seq     Message text                                            
    *RNF5276 30      7 000500  The specified Factor 2 entry is not allowed for READ  operation; specification is ignored.  
                     
    *RNF7416 30      9 000700  The types of the right and left hand side do not match in the EVAL operation.          
                              
    *RNF5276 30     12 001000  The specified Factor 2 entry is not allowed for READ   operation; specification is ignored.                    
    620 pointsBadges:
    report
  • deepu9321
    Below are the reasons for these errors. Correct and try.

    1. On READ Opcode, File name should be used, You have used Record format name. 
    READ FLAT1
    2. On Eval Statement, Here FLAT1 is being considered as File name. Identify the field name in flat file and mention that. 
    If field name is same as File name, Use PREFIX(F_) on F Spec.

    Eval DS1 = F_FLAT1 (Use field name if it is different from file name).

    3. READ FLAT1

    Try this and see.

    Pradeep.
    4,980 pointsBadges:
    report
  • chowas400
    Hi Deepu,

    Thanks for your prompt response..

    still i got the below error..

    0001.00 fflat1     ip   e             disk    rename(flat1:flat11) prefix(f_) 
    0002.00 dds1              ds                                                  
    0003.00 dsid                      1      4                                    
    0004.00 dsname                    6     14                                    
    0005.00 c                   READ      flat1                                   
    0006.00 c                   dow       not%eof(flat1)                          
    0007.00 c                   eval      ds1=f_flat1                             
    0008.00 c     sid           dsply                                             
    0009.00 c     sname         dsply                                             
    0010.00 c                   READ      flat1                                   
    0011.00 c                   enddo                                             
    0012.00 c                   seton                                        lr   

    Msg id     Sv Number Seq    Messagetext                                          *RNF5276 30      7 000500  The specified Factor 2 entry is not allowed for READ  operation; specification is ignored.                 
     *RNF5276 30     12 001000  The specified Factor 2 entry is not allowed for READ  operation; specification is ignored.                 
    620 pointsBadges:
    report
  • philpl1jb

    0001.00 fflat1     ip   e             disk    rename(flat1:flat11) prefix

    should be

    0001.00 fflat1     if   e             disk    rename(flat1:flat11) prefix

    P-Primary is used in RPG II/III for automatic processing .. read would not be allowed to this file designation

    F-Full procedural file

    Either the file name FLAT1 or record name FLAT11 could be used in the READ statements.

    54,090 pointsBadges:
    report
  • chowas400
    Hi Philp,

    It's working now,
    Thank you very much. :)


    620 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: