ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Looping in a file?

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

  • Looping in a file?

    Hey all,
    Hope ur doing fine.
    I got a question if anyone can help me out
    i have a file with 2 fields (CODE SUBCODE)
    TES01
    CODE SUBCODE
    T01 001
    T01 003
    T02 004
    where a same code can have multiple subcodes
    AND another table (SUB CODE TOTAL)
    TES02
    SUBCODE TOTAL001 388
    003 877
    003 500

    in my program i need to have for each CODE to make the total for its related subcodes and write them in a table?

    Can u just provide me with the hint for how i can loop the initial file so i can make the sum for each code?

    Thanks have a nice day!

  • #2
    Re: Looping in a file?

    First welcome back -- its not been the same since you left us..

    Can you use sql? -- jamie
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Re: Looping in a file?

      thanks jamief the site looks so great now
      no too bad i cant use SQL

      Comment


      • #4
        Re: Looping in a file?

        something like this

        PHP Code:

        setll 
        *start file#1 
        read file#1
        dow not %eof(file#1)
        clear totalsubcodes

        setll 
        (subcode#1) file#2
        reade (subcode#1) file#2
        dow not %eof(file#2) 
         
        totalsubcodes +=1
        reade 
        (subcode#1) file#2
        enddo

        read file
        #1
        enddo 
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Looping in a file?

          thanks for your help and time but why the reade instead of read?

          Comment


          • #6
            Re: Looping in a file?

            because you are reading the table by a key value only...

            so it would read all the "001" records first then
            %eof will be set to on and it falls out of the do loop.

            then the next reade starts with "002" and again and again till file#1 hits %eof (end of file)
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Looping in a file?

              Originally posted by jamief View Post
              because you are reading the table by a key value only...

              so it would read all the "001" records first then
              %eof will be set to on and it falls out of the do loop.

              then the next reade starts with "002" and again and again till file#1 hits %eof (end of file)
              but jamief i don't want to put hard coded codes in my code....can we?

              Comment


              • #8
                Re: Looping in a file?

                they are NOT hardcoded the field on the read equal is the field "SUBCODE" from file# 1
                All my answers were extracted from the "Big Dummy's Guide to the As400"
                and I take no responsibility for any of them.

                www.code400.com

                Comment


                • #9
                  Re: Looping in a file?

                  ah oki Thanks alot for ur time

                  Comment


                  • #10
                    Re: Looping in a file?

                    post a sample when you get it written.. please
                    All my answers were extracted from the "Big Dummy's Guide to the As400"
                    and I take no responsibility for any of them.

                    www.code400.com

                    Comment


                    • #11
                      Re: Looping in a file?

                      hey here wut am writing but i cannot test it now...I also included here the values i have in the files
                      I

                      file one : RP00LF
                      DATARP00CDE RP00SCD
                      T01 001
                      T01 005
                      T02 009

                      File two RP02LF

                      RPO2SCD RP02TOT
                      001 1200
                      005 1300
                      002 6300

                      out put file should be as follow :
                      RP03PF
                      CODE TOTAL
                      T01 (1200+1300)=2500
                      T02 6300
                      N.B: In the second file each sub code have one record only so can't we use chain in the second part of the code???

                      PHP Code:
                      *LOVAL SETLL RP00LF   
                      READ   RP00R
                      DOW NOT 
                      %EOF(RP00LF)  
                       
                      EVAL 
                      TOT1 = *ZEROS 

                      RP00SCD  SETLL RP02LF
                      READE RP02SCD   RP02LF

                      DOW NOT 
                      %EOF(RP02LF)
                        
                      TOT1  TOT1 RP02TOT
                       READE RP00SCD RP02LF
                      ENDDO

                      READ RP00R
                      ENDDO 

                      Comment


                      • #12
                        Re: Looping in a file?

                        Originally posted by casporov View Post
                        bad i cant use SQL
                        Grrrrrr.... Why not ?
                        Patrick

                        Comment


                        • #13
                          Re: Looping in a file?

                          your first reade is not the same as the others...
                          All my answers were extracted from the "Big Dummy's Guide to the As400"
                          and I take no responsibility for any of them.

                          www.code400.com

                          Comment


                          • #14
                            Re: Looping in a file?

                            PHP Code:
                            *LOVAL SETLL RP00LF   
                            READ   RP00R
                            DOW NOT 
                            %EOF(RP00LF)  
                             
                            EVAL 
                            TOT1 = *ZEROS 

                            RP00SCD  SETLL RP02LF
                            READE RP02SCD   RP02LF

                            [B]KEY       CHAIN     RP02LF 
                            IF  %FOUND(RP02LF)  
                            TOT1 TOT1 RP02TOT
                            ENDIF[/B]
                            READ RP00R
                            ENDDO 
                            will this code do the job u think?
                            Thanks Again!

                            Comment


                            • #15
                              Re: Looping in a file?

                              That would be a gigantic NO
                              All my answers were extracted from the "Big Dummy's Guide to the As400"
                              and I take no responsibility for any of them.

                              www.code400.com

                              Comment

                              Working...
                              X