Skip to Content
0
Jul 26, 2023 at 03:52 PM

Extend the Material to Plant to Plant

165 Views Last edit Jul 31, 2023 at 07:26 AM 2 rev

Hi Experts,

I need to Extend the Material from one Plant to other Plant. Ie., 11(material no) From M001 (Plant) to M002(Plant)

In return i getting Material was created and extended, but in Table level not updating . Kindly help

image.png

FORM read_file .
  BREAK senthilg.
  IF po_matnr IS NOT INITIAL.
    SELECT matnr FROM mara INTO TABLE @DATA(it_mara) WHERE matnr EQ @po_matnr.
*    IF it_mara IS NOT INITIAL.

*      SELECT matnr ,werks FROM mard INTO TABLE @DATA(it_mard) FOR ALL ENTRIES IN @it_mara WHERE matnr EQ @it_mara-matnr.
*    ENDIF.

    LOOP AT it_mara INTO DATA(wa_mara).
      APPEND VALUE ty_extend( matnr = wa_mara-matnr
                              tem_matnr = to_matnr
                              werks     = po_werks
                              tem_werks = to_werks ) TO it_extend.
    ENDLOOP.
  ENDIF.

ENDFORM.
FORM extend_form .

  DATA: ls_get_material TYPE bapi_mara_ga,
        ls_get_plant    TYPE bapi_marc_ga,
        ls_headata      TYPE bapimathead,
        ls_PLANTDATA    TYPE bapi_marc,
        ls_PLANTDATAX   TYPE bapi_marcx,
        ls_return       TYPE bapiret2,
        lt_EXTENSIONIN  TYPE TABLE OF bapiparex,
        lt_EXTENSIONINX TYPE TABLE OF bapiparexx,
        ls_plant        TYPE bapi_te_marc,
        ls_plantx       TYPE BAPI_TE_MARCx.

  SELECT  matnr,werks FROM marc INTO TABLE @DATA(it_marc) FOR ALL ENTRIES IN @it_extend WHERE matnr EQ @it_extend-matnr.

  LOOP AT it_extend INTO DATA(ls_extend).

    CALL FUNCTION 'BAPI_MATERIAL_GET_ALL'
      EXPORTING
        material   = ls_extend-tem_matnr
        plant      = ls_extend-tem_werks
      IMPORTING
        clientdata = ls_get_material
        plantdata  = ls_get_plant.

    IF ls_get_material-material IS NOT INITIAL.
      APPEND VALUE ty_final( matnr = ls_extend-matnr
                             tem_matnr = ls_extend-tem_matnr
                             werks     = ls_extend-werks
                             tem_werks = ls_extend-tem_werks ) TO it_final.

    ENDIF.

    ls_headata-material =  ls_get_material."ls_extend-matnr .

    LOOP AT it_marc INTO DATA(ls_marc).

      ls_PLANTDATA-plant =  ls_get_plant."ls_marc-werks.
      ls_PLANTDATAx-plant =  ls_marc-werks.

      ls_plant-plant  =   ls_get_plant ." ls_marc-werks.
      ls_plantx-plant  =  ls_get_plant." ls_marc-werks.

      APPEND VALUE bapiparex( structure = 'BAPI_TE_MARC'
                                   valuepart1 = ls_plant ) TO lt_extensionin.


      APPEND VALUE bapiparex( structure = 'BAPI_TE_MARCX'
                                   valuepart1 = ls_plantx ) TO lt_extensioninx.

      CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
        EXPORTING
          headdata     = ls_headata
          plantdata    = ls_PLANTDATA
          plantdatax   = ls_PLANTDATAx
        IMPORTING
          return       = ls_return
        TABLES
          extensionin  = lt_extensionin
          extensioninx = lt_extensioninx.

      IF ls_return IS NOT INITIAL .


        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
          EXPORTING
            wait = ' '.
        WAIT UP TO 10 SECONDS.


      ENDIF.

    ENDLOOP.

  ENDLOOP.
ENDFORM.

Attachments

image.png (5.5 kB)