SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Implements custom parameters, similar SAP instance param



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sun Nov 18, 2007 8:36 pm    Post subject: Implements custom parameters, similar SAP instance param Reply with quote

This function module implements custom parameters, similar to the SAP instance parameters

Code:
FUNCTION Z_GET_CUSTOMER_SYSTEM_PARAM.
*"----------------------------------------------------------------------
*"*"Local interface:
*"       IMPORTING
*"             VALUE(PARAMETER_NAME) TYPE  C
*"       EXPORTING
*"             VALUE(PARAMETER_VALUE) TYPE  C
*"----------------------------------------------------------------------
************************************************************************
* This function module implements custom system parameters, very
* similar to the regular SAP system parameters. It can be called from
* any abap to query a parameter value. The value can be set either
* in the default profile or in the instance profile. If it is not
* set there, the functiom module will return it's hard coded default
* value. Call the function module like this:
*
* report zimretst.
*   data: parameter_value(30).
*   call function 'Z_GET_CUSTOMER_SYSTEM_PARAM'
*       exporting
*            parameter_name  = 'custom/trace'
*       importing
*            parameter_value = parameter_value.
*   write: parameter_value.
*
* Default value: hardcoded, just like the real SAP system parameter
* default values in the kernel
*@@ custom/trace = NO
*@@ custom/aaaaa = 1
*@@ custom/bbbbb = 0
*@@ custom/ccccc = /tmp
************************************************************************

* Find out the name and location of the active instance profile
  DATA: BEGIN OF P OCCURS 500,
      STATUS LIKE SY-INDEX, NAME(60), CURRENT(60), DEFAULT(60),
  END OF P.
  DATA: INSTPROF(60).
  CALL 'C_SAPGALLPARAM' ID 'PAR_SUB' FIELD P-*SYS*.
  LOOP AT P.
    IF P-NAME = 'SAPPROFILE_IN_EFFECT'.
      EXIT.
    ENDIF.
  ENDLOOP.
  INSTPROF = P-CURRENT.
  IF INSTPROF IS INITIAL.
    INSTPROF = P-DEFAULT.
  ENDIF.

* Find out the name and location of the active default profile
  DATA: DEFPROF(60), I TYPE I, A.
  DEFPROF = INSTPROF.
  DO.
    SHIFT DEFPROF RIGHT.
    A = DEFPROF+59.
    IF A = '/'.
      I = SY-INDEX.
      EXIT.
    ENDIF.
  ENDDO.
  SHIFT DEFPROF LEFT BY I PLACES.
  DEFPROF+49 = 'DEFAULT.PFL'.
  CONDENSE DEFPROF NO-GAPS.

* First read the default profile
  DATA: L(100),
        C.
  OPEN DATASET DEFPROF FOR INPUT IN TEXT MODE.
  DO.
    READ DATASET DEFPROF INTO L.
    IF SY-SUBRC <> 0. EXIT. ENDIF.
    IF L CS PARAMETER_NAME.
      C = L.
     IF C <> '#'.              "The line in the profile is not commented
        SHIFT L LEFT UP TO '='.
        SHIFT L LEFT.
        CONDENSE L NO-GAPS.
        PARAMETER_VALUE = L.
        EXIT.
      ENDIF.
    ENDIF.
  ENDDO.

* No such parameter in the default profile: read the instance profile
  IF PARAMETER_VALUE IS INITIAL.
    OPEN DATASET INSTPROF FOR INPUT IN TEXT MODE.
    DO.
      READ DATASET INSTPROF INTO L.
      IF SY-SUBRC <> 0. EXIT. ENDIF.
      IF L CS PARAMETER_NAME.
        C = L.
        IF C <> '#'.          "The line in the profile is not commented
          SHIFT L LEFT UP TO '='.
          SHIFT L LEFT.
          CONDENSE L NO-GAPS.
          PARAMETER_VALUE = L.
          EXIT.
        ENDIF.
      ENDIF.
    ENDDO.
  ENDIF.

* The parameter is not defined in the profiles: set it to default
  DATA: BEGIN OF PROG_TAB OCCURS 300,
  LINE(72),
  END OF PROG_TAB.
  IF PARAMETER_VALUE IS INITIAL.
    READ REPORT 'LZTSTU01' INTO PROG_TAB.  "source code name of the f.m.
    LOOP AT PROG_TAB.
      IF PROG_TAB CS PARAMETER_NAME AND PROG_TAB CS '@@'.
        SHIFT PROG_TAB LEFT UP TO '='.
        SHIFT PROG_TAB LEFT.
        CONDENSE PROG_TAB NO-GAPS.
        PARAMETER_VALUE = PROG_TAB.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDIF.
ENDFUNCTION.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.