Skip to end of metadata
Go to start of metadata

Author: Andrea Olivieri
Supported Releases: SAP ECC 6.0
Submitted: 20 September 2010

Highlights

Original source code taken from the ASU variant restore Tool RASUVSAV
Please see the parent page Discover All the Report Variants with Parameters - Select Options of type BUKRS



Variant Data Save- General Flow and Pre-requisites

Function Groups ASU2,ASU4 as well as the DDIC Tables TASUVCAT, TASUVEXT, TASUVSVD and TASUNSVO should exist.

Processing

Starting from the variant catalog table TASUVCAT , the current variant data and attributes are stored in both tables TASUVSVD and TASUVSVO.
The TASUVSVD table contains the variant data and TASUVSVO contains the technical field descriptions (TVARV variables, protected fields, and so on).

Remarks

The program saves only the values of the parameters related to a data element with domain bukrs.

(...)
* Get active Data Elemnts for Domain BUKRS
select rollname from dd04l
                    into table lt_repository bypassing buffer
                    where domname eq 'BUKRS' and
                         ( refkind eq space or refkind eq 'D' )
                          and as4local eq 'A'.
sort lt_repository.
(...)
read table lt_repository with key rollname = ls_dfies-rollname transporting no fields.
check sy-subrc = 0.

Text Elements

Selection Texts:

IV_REPID	Report Name
IV_TEST	Testrun

Text Symbols

003	Report name
004	Only variants for ...
005	all reports will be saved
006	are you sure?
007	saving report variants
008	saved
009	tested

ABAP Source Code

Error rendering macro 'code': Invalid value specified for parameter 'com.atlassian.confluence.ext.code.render.InvalidValueException'
*&---------------------------------------------------------------------*
*& Report  ZSDN_PROG_VARIANT_BUKRS_SAVE
*----------------------------------------------------------------------*
*& Report Name: Save Program Variants with BUKRS                       *
*& Created by: Andrea Olivieri                                         *
*& Company: Techedge SpA                                               *
*& Created on: 13.09.2010 at 13:10:12 CET                              *
*& Source Code taken from ASU variant Restore Tool RASUVSAV
*&---------------------------------------------------------------------*

report  zsdn_prog_variant_bukrs_save.
.

tables: tasuvcat, tadir, varid, tasuvsvd, tasuvsvo.

include iasudata.

*- SELECTION-SCREEN ---------------------------------------------------
selection-screen begin of block report with frame title text-004.
selection-screen begin of line.
selection-screen comment 1(25) text-003 for field iv_repid.
parameters: iv_repid like tasuvcat-report.
selection-screen end of line.
selection-screen end of block report.

parameters: iv_test as checkbox default 'X'.

*- DATA ---------------------------------------------------------------
data: lv_true(1)        type c value 'X'.
data: lv_undefined(1)   type c value '*'.
data: lv_answer_yes(1)  type c value 'J'.
data: lv_answer_no(1)   type c value 'N'.
data: lv_pgmid_r3tr     like tadir-pgmid value 'R3TR'.
data: lv_object_prog    like tadir-object value 'PROG'.

data: lv_standard_screen like sy-dynnr value '1000'.
data: lv_db_count_max like sy-tabix value 1.
data: ld_undef(1).
data: ld_error  like sy-subrc.
data: returned(1).

data: lv_db_count    like sy-tabix.
data: lv_ddobjname   like  dcobjdef-name.
data: lv_structlen   type i.
data: lv_intlen      type i.
data: lv_intlen_max  like dfies-intlen value 45.
data: lt_dynnr       like rsdynnr occurs 0.
data: ls_variscreen  like rsdynnr.
data: lt_variscreen  like rsdynnr occurs 0.
data: ls_dfies       like dfies.
data: lt_dfies       like dfies    occurs 0.
data: ls_params      like rsparams.
data: lt_params      like rsparams occurs 0.
data: ls_objects     like vanz.
data: lt_objects     like vanz     occurs 0.
data: ls_tasuvsvo    like tasuvsvo.
data: lt_tasuvsvo    like tasuvsvo occurs 0.
data: ls_tadir       like tadir.                            "#EC NEEDED
data: ls_varid       like varid.                            "#EC NEEDED
data: ls_sscr        like rsscr.
data: lt_sscr_d      like rsscr    occurs 0.
data: lt_sscr        like rsscr    occurs 0.
data: ls_tasuvcat    like tasuvcat.
data: lt_tasuvcat    like tasuvcat occurs 0.
data: lt_save_tasuvcat like tasuvcat occurs 0.
data: ls_tasuvsvd    like tasuvsvd.
data: ls_tasuvsvd2   like tasuvsvd.
data: lt_tasuvsvd    like tasuvsvd occurs 0.
data: begin of lt_repository occurs 0,
         rollname type dd04vvt-rollname,
      end of lt_repository.
field-symbols: <f>.
* Unicode detection
data:
  ls_x030l  type x030l,
  l_flg_unicode.
data save_tabix type sy-tabix.
*- PROGRAM ------------------------------------------------------------
* Get active Data Elemnts for Domain BUKRS
select rollname from dd04l
                    into table lt_repository bypassing buffer
                    where domname eq 'BUKRS' and
                         ( refkind eq space or refkind eq 'D' )
                          and as4local eq 'A'.
sort lt_repository.


do 1 times.

  if iv_repid is initial.
    data: lv_answer type c.
    if sy-batch = 'X'.
      lv_answer = lv_answer_yes.
    else.
      call function 'POPUP_TO_CONFIRM_STEP'
        exporting
          defaultoption  = lv_answer_no
          textline1      = text-005
          textline2      = text-006
          titel          = text-007
          cancel_display = lv_true
        importing
          answer         = lv_answer.
    endif.
    check lv_answer eq lv_answer_yes.
    select * from tasuvcat into table lt_tasuvcat
                            where saved = space.
  else.
    select * from tasuvcat into table lt_tasuvcat
                            where report = iv_repid. " AND
*                                  saved  = space.
    if not sy-subrc is initial.
      exit.
    endif.
  endif.

* set maximum of structure length
  describe field ls_params-low length lv_intlen_max in character mode.

* process all variants
  loop at lt_tasuvcat into ls_tasuvcat.
*...check if report still exists
    select single * from tadir into ls_tadir
                         where pgmid    = lv_pgmid_r3tr
                           and object   = lv_object_prog
                           and obj_name = ls_tasuvcat-report.
    if not sy-subrc is initial.
      ls_tasuvcat-errorflg = lv_true.
      modify tasuvcat from ls_tasuvcat.
      commit work.
      continue.
    endif.
*...check if variant exists
    select single * from varid into ls_varid
                         where report  = ls_tasuvcat-report
                           and variant = ls_tasuvcat-vari.
    if not sy-subrc is initial.
      ls_tasuvcat-errorflg = lv_true.
      modify tasuvcat from ls_tasuvcat.
      commit work.
      continue.
    endif.
    clear returned.
    clear ld_error.
*...needs to be done via RFC, otherwise
*...ABAP/4 processor: LOAD_COMMON_PART could occur
    refresh: lt_params, lt_objects.
    call function 'FASU_V_VARIANT_CONTENTS'
      starting new task 'SLO'
      destination 'NONE'
      performing return_content on end of task
      exporting
        report  = ls_tasuvcat-report
        variant = ls_tasuvcat-vari
      exceptions
        error   = 1
        others  = 2.
    wait until returned = 'X'.
    check ld_error is initial.
*   check sy-subrc is initial.
    loop at lt_objects into ls_objects.
      clear ls_tasuvsvo.
      move-corresponding ls_objects to ls_tasuvsvo.
      ls_tasuvsvo-report = ls_tasuvcat-report.
      ls_tasuvsvo-vari   = ls_tasuvcat-vari.
      append ls_tasuvsvo to lt_tasuvsvo.
    endloop.

*   get all screens for variant into ls_varis
    clear returned.
    clear ld_error.
*...needs to be done via RFC, otherwise
*...ABAP/4 processor: LOAD_COMMON_PART could occur
    refresh: lt_variscreen, lt_dynnr.
    call function 'FASU_V_GET_SCREENS_4_1_VARIANT'
      starting new task 'SLO'
      destination 'NONE'
      performing return_screens on end of task
      exporting
        program = ls_tasuvcat-report
        variant = ls_tasuvcat-vari
      exceptions
        error   = 1
        others  = 2.

    wait until returned = 'X'.
    check ld_error is initial.
*   read information about definition of parameters, but only for the
*   selected screen of tASUVCAT
    loop at lt_variscreen into ls_variscreen
                          where ( dynnr eq ls_tasuvcat-dynnr or
                                  dynnr eq lv_undefined ).

*     sometimes the standard screen is dynpro 1000, sometimes *.
*     if both exist, ignore dynpro *
      clear ld_undef.
      if ls_variscreen-dynnr eq lv_undefined.
        read table lt_variscreen transporting no fields
                                 with key dynnr = lv_standard_screen.
        if not sy-subrc is initial.
          ls_variscreen-dynnr = lv_standard_screen.
          ld_undef = 'X'.
        else.
          continue.
        endif.
      endif.

      call function 'RS_ISOLATE_1_SELSCREEN'
        exporting
          program     = ls_tasuvcat-report
          dynnr       = ls_variscreen-dynnr
        tables
          screen_sscr = lt_sscr_d
          global_sscr = lt_sscr
        exceptions
          no_objects  = 1
          others      = 2.
      check sy-subrc is initial.
      data: lrsscr type rsscr,
            lv_fieldname type dfies-lfieldname.


      loop at lt_sscr_d into lrsscr where kind = 'S' or kind = 'P' .

        read table lt_params with key selname = lrsscr-name transporting no fields.
        check sy-subrc = 0.                          "<<<<<<<<<<<<<<<<<<<<<
        save_tabix = sy-tabix.


        loop at lt_params into ls_params from save_tabix.
          if ls_params-selname <> lrsscr-name .
            exit.
          endif.
          if lrsscr-dbfield ca '-'.
            split lrsscr-dbfield at '-' into lv_ddobjname lv_fieldname.

            refresh lt_dfies.
            call function 'DDIF_NAMETAB_GET'
              exporting
                tabname    = lv_ddobjname
                lfieldname = lv_fieldname
              importing
                dfies_wa   = ls_dfies
                x030l_wa   = ls_x030l
              exceptions
                not_found  = 1
                others     = 2.


            if sy-subrc = 0.

              if ls_x030l-unicodelg > 1.
                l_flg_unicode = 'X'.
              else.
                l_flg_unicode = ' '.
              endif.

              if  l_flg_unicode = 'X'.
                ls_dfies-offset = ls_dfies-offset / 2.
                ls_dfies-intlen = ls_dfies-intlen / 2.
              endif.

              read table lt_repository with key rollname = ls_dfies-rollname transporting no fields.
              check sy-subrc = 0.

              clear lv_structlen.
*...........check if this parameter is new or a multiple selection
*            read table lt_params into ls_params with key selname = lrsscr-name.
*            check sy-subrc = 0.                          "<<<<<<<<<<<<<<<<<<<<<
              loop at lt_tasuvsvd into ls_tasuvsvd2
                          where report = ls_tasuvcat-report
                            and vari   = ls_tasuvcat-vari
                            and dynnr  = ls_tasuvsvd-dynnr
                            and struc  = ls_params-selname
                            and field  = ls_dfies-fieldname.
                ls_tasuvsvd-pos = ls_tasuvsvd-pos + 1.
              endloop.
              if sy-subrc <> 0.
                ls_tasuvsvd-pos = 1.
                ls_tasuvsvd-report  = ls_tasuvcat-report.
                ls_tasuvsvd-vari    = ls_tasuvcat-vari.
                ls_tasuvsvd-dynnr   = ls_tasuvsvd-dynnr.
              endif.
*             set new sum of structure length
              lv_structlen = lv_structlen + ls_dfies-intlen.
*             check against maximum of structure length
              if lv_structlen gt lv_intlen_max.
                lv_intlen = lv_intlen_max -
                            ( lv_structlen - ls_dfies-intlen ).
                if lv_intlen le 0.
                  exit.
                endif.
              else.
                lv_intlen = ls_dfies-intlen.
              endif.
              ls_tasuvsvd-struc = ls_params-selname.
              ls_tasuvsvd-field = ls_dfies-fieldname.
              sy-subrc = 0.
              "ASSIGN ls_params-low+ls_dfies-offset(lv_intlen)
              assign ls_params-low(lv_intlen)
              to <f>.
              if <f> is assigned .
                ls_tasuvsvd-low = <f>.
              endif.
              sy-subrc = 0.
              "ASSIGN ls_params-high+ls_dfies-offset(lv_intlen)
              assign ls_params-high(lv_intlen)
              to <f>.
              if <f> is assigned .
                ls_tasuvsvd-high = <f>.
              endif.
              ls_tasuvsvd-sign     = ls_params-sign.        "20100915+
              ls_tasuvsvd-opt      = ls_params-option.      "20100915+
              ls_tasuvsvd-intlen   = ls_dfies-intlen.
              ls_tasuvsvd-datatype = ls_dfies-datatype.
              append ls_tasuvsvd to lt_tasuvsvd.

*           CHECK lv_structlen GE lv_intlen_max.

*         no structure, but reference to DDIC
            else.
*...........check if this parameter is new or a multiple selection
*...........loop is necessary to get the highest pos
*            read table lt_params into ls_params with key selname = lrsscr-name.
*            check sy-subrc = 0.                          "<<<<<<<<<<<<<<<<<<<<<
              loop at lt_tasuvsvd into ls_tasuvsvd2
                          where report = ls_tasuvcat-report
                            and vari   = ls_tasuvcat-vari
                            and dynnr  = ls_tasuvsvd-dynnr
                            and struc  = space
                            and field  = ls_params-selname.
                ls_tasuvsvd-pos = ls_tasuvsvd-pos + 1.
              endloop.
              if sy-subrc <> 0.
                ls_tasuvsvd-pos = 1.
                ls_tasuvsvd-report  = ls_tasuvcat-report.
                ls_tasuvsvd-vari    = ls_tasuvcat-vari.
                ls_tasuvsvd-dynnr   = ls_tasuvsvd-dynnr.
              endif.
              ls_tasuvsvd-low      = ls_params-low.
              ls_tasuvsvd-high     = ls_params-high.
              ls_tasuvsvd-sign     = ls_params-sign.        "20100915+
              ls_tasuvsvd-opt      = ls_params-option.      "20100915+
              ls_tasuvsvd-intlen   = ls_sscr-length.
              ls_tasuvsvd-datatype = ls_sscr-dtyp.
              append ls_tasuvsvd to lt_tasuvsvd.
            endif.


          else.
*..... Direct type assignment
            data: lv_typename type typename,
                  lv_ttype    type tbatgobj,
                  lv_gotstate  type ddgotstate.
            lv_typename =  lrsscr-dbfield.
            call function 'DDIF_TYPEINFO_GET'
              exporting
                typename = lv_typename
              importing
                typekind = lv_ttype
                gotstate = lv_gotstate.
            check  lv_ttype = 'DTEL' and lv_gotstate = 'A'.
            read table lt_repository with key rollname = lv_typename transporting no fields.
            check sy-subrc = 0.
            lv_structlen = lv_structlen + ls_dfies-leng.
*             check against maximum of structure length
            if lv_structlen gt lv_intlen_max.
              lv_intlen = lv_intlen_max -
                          ( lv_structlen - ls_dfies-leng ).
              if lv_intlen le 0.
                exit.
              endif.
            else.
              lv_intlen = ls_dfies-leng.
            endif.

            loop at lt_tasuvsvd into ls_tasuvsvd2
                          where report = ls_tasuvcat-report
                            and vari   = ls_tasuvcat-vari
                            and dynnr  = ls_tasuvsvd-dynnr
                            and struc  = ls_params-selname
                            and field  = ls_dfies-fieldname.
              ls_tasuvsvd-pos = ls_tasuvsvd-pos + 1.
            endloop.
            if sy-subrc <> 0.
              ls_tasuvsvd-pos = 1.
              ls_tasuvsvd-report  = ls_tasuvcat-report.
              ls_tasuvsvd-vari    = ls_tasuvcat-vari.
              ls_tasuvsvd-dynnr   = ls_tasuvsvd-dynnr.
            endif.

            ls_tasuvsvd-struc = ls_params-selname.
            ls_tasuvsvd-field = ls_dfies-fieldname.
            sy-subrc = 0.
            assign ls_params-low+ls_dfies-offset(lv_intlen)
            to <f>.
            if <f> is assigned .
              ls_tasuvsvd-low = <f>.
            endif.
            sy-subrc = 0.
            assign ls_params-high+ls_dfies-offset(lv_intlen)
            to <f>.
            if <f> is assigned ..
              ls_tasuvsvd-high = <f>.
            endif.
            ls_tasuvsvd-intlen   = ls_dfies-intlen.
            ls_tasuvsvd-datatype = ls_dfies-datatype.
            ls_tasuvsvd-sign     = ls_params-sign.          "20100915+
            ls_tasuvsvd-opt      = ls_params-option.        "20100915+
            append ls_tasuvsvd to lt_tasuvsvd.

          endif.
        endloop.
      endloop.
    endloop.

    ls_tasuvcat-saved    = lv_true.
    ls_tasuvcat-savedate = sy-datum.
    ls_tasuvcat-savetime = sy-uzeit.
    ls_tasuvcat-saveuser = sy-uname.

    append ls_tasuvcat to lt_save_tasuvcat.
    lv_db_count = lv_db_count + 1.

  endloop.

* Set Mandt for DB Update
  clear ls_tasuvsvo.
  ls_tasuvsvo-mandt = sy-mandt.
  modify lt_tasuvsvo from ls_tasuvsvo transporting mandt where mandt is initial.
  clear ls_tasuvsvd.
  ls_tasuvsvd-mandt = sy-mandt.
  modify lt_tasuvsvd from ls_tasuvsvd transporting mandt where mandt is initial.

*...BUKRS Only
  loop at lt_tasuvsvo into ls_tasuvsvo.
    save_tabix = sy-tabix.
    read table lt_tasuvsvd with key mandt = ls_tasuvsvo-mandt
                                    report = ls_tasuvsvo-report
                                    vari   = ls_tasuvsvo-vari
                                    struc = ls_tasuvsvo-name transporting no fields.
    if sy-subrc <> 0.
      delete lt_tasuvsvo index save_tabix.
    endif.
  endloop.
*   save package
  if lv_db_count ge lv_db_count_max.
    if iv_test ne lv_true.
      modify tasuvcat from table lt_save_tasuvcat.
      commit work and wait.
*...needs to be done via RFC, because e.g. dec-fields
*...could lead to a dump during posting
      clear returned.
      clear ld_error.
      call function 'FASU_V_POST_DATA'
        starting new task 'SLO'
        destination 'NONE'
        performing return_posting on end of task
        tables
          it_tasuvsvd = lt_tasuvsvd
          it_tasuvsvo = lt_tasuvsvo
        exceptions
          error       = 1
          others      = 2.

      wait until returned = 'X'.
      if ld_error is initial.
*.......if commit was successful, set errorflg to space
        loop at lt_save_tasuvcat into ls_tasuvcat.
          clear ls_tasuvcat-errorflg.
          modify lt_save_tasuvcat from ls_tasuvcat index sy-tabix.
        endloop.
        modify tasuvcat from table lt_save_tasuvcat.
        commit work and wait.
      endif.
      loop at lt_save_tasuvcat into ls_tasuvcat.
        write: / ls_tasuvcat-report, ls_tasuvcat-dynnr,
                 ls_tasuvcat-vari, text-008.
      endloop.
*       initialize save data
      refresh:
        lt_save_tasuvcat,
        lt_tasuvsvd,
        lt_tasuvsvo.
      clear:
        lv_db_count.
    else.
      loop at lt_save_tasuvcat into ls_tasuvcat.
        write: / ls_tasuvcat-report, ls_tasuvcat-dynnr,
                 ls_tasuvcat-vari, text-009.
      endloop.
*       initialize save data
      refresh:
        lt_save_tasuvcat,
        lt_tasuvsvd,
        lt_tasuvsvo.
      clear:
        lv_db_count.
    endif.
  endif.

*ENDLOOP.

* save variants, which are not saved yet
  if not lt_save_tasuvcat[] is initial.
    if iv_test ne lv_true.
      modify tasuvcat from table lt_save_tasuvcat.
      commit work and wait.
*...needs to be done via RFC, because e.g. dec-fields
*...could lead to a dump during posting
      clear returned.
      clear ld_error.
      call function 'FASU_V_POST_DATA'
        starting new task 'SLO'
        destination 'NONE'
        performing return_posting on end of task
        tables
          it_tasuvsvd = lt_tasuvsvd
          it_tasuvsvo = lt_tasuvsvo
        exceptions
          error       = 1
          others      = 2.

      wait until returned = 'X'.
      if ld_error is initial.
*.....if commit was successful, set errorflg to space
        loop at lt_save_tasuvcat into ls_tasuvcat.
          clear ls_tasuvcat-errorflg.
          modify lt_save_tasuvcat from ls_tasuvcat index sy-tabix.
        endloop.
        modify tasuvcat from table lt_save_tasuvcat.
        commit work and wait.
      endif.
*.....list output
      loop at lt_save_tasuvcat into ls_tasuvcat.
        write: / ls_tasuvcat-report, ls_tasuvcat-dynnr,
                 ls_tasuvcat-vari, text-008.
      endloop.
*     initialize save data
      refresh:
        lt_save_tasuvcat,
        lt_tasuvsvd,
        lt_tasuvsvo.
      clear:
        lv_db_count.
    else.
      loop at lt_save_tasuvcat into ls_tasuvcat.
        write: / ls_tasuvcat-report, ls_tasuvcat-dynnr,
                 ls_tasuvcat-vari, text-009.
      endloop.
*     initialize save data
      refresh:
        lt_save_tasuvcat,
        lt_tasuvsvd,
        lt_tasuvsvo.
      clear:
        lv_db_count.
    endif.
  endif.

enddo.

*&---------------------------------------------------------------------*
*&      Form  return_content
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form return_content using taskname.

  receive results from function 'FASU_V_VARIANT_CONTENTS'
          tables
               valutab               = lt_params
               objects               = lt_objects
          exceptions
               syst_except           = 1
               communication_failure = 2
               system_failure        = 3
               variant_non_existent  = 4
               variant_obsolete      = 5
               error                 = 6.

  ld_error = sy-subrc.
  returned = 'X'.

endform.                    " RETURN_PARAMS
*&---------------------------------------------------------------------*
*&      Form  RETURN_SCREENS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form return_screens using taskname.

  receive results from function 'FASU_V_GET_SCREENS_4_1_VARIANT'
          tables
               dynnr                 = lt_dynnr
               variscreens           = lt_variscreen
          exceptions
               syst_except           = 1
               communication_failure = 2
               system_failure        = 3
               no_screens            = 4
               variant_not_existent  = 5
               error                 = 6.

  ld_error = sy-subrc.
  returned = 'X'.


endform.                    " RETURN_SCREENS
*&---------------------------------------------------------------------*
*&      Form  RETURN_POSTING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
form return_posting using taskname.

  receive results from function 'FASU_V_POST_DATA'
          exceptions
               syst_except           = 1
               communication_failure = 2
               system_failure        = 3
               error_happened        = 4
               error                 = 6.

  ld_error = sy-subrc.
  returned = 'X'.


endform.                    " RETURN_POSTING

Back to Discover Report Variants with Parameters - Select Options of type BUKRS