cancel
Showing results for 
Search instead for 
Did you mean: 

maintain activity relation

Former Member
0 Kudos

hello gurus,

I have used BAPI_NETWORK_MAINTAIN bapi to maintain network and activity relationship.

bellow is the code written by me .





START-OF-SELECTION.


 
  PERFORM modify_int_table.

  PERFORM write_msg.
 
  LOOP AT it_tab INTO wa_tab.
    IF wa_tab-constraint_start_date IS INITIAL.
      wa_tab-constraint_start_date = '00000000'.
    ENDIF.

    IF wa_tab-constraint_finish_date IS INITIAL.
      wa_tab-constraint_finish_date = '00000000'.
    ENDIF.

    CLEAR : l_tabix.
    l_tabix = sy-tabix.

    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
      EXPORTING
        input     = wa_tab-wbs_element
      IMPORTING
        output    = wa_tab-wbs
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
      EXPORTING
        input     = wa_tab-network_predecessor
      IMPORTING
        output    = wa_tab-net_pred
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
      EXPORTING
        input     = wa_tab-network_successor
      IMPORTING
        output    = wa_tab-net_succ
      EXCEPTIONS
        not_found = 1
        OTHERS    = 2.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.


    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = wa_tab-activity
      IMPORTING
        output = wa_tab-activity.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = wa_tab-activity_predecessor
      IMPORTING
        output = wa_tab-activity_predecessor.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = wa_tab-activity_successor
      IMPORTING
        output = wa_tab-activity_successor.

    CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
      EXPORTING
        datum         =  wa_tab-constraint_start_date
        dtype         = 'DATS'
     IMPORTING
*    ERROR         =
       idate         = wa_tab-constraint_start_date
*    MESSG         =
*    MSGLN         =
              .

    CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
      EXPORTING
        datum         = wa_tab-constraint_finish_date
        dtype         = 'DATS'
     IMPORTING
*    ERROR         =
       idate         = wa_tab-constraint_finish_date
*    MESSG         =
*    MSGLN         =
              .

    MODIFY it_tab FROM wa_tab INDEX l_tabix.
  ENDLOOP.

  SELECT aufnr projn
   FROM afpo
   INTO CORRESPONDING FIELDS OF TABLE it_network
   FOR ALL ENTRIES IN it_tab
   WHERE projn = it_tab-wbs
    OR   projn = it_tab-net_pred
    OR   projn = it_tab-net_succ.

  LOOP AT it_tab INTO wa_tab.
    READ TABLE it_network INTO wa_network WITH KEY projn = wa_tab-wbs.
    IF sy-subrc EQ 0.
      wa_tab-network = wa_network-aufnr.
    ENDIF.
    READ TABLE it_network INTO wa_network WITH KEY projn = wa_tab-net_pred.
    IF sy-subrc EQ 0.
      wa_tab-net_pd = wa_network-aufnr.
    ENDIF.
    READ TABLE it_network INTO wa_network WITH KEY projn = wa_tab-net_succ.
    IF sy-subrc EQ 0.
      wa_tab-net_sc = wa_network-aufnr.
    ENDIF.
    MODIFY it_tab FROM wa_tab TRANSPORTING network net_pd net_sc.
  ENDLOOP.

ENDFORM.                    " DATA_TRANSFER_TO_INTTABLE


*&---------------------------------------------------------------------*
*&      Form  MODIFY_INT_TABLE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM modify_int_table .

  FREE: it_method_project.
  CLEAR : wa_method_project.

  l_line = 0.

*  LOOP AT it_wbs INTO wa_wbs.
  LOOP AT it_tab INTO wa_tab." WHERE wbs_element = wa_wbs-wbs.
    l_line = l_line + 1.

    CONCATENATE wa_tab-network wa_tab-activity INTO w_objkey.
    wa_method_project-objecttype = 'NetworkActivity' .
    wa_method_project-method = 'UPDATE' .
    wa_method_project-refnumber = '000001'."l_line .
    wa_method_project-objectkey = w_objkey.
    APPEND wa_method_project TO it_method_project.
    CLEAR : wa_method_project.
    wa_method_project-method = 'SAVE' .
    APPEND wa_method_project TO it_method_project.

    wa_activity-network                        =   wa_tab-network.
    wa_activity-activity                       =   wa_tab-activity.
    wa_activity-duration_normal                =   wa_tab-duration_normal  .
    wa_activity-constraint_type_start          =   wa_tab-constraint_type_start.
    wa_activity-constraint_type_finish         =   wa_tab-constraint_type_finish.
    wa_activity-constraint_start_date          =   wa_tab-constraint_start_date .
    wa_activity-constraint_finish_date         =   wa_tab-constraint_finish_date.

    APPEND wa_activity TO it_activity.

    wa_activity_up-duration_normal             =   'X'.
    wa_activity_up-constraint_type_start       =   'X'.
    wa_activity_up-constraint_type_finish      =   'X'.
    wa_activity_up-constraint_start_date       =   'X'.
    wa_activity_up-constraint_finish_date      =   'X'.

    APPEND wa_activity_up TO it_activity_up.

    PERFORM call_bapi_act.

    CLEAR: wa_activity, wa_activity_up, wa_relation, wa_relation_up,wa_method_project.
    FREE: it_method_project,it_activity, it_activity_up, it_message_table.

*early code

  CONCATENATE wa_tab-relation_type wa_tab-net_pd wa_tab-activity_predecessor
                    wa_tab-net_sc wa_tab-activity_successor  INTO w_objkey.
*blocked

*changed code
*concatenate wa_tab-relation_type wa_tab-network wa_tab-activity wa_tab-network wa_tab-activity_predecessor wa_tab-activity_successor into w_objkey.
*condense w_objkey.
***
    wa_method_project-objecttype = 'NetworkRelation'.
    wa_method_project-method = 'CREATE'.
    wa_method_project-refnumber = '000001'.
    wa_method_project-objectkey = w_objkey.
    APPEND wa_method_project TO it_method_project.

    CLEAR : wa_method_project.
    wa_method_project-method = 'SAVE'.
    APPEND wa_method_project TO it_method_project.

    wa_relation-network_predecessor              =   wa_tab-net_pd .
    wa_relation-activity_predecessor             =   wa_tab-activity_predecessor.
    wa_relation-network_successor                =   wa_tab-net_sc .
    wa_relation-activity_successor               =   wa_tab-activity_successor.
    wa_relation-relation_type                    =   wa_tab-relation_type.
    wa_relation-duration_relation                =   wa_tab-duration_relation .
    wa_relation-duration_relation_unit_iso       =   text-002.

    APPEND wa_relation TO it_relation.

    wa_relation_up-network_predecessor          =    'X'.
    wa_relation_up-activity_predecessor         =    'X'.
    wa_relation_up-network_successor            =    'X'.
    wa_relation_up-activity_successor           =    'X'.
    wa_relation_up-relation_type                =    'X'.
    wa_relation_up-duration_relation            =    'X'.
    wa_relation_up-duration_relation_unit_iso   =    'X'.

    APPEND wa_relation_up TO it_relation_up.

    PERFORM call_bapi_reln.

    CLEAR: wa_activity, wa_activity_up, wa_relation, wa_relation_up,wa_method_project.
    FREE: it_method_project,it_relation, it_relation_up, it_message_table.

  ENDLOOP.

ENDFORM.                    " MODIFY_INT_TABLE


*&---------------------------------------------------------------------*
*&      Form  CALL_BAPI
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM call_bapi_act .

  CALL FUNCTION 'BAPI_PS_INITIALIZATION'
    .

  CALL FUNCTION 'BAPI_NETWORK_MAINTAIN'
   IMPORTING
     return                            = it_bapiret3
    TABLES
      i_method_project                  = it_method_project
*     I_NETWORK                         =
*     I_NETWORK_UPDATE                  =
     i_activity                        = it_activity
     i_activity_update                 = it_activity_up
*     i_relation                        = it_relation
*     i_relation_update                 = it_relation_up
     e_message_table                   = it_message_table
*     I_ACTIVITY_ELEMENT                =
*     I_ACTIVITY_ELEMENT_UPDATE         =
*     I_ACTIVITY_MILESTONE              =
*     I_ACTIVITY_MILESTONE_UPDATE       =
            .
  IF sy-subrc EQ 0.


  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait          = 'X'
*   IMPORTING
*     RETURN        =
            .

  IF sy-subrc EQ 0.
  if it_message_table[] is initial.
     wa_msgtab-message_type = 'S'.
      wa_msgtab-msg_txt = 'Successfully updated Project For' .
      CONCATENATE wa_msgtab-msg_txt ':' wa_activity-network '-' wa_activity-activity INTO wa_msgtab-msg_txt.
      APPEND wa_msgtab TO it_msgtab.

    ELSE.

      LOOP AT it_message_table INTO wa_message_table.
        wa_msgtab-message_type = wa_message_table-message_type.
        wa_msgtab-msg_txt = wa_message_table-message_text.
        APPEND wa_msgtab TO it_msgtab.
      ENDLOOP.
    ENDIF.
*  ENDIF.
 ELSE.
 endif.
  ENDIF.

ENDFORM.                    " CALL_BAPI_ACT


*&---------------------------------------------------------------------*
*&      Form  CALL_BAPI_RELN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM call_bapi_reln .

  CALL FUNCTION 'BAPI_PS_INITIALIZATION'
    .

  CALL FUNCTION 'BAPI_NETWORK_MAINTAIN'
   IMPORTING
     return                            = it_bapiret3
    TABLES
      i_method_project                  = it_method_project
*     I_NETWORK                         =
*     I_NETWORK_UPDATE                  =
*     i_activity                        = it_activity
*     i_activity_update                 = it_activity_up
     i_relation                        = it_relation
     i_relation_update                 = it_relation_up
     e_message_table                   = it_message_table
*     I_ACTIVITY_ELEMENT                =
*     I_ACTIVITY_ELEMENT_UPDATE         =
*     I_ACTIVITY_MILESTONE              =
*     I_ACTIVITY_MILESTONE_UPDATE       =
            .
            if sy-subrc eq 0.



  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
   EXPORTING
     wait          = 'X'
*   IMPORTING
*     RETURN        =
            .

  IF sy-subrc EQ 0.
  if it_message_table[] is initial.
     wa_msgtab-message_type = 'S'.
      wa_msgtab-msg_txt = 'Successfully updated Project For' .
      CONCATENATE wa_msgtab-msg_txt ':' 'Network' wa_tab-network 'Activity' wa_activity-activity INTO wa_msgtab-msg_txt.
      APPEND wa_msgtab TO it_msgtab.
    ELSE.

      LOOP AT it_message_table INTO wa_message_table.
        IF sy-tabix EQ 1.
          wa_msgtab-message_type = wa_message_table-message_type.
        ENDIF.
        wa_msgtab-msg_txt = wa_message_table-message_text.
        APPEND wa_msgtab TO it_msgtab.
        CLEAR wa_msgtab.
      ENDLOOP.
    ENDIF.
  ENDIF.
 else.
 endif.

ENDFORM.                    " CALL_BAPI_RELN



*&---------------------------------------------------------------------*
*&      Form  WRITE_MSG
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM write_msg .

  IF NOT it_msgtab[] IS INITIAL.

    WRITE:/1 sy-vline, 2'Message Type', 14 sy-vline,  'Message Text', 180 sy-vline.
    WRITE:sy-uline.

    LOOP AT it_msgtab INTO wa_msgtab.
      WRITE:/1 sy-vline, 6 wa_msgtab-message_type, 14 sy-vline, 15 wa_msgtab-msg_txt.
      WRITE: sy-uline.
    ENDLOOP.
  ENDIF.

the data maintained in excel sheet is (record1) (record2)

..........
WBS Element                                 S09WKA03-1-2-1             S09WKA03-2-1
activity(12)	                                   10                                      280
duration_normal(5)                          50                                        55
 constraint_type_start(1)
constraint_type_finish(1)	
constraint_start_date(8)	
constraint_finish_date(8)	
WBS_predecessor	                                                           S09WKA03-1-2-1
activity_predecessor(4)                                                               10	

WBS_successor	           S09WKA03-2-1
activity_successor(4)	         280
relation_type(2)	             fs                                            fs
duration_relation(5)                         2                                              5

and i am getting the bellow error message

"An incorrect object key was entered for object type Relationship"

kindly solve my problem .I am not able find out where is the mistake.

THANKS IN ADVANCE ,

PADMA.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

please check out this:

&----


*& Report Z_NETWORK_REL_CREATE

*&

&----


*&

*&

&----


REPORT z_network_rel_create.

DATA:

ls_return type bapireturn1,

lt_method_project TYPE STANDARD TABLE OF bapi_method_project,

lt_network TYPE STANDARD TABLE OF bapi_network,

lt_relation TYPE STANDARD TABLE OF bapi_network_relation,

lt_messages TYPE STANDARD TABLE OF bapi_meth_message.

DATA:

ls_method_project TYPE bapi_method_project,

ls_network TYPE bapi_network,

ls_relation TYPE bapi_network_relation.

*/ Network has the external name TRAINING0001 and two activities

*/ with number 0010 and 0020.

*/ This code create a FS relationsship between 0010 and 0020

ls_method_project-objecttype = 'NetworkRelation'.

ls_method_project-method = 'Create'.

*/ language dependend -> FS (table TCN2T)

ls_method_project-objectkey = 'FSTRAINING00010010TRAINING00010020'.

ls_method_project-refnumber = 000001.

ls_method_project-method = 'Save'.

APPEND ls_method_project TO lt_method_project.

ls_relation-network_predecessor = 'TRAINING0001'.

ls_relation-activity_predecessor = '0010'.

ls_relation-network_successor = 'TRAINING0001'.

ls_relation-activity_successor = '0020'.

*/ language dependend -> FS

ls_relation-relation_type = 'FS'.

APPEND ls_relation TO lt_relation.

ls_network-network = 'TRAINING0001'.

APPEND ls_network TO lt_network.

CALL FUNCTION 'BAPI_NETWORK_MAINTAIN'

IMPORTING

return = ls_return

TABLES

i_method_project = lt_method_project

i_network = lt_network

i_relation = lt_relation

e_message_table = lt_messages.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

Best regards

Peter

Former Member
0 Kudos

hi thanks for replay,

The difference I found is iam not passing it_network internal table to bapi.

is this giving the error.

one more doubt is in my excel sheet the wa_tab-net_pd (ie wbs_predecessor), wa_tab-activity_predecessor. (activity_predecessor) fields values are empty which we pass to

wa_relation-network_predecessor = wa_tab-net_pd

wa_relation-activity_predecessor = wa_tab-activity_predecessor.

these values are used to compose the objectkey..

kindly sugest the solution..

regards,

padmaja

Former Member
0 Kudos

Hi Padmaja

NETWORK_PREDECESSOR and ACTIVITY_PREDECESSOR and

NETWORK_SUCCESSOR and ACTIVITY_SUCCESSOR

has to be filled with the network number and activity number of the two activities.

A relationsship can be created between two network activities, alone. There is no WBS element.

However, I'm not sure whether I've got your last point .

Best regards

Peter