Wednesday 9 December 2020

Do It Yourself EWB Programming

 So I recently had to perform tasks described in note: https://launchpad.support.sap.com/#/notes/488765 the EWB - Engineering WorkBench... now "Do it yourself" is an interesting Business Model... on the one hand, you're giving people the flexibility to create and craft as they see fit... on the other hand, one might be thinking "Come on SAP, there should be a BAPI there..."

They come close, but it seems not as simple as a BAPI. Why do they not just tie the steps they've described up into a BAPI... like "To make a change, first you need to do the locking, reload, then make the change..."???

Another thing they note is "If you have difficulties using the API, we would like to support you within consulting."

I bet you would.

Anyway, here's some code that removes a Sequence from the "Sequences" part of CA02.


data: ls_plfl type plfl.
PARAMETERS: p_plnal type plnal DEFAULT '01',
            p_plnnr type plnnr DEFAULT 'G0000338',
            p_plnfl type PLNFOLGE DEFAULT '000022',
            p_plnty type plnty DEFAULT 'N'.

START-OF-SELECTION.
select single * from plfl into ls_plfl where plnal = p_plnal
                                        and plnnr = p_plnnr
                                        and plnfl = p_plnfl
                                        and plnty = p_plnty.

 DATA: lt_SEQ_INV            TYPE CPCL_SEQ_VERS_TAB_TYPE,
       lt_SEQ_LOCK           TYPE CPCL_SEQ_LOCK_TAB_TYPE,
       lt_SEQ_IDENT_ECM      TYPE CPCL_SEQ_TAB_TYPE,
       ls_seq_class_data type SEQ_CLASS_DATA.
 DATA: lt_SEQ_IDENT          TYPE CPCL_SEQ_TAB_TYPE,
       ls_seq_ident          type cpcl_seq_ident_type.
MOVE-CORRESPONDING ls_plfl to ls_seq_ident.
append ls_plfl to lt_seq_ident.
CALL FUNCTION 'CP_CL_P_SEQ_LOAD'
  EXPORTING
    I_FLG_SET_LOCK             = 'X'
  IMPORTING
    E_SEQ_INV                  = lt_seq_inv
    E_SEQ_LOCK                 = lt_seq_lock
    E_SEQ_IDENT_ECM            = lt_seq_ident_ecm
  CHANGING
    c_seq_ident                = lt_seq_ident .

 DATA: E_TSK_INV                TYPE CPCL_TSK_VERS_TAB_TYPE,
       E_TSK_LOCK               TYPE CPCL_TSK_LOCK_TAB_TYPE,
       E_TSK_IDENT_LOCK         TYPE CPCL_TSK_TAB_TYPE,
       E_TSK_IDENT_ECM          TYPE CPCL_TSK_TAB_TYPE.
 DATA: lt_TSK_IDENT              TYPE CPCL_TSK_TAB_TYPE,
       ls_TSK_IDENT              TYPE cpcl_tsk_ident_type.
 loop at lt_seq_ident into ls_seq_ident.
   MOVE-CORRESPONDING ls_seq_ident to ls_tsk_ident.
   append ls_tsk_ident to lt_tsk_ident.
 endloop.


CALL FUNCTION 'CP_CL_P_TSK_LOAD'
  IMPORTING
    E_TSK_INV                      = E_TSK_INV
    E_TSK_LOCK                     = E_TSK_LOCK
    E_TSK_IDENT_LOCK               = E_TSK_IDENT_LOCK
    E_TSK_IDENT_ECM                = E_TSK_IDENT_ECM
  CHANGING
    c_tsk_ident                    = lt_tsk_ident
          .


 DATA ls_NAME              TYPE SY-MSGV1.
CALL FUNCTION 'CP_CL_SEQ_LOCK'
  EXPORTING
    PLNTY                    = ls_plfl-plnty
   PLNNR                     = ls_plfl-PLNNR
   PLNAL                     = ls_plfl-PLNAL
   PLNFL                     = ls_plfl-plnfl
    _WAIT                     = ' '
  IMPORTING
    E_NAME                    = ls_NAME
  EXCEPTIONS
    FOREIGN_LOCK              = 1
    SYSTEM_FAILURE            = 2
    OTHERS                    = 3.
MOVE-CORRESPONDING ls_plfl to ls_seq_class_data.
ls_seq_class_data-loekz = 'X'.
 DATA ls_ECM_DATA_ERROR_TYPE TYPE CPCC_MESSAGE_TYPE.
CALL FUNCTION 'CP_CL_S_SEQ_CHANGE'
  EXPORTING
    I_ECN_S                       = ls_plfl-aennr
    i_key_date_s                  = ls_plfl-datuv "sy-datum
    I_FLG_SEQ_CHECK               = ' '                     "default 'X' try switching it off!?
*   I_MARK_TXT_UPDATE             = ' '
    i_seq_class_data              = ls_seq_class_data
    I_FLG_COLLECT_ALL_MSG         = 'X'
  IMPORTING
    E_ECM_DATA_ERROR_TYPE         = ls_ECM_DATA_ERROR_TYPE
  EXCEPTIONS
    SEQUENCE_NOT_CONSISTENT       = 1
    NO_AUTHORITY                  = 2
    NO_VALID_SEQUENCE             = 3
    SEQUENCE_NOT_LOCKED           = 4
    ECM_DATA_NOT_SUITABLE         = 5
    OTHERS                        = 6.

CALL FUNCTION 'CP_CL_P_SEQ_SAVE'
  EXCEPTIONS
    NO_SEQ_TO_SAVE       = 1
    OTHERS               = 2.
commit work and wait.

Wednesday 2 December 2020

PLPO - PLFL link

Okay,  I know the Select * s are inefficient, but makes the code more readable.
Had been struggling to work out what made the Sequence Items in CA02 disappear when we "Delete" one of the lines. Not sure why PLPO doesn't get it's own LOEKZ updated, but hey...

This finds ACTIVE sequence lines for Routings.


PARAMETERSp_plnnr type plnnr DEFAULT '51000070',

            p_vornr type vornr DEFAULT '0010'.

select from plfl into TABLE lt_plfl where plnnr p_plnnr
                                        and loekz ' '.

select from plas into TABLE lt_plas where plnnr p_plnnr .

select from plpo into TABLE lt_plpo where plnnr p_plnnr
                                        and vornr p_vornr.

if lt_plpo is not INITIAL.
  select from crhd into table lt_crhd FOR ALL ENTRIES IN lt_plpo
     where crhd~objid lt_plpo-arbid.
endif.

  loop at lt_plfl into ls_plfl.
     READ TABLE lt_plas into ls_plas with key plnnr ls_plfl-plnnr
                                              plnfl ls_plfl-plnfl.
     if sy-subrc 0.
       READ TABLE lt_plpo into ls_plpo with key plnnr ls_plas-plnnr
                                                plnkn ls_plas-plnkn.
       if sy-subrc 0.
         READ TABLE lt_crhd into ls_crhd with key objid ls_plpo-arbid.
         if sy-subrc 0.
           write:/ ls_plpo-plnnr':' ls_plpo-vornr':' ls_plfl-plnfl':'ls_crhd-arbpl.
         endif.
       endif.
     endif.
  endloop.