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

Using sets instead of TVARV



 
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: Tue Jan 04, 2011 1:12 pm    Post subject: Using sets instead of TVARV Reply with quote

Using sets instead of TVARV
Written by Kevin Wilson

TVARV is a good place to store your variables for use in your program selections.

Another option is to use sets. The one difference of sets over tvarv is that a set takes on the domain of the value you are storing so it can be validated at input time.

You use transaction GS01 / GS02 / GS03 to create / change and display a set.

The following example shows a set of material types that are used to populate a range table.

Code:
    select valsign valoption valfrom valto
      into (lv_valsign , lv_valoption , lv_valfrom , lv_valto )
      from setleaf
      where setclass = 0000 and
            subclass = '' and
            setname  = 'ZMTART'.

      wa_mtart-sign   = lv_valsign.
      wa_mtart-option = lv_valoption.
      wa_mtart-low    = lv_valfrom.
      wa_mtart-high   = lv_valto.
      append wa_mtart to lr_mtart.
      endselect.
Back to top
View user's profile Send private message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Tue Jan 04, 2011 1:16 pm    Post subject: Reply with quote

Fill ranges of any type from SET, selected by name.

Code:
FUNCTION z_get_range_by_setname.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(I_SETNAME) TYPE  SETNAMENEW
*"  TABLES
*"      T_RANGE
*"  EXCEPTIONS
*"      SET_NOT_FOUND
*"      WRONG_TABLE
*"----------------------------------------------------------------------
************************************************************************
*
*  Function name                        : Z_GET_RANGE_BY_SETNAME
*  Description                          : This function reads set values
*                                         and fills values into table
*                                         (range-like)
*
*************************************************************
  DATA:
      setnr    LIKE rgsbs-setnr,
      it_lines TYPE TABLE OF rgsbv WITH HEADER LINE.
  FIELD-SYMBOLS:
      <field> TYPE ANY.

  CALL FUNCTION 'G_SET_GET_ID_FROM_NAME'
    EXPORTING
      shortname                = i_setname
    IMPORTING
      new_setid                = setnr
    EXCEPTIONS
      no_set_found             = 1
      no_set_picked_from_popup = 2
      wrong_class              = 3
      wrong_subclass           = 4
      OTHERS                   = 5.
  IF NOT sy-subrc IS INITIAL.
    RAISE set_not_found.
  ELSE.
    CALL FUNCTION 'G_SET_FETCH'
      EXPORTING
        setnr           = setnr
      TABLES
        set_lines_basic = it_lines
      EXCEPTIONS
        no_authority    = 1
        set_is_broken   = 2
        set_not_found   = 3
        OTHERS          = 4.
    IF NOT sy-subrc IS INITIAL.
      RAISE set_not_found.
    ENDIF.
  ENDIF.

*--{ VGA ECDK934901:replace
*  MOVE 'IBT' TO t_range.
  CONSTANTS: lc_cp(2) TYPE c VALUE 'CP',
             lc_bt(2) TYPE c VALUE 'BT'.
  DATA       l_option(2) TYPE c.

  ASSIGN COMPONENT 'SIGN' OF STRUCTURE t_range TO <field>.
  IF NOT <field> IS ASSIGNED.
    RAISE wrong_table.
  ENDIF.
  <field> = 'I'.
*--} VGA ECDK934901:end

  LOOP AT it_lines.
*--{ VGA ECDK934901:insert
    IF it_lines-from CA '*+' AND it_lines-from EQ it_lines-to.
      l_option = lc_cp.
    ELSE.
      l_option = lc_bt.
    ENDIF.
*--} VGA ECDK934901:end

    ASSIGN COMPONENT 'LOW' OF STRUCTURE t_range TO <field>.
    IF NOT <field> IS ASSIGNED.
      RAISE wrong_table.
    ENDIF.
    MOVE it_lines-from TO <field>.

*--{ VGA ECDK934901:insert
    IF l_option NE lc_cp.
*--} VGA ECDK934901:end
      ASSIGN COMPONENT 'HIGH' OF STRUCTURE t_range TO <field>.
      IF NOT <field> IS ASSIGNED.
        RAISE wrong_table.
      ENDIF.
      MOVE it_lines-to TO <field>.
*--{ VGA ECDK934901:insert
    ENDIF.
    ASSIGN COMPONENT 'OPTION' OF STRUCTURE t_range TO <field>.
    IF NOT <field> IS ASSIGNED.
      RAISE wrong_table.
    ENDIF.
    <field> = l_option.
*--} VGA ECDK934901:end

    APPEND t_range.
  ENDLOOP.

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.