cancel
Showing results for 
Search instead for 
Did you mean: 

Enhancing SAP TPM promotion updates with robust ABAP coding for a more efficient and streamlined day

0 Kudos
95

Hi Everyone,

Happy weekend to all!

Recently, I encountered a scenario where I frequently performed a task manually. To streamline the process and save time, I developed an automation code that makes it much easier. As a family member I would like to share this new learning with you all. 

As an SAP BW-IP-TPM developer, this is one of the most common activities we handle regularly while working on Trade Promotion Management (TPM) in SAP.

The goal of this automation is to update the SAP TPM promotion status in the backend CRM system efficiently.

Thank me Later 🙂

Kishore
SAP BW-IP-TPM Developer

 

TABLES: crm_jest.

* Selection Screen Parameters
PARAMETERS: p_guid   TYPE char32 OBLIGATORY,  " GUID from user
            p_ostat  TYPE char8,           " Current Status (old)
            p_nstat  TYPE char8,            " New Status (new)
            p_active AS CHECKBOX,             " Checkbox to activate status
            p_insert AS CHECKBOX.             " Checkbox to insert new record

DATA: ls_jest TYPE crm_jest.

START-OF-SELECTION.

  " =========================== STEP 1: UPDATE STATUS (IF NEEDED) ===========================
  IF p_ostat IS NOT INITIAL AND p_nstat IS NOT INITIAL.
    " Fetch current status
    SELECT SINGLE * FROM crm_jest
    WHERE objnr = p_guid
      AND stat = p_ostat.

    IF sy-subrc = 0.
      " Update status from OLD to NEW
      UPDATE crm_jest
        SET stat = p_nstat
      WHERE objnr = p_guid
        AND stat = p_ostat.

      COMMIT WORK.
      WRITE: / 'Status changed from', p_ostat, 'to', p_nstat, 'for GUID:', p_guid.
    ELSE.
      WRITE: / 'No matching status', p_ostat, 'found for GUID:', p_guid.
    ENDIF.
  ENDIF.

  " =========================== STEP 2: CHANGE INACTIVE TO ACTIVE ===========================
  IF p_active = 'X'.
    " If the user selected 'Active', remove 'X'
    SELECT SINGLE * FROM crm_jest
    WHERE objnr = p_guid
      AND stat = p_nstat
      AND inact = 'X'.

    IF sy-subrc = 0.
      " Change status from Inactive (X) to Active (blank)
      UPDATE crm_jest
        SET inact = ''
      WHERE objnr = p_guid
        AND stat = p_nstat
        AND inact = 'X'.

      COMMIT WORK.
      WRITE: / 'Status', p_nstat, 'is now active for GUID:', p_guid.
    ELSE.
      WRITE: / 'No inactive status found for GUID:', p_guid.
    ENDIF.

  ELSE. " IF p_active is NOT selected, then make it inactive (X)

    SELECT SINGLE * FROM crm_jest
    WHERE objnr = p_guid
      AND stat = p_nstat
      AND inact = ''.

    IF sy-subrc = 0.
      " Change status from Active (blank) to Inactive (X)
      UPDATE crm_jest
        SET inact = 'X'
      WHERE objnr = p_guid
        AND stat = p_nstat
        AND inact = ''.

      COMMIT WORK.
      WRITE: / 'Status', p_nstat, 'is now inactive (X) for GUID:', p_guid.
    ELSE.
      WRITE: / 'No active status found for GUID:', p_guid.
    ENDIF.

  ENDIF.

 

 #SAPTPM #TPM #SAP #SAPBW #SAPIP #SAPBWIPTPM #TradePromotionManagement CRM Analytics RISE with SAP 

Accepted Solutions (0)

Answers (0)