Sat Aug 18, 2018 9:43 pm
Login Register Lost Password? Contact Us


Calling Macro Twice

Questions around writing code and queries

Fri Oct 27, 2017 5:28 pm Change Time Zone

I am trying to call the same macro twice with two different inputs but keep getting the same error. I have tried many variations but have not gotten anywhere.
Here is the calling code:
Code: Select all
IMPORT DirOne;
DirOne.mac_Build_GridNames('Place_One', 'Place_One', 'Place_One', 'OLD', QC2Place_OneResult);
OUTPUT(QC2Place_OneResult);
DirOne.mac_Build_GridNames('Place_Two', 'Place_Two', 'Place_Two', 'OLD', QC2Place_TwoResult);
OUTPUT(QC2Place_TwoResult);

Here is the macro:
Code: Select all
IMPORT * FROM DirOne;
IMPORT STD;

EXPORT mac_Build_GridNames(SharedConstants_Prefix, Constants_Prefix, Files_Suffix, Old_or_New, Result) := MACRO
  #UNIQUENAME(GridConstantsTemplate)
   LOCAL %GridConstantsTemplate% := #TEXT(
     #IF (Old_or_New = 'OLD')
         GridBaseFile := DirOne_UTILITIES.FILES.BASE_FILE_FILES_SUFFIX;
        GridKey := DirOne_UTILITIES.FILES.FILE_KEY_GRID_ROAD_FILES_SUFFIX;
        GridKeySF := DirOne_UTILITIES.FILES.FILE_KEY_GRID_ROAD_FILES_SUFFIX_SF;
      #ELSE
        GridBaseFile := DirOne.FILES.BASE_FILE_FILES_SUFFIX;
        GridKey := DirOne.FILES.FILE_KEY_GRID_ROAD_FILES_SUFFIX;
        GridKeySF := DirOne.FILES.FILE_KEY_GRID_ROAD_FILES_SUFFIX_SF;
      #END
   );
  #UNIQUENAME(GridConstants)
   %GridConstants% := STD.Str.FindReplace(
      STD.Str.FindReplace(
         STD.Str.FindReplace(
            %GridConstantsTemplate%,
            'SHAREDCONSTANTS_PREFIX',
            SharedConstants_Prefix
         ),
         'FILES_SUFFIX',
         Files_Suffix
      ),
      'CONSTANTS_PREFIX',
      Constants_Prefix
   );

   #EXPAND(%GridConstants%);

  #UNIQUENAME(Dogbreath)
    %Dogbreath% := DATASET(
      [
         {
            GridKey,
            GridKeySF,
            GridBaseFile,

         }
      ],
      DirOne_Utilities.Layouts.SETUP_FILE_NAMES
   );
   RESULT := %Dogbreath%;
ENDMACRO;


Here is the error:
Error: syntax error near ":=" (35, 20 -
DirOne.mac_Build_GridNames)
Error: While expanding macro <param> (34, 26 - DirOne.mac_Build_GridNames)
Error: While expanding macro mac_build_gridnames (6, 95)
Error: syntax error near ":=" (36, 14 - DirOne.mac_Build_GridNames)
Error: While expanding macro <param> (34, 26 - DirOne.mac_Build_GridNames)
Error: While expanding macro mac_build_gridnames (6, 95)
Error: Too many errors (max = 5); Aborting... (36, 16 - DirOne.mac_Build_GridNames)

If I just do this for Place_One I have no problems.
It is when I try to do this for Place_One and Place_Two I get the error.
I think it has to do with Result being the same in both but I do not know how to get around this. I have tried a lot of variations but have not succeeded, even trying LOCAL.

Any help is appreciated.
georgeb2d
 
Posts: 93
Joined: Wed Dec 24, 2014 3:36 pm

Fri Oct 27, 2017 5:52 pm Change Time Zone

If I just do this for Place_One I have no problems.
It is when I try to do this for Place_One and Place_Two I get the error.
Generating the same code twice is exactly the problem. Each time you call the MACRO it is generating a definition for GridBaseFile, GridKey, and GridKeySF. IOW, this MACRO is designed to run exactly once.

To correct that you need to use #UNIQUENAME on these three definitions so that they aren't named the same for every instance of the MACRO (the same way you're doing for GridConstants).

HTH,

Richard
rtaylor
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 1370
Joined: Wed Oct 26, 2011 7:40 pm

Fri Oct 27, 2017 6:01 pm Change Time Zone

Thanks. That did it.
georgeb2d
 
Posts: 93
Joined: Wed Dec 24, 2014 3:36 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 1 guest

cron