BaDI ME_PROCESS_REQ_CUST — Accessing Local Class from Global Class
I’ve gotten new functional spec from my functional teams, in this requirements, I have to fill value into EBAN-FISTL ( Fund Center ) in Account Assignment tab — ME51N tcode , I believe you have known number of enhancement for these tcode ( ME51N/ME52N) , I choose BaDI ME_PROCESS_REQ_CUST ( Enhancements for Processing Enjoy PReqs: Customer) and PROCESS_ITEM method for handling it.
I hope you are already familiar how to implement BaDI enhancement, as you know in this PROCESS_ITEM method have MEREQ_ITEM structure and i need to input value to FISTL field ( fund center ) in order this value will be saved to EBAN table.
After write ABAP code and test my enhancement code. so far nothing any error display, but EBAN-FISTL still empty, after debug this enhancement in OOP ABAP and exploring clue to solve this problem, suddenly i remember one article about how to accessing local class within global class..
Note: im_item (TYPE REF TO if_purchase_requisition_item) is instantiated as local class of function group MEREQ. However, after casting to the ROOT object (lo_obj) the public attribute MY_STATE (TYPE REF TO lcl_req_item_state) is accessible, at least in the debugger but not in the coding. and if you go to SE80 and open MEREQ Function Group and then you can’t missed all of local class on it, as you can see picture below.
Look at a picture, these local class could be used to solve my requirement, at this time go to LCL_ACCT_CONTAINER because FISTL field is own by COBL ( Coding Block ).
Note : You can experiment with other class as your own requirement.
Expanding LCL_ACCT_CONTAINER node and check in Method Definitions, and there are two method that get my attention i.e : GET_COBL and SET_COBL.
EXPORTING ex_cobl TYPE lty_t_cobl
ex_cobl_add TYPE lty_t_cobl_add,
IMPORTING im_cobl TYPE lty_t_cobl,
LTY_T_COBL refer to COBL, if you check into COBL you’ll found FISTL ( Fund Center ), ok these methed is exactly i need.
Below my full source code to populate Account Assignment in ME51N/ME52N.
FIELD-SYMBOLS : <lo_lcl> TYPE any.
DATA : ld_attr TYPE string,
lo_obj TYPE REF TO object,
lo_obj_2 TYPE REF TO object,
ld_method TYPE string.
DATA : lt_cobl TYPE TABLE OF cobl,
ls_cobl TYPE cobl.
DATA : ls_glcomm TYPE zta_glcomm.
SELECT SINGLE * FROM zta_glcomm INTO ls_glcomm WHERE bsart = ld_mereq_header-bsart.
IF sy-subrc EQ 0.
lo_obj ?= im_item.
ld_attr = 'MY_STATE->ACCT_CONTAINER'.
ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.
lo_obj_2 = <lo_lcl>.
ld_method = 'GET_COBL'.
CALL METHOD lo_obj_2->(ld_method) IMPORTING ex_cobl = lt_cobl.
READ TABLE lt_cobl INTO ls_cobl INDEX 1.
ls_cobl-fipos = ls_glcomm-fipos.
MODIFY lt_cobl FROM ls_cobl INDEX 1 TRANSPORTING fipos.
ld_method = 'SET_COBL'.
CALL METHOD lo_obj_2->(ld_method) EXPORTING im_cobl = lt_cobl.
Ok this is my short article today about ABAP, i hope this article could be a solution if you meet same problem.