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

Create variant dynamically



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



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Mon Feb 25, 2008 4:28 pm    Post subject: Create variant dynamically Reply with quote

Code:
REPORT z_dyn_variant.
DATA: jvari_desc LIKE varid,
  rc LIKE sy-subrc,
  variant_text LIKE varit-vtext,
  jvt LIKE varit OCCURS 0 WITH HEADER LINE,
  selpa LIKE rsparams OCCURS 0 WITH HEADER LINE,
  parms LIKE rsparams OCCURS 0 WITH HEADER LINE,
  objs LIKE vanz OCCURS 0 WITH HEADER LINE.

PARAMETERS: p_var LIKE rsvar-variant. "NAME OF VARIANT

jvari_desc-report = sy-repid.
jvari_desc-variant = p_var.
jvari_desc-ename = 'EXAMPLES'.
jvt-report = sy-repid.
jvt-variant = p_var.
jvt-langu = sy-langu.
jvt-vtext = 'FUNCTION EXAMPLES'.

APPEND jvt.
CLEAR selpa.

selpa-sign = 'I'.
selpa-option = 'EQ'.
selpa-kind = 'P'.
selpa-selname = 'P_VAR'.
selpa-low = p_var.
APPEND selpa.

* CHECK IF VARIANT EXISTS

CALL FUNCTION 'RS_VARIANT_EXISTS'
  EXPORTING
    report              = jvari_desc-report
    variant             = p_var
  IMPORTING
    r_c                 = rc
  EXCEPTIONS
    not_authorized      = 1
    no_report           = 2
    report_not_existent = 3
    report_not_supplied = 4
    OTHERS              = 5.

IF rc = 0 AND sy-subrc EQ 0.

* DELETE OLD VARIANT

  CALL FUNCTION 'RS_VARIANT_DELETE'
    EXPORTING
      report               = jvari_desc-report
      variant              = p_var
      flag_confirmscreen   = 'X'
    EXCEPTIONS
      not_authorized       = 1
      not_executed         = 2
      no_report            = 3
      report_not_existent  = 4
      report_not_supplied  = 5
      variant_locked       = 6
      variant_not_existent = 7
      no_corr_insert       = 8
      variant_protected    = 9
      OTHERS               = 10.

  IF sy-subrc NE 0.
    WRITE: 'UNABLE TO DELETE VARIANT:', p_var ,'STATUS=', sy-subrc.
    EXIT.
  ELSE.
    WRITE:/ p_var, 'DELETED'.
  ENDIF.
ELSE.
  WRITE:/ p_var, 'DOES NOT EXIST'.
ENDIF. " ALREADY EXISTS

CALL FUNCTION 'RS_CREATE_VARIANT'
  EXPORTING
    curr_report               = jvari_desc-report
    curr_variant              = p_var
    vari_desc                 = jvari_desc
  TABLES
    vari_contents             = selpa
    vari_text                 = jvt
  EXCEPTIONS
    illegal_report_or_variant = 1
    illegal_variantname       = 2
    not_authorized            = 3
    not_executed              = 4
    report_not_existent       = 5
    report_not_supplied       = 6
    variant_exists            = 7
    variant_locked            = 8
    OTHERS                    = 9.

IF sy-subrc EQ 0.
  WRITE:/ 'VARIANT', p_var, 'CREATED FOR PROGRAM', jvari_desc-report.
ELSE.
  WRITE:/ 'VARIANT', p_var, 'NOT CREATED FOR PROGRAM', jvari_desc-report.
  EXIT.
ENDIF.

CALL FUNCTION 'RS_VARIANT_CONTENTS'
  EXPORTING
    report               = jvari_desc-report
    variant              = p_var
  TABLES
    valutab              = parms
    OBJECTS              = objs
  EXCEPTIONS
    variant_non_existent = 1
    variant_obsolete     = 2
    OTHERS               = 3.

IF sy-subrc NE 0.

  WRITE : / 'ERROR READING VARIANT CONTENTS.'.

ELSE.

  CALL FUNCTION 'RS_VARIANT_TEXT'
    EXPORTING
      langu       = sy-langu
      curr_report = jvari_desc-report
      variant     = p_var
    IMPORTING
      v_text      = variant_text.
  WRITE:/ 'VARIANT DESCRIPTION:', variant_text.

  LOOP AT parms.
    CHECK parms-low NE space OR parms-high NE space.
    READ TABLE objs WITH KEY name = parms-selname.
    WRITE : /2 parms-selname, objs-text,
    45 parms-kind,
    parms-sign,
    parms-option,
    parms-low,
    parms-high.
    NEW-LINE.
  ENDLOOP.
  SKIP.
ENDIF.

some other approach....

Code:
* This function module selects the Selection Screen contents
CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
  EXPORTING
    curr_report     = sy-repid
  TABLES
    selection_table = loc_int_tab
  EXCEPTIONS
    not_found       = 1
    no_report       = 2
    OTHERS          = 3.
IF sy-subrc NE 0.
  MESSAGE i000 WITH 'Error in RS_REFRESH_FROM_SELECTOPTIONS'(029).
  LEAVE LIST-PROCESSING.
ENDIF.
* Craete the variant VAR1
CALL FUNCTION 'RS_CREATE_VARIANT'
  EXPORTING
    curr_report               = sy-repid
    curr_variant              = wf_variant
    vari_desc                 = loc_varid
  TABLES
    vari_contents             = loc_int_tab
    vari_text                 = loc_varit
  EXCEPTIONS
    illegal_report_or_variant = 1
    illegal_variantname       = 2
    not_authorized            = 3
    not_executed              = 4
    report_not_existent       = 5
    report_not_supplied       = 6
    variant_exists            = 7
    variant_locked            = 8
    OTHERS                    = 9.
IF sy-subrc 0.
  MESSAGE i000 WITH 'Error while creating dynamic variant'(028).
  LEAVE LIST-PROCESSING.
ENDIF.
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 -> Dynamic Programming | Динамическое программирование 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.