Quantcast
Channel: SCN : Discussion List - SAP CRM: Sales
Viewing all articles
Browse latest Browse all 1559

opportunities upload

$
0
0

Hi experts

 

please can someone help me ?

 

I have created this ABAP program to mass upload opportunities,
the problem is that the program works correctly in debug but after that i find only the first recording in the table.
the loop is working well and in debug i see the correct variable with the correct value.

 

Could some one help me please

 

Thank you Best regards

 


REPORT ZPROG_TEST36 ."NO STANDARD PAGE HEADING MESSAGE-ID ZMSGAP.

 

include crm_object_names_con.

 

      DATA: WSProxy TYPE REF TO ZOPCO_SERVICE1SOAP .

      DATA: ls_request TYPE ZOPGET_OPTY_QUOTE_SOAP_IN.

      DATA: ls_response TYPE ZOPGET_OPTY_QUOTE_SOAP_OUT.

      DATA: TAB TYPE ZOPOPTY_QUOTE_TAB.

      DATA: lv_data like line OF TAB .

 

      Data : star_Date(10) type c.

      Data : end_Date(10) type c.

      Data : sales_stage(10) type c.

 

 

  data:

*      All the tables to be created

 

      lt_orderadm_h      type  crmt_orderadm_h_comt,

      ls_orderadm_h      type  crmt_orderadm_h_com,

      lt_opport_h        type crmt_opport_h_comt,

      ls_opport_h        type line of crmt_opport_h_comt,

 

 

*     Other important things

      lt_input_fields    type  crmt_input_field_tab,

      ls_input_fields    type  crmt_input_field,

      lt_nametab         type  crmt_input_field_names_tab,

      ls_nametab         type  crmt_input_field_names,

      lt_save_guid       type  crmt_object_guid_tab,

      ls_save_guid       type  crmt_object_guid,

      lt_saved_objects   type  crmt_return_objects,

      ls_saved_objects   type  crmt_return_objects_struc,

      lv_lin             type   i,

      lv_order_object_id type  crmt_object_id,

      lv_order_object_guid  type  crmt_object_guid32.

 

 

**********************************************************************************

*

      TRY.

          CREATE OBJECT WSProxy .

      CATCH CX_AI_SYSTEM_FAULT .

      ENDTRY.

***********************************************************************************

 

      ls_request-PART = '11' .

 

        TRY.

            CALL METHOD WSProxy->GET_OPTY_QUOTE

        EXPORTING

          INPUT = ls_request

        IMPORTING

          OUTPUT = ls_response.

        CATCH CX_AI_SYSTEM_FAULT .

        CATCH CX_AI_APPLICATION_FAULT .

        ENDTRY.

        COMMIT WORK.

 

        TAB = ls_response-GET_OPTY_QUOTE_RESULT-OPTY_QUOTE.

 

*

loop at TAB into lv_data.

 

 

* Calculate the “handle” that will join all these attributes together

 

    call function 'CRM_INTLAY_GET_HANDLE'

    importing

      ev_handle = ls_input_fields-ref_handle.

 

* Populate orderadm_h with the process type and description

 

  ls_orderadm_h-handle       = ls_input_fields-ref_handle.

  ls_orderadm_h-process_type = 'Y002'.

  ls_orderadm_h-description = lv_data-OPTY_NAME .

  ls_orderadm_h-mode         = 'A'.

  ls_orderadm_h-ZZFLD0000T4 = lv_data-SIEBEL_QUOTE_ID.

 

 

INSERT  ls_orderadm_h INTO TABLE lt_orderadm_h.

 

*  Prepare table

 

  ls_nametab = 'DESCRIPTION'.

*  append ls_nametab to lt_nametab.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'MODE'.

INSERT ls_nametab INTO TABLE lt_nametab.

  ls_nametab = 'PROCESS_TYPE'.

INSERT ls_nametab INTO TABLE lt_nametab.

  ls_nametab = 'ZZFLD0000T4'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

 

* Populate lt_input_fields now

 

 

  ls_input_fields-ref_kind = 'A'.

  ls_input_fields-objectname = 'ORDERADM_H'.

  ls_input_fields-field_names[] = lt_nametab[].

  insert ls_input_fields into table lt_input_fields.

 

 

 

* Prepare the next table you want to create for this opportunity: opport_h

 

  clear: ls_nametab, lt_nametab[].

 

* Populate ls_opport_h with appropriate values

 

 

star_Date = LV_DATA-OPTY_STAGE_START_DATE.

REPLACE ALL OCCURRENCES OF '/' IN star_Date WITH ''.

 

end_date = LV_DATA-OPTY_CLOSE_DATE.

REPLACE ALL OCCURRENCES OF '/' IN end_date WITH ''.

 

if LV_DATA-OPTY_SALES_STAGE = 'Identification'.

  sales_stage  = 'Y1'.

 

ELSEIF LV_DATA-OPTY_SALES_STAGE = 'Qualification'.

    sales_stage  = 'Y2'.

 

ELSEIF  LV_DATA-OPTY_SALES_STAGE = 'Development'.

    sales_stage  = 'Y3'.

 

ELSEIF  LV_DATA-OPTY_SALES_STAGE = 'Propsal & negocaition'.

    sales_stage  = 'Y4'.

 

ELSEIF  LV_DATA-OPTY_SALES_STAGE = 'Closed'.

    sales_stage  = 'Y5'.

  ENDIF.

 

 

 

 

 

  ls_opport_h-ref_handle      = ls_input_fields-ref_handle.

  ls_opport_h-exp_revenue     = LV_DATA-REVENUE.

  ls_opport_h-startdate       = star_Date.

  ls_opport_h-expect_end      = end_date.

  ls_opport_h-curr_phase      = sales_stage.

 

  ls_opport_h-mode            = 'A'.

 

 

 

INSERT ls_opport_h INTO TABLE LT_opport_h.

 

 

 

* Prepare the lt_nametab table – remember to be alphabetical again!

 

  ls_nametab = 'CURR_PHASE'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'EXPECT_END'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'EXP_REVENUE'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'MODE'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'PROBABILITY'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'SOURCE'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'STARTDATE'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

  ls_nametab = 'TYPE'.

INSERT ls_nametab INTO TABLE lt_nametab.

 

 

 

 

* Add to lt_input fields the new table you want to create.

 

  ls_input_fields-ref_kind = 'A'.

  ls_input_fields-objectname = 'OPPORT_H'.

  ls_input_fields-field_names[] = lt_nametab[].

  insert ls_input_fields into table lt_input_fields.

 

 

* call crm_order_maintain now

 

call function 'CRM_ORDER_MAINTAIN'

      exporting

        it_opport_h       = lt_opport_h

      changing

        ct_orderadm_h     = lt_orderadm_h

        ct_input_fields   = lt_input_fields

      exceptions

        error_occurred    = 1

        document_locked   = 2

        no_change_allowed = 3

        no_authority      = 4

        others            = 5.

 

 

 

 

* Read the table that has been changed and get the GUID that was created.

 

case sy-subrc.

      when '0'.

        read table lt_orderadm_h into ls_orderadm_h index 1.

        ls_save_guid = ls_orderadm_h-guid.

 

        INSERT ls_save_guid INTO TABLE lt_save_guid.

endcase.

 

 

 

 

* SAVE the changes

 

    call function 'CRM_ORDER_SAVE'

      exporting

        it_objects_to_save = lt_save_guid

      importing

        et_saved_objects   = lt_saved_objects

      exceptions

        document_not_saved = 1

        others             = 2.

    case sy-subrc.

      when '0'.

        clear lv_lin.

        describe table lt_saved_objects lines lv_lin.

        if lv_lin = 1.

          read table lt_saved_objects into ls_saved_objects index 1.

          lv_order_object_guid = ls_saved_objects-guid.

          lv_order_object_id   = ls_saved_objects-object_id.

 

* 11. Call the function to COMMIT the changes to CRM.

 

          call function 'BAPI_TRANSACTION_COMMIT'.

        endif.

    endcase.

 

*Your new opportunity will now exist in CRM – use CRM_ORDER_READ to read it, using its GUID

 

endloop.


Viewing all articles
Browse latest Browse all 1559

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>