Reading attribute of a BOR (Business Object) in ABAP

Many times I've looked at transaction SWO1 for a business object and seen how it displays all sorts of useful functions (e.g Line Item Texts etc. etc.). Many of these attributes can only be got at in normal programming via convoluted abap tinkering. -- How many times for example do you want to get texts to include on a smartform etc.

However it's really easy to get the attribute from the BOR itself using very simple coding.

Most people shy away from this since a BOR is usually used in SAP workflow and most abap developers haven't had a lot of exposure to OO programming or SAP workflow.

Anyway here's sample code to return an Attribute of a BOR. 

program zzreadbor.

* Get an attribute of a business object.

parameters: p_busobj(10) type c default 'BUSISM007',  "IS Media 
customer
            p_key(70) type c,
            p_attr(32) type c default 'Xmediacustomer'.
data:
    i_objtype TYPE swo_objtyp,
    i_objkey TYPE swo_typeid,
    i_element TYPE swo_verb.
     DATA object TYPE swo_objhnd.
    DATA verb TYPE swo_verb.
    DATA return TYPE swotreturn.
 DATA lt_container TYPE STANDARD TABLE OF swcont.
 data line type swcont.

i_objtype = p_busobj.
i_element = p_attr.
i_objkey = p_key.
*  instantiate the business object. I.e give it a key and create it.
  CALL FUNCTION 'SWO_CREATE'
    EXPORTING
      objtype = i_objtype
      objkey  = i_objkey
    IMPORTING
      object  = object.

* return attribute.
  CALL FUNCTION 'SWO_INVOKE'
    EXPORTING
      access     = 'G'
      object     = object
      verb       = i_element

    IMPORTING
      return     = return
      verb       = verb
    TABLES
      container  = lt_container.
* the attribute value is returned in field line-value.
  IF return-code = 0.
  loop at lt_container into line.
  write: / line-value.
  endloop.
endif.

* The above example will return an 'X' if the customer is an IS Media customer or blank otherwise.

Other good business objects to use are sales docs (header / line items), invoices, Info types etc etc.

You can also call methods this way as well -- change the access to 'C' in the SWO_INVOKE and pass the parameters to the method. Method name is in VERB. A bit more complex as in the case of Supertypes you need to find the program -- will post an example later --however to start with even the attributes are useful since on "Instantiation" of the BOR you have access to ALL the attribites of that BOR.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值