14 Replies Latest reply: Oct 10, 2014 11:33 AM by Friedrich Hofmann RSS

    Clean-up routine to load in a FOR_EACH loop

    Friedrich Hofmann

      Hi,

       

      I have to build a FOR EACH loop using a searchmask for files created in a subroutine - there might be I don't know how many, one generated in every iteration.

      The format is 'SOFA_n.qvd' - where n is a number.

      There are other files named like 'SOFA_nnnn.qvd', so it is important to specify that there is just one number behind the underscore - or I'd have to correct several parts of the script.

      I have seen in the help_file that the '?' is a wildcard for exactly one digit?

      So far, I have

      >> SET v_fileformat_SOFA_gesäubert = 'SOFA_?.qvd'; <<

      Can anybody tell me what's wrong here? When I put an EXIT SCRIPT right behind that, the variable is not there.

      Thanks a lot!

       

      Best regards,

       

      DataNibbler

        • Re: Clean-up routine to load in a FOR_EACH loop
          Alessandro Saccone

          Try using let instead of set

            • Re: Clean-up routine to load in a FOR_EACH loop
              Friedrich Hofmann

              Hi Alessandro,

               

              SET is ok. I was doing something wrong, or maybe I just overlooked the variable, I have so many, that's a problem. I tested just that piece of code in a small app and it works fine.

              The '?' is a placeholder for exactly one digit, so the searchmask won't fit qvd_files that are named like "SOFA_unsauber.qvd", correct?

              That is an important point of course.

              Thanks a lot!

                • Re: Clean-up routine to load in a FOR_EACH loop
                  Alessandro Saccone

                  Yes ? stands for just one char.

                    • Re: Clean-up routine to load in a FOR_EACH loop
                      Friedrich Hofmann

                      Thanks!

                       

                      I have a problem here now. There is just one file in this instance, "SOFA_1". So I want to load this in a loop.

                      To know the exact fieldnames - I want to avoid the * in a LOAD - I loaded the table as a standalone in a separate app.

                      There, the table loads quite normally and there is a field called "Werk_unsauber".

                      => So I know the name of all the fields and I can write my LOAD into the loop, taking care to get a specific order of fields and to use the AS option every time - I want to append the LOAD to another one later, so the names have to be equal.

                      Still, I kept getting an error "Field not found >Werk_unsauber<

                      I copied it over from the standalone_LOAD several times to make sure there was no typo.

                      Then I just tried loading the file in the loop with an * and just look what the fields are like.

                      <=> now I get some xml stuff - describing the correct record, though.

                       

                      I cannot make head or tail of this - the file is definitely qvd, not txt, my searchmask says *.qvd, and I have a counter_variable made up of part of the searchmask because one field has that as a suffix.

                       

                      Can you help me there?

                       

                      P.S.: I have used Filename() and confirmed that the code is definitely loading the correct file - and in my separate test_app, it's loading all normal ...

                       

                      P.P.S.: Must be that * - when I do a LOAD * in the test_app, I get the same crap. When I type up every fieldname instead, it's fine...

                       

                      It looks like that is a txt file - but how can that be?

                • Re: Clean-up routine to load in a FOR_EACH loop
                  Marcus Sommer

                  Loading with variables as field(parts) or fieldnames is generally difficult but it should work. Maybe you need a different syntax like:

                   

                  Sachnr_und_Anz_'$(v_Ctr)' as newname

                  'Sachnr_und_Anz_$(v_Ctr)' as newname

                  Sachnr_und_Anz_v_Ctr as newname

                   

                  or you create the complete field outside from loop in a variable:

                   

                  let v = 'Sachnr_und_Anz_' & '$(v_Ctr)';

                   

                  and then

                   

                  $(v) as newname

                   

                  - Marcus

                    • Re: Clean-up routine to load in a FOR_EACH loop
                      Friedrich Hofmann

                      Hi Marcus,

                       

                      I'll try those variations.

                      I've already tried creating the entire fieldname as a variable, but how shall I do that outside the loop? I have a FOR EACH loop, the counter does not exist or is not incremented outside the loop.

                       

                      P.S.: If all that doesn't work, I will just have to drop all superfluous fields so I have only those I need (to append that file to the one before) and rename the fields so I can just use a LOAD * lateron. (the files are stored and dropped at that point anyway, to be loade again only for the final assembly)