How to create Opportunity in SAP CRM?

731 Views Asked by At

I am Java developer and I am pretty new to SAP CRM, but the requirement in current project requires me to have a basic understanding of the SAP CRM system. I want to know on which Tool I can find the Accounts, Opportunity, Leads etc in SAP. If the question is not complete please ask me appropriate question, I will try to explain to the best of my knowledge.

I have already gone through multiple videos and tutorials but to no help, code is not available at the moment

I expect somebody to let me know where exactly I can find the above fields (Accounts, Opportunity, Cases, etc like in Salesforce) in SAP CRM.

1

There are 1 best solutions below

1
On BEST ANSWER

Use BAPI_OPPORTUNITY_CREATEMULTI for that, and don't forget to run commit after the BAPI, otherwise your opportunity will not appear in tables. Here is the sample:

DATA: return            TYPE TABLE OF BAPIRET2 WITH HEADER LINE,
      it_opportunity    TYPE BAPIBUS20001_OPPORTUNITY,
      it_header         TYPE BAPIBUS20001_HEADER_INS,
      it_item           TYPE BAPIBUS20001_ITEM,
      it_input_fields   TYPE BAPIBUS20001_INPUT_FIELDS,
      it_pricing        TYPE BAPIBUS20001_PRICING,
      <fs_partner>      TYPE BAPIBUS20001_PARTNER_INS,
      w_status          TYPE BAPIBUS20001_STATUS_INS.

* gc_handle_1 is used for an item to bind it to a opportunity and gc_handle_2 is used to bind the information for an item to an item.
CONSTANTS: gc_handle_1 TYPE crmt_handle VALUE '0000000001',
           gc_handle_2 TYPE crmt_handle VALUE '0000000002'.

* --ITEM DATA--

APPEND INITIAL LINE TO it_item ASSIGNING FIELD-SYMBOL(<fs_item>).
<fs_item>-mode = 'A'.
<fs_item>-ordered_prod = int_tab-produkt. "your product
<fs_item>-itm_type = 'ZOPT'.
<fs_item>-handle = gc_handle_2. "Identification of this item
<fs_item>-header_handle = gc_handle_1. "Refers to the opportunity for which this item is for.

APPEND INITIAL LINE TO it_input_fields ASSIGNING FIELD-SYMBOL(<fs_fields>).
<fs_fields>-ref_handle = gc_handle_2. "Refers to the item for which this information is for 
<fs_fields>-objectname = 'ORDERADM_I'.
<fs_fields>-ref_kind = 'B'.
<fs_fields>-fieldname = 'ORDERED_PROD'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'ITM_TYPE'.

CLEAR return.

* --HEADER DATA --

APPEND INITIAL LINE TO it_header ASSIGNING FIELD-SYMBOL(<fs_header>).
<fs_header>-guid = ''.
<fs_header>-handle = gc_handle_1. "Identification of this opportunity
CONCATENATE 'Konv: ' int_tab-betegnelse INTO <fs_header>-description SEPARATED BY space.
<fs_header>-process_type = 'ZOPP'.
<fs_header>-descr_language = 'K'.
<fs_header>-langu_iso = 'DA'.
<fs_header>-posting_date = sy-datum.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-ref_handle = gc_handle_1.
<fs_fields>-objectname = 'ORDERADM_H'.
<fs_fields>-ref_kind = 'A'.
<fs_fields>-fieldname = 'PROCESS_TYPE'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'OBJECT_ID'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'DESCRIPTION'.

* --PARTNER DATA--

APPEND INITIAL LINE TO <fs_partner> ASSIGNING FIELD-SYMBOL(<fs_partner>).
<fs_partner>-ref_handle = gc_handle_1.
<fs_partner>-display_type = 'BP'.
<fs_partner>-no_type = 'BP'.
<fs_partner>-ref_kind = 'A'.
<fs_partner>-ref_partner_handle = '0000'.
<fs_partner>-partner_no = int_tab-kundeemne.
<fs_partner>-partner_fct = '00000021'.
<fs_partner>-mainpartner = 'X'.

APPEND INITIAL LINE TO <fs_partner> ASSIGNING <fs_partner>.
<fs_partner>-mainpartner = ''.
<fs_partner>-partner_no = int_tab-kontpers.
<fs_partner>-partner_fct = '00000015'.

APPEND INITIAL LINE TO <fs_partner> ASSIGNING <fs_partner>.
<fs_partner>-partner_no = int_tab-amedarb.
<fs_partner>-partner_fct = 'Z0000014'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-objectname = 'PARTNER'.
<fs_fields>-logical_key = '0000'.
<fs_fields>-fieldname = 'PARTNER_FCT'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'PARTNER_NO'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'DISPLAY_TYPE'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'NO_TYPE'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'KIND_OF_ENTRY'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'MAINPARTNER'.

* --OPPORTUNITY DATA--

APPEND INITIAL LINE TO it_opportunity ASSIGNING FIELD-SYMBOL(<fs_opportunity>).
<fs_opportunity>-ref_handle = gc_handle_1.
<fs_opportunity>-startdate = int_tab-start.
<fs_opportunity>-expect_end = int_tab-****.
<fs_opportunity>-probability = int_tab-succes.
<fs_opportunity>-curr_phase = int_tab-aktfas.
<fs_opportunity>-forecast_rel = int_tab-relpro.
<fs_opportunity>-type = int_tab-smgrp.
<fs_opportunity>-importance = int_tab-priori.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-objectname = 'OPPORT_H'.
<fs_fields>-fieldname = 'STARTDATE'.

* --PRICING DATA-
READ TABLE it_opportunity ASSIGNING FIELD-SYMBOL(<fs_opp>) INDEX 1.

*-- Needed to store CURRENCY.
CLEAR it_pricing.
APPEND INITIAL LINE TO it_it_pricing ASSIGNING FIELD-SYMBOL(<fs_pricing>).
<fs_pricing>-REF_HANDLE = 1.
<fs_pricing>-REF_GUID = g_BlankGuid.
<fs_pricing>-REF_KIND = 'A'.
<fs_pricing>-CURRENCY = <fs_opp>-CURRENCY.
<fs_pricing>-CURRENCY_ISO = <fs_opp>-CURRENCY_ISO.

* --OPPORTUNITY DATA--

CLEAR w_status.
w_status-ref_guid = l_opportunity_guid.
w_status-ref_handle = l_count_ref_handle.
w_status-ref_kind = 'A'.
w_status-status = 'E0001'.
w_status-user_stat_proc = 'ZOPPRSTU'.
w_status-activate = 'X'.
APPEND w_status TO t_status.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-ref_handle = l_count_ref_handle.
<fs_fields>-ref_guid = l_opportunity_guid.
<fs_fields>-ref_kind = 'A'.
<fs_fields>-objectname = 'STATUS'.
CONCATENATE w_status-status w_status-user_stat_proc INTO <fs_fields>-logical_key.
<fs_fields>-fieldname = 'STATUS'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'USER_STAT_PROC'.

APPEND INITIAL LINE TO it_input_fields ASSIGNING <fs_fields>.
<fs_fields>-fieldname = 'ACTIVATE'.

CALL FUNCTION 'BAPI_OPPORTUNITY_CREATEMULTI'
  EXPORTING
    TESTRUN = ' '
  TABLES
    HEADER = it_header
    OPPORTUNITY = it_opportunity
    PARTNER = it_partner
    PRICING = it_pricing
    INPUT_FIELDS = it_input_fields
    RETURN = return
    ITEM = it_item
    STATUS = w_status.

* Opportunity will not appear until you commit.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  EXPORTING
   WAIT = abap_true.

Also check report CRM_REPORT_CREATE_MASS_OPPT.

Using the tcode /ncrmd_BUS2000111 you can create opportunity in GUI mode.

What concerns

where exactly I can find the above fields(Accounts, Opportunity, Cases, etc like in Salesforce) in SAP CRM

they are all stored in CRM tables, presumably CRMD_ORDERADM_H and CRMD_ORDERADM_I and all business objects manipulations in CRM are made via WebUI. If you have appropriate business role (e.g. SALESPRO) you will find opportunity in the navigation bar at the left.