Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
Faaiez
Advisor
Advisor
0 Kudos

Armed with only ABAP development experience and hardly any BW or BPC Script Logic experience I had to consider where to start?

...SCN..of course :smile:

With my first search I found this document which was really helpful in explaining how I can use the exit framework which allows customers to use ABAP within BPC Script Logic by calling a BADI within the Script Logic.

After creating the implementation as required:

The document explained to me how to implement the BADI but obviously did not have the logic to call the BW planning sequence.

In order to do this I had to implement the BADI UJ_CUSTOM_LOGIC and wrote the code in the EXECUTE method of the implementing Class:

Logic to call the BW planning sequence

METHOD if_uj_custom_logic~execute.
  DATA: ls_param             TYPE LINE OF ujk_t_script_logic_hashtable,
             lv_plan_seq         TYPE rspls_seqnm,
             lt_bapiret2           TYPE TABLE OF bapiret2,
             lcl_area_handle    TYPE REF TO zcl_bwip_shared_area,
             lcl_memory          TYPE REF TO zcl_bwip_shared_memory.
  READ TABLE it_param INTO ls_param WITH TABLE KEY hashkey = 'ZPLAN_SEQ'.
  IF sy-subrc EQ 0.
    TRY.
        CALL METHOD zcl_bwip_shared_area=>attach_for_write
          RECEIVING
            handle = lcl_area_handle.
      CATCH cx_shm_exclusive_lock_active .
      CATCH cx_shm_version_limit_exceeded .
      CATCH cx_shm_change_lock_active .
      CATCH cx_shm_parameter_error .
      CATCH cx_shm_pending_lock_removed .
    ENDTRY.
    TRY.
        CREATE OBJECT lcl_memory AREA HANDLE lcl_area_handle.
        lcl_area_handle->set_root( lcl_memory ).
        lcl_memory->set_t_param( it_param ).
        lcl_area_handle->detach_commit( ).
      CATCH cx_shm_error.
    ENDTRY.
    lv_plan_seq = ls_param-hashvalue.
    CALL FUNCTION 'RSPLAPI_PLSEQ_EXECUTE'
      EXPORTING
        i_sequence       = lv_plan_seq
*     IMPORTING
*       E_SUBRC          =
      TABLES
        e_t_return       = lt_bapiret2
              .
  ENDIF.
ENDMETHOD.

Being the lazy developer that I am, I'm always looking for ways to make life easier for me.

I did not want to keep going to BPC to test the call to the BADI by the Script Logic, so I looked for an easier way to do my testing.

I came across another useful post in SCN which explained the use of Tx UJKT.

I then used Tx UJKT to enter and execute the following Script Logic.

 

*START_BADI ZPLAN_SEQ
ZPLAN_SEQ = /CPMB/ZGL01
ZGLPORT = $ZGLPORT$
ZVERSION = $ZVERSION$*END_BADI

In the above Script Logic I call the BADI using the filter 'ZPLAN_SEQ'.

I am also passing 3 parameters through to the BADI. NB: The BADI can accept any number of parameters.

The logic above in the EXECUTE method caters for calling any planning sequence with any number of parameters.

I am using a shared memory object which was available since NetWeaver 6.40.

These parameters however must still be read by the planning sequence being called.

When the planning sequence is created these parameters must be created as SAP Exit parameters.

This will then invoke the standard SAP exit for the parameter (EXIT_SAPLRRS0_001):

I then added the following code to read the saved parameters in the SAP exit:

   data: lt_param TYPE UJK_T_SCRIPT_LOGIC_HASHTABLE,
       ls_param type LINE OF UJK_T_SCRIPT_LOGIC_HASHTABLE,
       lcl_area_handle TYPE REF TO zcl_bwip_shared_area,
       lcl_memory      TYPE REF TO zcl_bwip_shared_memory.
    TRY.
        CALL METHOD zcl_bwip_shared_area=>attach_for_read
          RECEIVING
            handle = lcl_area_handle.
      CATCH cx_shm_exclusive_lock_active .
      CATCH cx_shm_version_limit_exceeded .
      CATCH cx_shm_change_lock_active .
      CATCH cx_shm_parameter_error .
      CATCH cx_shm_pending_lock_removed .
    ENDTRY.
    TRY.
        lt_param = lcl_area_handle->root->get_t_param( ).
        lcl_area_handle->detach( ).
      CATCH cx_shm_error.
    ENDTRY.
    READ TABLE lt_param into ls_param WITH TABLE KEY hashkey = I_VNAM.
    if sy-SUBRC eq 0 and i_step = 1.
      wa_range-sign = 'I'.
      wa_range-opt  = 'EQ'.
      wa_range-low  = ls_param-HASHVALUE.
      wa_range-high  = ls_param-HASHVALUE.
      append wa_range to e_t_range.
    endif.

This is how I managed to pass parameters from Script Logic to BADI and then execute Planning Sequence with the parameters entered for Script Logic.