Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
philipdavy
Contributor
This is a continuation of my post series,

Part 1 : https://blogs.sap.com/2021/07/09/abap-lesser-known-heroes-series-group-column-part-1/comment-page-1/...

Part 2 : ABAP Lesser Known Heroes Series – Value Operator : Part 2

Part 3 : ABAP Lesser Known Heroes Series – TYPE RANGE OF : Part 3 | SAP Blogs

Value Operator

Value operator is a relatively new addition to the ABAP language and the developers already  have started extensively using this feature. But here I am writing about one of its functionality which is not widely noticed . 

More about value operator from ABAP documentation,

https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abenconstructor_expression_value.htm

Value operator is particularly helpful in feeding internal table with values .
REPORT ZSAMPLE_VALUE.

TYPES: gtt_sflight TYPE STANDARD TABLE OF SFLIGHT WITH DEFAULT KEY .

DATA(lt_flights) = VALUE gtt_sflight( ( carrid = 'AA' connid = '0017' fldate = '26.11.2020' price = '422,94' )
( carrid = 'AZ' connid = '0018' fldate = '29.12.2020' price = '100.89' )
( carrid = 'DL' connid = '0019' fldate = '30.05.2021' price = '422,94' ) ).

And here is the utility of 'value' operator which I accidently found out while using 'where used' list of a BAPI.
   CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
EXPORTING
headdata = VALUE bapimathead( material_long = rv_matnr
ind_sector = 'M'
matl_type = 'FERT'
basic_view = 'X'
storage_view = 'X'
account_view = 'X'
purchase_view = 'X' )
clientdata = VALUE bapi_mara( matl_group = get_material_group( )
base_uom = get_unconverted_uom( )
net_weight = '10'
unit_of_wt = 'KG' )
clientdatax = VALUE bapi_marax( matl_group = 'X'
base_uom = 'X'
net_weight = 'X'
unit_of_wt = 'X' )
plantdata = VALUE bapi_marc( plant = get_plant( )
pur_group = get_purch_group( ) )
plantdatax = VALUE bapi_marcx( plant = get_plant( )
pur_group = 'X' )
valuationdata = VALUE bapi_mbew( val_area = get_valuation_area( )
price_ctrl = lv_price_ctrl
std_price = '10.00'
price_unit = lv_price_unit
moving_pr = '10.00'
val_class = get_valuation_class( iv_matl_type = 'FERT' ) ) "3300/7920 depends on system
valuationdatax = VALUE bapi_mbewx( val_area = get_valuation_area( )
price_ctrl = 'X'
std_price = 'X'
moving_pr = 'X'
price_unit = 'X'
val_class = 'X' )
storagelocationdata = VALUE bapi_mard( plant = get_plant( )
stge_loc = get_storage_location( ) )
storagelocationdatax = VALUE bapi_mardx( plant = get_plant( )
stge_loc = get_storage_location( ) )
TABLES
materialdescription = lt_create_material_matdscr
returnmessages = lt_returnmessages.

    Code from CL_API_RESERVATION_DOC_DPC_EXT - Local Test Class


    We no more have to declare the input structures for a FM/BAPI separately . We could use the value statement with the corresponding structure and feed with the values for the parameters. This feature is useful particularly when used in test classes. The icing on the cake is, we could even assign a functional method to the parameter list. Easy huh ??

Footnote:  But one strange thing which I noticed is that , we can only feed structures with a value to the function modules/BAPI's but not internal tables. I wonder why. May be the list gets longer? But could have been good enough for testing classes with one or two line items?
 TABLES
materialdescription = value t_bapi_makt( ( langu = 'D'
langu_iso = 'DE'
matl_desc = 'Sample Material'
del_flag = ' ' ) )
returnmessages = value cfx_bi_tt_bapi_matreturn2( ( type = 'E'
ID = 'SD'
number = '120'
message = 'Sample' ) ).

The above code throws error when used with BAPI 'BAPI_MATERIAL_SAVEDATA' .

May be horst.keller can show some light on this ?

Philip Davy
13 Comments