Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI_EQUI_CREATE

Former Member
0 Likes
2,230

Hi,

I need to create equipment master data using another

equipment as reference.

Currently i am using the BAPI_EQUI_CREATE in the program.

From IE01 , the reference field is RM63E-REFEQ.

In the BAPI i tried several fields like READ_CUREF and

READ_SUPEQ but no luck.

Has anybody worked on it.

Any help would be greatly appreciated.

Thanks,

Rao

3 REPLIES 3
Read only

Former Member
0 Likes
1,351

Hi,

I am using the following BAPI, to create equipments with reference to another equipment.

CALL FUNCTION 'BAPI_EQUI_CREATE_BY_REFERENCE'

EXPORTING

reference_number = p_w_equi-equipment_ref

valid_date = p_w_equi-valid_date

copy_flags = w_flags

IMPORTING

equipment = p_w_equi-equipment

data_general_exp = p_w_general

data_specific_exp = p_w_specific

return = p_w_return.

Hope this helps.

Sumant.

Read only

0 Likes
1,351

Hi Sumant,

In a way this works for me but

i also need to pass the material number.

Currently i am doing like this.

lt_specific-material = p_matnr.

lt_specific-equicatgry = p_eqtyp. "equi catergory of the material

clear g_equipment_no.

call function 'BAPI_EQUI_CREATE'

exporting

data_general = lt_datageneral

data_specific = lt_specific

valid_date = sy-datum

importing

equipment = g_equipment_no

return = wa_return.

Thanks,

Rao

Read only

Former Member
0 Likes
1,351

Hi,

In my scenario, I first create a equipment with refernece and then I go and change it with equipment specific data.

Here is the actual code from my program:


*     Create Equipments with reference via a BAPI call
      PERFORM create_equipment_ref USING    testrun
                                   CHANGING w_equi
                                            w_general
                                            w_specific
                                            w_return.
      IF w_return-type = c_err_type.
* Based on the BAPI return type, set the record status
* Successfuly processed (w_equi-status = c_status_c)
* Failed to process (w_equi-status = c_status_e)
        w_equi-status = c_status_e.
        MODIFY equi_data FROM w_equi.
        MOVE-CORRESPONDING w_return TO w_msgs.
        w_msgs-row_id = w_equi-row_id.
        APPEND w_msgs TO messages.
      ELSE.
        w_equi-status = c_status_c.
        MODIFY equi_data FROM w_equi.
      ENDIF.

The code for the subroutine create_equipment_ref:


FORM create_equipment_ref USING p_w_testrun  TYPE testrun
               CHANGING p_w_equi LIKE /sie/e_cs_equi_data
                        p_w_general  LIKE bapi_itob
                     p_w_specific LIKE bapi_itob_eq_only
                     p_w_return   LIKE bapiret2.

* Note: When creating Equipment with reference to 
*       another Equipment, you
*       do not have option to change some parts of the 
*       data and also you
*       cann't install the Equipment at a particular 
*       Functional Location
*       So, I had synchronize 3 different BAPIs to 
*       achieve this complete functionality.

  DATA: w_tc_return TYPE bapiret2.

  FIELD-SYMBOLS: <fg>.

  CLEAR: w_flags, w_instal, w_gen2, w_genx, w_spec2, w_specx.
  CLEAR: w_f1,    w_f2.

* These flags will tell the BAPI what parts of the reference equipment
* data must be copied to the new equipment
  w_flags = 'XXXXX XX'.

* If the Equi.Valid date is initial, then set it to current date.
* This is required for maintenance scheduling
  IF p_w_equi-valid_date IS INITIAL.
    p_w_equi-valid_date = sy-datum.
  ENDIF.

* 1. Create Equipment with refernece to another Equipment
  CALL FUNCTION 'BAPI_EQUI_CREATE_BY_REFERENCE'
       EXPORTING
            reference_number  = p_w_equi-equipment_ref
            valid_date        = p_w_equi-valid_date
            copy_flags        = w_flags
       IMPORTING
            equipment         = p_w_equi-equipment
            data_general_exp  = p_w_general
            data_specific_exp = p_w_specific
            return            = p_w_return.

  IF p_w_testrun IS INITIAL.

    IF p_w_return-type = c_err_type.

*     Rollback BAPI_EQUI_CREATE_BY_REFERENCE Work
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

    ELSE.

*     Commit Equi Create with reference BAPI work
*     If Commit fails, then again Rollback
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
                wait   = 'X'
           IMPORTING
                return = w_tc_return.

      IF NOT w_tc_return IS INITIAL.
        p_w_return = w_tc_return.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ENDIF.

*     2. Install the newly created Equipment at the required Location
      MOVE-CORRESPONDING p_w_equi TO w_instal.

      CALL FUNCTION 'BAPI_EQUI_INSTALL'
           EXPORTING
                equipment         = p_w_equi-equipment
                data_install      = w_instal
           IMPORTING
                data_general_exp  = p_w_general
                data_specific_exp = p_w_specific
                return            = p_w_return.

      IF p_w_return-type = c_err_type.

*       Rollback BAPI_EQUI_INSTALL work
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

      ELSE.

*       Commit BAPI_EQUI_INSTALL Work
*       If Commit fails, then again Rollback
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
             EXPORTING
                  wait   = 'X'
             IMPORTING
                  return = w_tc_return.

        IF NOT w_tc_return IS INITIAL.
          p_w_return = w_tc_return.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        ENDIF.

      ENDIF.

*     3. Change any specific data for the Equipment, if provided
*     This logic will dynamically check which fields in the receiving
*     interface structure are filled with data and will transfer the
*     contents onto corresponding fields of the BAPI structure
      MOVE-CORRESPONDING p_w_equi TO w_gen2.
      IF NOT w_gen2 IS INITIAL.

        CLEAR:   i_fields.
        REFRESH: i_fields.

        SELECT * FROM dd03l INTO TABLE i_fields
                            WHERE tabname = 'BAPI_ITOB'.
        LOOP AT i_fields.

          CLEAR: w_f1.
          CONCATENATE 'W_GEN2-'  i_fields-fieldname INTO w_f1.
          ASSIGN (w_f1) TO <fg>.

          IF NOT <fg> IS INITIAL .
            w_f2 = sy-tabix - 1.
            w_genx+w_f2(1) = 'X'.
          ENDIF.

          UNASSIGN <fg>.

        ENDLOOP.

        CALL FUNCTION 'BAPI_EQUI_CHANGE'
             EXPORTING
                  equipment         = p_w_equi-equipment
                  data_general      = w_gen2
                  data_generalx     = w_genx
                  data_specific     = w_spec2
                  data_specificx    = w_specx
             IMPORTING
                  data_general_exp  = p_w_general
                  data_specific_exp = p_w_specific
                  return            = p_w_return.

        IF p_w_return-type = c_err_type.

*         Rollback BAPI_EQUI_CHANGE Work
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

        ELSE.

*         Commit BAPI_EQUI_CHANGE Work
*         If Commit fails, then again Rollback
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
               EXPORTING
                    wait   = 'X'
               IMPORTING
                    return = w_tc_return.

          IF NOT w_tc_return IS INITIAL.
            p_w_return = w_tc_return.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ENDIF.

        ENDIF.

      ENDIF.

    ENDIF.

  ELSE.

*   Rollback Equipment Create with Reference BAPI work
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

  ENDIF.

ENDFORM.                    " create_equipment_ref

Regards,

Sumant.