cancel
Showing results for 
Search instead for 
Did you mean: 

Add Text to Activity using BAPI_ACTIVITYCRM_CREATEMULTI

former_member187506
Contributor
0 Kudos

All:

I am creating activities as part of a data load.

One of the requirements is to assign text to a text type associated with an activity journal. However, I am struggling with this last piece of the puzzle.

I have lifted most of my code from the program "CRM_CALL_ACTIVITY_INTERFACE". Unfortunately, the demo program does not include parameters for passing text.

The snippet below is from my workup program.

Any ideas why the text is not making through the bapi?

data: text type standard table of BAPIBUS20001_TEXT_INS,

wa_text type BAPIBUS20001_TEXT_INS,

TEXTX type standard table of BAPIBUS20001_TEXT_INSX,

wa_TEXTX type BAPIBUS20001_TEXT_INSX.

  • TEXT

wa_text-ref_Guid = wa_header-GUID.

wa_text-tdid = '0200'.

wa_text-tdspras = 'E'.

wa_text-tdline = 'This is my test text.'.

wa_text-tdstyle = 'SYSTEM'.

wa_text-tdform = 'SYSTEM'.

wa_text-mode = 'I'. "guess

wa_text-tdformat = '*'.

append wa_text to text.

wa_textx-ref_guid = 'X'.

wa_textx-tdid = 'X'..

wa_textx-tdspras = 'X'.

wa_textx-tdline = 'X'.

wa_textX-tdstyle = 'X'.

wa_textX-tdform = 'X'.

wa_textx-mode = 'X'.

wa_textx-tdformat = 'X'.

append wa_textx to textx.

CALL FUNCTION 'BAPI_ACTIVITYCRM_CREATEMULTI'

TABLES

HEADER = header

HEADERX = headerx

PARTNER = partner

PARTNERX = partnerx

  • ORGANISATION =

  • ORGANISATIONX =

  • DATE =

  • DATEX =

TEXT = text

TEXTX = textx

  • REASON =

  • REASONX =

  • OUTCOME =

  • OUTCOMEX =

  • STATUS =

  • STATUSX =

  • LOCATION =

  • LOCATIONX =

  • INPUT_FIELDS =

CREATED_PROCESS = CREATEDPROCESS

RETURN = return

  • DOCUMENT_FLOW =

JOURNAL = journal

JOURNALX = journalx

MATERIAL = material

MATERIALX = materialx

EXTENSIONIN = lt_extensionin

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

MauricioMiao
Contributor
0 Kudos

Hello Roger,

As you are creating new documents you should use field wa_text-ref_handle instead of ref_guid.

Because if you don´t create the activity yet, how do you have the activity header GUID?

So pass 1 to handle in structure HEADER and 1 in this structure. Doing this the function stablish a relation between the tables based on this field. Do you understand?

Also you need to specify field REF_KIND. If it is a header text you fill ref_kind with A, if it is a item text you fill ref_kind with B.

And correct structure wa_textx to reflect your changes.

If you need more help, just reply back.

Regards,

Mauricio

former_member187506
Contributor
0 Kudos

Mauricio:

I have lifted my logic from the demo program "CRM_CALL_ACTIVITY_INTERFACE".

The header GUID is generated in a function module called in a step not shown in my code snippet. The header GUID is populated in a variable passed into the text structure.

My understanding of your comments are that if the header GUID is not generated in advance of the call to the BAPI_ACTIVITYCRM_CREATEMULTI, setting ref_handle to 1 in the Header table and the Text table will allow the activity to be created.

At this point I can create the activity and the activity journal, the only issue at the moment is moving in the text to assign to the corresponding journal.

I suspect my problem is as you suggest with the REF_KIND value. I will add the "B" value to the code and let you know.

MauricioMiao
Contributor
0 Kudos

Roger,

Ok, I understood your poit about REF_GUID and you are right.

But I have another point based on your last reply.

You said that you will add value 'B', but B is for item data, in case of header data you must add value A.

Also you can check if it is B or A debugging the standard transaction for activities. Fill the text into the standard, insert the /h code, press enter, and add a break-point into function CRM_ORDER_MAINTAIN. Take a look at table IT_TEXT to see how the standard fill REF_KIND and the other fields.

Regards,

Mauricio

former_member187506
Contributor
0 Kudos

Mauricio:

Pardon me. You were right about the GUID. I haven't gone through a deep debug, but the results are there.

The GUID is generated a the start of the program and passed to all of the tables required by the function module. This follows the logic laid out in the demo program.

Following your logic, I removed the generated GUID from the table TEXT. Poof my item text appeared in the new generated activity journal.

Thanks for your help.

RM

I have included my code for anyone's perusal. No warranties implied or expressed. Use at you own risk.



*&---------------------------------------------------------------------*
*& Report  Z_LOAD_ACTIVITIES_FROMDATA                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  Z_LOAD_ACTIVITIES_FROMDATA              .


data: header type standard table of BAPIBUS2000110_HEADER_INS,
      wa_header type BAPIBUS2000110_HEADER_INS,
      headerX type standard table of BAPIBUS2000110_HEADER_INSX,
      wa_headerX type BAPIBUS2000110_HEADER_INSX,
      partner type standard table of BAPIBUS20001_PARTNER_INS,
      wa_partner type BAPIBUS20001_PARTNER_INS,
      PARTNERX type standard table of BAPIBUS20001_PARTNER_INSX,
      wa_partnerx type BAPIBUS20001_PARTNER_INSX,
      return type standard table of BAPIRET2,
      MATERIAL type standard table of  BAPIBUS2000110_MATERIAL,
      wa_MATERIAL type BAPIBUS2000110_MATERIAL,
      MATERIALX type standard table of BAPIBUS2000110_MATERIALX ,
      wa_MATERIALX type BAPIBUS2000110_MATERIALX,
      EXTENSIONIN type standard table of BAPIPAREX,
      wa_EXTENSIONIN type BAPIPAREX,
      JOURNAL type standard table of  BAPIBUS2000110_JOURNAL,
      wa_JOURNAL type BAPIBUS2000110_JOURNAL,
      JOURNALX type standard table of BAPIBUS2000110_JOURNALX,
      wa_JOURNALX type BAPIBUS2000110_JOURNALX,
      text type standard table of BAPIBUS20001_TEXT_INS,
      wa_text type  BAPIBUS20001_TEXT_INS,
      TEXTX type standard table of BAPIBUS20001_TEXT_INSX,
      wa_TEXTX type BAPIBUS20001_TEXT_INSX.

constants: gc_lenstruc   type i value 30.

constants: begin of gc_bapi_te,
            activity_i   type  crmt_object_name  value
                              'BAPI_TE_CRMD_ACTIVITY_I',
            activity_ix  type  crmt_object_name  value
                              'BAPI_TE_CRMD_ACTIVITY_IX',
            product_i    type  crmt_object_name  value
                              'BAPI_TE_CRMD_PRODUCT_I',
            lead_h       type  crmt_object_name  value
                              'BAPI_TE_CRMD_LEAD_H',
            opport_h     type  crmt_object_name  value
                              'BAPI_TE_CRMD_OPPORT_H',
            orderadm_h   type  crmt_object_name  value
                              'BAPI_TE_CRMD_ORDERADM_H',
            orderadm_i   type  crmt_object_name  value
                              'BAPI_TE_CRMD_ORDERADM_I',
            shipping     type  crmt_object_name  value
                              'BAPI_TE_CRMD_SHIPPING',
            sales        type  crmt_object_name  value
                              'BAPI_TE_CRMD_SALES',
            schedlin     type  crmt_object_name  value
                              'BAPI_TE_CRMD_SCHEDLIN',
            pricing      type  crmt_object_name  value
                              'BAPI_TE_CRMD_PRICING',
            pricing_i    type  crmt_object_name  value
                              'BAPI_TE_CRMD_PRICING_I',
            billing      type  crmt_object_name  value
                              'BAPI_TE_CRMD_BILLING',
            ordprp_i     type  crmt_object_name  value
                              'BAPI_TE_CRMD_ORDPRP_I',

           end of gc_bapi_te.

* My structure for loading the journal
data: ls_activity_i_add_fields type zzcrmt_activity_i_add_fields,
      ls_te_activity_i  type bapi_te_crmd_activity_i,
      ls_te_activity_ix type bapi_te_crmd_activity_ix,
      ls_extensionin    type bapiparex,
      lt_extensionin    type table of bapiparex.
.



data: ls_activity_bapi  type bapibus2000110_header_ins,
      lt_return2 type standard table of bapiret2,
      createdProcess type standard table of BAPIBUS20001_HEADER_INS.

 field-symbols: <lv_anyfield>     type simple,
               <lv_flagfield>    type simple,
               <lv_fn>   type any,
               <lv_ft>   type any.



 data:
 laeng    type zzcrmt_activity_i_add_fields-laeng,
  breit    type zzcrmt_activity_i_add_fields-breit,
  hoehe    type zzcrmt_activity_i_add_fields-hoehe,
  meabm    type zzcrmt_activity_i_add_fields-meabm,
  prava    type zzcrmt_activity_i_add_fields-prava,
  pravb    type zzcrmt_activity_i_add_fields-pravb,
  subjecta type zzcrmt_activity_i_add_fields-subjecta,
  subjectb type zzcrmt_activity_i_add_fields-subjectb,
  result   type zzcrmt_activity_i_add_fields-kv_result,
  resreas  type zzcrmt_activity_i_add_fields-resreas,
  kv_deko  type zzcrmt_activity_i_add_fields-kv_deko,
  dekotp   type zzcrmt_activity_i_add_fields-dekotp,
  kv_stock type zzcrmt_activity_i_add_fields-kv_stock,
  posloc   type zzcrmt_activity_i_add_fields-posloc,
  kv_zpanz type zzcrmt_activity_i_add_fields-kv_zpanz,
  kv_zpava type zzcrmt_activity_i_add_fields-kv_zpava,
  nrmshf   type zzcrmt_activity_i_add_fields-nrmshf,
  nrpshf   type zzcrmt_activity_i_add_fields-nrpshf,
  posver   type zzcrmt_activity_i_add_fields-posver,
  poshor   type zzcrmt_activity_i_add_fields-poshor,
  posqli   type zzcrmt_activity_i_add_fields-posqli,
  ecropt   type zzcrmt_activity_i_add_fields-ecropt,
  nroffac  type zzcrmt_activity_i_add_fields-nroffac,
  faclen   type zzcrmt_activity_i_add_fields-faclen,
  facwid   type zzcrmt_activity_i_add_fields-facwid,
  facdep   type zzcrmt_activity_i_add_fields-facdep,
  facunit  type zzcrmt_activity_i_add_fields-facunit,
  sprice   type zzcrmt_activity_i_add_fields-sprice,
  oprice   type zzcrmt_activity_i_add_fields-oprice,
  aprice   type zzcrmt_activity_i_add_fields-aprice,
  kvcurr1  type zzcrmt_activity_i_add_fields-kvcurr1,
  phrefnr  type zzcrmt_activity_i_add_fields-phrefnr,
  storno   type zzcrmt_activity_i_add_fields-storno,
  lbval    type zzcrmt_activity_i_add_fields-lbval,
  grade    type ZZCRMT_ACTIVITY_I_ADD_FIELDS-grade,
  trade_name type ZZCRMT_ACTIVITY_I_ADD_FIELDS-grade.


data: logsys  type bapibus20001_doc_flow_ins-logsys_a.

data: lr_structdescr_bapi_te    type ref to cl_abap_structdescr,
      lr_structdescr_add_fields type ref to cl_abap_structdescr,
      lv_component   like line of cl_abap_structdescr=>components.



*----------------------------------------------------------------------*
*  INITIALIZATION                                                      *
*----------------------------------------------------------------------*
initialization.
  data: lv_datum(10) type c,
        lv_uzeit(6)  type c..
  write: sy-datum to lv_datum dd/mm/yyyy,
         sy-uzeit to lv_uzeit using edit mask '__:__'..



  call function 'OWN_LOGICAL_SYSTEM_GET'
    importing
      own_logical_system = logsys
    exceptions
      others             = 0.
  lr_structdescr_bapi_te    ?= cl_abap_typedescr=>describe_by_data(
ls_te_activity_i ).
  lr_structdescr_add_fields ?= cl_abap_typedescr=>describe_by_data(
ls_activity_i_add_fields ).


start-of-selection.

* Test journal entries

  subjecta = 'Z000000001'.
  subjectb = 'Z007'.
  FACUNIT = 'KG'.
  grade = '200%'.
  trade_name = 'Chlorine Tonner'.


call function 'GUID_CREATE'
    importing
      ev_guid_32 = wa_header-GUID.
* My Activity Type
      wa_header-PROCESS_TYPE = 'ZCON'.
      wa_header-description = 'This is my bapi test'.
* My Activity Category
      wa_header-CATEGORY = 'Z01'.
      wa_header-PRIORITY = '5'.
      wa_header-posting_date = sy-datum.
      wa_header-MODE = 'A'.
      wa_header-direction = 0.

      append wa_header to header.

      wa_headerx-GUId = 'X'.
      wa_headerx-PROCESS_TYPE = 'X'.
      wa_headerx-DESCRIPTION = 'X'.
      wa_headerx-CATEGORY = 'X'.
      wa_headerx-PRIORITY = 'X'.
      wa_headerx-OBJECTIVE = 'X'.
      wa_headerx-POSTING_DATE = 'X'.
      wa_headerx-MODE = 'X'.
      wa_headerx-DIRECTION = 'X'.


      append wa_headerx to headerx.
      wa_partner-ref_guid = wa_header-GUID.
      wa_partner-REF_KIND = 'A'.
      wa_partner-REF_PARTNER_HANDLE = '0001'.
      wa_partner-PARTNER_FCT = '00000009'.
      wa_partner-partner_no = '45000181'.
      wa_partner-NO_TYPE = 'BP'.
      wa_partner-DISPLAY_TYPE = 'BP'.

      append wa_partner to partner.

      wa_partner-REF_PARTNER_HANDLE = '0002'.
      wa_partner-PARTNER_FCT = '00000022'.
*User Name
      wa_partner-partner_no = 'RMYERS'.
      wa_partner-NO_TYPE = 'US'.
      wa_partner-DISPLAY_TYPE = 'US'.

      append wa_partner to partner.



      wa_partnerx-REF_GUID = 'X'.
      wa_partnerx-REF_KIND = 'X'.
      wa_partnerx-REF_PARTNER_HANDLE = 'X'.
      wa_partnerx-PARTNER_FCT = 'X'.
      wa_partnerx-PARTNER_NO = 'X'.
      wa_partnerx-NO_TYPE = 'X'.
      wa_partnerx-DISPLAY_TYPE = 'X'.

      append wa_partnerx to partnerx.


     wa_material-header = wa_header-GUID.
     wa_material-handle = 1.
*Product GUID
     wa_material-product ='A105BA8D09107646BF7C58408DCECEFA'.
     wa_material-ORDERED_PROD = '90000113'.
* using volume not quanitiy fileds
     wa_material-volume = 100.
*     wa_material-QUANTITY = 100.
     append wa_material to material.

     wa_materialx-HANDLE = 'X'.
     wa_materialx-PRODUCT = 'X'.
     wa_materialx-HEADER = 'X'.
     wa_materialx-volume = 'X'.
     wa_material-ORDERED_PROD = 'X'.
     wa_materialx-QUANTITY = 'X'.

     append wa_materialx to materialx.

  data j_guid like wa_JOURNAL-journal_guid.
  j_guid = 'B845C68411370348807A9C46F74A756C'.


  wa_JOURNAL-ref_handle = '0000000001'.
* My journal GUID
  wa_JOURNAL-journal_guid = 'B845C68411370348807A9C46F74A756C'.
  append wa_journal to journal.

  wa_JOURNALX-journal_guid = 'X'.
  wa_JOURNALX-ref_handle  = 'X'.
  append wa_JOURNALX to journalx.



move: laeng    to ls_activity_i_add_fields-laeng,
        breit    to ls_activity_i_add_fields-breit,
        hoehe    to ls_activity_i_add_fields-hoehe,
        meabm    to ls_activity_i_add_fields-meabm,
        prava    to ls_activity_i_add_fields-prava,
        pravb    to ls_activity_i_add_fields-pravb,
        subjecta to ls_activity_i_add_fields-subjecta,
        subjectb to ls_activity_i_add_fields-subjectb,
        result   to ls_activity_i_add_fields-kv_result,
        resreas  to ls_activity_i_add_fields-resreas,
        kv_deko  to ls_activity_i_add_fields-kv_deko,
        dekotp   to ls_activity_i_add_fields-dekotp,
        kv_stock to ls_activity_i_add_fields-kv_stock,
        posloc   to ls_activity_i_add_fields-posloc,
        kv_zpanz to ls_activity_i_add_fields-kv_zpanz,
        kv_zpava to ls_activity_i_add_fields-kv_zpava,
        nrmshf   to ls_activity_i_add_fields-nrmshf,
        nrpshf   to ls_activity_i_add_fields-nrpshf,
        posver   to ls_activity_i_add_fields-posver,
        poshor   to ls_activity_i_add_fields-poshor,
        posqli   to ls_activity_i_add_fields-posqli,
        ecropt   to ls_activity_i_add_fields-ecropt,
        nroffac  to ls_activity_i_add_fields-nroffac,
        faclen   to ls_activity_i_add_fields-faclen,
        facwid   to ls_activity_i_add_fields-facwid,
        facdep   to ls_activity_i_add_fields-facdep,
        facunit  to ls_activity_i_add_fields-facunit,
        sprice   to ls_activity_i_add_fields-sprice,
        oprice   to ls_activity_i_add_fields-oprice,
        aprice   to ls_activity_i_add_fields-aprice,
        kvcurr1  to ls_activity_i_add_fields-kvcurr1,
        phrefnr  to ls_activity_i_add_fields-phrefnr,
        storno   to ls_activity_i_add_fields-storno,
        lbval    to ls_activity_i_add_fields-lbval,
        grade    to  ls_activity_i_add_fields-grade,
        trade_name to  ls_activity_i_add_fields-trade_name.
        .

  move-corresponding ls_activity_i_add_fields to ls_te_activity_i.
  include: crm_bapi_eewfields_move.
  while sy-subrc eq 0. "// Set the X-flags generic
    assign component sy-index of structure ls_te_activity_i to
<lv_anyfield>.
    if sy-subrc eq 0.
      if not <lv_anyfield> is initial.
        assign component sy-index of structure ls_te_activity_ix to
<lv_flagfield> casting type bapiupdate.
        if sy-subrc eq 0.
          <lv_flagfield> = 'X'.
        endif.
      endif.
    endif.
  endwhile.
  if not ls_te_activity_ix is initial.
    ls_te_activity_i-ref_handle   = ls_te_activity_ix-ref_handle   = 1.
 ls_te_activity_i-journal_guid = ls_te_activity_ix-journal_guid = j_guid
.
    call method cl_abap_container_utilities=>fill_container_c
      exporting
        im_value               = ls_te_activity_i
      importing
        ex_container           = ls_extensionin+gc_lenstruc
      exceptions
        illegal_parameter_type = 1
        others                 = 2.
    move gc_bapi_te-activity_i to ls_extensionin-structure.
    append ls_extensionin to lt_extensionin.
    call method cl_abap_container_utilities=>fill_container_c
      exporting
        im_value               = ls_te_activity_ix
      importing
        ex_container           = ls_extensionin+gc_lenstruc
      exceptions
        illegal_parameter_type = 1
        others                 = 2.
    move gc_bapi_te-activity_ix to ls_extensionin-structure.
    append ls_extensionin to lt_extensionin.
  endif.



* TEXT

*    wa_text-ref_Guid = wa_header-GUID.
    wa_text-ref_handle = '0000000001'.
    wa_text-REF_KIND = 'B'.
    wa_text-tdid = '0200'.
    wa_text-tdspras = 'E'.
    wa_text-tdline = 'This is my test text.'.
    wa_text-tdstyle = 'SYSTEM'.
    wa_text-tdform = 'SYSTEM'.
    wa_text-mode = 'B'.   "guess
    wa_text-tdformat = '*'.

    append wa_text to text.

*    wa_textx-ref_guid = 'X'.
    wa_textx-REF_KIND = 'X'.
    wa_textx-tdid = 'X'..
    wa_textx-tdspras = 'X'.
    wa_textx-tdline = 'X'.
    wa_textX-tdstyle = 'X'.
    wa_textX-tdform = 'X'.
    wa_textx-mode = 'X'.
    wa_textx-tdformat = 'X'.

    append wa_textx to textx.



 data: ls_process_settings type bapibus20001_procsettings,
       lt_created_header   type table of bapibus20001_header_ins,
       ls_created_header   type bapibus20001_header_ins.

       ls_process_settings-msglevel = 8   ."gc_msglevel-administrator.
       ls_process_settings-save     = 'X' . "true.




 call function 'BAPI_BUSPROCESSND_PROCSETTINGS'
    exporting
     process_settings_in = ls_process_settings
    tables
      return              = lt_return2.

CALL FUNCTION 'BAPI_ACTIVITYCRM_CREATEMULTI'
  TABLES
    HEADER                = header
    HEADERX               = headerx
    PARTNER               = partner
     PARTNERX             = partnerx
*   ORGANISATION          =
*   ORGANISATIONX         =
*   DATE                  =
*   DATEX                 =
    TEXT                  =  text
    TEXTX                 =  textx
*   REASON                =
*   REASONX               =
*   OUTCOME               =
*   OUTCOMEX              =
*   STATUS                =
*   STATUSX               =
*   LOCATION              =
*   LOCATIONX             =
*   INPUT_FIELDS          =
   CREATED_PROCESS        = CREATEDPROCESS
    RETURN                =  return
*   DOCUMENT_FLOW         =
   JOURNAL                = journal
   JOURNALX               = journalx
    MATERIAL              = material
    MATERIALX             = materialx
   EXTENSIONIN            = lt_extensionin
       .



  if sy-subrc = 0 .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
          .

  endif.

  field-symbols: <cp> type BAPIBUS20001_HEADER_INS,
                  <rt> type BAPIRET2.

  loop at createdprocess assigning <cp>.
    write: / <cp>-OBJECT_ID,
             <cp>-description.

  endloop.

  loop at return assigning <rt>.

  write:/ <rt>-message.

  endloop.



Answers (0)