Copyright 2022 - BV TallVision IT

Whenever a file name or path name is entered in a selection screen, it could be quite convenient if variables like {S} for system could be used. This is quite easy to implement, but I found that I was doing this in slightly deviating ways for several developments. Hence an example that can easily be incorporated in your coding. 

The following method can be added to your class. Call is to resolve variables. It even supports resolving system variables which are listed on RSPARAM. Definition:


  CLASS-METHODS: variabele_parser CHANGING parse_field TYPE string.

And implementation

  METHOD variabele_parser.
    DATA: lv_system TYPE c LENGTH 15,
          lv_system_str TYPE string,
          begin of lw_tokens,
            t1 type string,
            t2 type string,
            t3 type string,
            t4 type string,
            t5 type string,
          end of lw_tokens,
          lw_sys_parameter type SPFPFLPAR.

   CONCATENATE sy-sysid sy-mandt INTO lv_system SEPARATED BY '_'.
   CONDENSE lv_system NO-GAPS.
   lv_system_str = lv_system.

   REPLACE ALL OCCURENCES OF '{S}' IN parse_field WITH lv_system_str.
   REPLACE ALL OCCURENCES OF '{I}' IN parse_field WITH sy-sysid(3).
   REPLACE ALL OCCURENCES OF '{C}' IN parse_field WITH sy-mandt(3).
   REPLACE ALL OCCURENCES OF '{Y}' IN parse_field WITH sy-datum(4).
   REPLACE ALL OCCURENCES OF '{H}' IN parse_field WITH sy-host.
* Special processing for parameter references, which will check RSPARAM settings
   while parse_field cs '{P='.
     split parse_field at '{P=' into lw_tokens-t1 lw_tokens-t2.  
     "\tmp\{P=INSTANCE_NAME}\more\ to \tmp\ and INSTANCE_NAME}\more\
     split lw_tokens-t2 at '}' into lw_tokens-t3 lw_tokens-t4. 
     "INSTANCE_NAME}\more\ to INSTANCE_NAME and \more\
     lw_sys_parameter-PARNAME = lw_tokens-t3.
         I_NAME           = lw_sys_parameter-PARNAME
         E_VALUE          = lw_sys_parameter-PVALUE
         OTHERS           = 4.
     IF SY-SUBRC <> 0.
       lcl_logging=>set_error( message = 'Invalid parameter {P=&}' par1 = lw_sys_parameter-PARNAME ).
       concatenate lw_tokens-t1 '#ERROR#' lw_tokens-t4 into parse_field.
       concatenate lw_tokens-t1 lw_sys_parameter-PVALUE lw_tokens-t4 into parse_field.



OMG! This is ARTICLE 500 !!!!!