`
Jack Wu
  • 浏览: 865069 次
  • 来自: ...
社区版块
存档分类
最新评论

abap--关于集(set)的读取(如读取成本中心组下的所有成本中心)

阅读更多

在sap中很多地方使用了集(set)来存储层次关系的数据,如:
Cost Center Group
Cost Element Group
Order Group
Statistical Key Figure Group
Activity Type Group
Profit Center Group
Business Process Group
Cost Object Group
Account Group
WBS Element Group
Fund Group
Functional Area Group
Grant Group
Business Entities Set
Real Estate Set
Buildings Set
Rental Units Set
Rental Agreements Set
Management Contracts Set
Settlement Units Set
General Contracts Set
... 等等....,具体参见SETCLS表.

相关TCODE
GS01
GS02
GS03
GS04

相关数据表
setcls:Set Classes(SETCLASS(4))
SETCLST: Set Class Descriptions(LANGU(2),SETCLASS(4))
setheader:Set Header and Directory(SETCLASS(4),SUBCLASS(10),SETNAME(24))
setnode:Lower-level sets in sets((SETCLASS(4),SUBCLASS(10),SETNAME(24),LINEID(10))
setleaf:Values in Sets(SETCLASS(4),SUBCLASS(10),SETNAME(24),LINEID(10))

相关函数
'G_SET_GET_ALL_VALUES'
'G_SET_FETCH'

代码样例
该样例代码是提取某个成本中心组下的成本中心到range: s_kostl
*&---------------------------------------------------------------------*
*&      Form  GET_TREE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_kostl.
  data: l_count type i.
  data: begin of i_tree occurs 0,
      setname like setnode-setname,
    end of i_tree.
  data: i_subtree like i_tree occurs 0 with header line,
    i_temptree like i_tree occurs 0 with header line.
  select setname into  i_tree
    from setheader
    where setclass = '0101' and subclass = '1000'
      and setname in s_cengrp.
    read table i_setheader with key setname = i_tree-setname.
    if sy-subrc = 0.
      append i_tree to i_tree.
    endif.
  endselect.
  i_subtree[] = i_tree[].
  l_count = 1.
  while l_count > 0.
    read table i_subtree index 1.
    delete i_subtree index 1.
    select subsetname as setname
      into table i_temptree
      from setnode
      where setclass = '0101'
       and subclass = '1000' and subsetcls = '0101'
       and subsetscls = '1000' and setname = i_subtree-setname.
    append lines of i_temptree to i_tree.
    append lines of i_temptree to i_subtree.
    describe table i_subtree lines l_count.
  endwhile.
  select valsign as sign   valoption as option
    valfrom as low   valto   as high
    into table s_kostl
  from setleaf
    for all entries in i_tree
  where setclass = '0101'
    and subclass = '1000'  and setname = i_tree-setname.
endform.                    " GET_KOSTL
 代码二
DATA: t_set_values TYPE TABLE OF rgsb4.

CALL FUNCTION 'G_SET_GET_ALL_VALUES'
  EXPORTING
    client        = sy-mandt
    setnr         = 'NP_SLOC_SERV'
    table         = 'MARD'
    class         = '0000'
    fieldname     = 'LGORT'
  TABLES
    set_values    = t_set_values
  EXCEPTIONS
    set_not_found = 1
    OTHERS        = 2.
代码三

REPORT YTEST_GRP .

* -- Constant for the Set Class
CONSTANTS: c_cls_0106 TYPE rgsbs-class VALUE '0106'.

DATA: l_wa_set_lines_basic TYPE rgsbv,
      l_wa_hdr             TYPE rgsbs,
      l_i_for_lin          TYPE STANDARD TABLE OF rgsbf,
      l_i_set_lines_basic  TYPE STANDARD TABLE OF rgsbv,
      l_i_set_lines_data   TYPE STANDARD TABLE OF rgsb3,
      l_i_set_lines_multi  TYPE STANDARD TABLE OF rgsb2,
      l_i_set_lines_single TYPE STANDARD TABLE OF rgsb1.

DATA: l_v_setnr TYPE char50.

PARAMETERS: p_PCGRP type PCGRP,      " Profit Centre Group
            p_kokrs type kokrs.      " Controlling Area

CONCATENATE p_kokrs p_pcgrp INTO l_v_setnr.

*-- Get the Set description
CALL FUNCTION 'G_SET_FETCH'
EXPORTING
       class = c_cls_0106
       setnr = l_v_setnr
IMPORTING
       set_header = l_wa_hdr
TABLES
       formula_lines    = l_i_for_lin
       set_lines_basic  = l_i_set_lines_basic
       set_lines_data   = l_i_set_lines_data
       set_lines_multi  = l_i_set_lines_multi
       set_lines_single = l_i_set_lines_single
EXCEPTIONS
       no_authority = 1
       set_is_broken = 2
       set_not_found = 3
       OTHERS = 4.

*-- handle your exceptions here

      loop at l_i_set_lines_basic into l_wa_set_lines_basic.

        write :/ l_wa_set_lines_basic-from,
                 l_wa_set_lines_basic-to,
                 l_wa_set_lines_basic-title.
      endloop.

参考:https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/5541

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics