CRM and CX Blogs by Members
Find insights on SAP customer relationship management and customer experience products in blog posts from community members. Post your own perspective today!
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member
40,936


In a previous blog I http://scn.sap.com/community/crm/blog/2013/02/07/crmorderread-simple-example-for-those-new-to-crm-an... gave a very simple example of how to read an order using CRM_ORDER_READ.

Then in another blog I explained how to UPDATE an order: http://scn.sap.com/community/crm/blog/2013/02/07/crmordermaintain-simple-example-to-update-an-order-...
Now I’ll give a simple example of how to create an order using CRM_ORDER_MAINTAIN.

This blog will show you how to CREATE an order from scratch using ABAP.
I’ve tried to make this as simple as possible but while including the most important (useful) information.
For this example I will create an order with two tables populated: orderadm_h and opport_h (which signifies that this is an OPPORTUNITY that I’m creating)

include crm_object_names_con.
  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.
* Calculate the “handle” that will join all these attributes together
  call function 'CRM_INTLAY_GET_HANDLE'
    importing
      ev_handle = ls_input_fields-ref_handle.
* 1. Populate orderadm_h with the process type and description
  ls_orderadm_h-handle       = ls_input_fields-ref_handle.
  ls_orderadm_h-process_type = ‘process type string’.
  ls_orderadm_h-description = ‘this is a description’.
  ls_orderadm_h-mode         = 'A'.
  append ls_orderadm_h to lt_orderadm_h.
* 2. Prepare table first.
* The lines you enter into table lt_nametab MUST be entered (appended)
* in alphabetical order, as lt_nametab is sorted.
* See here that the 3 entried are the three attributes you populated in ls_orderadm_h above.
  ls_nametab = 'DESCRIPTION'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'MODE'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'PROCESS_TYPE'.
  append ls_nametab to lt_nametab.
* 3. Populate lt_input_fields now
* You need to add this table that you want to create to the input fields.
  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.
* 4. Prepare the next table you want to create for this opportunity: opport_h
  clear: ls_nametab, lt_nametab[].
* 5. Populate ls_opport_h with appropriate values (see examples or attributes to populate)
  ls_opport_h-ref_handle      = ls_input_fields-ref_handle.
  ls_opport_h-exp_revenue     = iv_expt_sales.
  ls_opport_h-startdate       = iv_sc_sdate.
  ls_opport_h-expect_end      = iv_sc_cdate.
  ls_opport_h-curr_phase      = iv_sales_stage.
  ls_opport_h-probability     = iv_chanceofsuc.
  ls_opport_h-source          = iv_origin.
  ls_opport_h-type            = iv_serv_line.
  ls_opport_h-mode          = 'A'.
  append ls_opport_h to lt_opport_h.
* 6. Prepare the lt_nametab table – remember to be alphabetical again!
  ls_nametab = 'CURR_PHASE'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'EXPECT_END'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'EXP_REVENUE'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'MODE'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'PROBABILITY'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'SOURCE'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'STARTDATE'.
  append ls_nametab to lt_nametab.
  ls_nametab = 'TYPE'.
  append ls_nametab to lt_nametab.
* 7. 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.
* 8. You’re ready to 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.
* 9. 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.
        append ls_save_guid to lt_save_guid.
endcase.
* 10. SAVE the changes (all creations must be saved and committed before they exist in CRM)
    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
42 Comments
stephenjohannes
Active Contributor
0 Kudos

Welcome to SCN! Thanks for sharing, although it looks like you posted this blog twice, so you might want to delete the other version of your post.

Since you are interesting in sharing on this topic, a long time ago I started a wiki area to share information for CRM:

http://wiki.sdn.sap.com/wiki/display/CRM/CRM+Developer%27s+Knowledge+Corner

Never got that far, but if you if you want to contribute there or continue to add blogs, that would be great.

Take care,

Stephen

Former Member
0 Kudos

Thanks Stephem, I'll have a look. I'm still learning where to post things.

With regards to me having posted this Blog twice, the other one is for updating an order (whereas this one is for creating a new order) I made them as separate blogs so anyone searching would be able to find the one that helped them best, I hope this is right?

Also, I wanted to includ my code snippets in the way I've seen others do it (where you see lines and it's properly formatted) but I couldn't figure out how. Can you give me any advice on this?

Thank you for your feedback.

Lindsay

stephenjohannes
Active Contributor
0 Kudos

Ok, I'm going to admit that I didn't read your titles fully only saw the part looking similar.  You might want to change around the blog titles in order so that it's easier for people to see the distinction.  On twitter the blog titles get truncated and it looks like two duplicate blogs.  Yeah I think having them separate is good, just need to adjust the names to end any confusion.

I'm going to admit I keep my blog formatting very simple, so I really have put code in blogs before.  There is a section on the blog editor that looks like >>> and then has a dropdown for syntax highlighting,  If you choose plain then it will put your code in a nice and neat block.  Yes there is no option for ABAP on the list, but it will still look better than bold text.

Take care,

Stephen

Former Member
0 Kudos

Lindsay, nice and detailed blog, thank you for taking time to share this blog.

I have a question on FM - CRM_ORDER_MAINTAIN, this function module is not released which means it is assumed it is for SAP internal use but I see a lot of posts recommending the usage of CRM_ORDER_MAINTAIN.

I just wanted to check if this is any way endorsed by SAP or does SAP recommends any alternative solutions?

Thank you.

Regards,

Ram.

nagarajan_ramudu
Active Participant
0 Kudos

Is there any blog which explains creating quotation in CRM? I need to mass load quotes in CRM. Thank you.

Former Member
0 Kudos

Hi Ram B,

Can I clarify what you mean by "this function module is not released" please?

This function module is activly used in CRM internally. If you're talking about it being remote-enabled, the way I've been using it externally from CRM is through Gateway, so it doesn't matter that it isn't remote enabled. Does this answer what you're asking? If not I think I might have misunderstood your question, please give some more detail.

I hope this helps (although I fear it may not yet)

Let me know what you need and I will  answer if I can.

Regards,

Lindsay

Former Member
0 Kudos

Hi Nagarajan,

I don't know of such a blog/example, and unfortunatly I have never created a quatation this way. If I find any information about it I'll let you know.

I hope that maybe this blog can help a bit, but I see that it might not be able to.

Regards,

Lindsay

stephenjohannes
Active Contributor
0 Kudos

Nope it's not officially released, but it's pretty safe to use.  If you really want to be strict about usage then use CRMXIF_ORDER_SAVE instead.  That function module is released.

Honestly we use a lot of function modules that were for internal use to get things done, but it's just fact that until SAP decides to completely re-write the one order framework, we are safe.  Those function modules in basic form haven't changed much in the last 10 years, so we are good.

Take care,

Stephen

stephenjohannes
Active Contributor
0 Kudos

Remember a quote is a business transaction.  CRM_ORDER_MAINTAIN is for business transactions, so yep you can use it, provided you pass in the correct data needed.  The segments of the business transaction vary by business object type.

Take care,

Stephen

Former Member
0 Kudos

Lindsay, every Function Module has a status associated with and this can be seen on Attributes tab in SE37.

The general guidance is try to use only Released as these are approved by SAP to use in Custom programs. For e.g. the BAPIs.

Former Member
0 Kudos

Stephen, thanks for assurance. I am trying to find out if SAP has any official say on it as I said it is a widely used FM. 

Former Member
0 Kudos

Wow, I didn't know about this. I've just had a look and I now see what you're refereing to, "Not released". As I'm relatively new to SAP (only worked with it for 6 months) this is the kind of valuable information I was hoping to gain from the SCN, thank you!

And thanks also to Steffen (below) for that information - I'm going to have a look into CRMXIF_ORDER_SAVE to see how it works.

Valuable information, both.

stephenjohannes
Active Contributor
0 Kudos

SAP has never told me not to use those function modules privately or publicly despite the fact that I have shared the knowledge about them since 2005.  However part of that is that is the fact for most BADI's in the one-order framework you need to use the one-order API to make things work correctly.  In addition I would guess that most CRM customers who have custom code or enhancements use them any so trying to issue an edict against use is a losing battle!

If you look at the BOL object implementation for one-order you will notice that all the internal API's that aren't "released" are still used in the code SAP delivered.  Besides the only time you get burned is during an upgrade if they change the interface or usage.  SAP even released documentation on how all those API's worked in a publicly available OKP for CRM 2007/7.0(can't remember which release) that was available for customer purchase. 

I'm not saying as a customer you should ignore SAP completely, but sometimes there are good reasons to not follow the rules.

Take care,

Stephen

Former Member
0 Kudos

Kudos, you have just started with SAP and you are already started sharing your knowledge.

Former Member
0 Kudos

Thanks for sharing this

" SAP even released documentation on how all those API's worked in a publicly available OKP for CRM 2007/7.0(can't remember which release) that was available for customer purchase. "

Former Member
0 Kudos

I checked with SAP today and they are very clear that the usage of this Function Module is

not supported by SAP.

Former Member
0 Kudos

I checked with SAP today and they are very clear that the usage of this Function Module is

not supported by SAP.

stephenjohannes
Active Contributor
0 Kudos

Once again if you asked SAP via any official channel, they are going to tell you no.  Now what they aren't going to do is spend any time/effort/money in creating proper API function modules for all SAP applications.  Instead they are going to focus on everything but fixing the technical issues of SAP ERP, CRM, SCM, etc and say those problems are resolved by putting HANA on as a database because everything is faster.

It's also like the SAP Certification folks whose heads are buried in the sand and try to say that their other certifications cover all the material web client and they don't need a separate certification exam for it..  However they offer two classes on the webclient development separate from the standard courses.  They also don't acknowledge valid job roles for CRM Projects and instead live in fantasyland of CRM job roles.

So go ahead and listen to SAP and make your life more difficult.  Once again it's not like we are saying perform a core modification(I'm strongly against those) or create an implicit enhancement.  Instead what is shared is a common example generally accepted by most SAP CRM customers.  IMHO How customers use the system to meet their business requirements is much more important that following mindless rules created by the vogon like SAP bureaucracy with no reasonable alternatives.

Take care,

Stephen 

former_member203139
Participant
0 Kudos

Nice Job Lindsay and thanks for your knowledge share.

Regards

Jon

former_member203215
Participant
0 Kudos

HAI Lindays i'm new to crm..........

i dont know what is the use of crm_order_read,

crm_order_maintain,

crm_order_save...

y we use this function modules....

when we use..........................

please give me info..........................

Former Member
0 Kudos

Hi Ravichand,

Here is a quick explaination of these 3 function modules:

  • CRM_ORDER_READ is used to read orders which are stored in CRM (as the name suggests). "Order" refers to documents/transactions, for example a Proposal can be read using this, or an Opportunity, or a Lead. You would use CRM_ORDER_READ when you need to get all the details of the proposal for some use - for example I have used it to expose Proposal data using Gateway, so it can be viewed in an web page (rather than by logging in to SAP CRM)
  • CRM_ORDER_MAINTAIN is used to create new "orders", and also to update existing orders. It allows you to do this without using one of the CRM GUIs - Again, I have used this so an external web service can make OData POSTs and PUTs in order to create/update a Proposal - which in CRM attaches to the code which uses this function module.
  • CRM_ORDER_SAVE is used after a crm_order_maintain call, to save the data, out of memory and to the database, so it is not just help within the session memory. Afeter CRM_ORDER_SAVE I perform a BAPI_TRANSACTION_COMMIT which commits everything to the database

I hope this has helped you to understand these function modules a bit better.

If not, please ask more questions and I will try to answer!

Thanks,

Lindsay

former_member203215
Participant
0 Kudos

thanks lindsay.............

Can u please provide me the code for

I have scenario like this..........

i have dropdown list ... which contains country codes when i select a country code

data related to that code data has to be displayed in a text box or text area..

please provide the code...........

Former Member
0 Kudos

Hi Ravichand,

I don't quite understand what you mean, but I think what you describe would not use crm_order_maintain.

From what I understand you have country codes (eg EN, ES, FR) and want to get the text values for these codes (eg England, Spain, France), is that correct?

To get this list - this is how I would do it:

Then double click on the domain "LAND1" and navigate to the tab "Value Range".

Double click on T005 - and there is the table of values for country:

Click on this icon to see all the values.

I hope this is what you need. This then shows you a list of all the country codes, and their full names.

Thanks

Lindsay

Former Member
0 Kudos

Hello Lindsay,

very nice tutorial for first step in order creation (your other tutorial for changing helped me alot). Did you ever create an appointment? Seems to be harder than opportunity and I´m stuck with populating the appointment table.

Any suggestions or advices?

Best regards, Dominik

Former Member
0 Kudos

Hi Dominik,

Sorry I've taken a while to get back to you.

I don't think I have created an appointment before.. but I imagine it would take the same principal.

My advice would be to set a break point right at the start of CRM_ORDER_MAINTAIN and see what is being passed in and out. Then look at the call stack and see what is being called before and then after, to see if there is anything extra you need to call.

I hope you get on alright - sorry I couldn't be more help on this one!

Kind Regards,

Lindsay

Former Member
0 Kudos

Hello Lindsay,

thank you for replying. My issue is already solved. In the end, I did exactly the same as you suggested in your reply.

Thank you for your reply.

Best regards, Dominik

clinton_jones2
Active Participant
0 Kudos

Hi Lindsay

Have you had any experience of using this FM to create a non sales or non service related complaint?

Former Member
0 Kudos

Hi Clinton,

sorry to say I do not have experience using this FM for non sales or service related complaints. However I would suggest that the best way to work out how to use them for this would be to stick in a breakpoint and run the transaction to create the object you want, and see what gets passed in, how and when :smile:

former_member182874
Active Contributor
0 Kudos

HI Lindsay,

I am trying to use CRM_ORDER_MAINTAIN in my gateway service for creating Knowledge article ID. Is this the right approach to create knowledge article id( OBJECT_ID)  through this FM ?

Regards,

Tejas

Former Member
0 Kudos

Hi Tejas,

When you say "knowledge article id" do you mean just the ID? Or do you want to create the object itself as well? CRM_ORDER_MAINTAIN will create an actual object too, and save it to the database, not just get you an ID.

From reading around thsi, I think CRM_ORDER_MAINTAIN would be the FM you need to call to read create/update a knowledge article, but if all you need is to read the ID of one that already exists, then use CRM_ORDER_READ.

Have you tried putting a breakpoint in the FM and then creating a knowledge article through the SAP GUI? If CRM_ORDER_MAINTAIN is the right FM for you, your breakpoint will be hit, and you will be able to see what parameters you need to populate in each of the structure :smile:

Let me know how you get on, I hope this helps,

Lindsay

former_member182874
Active Contributor
0 Kudos

Hi Lindsay

I want to create a knowledge article id(OBJECT_ID in CRM_ORDER_READ) only, but along with that I will need other details as well, which i see when i execute CRM ORDER READ from SE38. Like ET_TEXT, ES_ORDERADM_H. So figuring out , where do I enter these details in CRM_ORDER_MAINTAIN in Input.

Regards

Tejas

former_member182874
Active Contributor
0 Kudos

HI Lindsay,

I figured out my issue. Your blog is helpful :smile:

Regards,

Tejas

Former Member
0 Kudos

when i run this  program a dump is generated.Following error occurs

it is showing error in following code:

READ TABLE it_objects_to_save INDEX 1 INTO lv_guid.

   IF lv_guid EQ gc_empty_guid.

>>>>     MESSAGE x009.

   ENDIF.

    The current application program has detected a situation that should

    not occur. A termination with short dump has therefore been triggered

    by the key word MESSAGE (type X).

If the error occurs in a non-modfied SAP program, you might be able to

find a solution in the SAP Notes system. If you have access to the SAP

Notes system, check there first using the following keywords:

"MESSAGE_TYPE_X"

"SAPLCRM_ORDER_API" bzw. LCRM_ORDER_APIU03

"CRM_ORDER_SAVE"

Error analysis

    Short text of the error message:

    Program error; incorrect values in interface parameters

    Long text of the error message:

    Technical information about the message:

    Message class....... CRM_ORDER

    Number.............. 009

    Variable 1..........

    Variable 2..........

    Variable 3..........

    Variable 4.......... " "

|Source Code Extract                                                                               |

----------------------------------------------------------------------------------------------------

|Line |SourceCde                                                                                   |

----------------------------------------------------------------------------------------------------

|   12|*"     REFERENCE(ET_SAVED_OBJECTS) TYPE  CRMT_RETURN_OBJECTS                                |

|   13|*"     REFERENCE(ET_EXCEPTION) TYPE  CRMT_EXCEPTION_T                                       |

|   14|*"     REFERENCE(ET_OBJECTS_NOT_SAVED) TYPE  CRMT_OBJECT_GUID_TAB                           |

|   15|*"  CHANGING                                                                                |

|   16|*"     REFERENCE(CV_LOG_HANDLE) TYPE  BALLOGHNDL OPTIONAL                                   |

|   17|*"     REFERENCE(CT_NOCHECK_BEFORE_SAVE) TYPE  CRMT_OBJECT_GUID_TAB                         |

|   18|*"         OPTIONAL                                                                         |

|   19|*"  EXCEPTIONS                                                                              |

|   20|*"      DOCUMENT_NOT_SAVED                                                                  |

|   21|*"----------------------------------------------------------------------                    |

|   22|  DATA: guids_to_init TYPE crmt_object_guid_tab,                                            |

|   23|        ls_saved_object TYPE crmt_return_objects_struc,                                     |

|   24|        lv_keep_lock TYPE crmt_boolean,                                                     |

|   25|        lv_guid TYPE crmt_object_guid,                                                      |

|   26|        lv_cancelled_when_error TYPE crmt_boolean,                                          |

|   27|        ls_exception TYPE crmt_exception_logical_key,                                       |

|   28|        lv_message(200) TYPE c,                                                             |

|   29|        lv_msgnr_at_db TYPE crmt_msgnr_from_db,                                             |

|   30|        lt_msgh TYPE bal_t_msgh,                                                            |

|   31|        ls_msg  TYPE bal_s_msg,                                                             |

|   32|        ls_msg_info TYPE crmt_msg_info,                                                     |

|   33|        ls_msgh TYPE balmsghndl,                                                            |

|   34|        ls_exception_wa type CRMT_EXCEPTION.                                                |

|   35|                                                                                            |

|   36|* Debug functionality for external calls of One Order APIs                                  |

|   37|  INCLUDE crm_trace_save.                                                                   |

|   38|                                                                                            |

|   39|* check importing parameter                                                                 |

|   40|  READ TABLE it_objects_to_save INDEX 1 INTO lv_guid.                                       |

|   41|  IF lv_guid EQ gc_empty_guid.                                                              |

|>>>>>|    MESSAGE x009.                                                                           |

|   43|  ENDIF.                                                                                    |

|   44|                                                                                            |

|   45|  IF et_exception IS REQUESTED.                                                             |

|   46|    lv_cancelled_when_error = true.                                                         |

|   47|  ENDIF.                                                                                    |

|   48|                                                                                            |

|   49|  CALL FUNCTION 'CRM_MESSAGES_REGISTER'                                                     |

|   50|    EXPORTING                                                                               |

|   51|      iv_log_class  = gc_log_class-save                                                     |

|   52|      iv_set_regmsg = true                                                                  |

|   53|    CHANGING                                                                                |

|   54|      cv_log_handle = cv_log_handle.                                                        |

|   55|                                                                                            |

|   56|  CALL FUNCTION 'CRM_ORDER_SAVE_OW'                                                         |

|   57|    EXPORTING                                                                               |

|   58|      it_objects_to_save   = it_objects_to_save                                             |

|   59|      iv_update_task_local = iv_update_task_local                                           |

|   60|      iv_log_handle        = cv_log_handle                                                  |

|   61|      iv_save_frame_log    = iv_save_frame_log                                              |

GopalakrishnanS
Participant
0 Kudos

Hi Akshay,

Check the order_maintain function module executes with out any error ie sy-subrc eq 0. You will be getting the orderadm_h guids list in the ct_orderadm_h. Then you have to pass these guids list to the it_objects_to_save  of crm_order_save function module.

Please post your code also to verify what went wrong.

Regards,

GK.

Former Member
0 Kudos

in case of multiple entries updation to crmd_orderadm_h i am unable to update the entry only the last entry is updated

Former Member
0 Kudos

REPORT z_serviceticket.

*TYPE-POOLS truxs.

TABLES : crmd_orderadm_h.

* Selection screen

PARAMETER p_file TYPE rlgrap-filename DEFAULT 'C:\Users\aksha_000\Desktop\data fields for service ticket.txt'.

*DATA itab LIKE crmd_orderadm_h OCCURS 1 WITH HEADER LINE.

*DATA :

*itab type TABLE OF crmd_orderadm_h ,

*       wa_crm type crmd_orderadm_h.

DATA:

   BEGIN OF itab1 OCCURS 0,

     object_id      TYPE c LENGTH 10,

     process_type   TYPE c LENGTH 4,

     object_type    TYPE c LENGTH 10,

     posting_date   TYPE crmd_orderadm_h-posting_date,

     description    TYPE c LENGTH 40,

     descr_language TYPE c LENGTH 1,

     created_at     TYPE c LENGTH 15,

     changed_at     TYPE c LENGTH 15,

     valid_from     TYPE c LENGTH 15,

     input_channel  TYPE c LENGTH 3,

   END OF itab1.

*DATA :

* t_upload  TYPE TABLE OF itab WITH HEADER LINE.

**  wa_upload TYPE t_tab.

CALL FUNCTION 'GUI_UPLOAD'

   EXPORTING

     filename            = 'C:\Users\aksha_000\Desktop\data fields for service ticket.txt'

     filetype            = 'ASC'

     has_field_separator = 'X'

*   HEADER_LENGTH       = 01

*   READ_BY_LINE        = '1'

*   DAT_MODE            = ' '

*   CODEPAGE            = ' '

*   IGNORE_CERR         = ABAP_TRUE

*   REPLACEMENT         = '#'

*   CHECK_BOM           = ' '

*   VIRUS_SCAN_PROFILE  =

*   NO_AUTH_CHECK       = ' '

* IMPORTING

*   FILELENGTH          =

*   HEADER              =

   TABLES

     data_tab            = itab1.

** CHANGING

*   ISSCANPERFORMED               = ' '

* EXCEPTIONS

*   FILE_OPEN_ERROR               = 1

*   FILE_READ_ERROR               = 2

*   NO_BATCH                      = 3

*   GUI_REFUSE_FILETRANSFER       = 4

*   INVALID_TYPE                  = 5

*   NO_AUTHORITY                  = 6

*   UNKNOWN_ERROR                 = 7

*   BAD_DATA_FORMAT               = 8

*   HEADER_NOT_ALLOWED            = 9

*   SEPARATOR_NOT_ALLOWED         = 10

*   HEADER_TOO_LONG               = 11

*   UNKNOWN_DP_ERROR              = 12

*   ACCESS_DENIED                 = 13

*   DP_OUT_OF_MEMORY              = 14

*   DISK_FULL                     = 15

*   DP_TIMEOUT                    = 16

*   OTHERS

LOOP AT itab1.

   WRITE:/ itab1-object_id,

   itab1-process_type.

ENDLOOP.

INCLUDE crm_object_names_con.

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.

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

LOOP at itab1.

CALL FUNCTION 'CRM_INTLAY_GET_HANDLE'                   "we need a unique handel for each entry

   IMPORTING

     ev_handle = ls_input_fields-ref_handle.

* 1. Populate orderadm_h with the process type and description

*LOOP at  crmd_orderadm_h.

*

*IF ( crmd_orderadm_h-object_id = itab1-object_id ) AND ( crmd_orderadm_h-process_type = itab1-process_type ) AND ( crmd_orderadm_h-posting_date = itab1-posting_date ).

*

*WRITE: / 'caught'.

*

*endloop.

*

*else.

ls_orderadm_h-handle       = ls_input_fields-ref_handle.

ls_orderadm_h-process_type = itab1-process_type.

ls_orderadm_h-object_id = itab1-object_id.

ls_orderadm_h-PREDECESSOR_OBJECT_TYPE = itab1-object_type.

ls_orderadm_h-posting_date = itab1-posting_date.

ls_orderadm_h-description = itab1-description.

ls_orderadm_h-descr_language = itab1-descr_language.

ls_orderadm_h-created_at = itab1-created_at.

ls_orderadm_h-changed_at = itab1-changed_at.

ls_orderadm_h-valid_from_ext = itab1-valid_from.

ls_orderadm_h-input_channel = itab1-input_channel.

ls_orderadm_h-mode         = 'A'.

APPEND ls_orderadm_h TO lt_orderadm_h.

ENDloop.

* 2. Prepare table first.

* The lines you enter into table lt_nametab MUST be entered (appended)

* in alphabetical order, as lt_nametab is sorted.

* See here that the 3 entried are the three attributes you populated in ls_orderadm_h above.

ls_nametab = 'CHANGED_AT'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'CREATED_AT'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'DESCRIPTION'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'DESCR_LANGUAGE'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'INPUT_CHANNEL'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'MODE'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'OBJECT_ID'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'POSTING_DATE'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'PREDECESSOR_OBJECT_TYPE'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'PROCESS_TYPE'.

APPEND ls_nametab TO lt_nametab.

ls_nametab = 'VALID_FROM_EXT'.

APPEND ls_nametab TO lt_nametab.

* 3. Populate lt_input_fields now

* You need to add this table that you want to create to the input fields.

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.

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

CLEAR: ls_nametab, lt_nametab[].

* 5. Populate ls_opport_h with appropriate values (see examples or attributes to populate)

*  ls_opport_h-ref_handle      = ls_input_fields-ref_handle.

*  ls_opport_h-exp_revenue     = iv_expt_sales.

*  ls_opport_h-startdate       = iv_sc_sdate.

*  ls_opport_h-expect_end      = iv_sc_cdate.

*  ls_opport_h-curr_phase      = iv_sales_stage.

*  ls_opport_h-probability     = iv_chanceofsuc.

*  ls_opport_h-source          = iv_origin.

*  ls_opport_h-type            = iv_serv_line.

*  ls_opport_h-mode          = 'A'.

*  append ls_opport_h to lt_opport_h.

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

*  ls_nametab = 'CURR_PHASE'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'EXPECT_END'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'EXP_REVENUE'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'MODE'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'PROBABILITY'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'SOURCE'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'STARTDATE'.

*  append ls_nametab to lt_nametab.

*  ls_nametab = 'TYPE'.

*  append ls_nametab to lt_nametab.

* 7. 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.

* 8. You’re ready to call crm_order_maintain now

LOOP AT lt_orderadm_h into  ls_orderadm_h.

CALL FUNCTION 'CRM_ORDER_MAINTAIN'

*      exporting

*        it_service_h       = lt_service_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.

* 9. 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.

     APPEND ls_save_guid TO lt_save_guid.

ENDCASE.

* 10. SAVE the changes (all creations must be saved and committed before they exist in CRM)

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.

   endloop.


this is the prog i have used

Former Member
0 Kudos

I am getting an error

Update was terminated

Created  Author Address   Developer ABAPon   18.06.2015   14:57:53

Update was terminated

System ID....   CRD
Client.......   100
User.....   ABAPDEV
Transaction..   SE38
Update key...   557E2B144FAC0393E1000000AC10147A
Generated....   18.06.2015, 14:57:53
Completed....   18.06.2015, 14:57:53
Error Info...   Internal session terminated with a runtime error DBSQL_DUPLICATE_KEY_ERROR (see
                                                                                                                                                           
GopalakrishnanS
Participant
0 Kudos

Hi Akshay,

Please refer the report program CRM_TEST_ORDER_MAINTAIN. Try to debug the program and you will get better idea in updating multiple entries.

Hope this will help you.

Regards,

Gk.

former_member202771
Contributor
0 Kudos

This helped me a  lot.

Thanks Lindsay :smile:

coolomi1
Explorer
0 Kudos

Hi stanger.lindsay,

I have a requirement to Recalculate all the  pricing condition for the Service Contract (reprice the Contract item or recalculate the price at the item level)   to our custom program  as same as the Standard :

I need to know the any related  function module and its parameter to be passed  else any approach to achieve the same.

Please help me out ..

you would be highly appreciated ...

Thanks and Regards,

Om Prakash.

Former Member
0 Kudos
Hi,

I am new in SAP and have a requirement to create an interaction record for non SAP system, may you please guide me on how i can go about it.

Many Thanks.

Hulisani
mhmtlsbs
Explorer
0 Kudos
Hi Lindsay,

 

I execute your code but its not working. Also I don't understand why we are using orderadm_h if we are going to create a opputunity?
Labels in this area