Modifying filenames at runtime

When you need multiple versions of the same file definition (for example, if you have an “AROxxx” filename, where xxx is a client‑specific code), Repository enables you to create one file definition and then map the filename when necessary. Every time ReportWriter opens a file, the RPS_FILNAM_METHOD subroutine is called to do any filename mapping. You can supply your own version of this subroutine and link it with ReportWriter.

RPS_FILNAM_METHOD

subroutine RPS_FILNAM_METHOD
    a_inp_file          ,a      ;Original filename (a64)
    a_out_file          ,a      ;Returned with mapped filename (a64)

Discussion

Use RPS_FILNAM_METHOD to map a filename. ReportWriter passes the data filename that you entered at the Open filename prompt in your file definition to this subroutine as a_inp_file. For example, if you’ve defined the file that contains your customer data, you could map the data filename to the appropriate name for your customer and return that name as a_out_file.

The version of RPS_FILNAM_METHOD that is supplied with your ReportWriter distribution returns the original filename, unmodified, in a_out_file.

If you’re using xfODBC, this routine must be named USR_DD_FILNAM. For additional information, see Using USR_DD_FILNAM to change replaceable characters.

Examples

This is an example of a user‑supplied filename mapping subroutine which replaces various tokens contained in the filenames.

;
; Source:               UTS:usrdd.def 
;
; Description:          Global data section for sample rps_filnam_method 
;                       routine
;
.ifdef USRDD_INIT
global data section usrdd, init
.iff
global data section usrdd
.endc

record usrdd_ctls
    usrdd_needinfo              ,d1,  1         ;Cleared when info supplied
    usrdd_cltdesc               ,a30, 'Client Number'
    usrdd_pathdesc              ,a30, 'Data Location'
    usrdd_cltno                 ,d5             ;Client Number
    usrdd_ttnum                 ,d3             ;Terminal Number
    usrdd_path                  ,a40            ;Data Location
    usrdd_pathlen               ,d2             ;%trim of usrdd_path
endglobal
subroutine rps_filnam_method
;
; Description:  Perform filename mapping
;
; The location of #### is replaced by the 4-digit client number.
; The location of ##### is replaced by the 5-digit client number
; The location of %%% is replaced by the 3-digit terminal number.
; The location of $$$ is replaced by the variable-length data path.
;
    a_filnam            ,a              ;Repository filename
    a_retnam            ,a              ;Returned filtered filename
.define USRDD_INIT
.include "UTS:usrdd.def"                ;Global region
record
    retlen              ,d3             ;Return value length
    loc                 ,d3             ;Instr pointer
proc
    a_retnam = a_filnam                 ;Map filename initially
    retlen = %len(a_retnam)
    while (%instr(1, a_retnam, '#####', loc))
      begin
        if (usrdd_needinfo)
          xcall rps_getinfo_method
        a_retnam(loc:5) = usrdd_cltno, 'XXXXX'
      end
    while (%instr(1, a_retnam, '####', loc))
      begin
        if (usrdd_needinfo)
          xcall rps_getinfo_method
        a_retnam(loc:4) = usrdd_cltno, 'XXXX'
      end
    while (%instr(1, a_retnam, '%%%', loc))
      begin
        if (usrdd_needinfo)
          xcall rps_getinfo_method
        a_retnam(loc:3) = usrdd_ttnum
      end
    while (%instr(1, a_retnam, '$$$', loc))
      begin
        if (usrdd_needinfo)
          xcall rps_getinfo_method
        a_retnam(loc+usrdd_pathlen, retlen) = a_retnam(loc+4, retlen)
        a_retnam(loc:usrdd_pathlen) = usrdd_path
      end
xreturn
endsubroutine
subroutine rps_getinfo_method
;
; Description: Get information from the user for rps_filnam_method
;
; Arguments: None
.include "UTS:usrdd.def"
.include "WND:tools.def"
record
    chn                 ,d2             ;Library channel
    id                  ,d2             ;Window ID
    srch                ,d2             ;Search variable
proc
    xcall tnmbr(usrdd_ttnum)
    xcall e_enter
    xcall u_open(chn, 'I:I', 'SYR:utwlib', srch)
    xcall i_ldinp(id, chn, 'utdd_info', srch)
    xcall i_dspfld(id, 'cltdesc', usrdd_cltdesc)
    xcall i_dspfld(id, 'pathdesc', usrdd_pathdesc)
    if (usrdd_path) then
      nop
    else
      usrdd_path = 'DAO:'               ;Default
    repeat
      begin
        xcall i_input(id,, usrdd_ctls,,,,D_NOTERM)
        if (g_select) then
          begin
            case g_entnam of
              begincase
                'O_EXIT':
                  exitloop
              endcase
            else
              call beep
          end
        else
          if (.not. g_setsts)
            exitloop
      end
    xcall e_exit
    clear usrdd_needinfo
    usrdd_pathlen = %trim(usrdd_path)
    xreturn
beep,
            display(g_terminal, 7)
    return
endsubroutine