工作生活与爱好

工作中的记录; 生活中的记忆; 业余爱好的记载。

2007-01-16

 

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.


Comments: 发表评论



<< Home

Archives

1990年1月15日   2007年1月14日   2007年1月15日   2007年1月16日   2007年1月17日   2007年1月18日   2007年1月19日   2007年1月20日   2007年1月22日   2007年1月23日   2007年1月24日   2007年1月25日   2007年1月26日   2007年1月27日   2007年1月29日   2007年1月30日   2007年1月31日   2007年2月1日   2007年2月2日   2007年2月3日   2007年3月13日   2007年5月15日   2007年5月16日   2007年6月2日  

This page is powered by Blogger. Isn't yours?