SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create material Substitution



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Fri Feb 13, 2009 1:21 pm    Post subject: Create material Substitution Reply with quote

Code:
FUNCTION z_create_mat_substitution.
*"----------------------------------------------------------------------
  ""Local Interface:
*" IMPORTING
*" REFERENCE(IT_MAT_SUB) TYPE ZMATERIAL_SUBSTITUTION_T
*" EXPORTING
*" REFERENCE(ET_BAPIRET2) TYPE BAPIRET2_T
*" EXCEPTIONS
*" FAILED
*"----------------------------------------------------------------------
*" This function uses the following standard function modules to
*" create material substitutions:
*" RV_KONDITION_SICHERN
*" RV_MAT_SUB_SAVE
*"----------------------------------------------------------------------

  DATA: ls_mat_sub LIKE zmaterial_substitution,
  ls_vakedb LIKE vakedb,
  ls_xkonddvb LIKE konddvb,
  ls_bapiret2 LIKE bapiret2,
  lt_vakedb LIKE STANDARD TABLE OF vakedb,
  lt_xkonddvb LIKE STANDARD TABLE OF konddvb,
  lt_ykonddvb LIKE STANDARD TABLE OF konddvb,
  lt_xkonddpvb LIKE STANDARD TABLE OF konddpvb,
  lt_ykonddpvb LIKE STANDARD TABLE OF konddpvb,
  lv_knumh TYPE knumh.

  LOOP AT it_mat_sub INTO ls_mat_sub.
    CLEAR: ls_vakedb,
    ls_xkonddvb,
    lt_vakedb[],
    lt_xkonddvb[].

* Populate structure for RV_KONDITION_SICHERN.
    MOVE: 'D' TO ls_vakedb-kvewe,
    '001' TO ls_vakedb-kotabnr,
    'V' TO ls_vakedb-kappl,
    'A001' TO ls_vakedb-kschl,
    ls_mat_sub-matwa TO ls_vakedb-vakey,
    ls_mat_sub-datbi TO ls_vakedb-datbi,
    ls_mat_sub-datab TO ls_vakedb-datab,
    'I' TO ls_vakedb-xxdbaction.

* Populate structure for RV_MAT_SUB_SAVE.
    MOVE: sy-mandt TO ls_xkonddvb-mandt,
    ls_mat_sub-smatn TO ls_xkonddvb-smatn,
    ls_mat_sub-meins TO ls_xkonddvb-meins,
    ls_mat_sub-sugrd TO ls_xkonddvb-sugrd,
    'I' TO ls_xkonddvb-updkz.

* Determine next available condition record number.
    CALL FUNCTION 'NUMBER_GET_NEXT'
         EXPORTING
              nr_range_nr = '01'
              object      = 'KOND'
         IMPORTING
              number      = lv_knumh.

    ls_vakedb-knumh = ls_xkonddvb-knumh = lv_knumh.

* Append to internal tables.
    APPEND: ls_vakedb TO lt_vakedb,
    ls_xkonddvb TO lt_xkonddvb.

  ENDLOOP.

* Call RV_KONDITION_SICHERN.
  CALL FUNCTION 'RV_KONDITION_SICHERN' IN UPDATE TASK
       TABLES
            vakedb_tab = lt_vakedb.


* Call RV_MAT_SUB_SAVE to complete creation of Material Substitution.
  CALL FUNCTION 'RV_MAT_SUB_SAVE' IN UPDATE TASK
       TABLES
            x_konddvb  = lt_xkonddvb
            y_konddvb  = lt_ykonddvb
            x_konddpvb = lt_xkonddpvb
            y_konddpvb = lt_ykonddpvb.


* Commit to DB and wait as we need to check if the updates have been
  successful or not.
  COMMIT WORK AND WAIT.

* Check that substitutions have been created successfully.
  LOOP AT it_mat_sub INTO ls_mat_sub.

    SELECT SINGLE matwa INTO ls_mat_sub-matwa
    FROM kotd001
    WHERE kappl EQ 'V'
    AND kschl EQ 'A001'
    AND matwa EQ ls_mat_sub-matwa
    AND datbi GE sy-datum
    AND datab LE sy-datum.

    CLEAR: ls_bapiret2.

    IF sy-subrc EQ 0.

* Return success message.
      ls_bapiret2-type = 'S'.
      ls_bapiret2-id = 'ZMD_TOOL'.
      ls_bapiret2-number = '010'.
      ls_bapiret2-message_v1 = ls_mat_sub-matwa.
      ls_bapiret2-message_v2 = ls_mat_sub-smatn.
    ELSE.

* Return error message.
      ls_bapiret2-type = 'E'.
      ls_bapiret2-id = 'ZMD_TOOL'.
      ls_bapiret2-number = '011'.
      ls_bapiret2-message_v1 = ls_mat_sub-matwa.
      ls_bapiret2-message_v2 = ls_mat_sub-smatn.
    ENDIF.

    SHIFT: ls_bapiret2-message_v1 LEFT DELETING LEADING '0',
    ls_bapiret2-message_v2 LEFT DELETING LEADING '0'.


* Obtain message text.
    CALL FUNCTION 'BALW_BAPIRETURN_GET2'
         EXPORTING
              type   = ls_bapiret2-type
              cl     = ls_bapiret2-id
              number = ls_bapiret2-number
              par1   = ls_bapiret2-message_v1
              par2   = ls_bapiret2-message_v2
         IMPORTING
              return = ls_bapiret2.

    APPEND ls_bapiret2 TO et_bapiret2.

  ENDLOOP.

ENDFUNCTION.

The only extra bit you need to do is create a structure called ZMATERIAL_SUBSTITUTION with the following fields:
MATWA
SMATN
MEINS
SUGRD
DATBI
DATAB

.... and then a Table Type based on this structure.

Author: Chris Bailey
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ММ All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.