i use a macro to lock a Dataset:
%macro lockTab(member=APP_DATABASE,timeout=30,retry=500);
%global LOCK_&member;
%let LOCK_&member = ;
%local starttime;
%let starttime = %sysfunc(datetime());
%put try to lock &member.: &starttime;
%do %until (&syslckrc = 0
or %sysevalf(%sysfunc(datetime()) > (&starttime + &timeout)));
lock APPLIB.&member.;
%put syslckrc=&syslckrc;
%if &syslckrc > 0 %then %let rc=%sysfunc(sleep(&retry.));
%end;
%let endtime = %sysfunc(datetime());
%put end of try to lock &member.: &endtime;
%if &syslckrc <= 0 %then %do;
%let LOCK_&member = LOCK;
%end;
%else %do;
%let _appRetcode = 12;
%let _appErrtext = Database is locked.;
%end;
%put ende Locktab: appretcode: &_appRetcode;
%put ende Locktab: syslckrc: &syslckrc;
%mend;
This is my code using the macro (_appRetcode is a global variable), macro spinner is just a datastep to Show a loading spinner on the web page. Then lock the dataset and put out _appRetcode which is set in lockTab. %debug prints out all macro variables with scope.
%spinner(show)
%lockTab
%put EYECATCHER &_appRetcode;
%debug(DUMP Variablen nach LOCKTAB)
and this is my SASlog:
NOTE: 1 record was written to the file _WEBOUT.
The minimum record length was 42.
The maximum record length was 42.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
SYMBOLGEN: Macro variable _APPRETCODE resolves to 0
EYECATCHER 0
SYMBOLGEN: Macro variable MEMBER resolves to APP_DATABASE
SYMBOLGEN: Macro variable MEMBER resolves to APP_DATABASE
SYMBOLGEN: Macro variable MEMBER resolves to APP_DATABASE
The SAS System
SYMBOLGEN: Macro variable STARTTIME resolves to 1834989255.00056
try to lock APP_DATABASE: 1834989255.00056
SYMBOLGEN: Macro variable MEMBER resolves to APP_DATABASE
ERROR: A lock is not available for APPLIB.APP_DATABASE.DATA.
ERROR: Lock held by process 1360575.
SYMBOLGEN: Macro variable SYSLCKRC resolves to 70031
syslckrc=70031
SYMBOLGEN: Macro variable SYSLCKRC resolves to 70031
SYMBOLGEN: Macro variable RETRY resolves to 500
SYMBOLGEN: Macro variable SYSLCKRC resolves to 70031
SYMBOLGEN: Macro variable STARTTIME resolves to 1834989255.00056
SYMBOLGEN: Macro variable TIMEOUT resolves to 30
SYMBOLGEN: Macro variable MEMBER resolves to APP_DATABASE
ERROR: A lock is not available for APPLIB.APP_DATABASE.DATA.
ERROR: Lock held by process 1360575.
.......
end of try to lock APP_DATABASE: 1834989285.01467
SYMBOLGEN: Macro variable SYSLCKRC resolves to 70031
SYMBOLGEN: Macro variable _APPRETCODE resolves to 12
ende Locktab: appretcode: 12
The SAS System
SYMBOLGEN: Macro variable SYSLCKRC resolves to 70031
ende Locktab: syslckrc: 70031
Why is EYECATCHER printed out before the Output of my macro?
I expected first output of macro lockTab, and then "EYECATCHER 12". ?????
%debug gives: (scope/variable/value) GLOBAL / _APPRETCODE / 12