/*****************************************************************/ /* S A S S A M P L E L I B R A R Y */ /* */ /* NAME: IMSMAC */ /* TITLE: Source for macros to convert an IMS DBD into SAS */ /* Access Descriptor line mode statements. */ /* PRODUCT: SAS/ACCESS INTERFACE TO IMS-DL/I */ /* SYSTEM: OS/390 */ /* KEYS: */ /* PROCS: */ /* SUPPORT: sasrtr UPDATE:02JUN98 */ /* REF: SAS/ACCESS Interface to IMS-DLI: */ /* Usage and Reference */ /* Version 7, First Edition */ /* */ /*****************************************************************/ %macro getfld(var); %*************************************************************; %*** This macro is used to scan a string for a keyword ***; %*** variable (e g , NAME=xxxxxx) The variable data is ***; %*** terminated by a comma or blank In the case of ***; %*** parentheses the first word or parameter within is ***; %*** the variable data ***; %*************************************************************; s = index(rest,"&var="); l = length("&var="); if s > 0 then do; s = s + l; t = indexc(substr(rest,s),', ') - 1; do while (substr(rest,s,1) = '(' ); if substr(rest,t+s-1,1) = ')' then t = t - 2; else t = t - 1; s = s + 1; end; %if &var = BYTES or &var = START %then %do; if t < 0 then &var = input(substr(rest,s),8.); else &var = input(substr(rest,s,t),8.); %end; %else %do; if t < 0 then &var = substr(rest,s); else &var = substr(rest,s,t); %end; end; %mend; %macro imsdbd(dbd); %*************************************************************; %*** This macro is used to convert an IMS DBD to SAS ***; %*** Access descriptor line mode statements which define ***; %*** the segments and fields within a data base. ***; %*** ***; %*** The PDS containing the dbd source must be allocated ***; %*** to DDname PSBDBD ***; %*** ***; %*** The PDS that the access descriptor info will be ***; %*** written into must be allocated to DDname MAC ***; %*************************************************************; %************************************************************; %*** This data step reads in the DBD source statements ***; %*** and creates a SAS data set with all the fields ***; %*** necessary to generate SAS Access descriptor line ***; %*** mode statements. ***; %************************************************************; data field (keep=name type bytes start key segno access); length cmd name access $8 rest $71; retain segno 0 access; format bytes 4. start 4. type $1.; infile psbdbd(&dbd) missover; input cmd $ rest $; if cmd = 'DBD' then do; %getfld(ACCESS) end; else if cmd = 'FIELD' or cmd =: 'FLD' then link field; else if cmd = 'SEGM' then link segm; return; %************************************************************; %*** Process DBD FIELD statements ***; %************************************************************; field: %getfld(NAME) %getfld(BYTES) %getfld(START) %getfld(TYPE) if name=' ' then goto error; if index(rest,',SEQ,') > 0 or cmd = 'FLDK' then key='Y'; else key=' '; if bytes = . or start = . or type = ' ' then do while (index(rest,', ') > 0); input @1 rest $71.; if bytes = . then do; %getfld(BYTES) end; if start = . then do; %getfld(START) end; if type = ' ' then do; %getfld(TYPE) end; end; output field; return; %************************************************************; %*** Process DBD SEGM statements ***; %************************************************************; segm: %getfld(NAME) %getfld(BYTES) if name = ' ' then goto error; if bytes = . then do while (index(rest,', ') > 0); input @1 rest $71.; if bytes = . then do; %getfld(BYTES) end; end; segno = segno + 1; output field; return; error: put 'NAME NOT FOUND'; put _infile_; return; run; %************************************************************; %*** This data step reads in the SAS data set with all ***; %*** the fields necessary to generate SAS Access ***; %*** descriptor line mode statements and writes the SAS ***; %*** Access descriptor line mode statements to a PDS. ***; %************************************************************; data _null_; retain pos; set field end=last; by segno; file mac(&dbd); name2 = translate(name,'_','-'); m = -1; if _n_ = 1 then do; put "proc access dbms=ims;"; put " create work.&dbd..access;"; put " dbd=&dbd dbtype=" access ';'; end; if first.segno then do; put " record=" name " sg=" name " sl=" bytes ";"; pos = 1; return; end; if start > pos then do; long=left(put(start-pos,3.)); put ' item=fil' _n_ ' lv=2 dbf=$char' long +m '. ' 'se=fil' _n_ '; '; pos = start; end; put ' item=' name2 ' lv=2 ' @; if type = 'C' then put 'dbf=$char' bytes +m '. ' @; else if type = 'P' then put 'dbf=pd' bytes +m '. ' @; else if type = 'X' then put 'dbf=hex' bytes +m '. ' @; else if type = 'F' then put 'dbf=pib' bytes +m '. ' @; else if type = 'H' then put 'dbf=id' bytes +m '. ' @; put 'se=' name2 @; if key = 'Y' then put 'key=y' @; put ';'; pos = start + bytes; if last then do; put ' list all;'; put 'run;'; end; run; %mend; /*--------------------------------------------------------------*/ /* Allocate the PDS files. */ /* Note 1: Replace (your.ims.dbdsrc) with the data set */ /* name for the DBD source PDS dataset. */ /* Note 2: Replace (your.ims.access) with the data set */ /* name for the output access descriptor PDS */ /* dataset. */ /*--------------------------------------------------------------*/ filename psbdbd '(your.ims.dbdsrc)' disp=shr; filename mac '(your.ims.access)' disp=old; /*--------------------------------------------------------------*/ /* Invoke the IMSDBD macro to generate the SAS Access */ /* descriptor line mode statements . */ /* Note 3: Replace xxxxxxxx with the name of the DBD to */ /* generate an access descriptor from. */ /*--------------------------------------------------------------*/ %imsdbd(xxxxxxxx); /*--------------------------------------------------------------*/ /* Deallocate the PDS files. */ /*--------------------------------------------------------------*/ filename psbdbd clear; filename mac clear; /*--------------------------------------------------------------*/ /* Create IMS SAS Access Descriptors from the SAS Access */ /* descriptor line mode statements . */ /* Note 4: Replace (your.ims.access) with the data set */ /* name for the output access descriptor PDS */ /* dataset. */ /* Note 5: Replace xxxxxxxx with the name of the DBD to */ /* generate an access descriptor from. */ /*--------------------------------------------------------------*/ %include '(your.ims.access)(xxxxxxxx)';