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

bdc for material master extension

Former Member
0 Likes
2,403

hello everybody,

i have developed a bdc program to extend material from one plant to other plant.

here we r changing only the plant and storage location data, program is working fine

and i was able to extend the material but my problem was for each material i need to select views separately

but user wants that the views to  be selected defaultly if they set default values for one material.

how can i acheive this

can anybody pls help me...

1 ACCEPTED SOLUTION
Read only

former_member377111
Participant
0 Likes
1,797

Hi,

The field VPSTA and PSTAT in MARA helps us in identifying the views maintained for a material. The difference between these 2 fields is:

VPSTA – This contains the views that have been created for the material.

PSTAT – Contains the list of views that have been created manually.


7 REPLIES 7
Read only

former_member377111
Participant
0 Likes
1,798

Hi,

The field VPSTA and PSTAT in MARA helps us in identifying the views maintained for a material. The difference between these 2 fields is:

VPSTA – This contains the views that have been created for the material.

PSTAT – Contains the list of views that have been created manually.


Read only

Former Member
0 Likes
1,797

Hi ,

You can use Bapi in place of BDC to extend material to plant or storage location  and u do need to think abt views its only extension .

BAPI_MATERIAL_SAVEDATA .

* Call BAPI to Extend

   call function 'BAPI_MATERIAL_SAVEDATA'

     exporting

       headdata             = p_bapi_head

       plantdata            = p_bapi_marc1

       plantdatax           = p_bapi_marcx

       storagelocationdata  = p_bapi_mard

       storagelocationdatax = p_bapi_mardx

       valuationdata        = p_bapi_mbew

       valuationdatax       = p_bapi_mbewx

     importing

       return               = p_bapi_return.

* BAPI COMMIT & WAIT

   call function 'BAPI_TRANSACTION_COMMIT'

     exporting

       wait = '2'.

Its easy and correct way to extend existing material .

Regards,

Yukti

Read only

0 Likes
1,797

hi yukti,

thanks for the help,

i have some doubts rgarding bapi,in this case ,am i need to pass

all the parameters  for the material like in creation or else it will fetch the data from existing

material depends on the views selected,

can u pls clarify me,

   in my requirement i need to change the plant and storage location , which bapi structures i need to use.

can u pls help me.

thanks.

Read only

0 Likes
1,797

Process :
- First read current data via or BAPI_MATERIAL_GET_ALL (or BAPI_MATERIAL_GETALL)
- Then, as yukti wrote, use the received data to fill plantdata(x) and storagelocationdata(x).

Regards,
Raymond

Read only

0 Likes
1,797

Hi,

You can use BAPI BAPI_MATERIAL_GET_ALL to get the necessary details for existing materials.

Set the respective 'X' parameters.

Pass the same to BAPI BAPI_MATERIAL_SAVEDATA.

Check the BAPIs. Revert in case of query.

Regards

Read only

0 Likes
1,797

Hi sample code for you  ,

tables:t001k,mara,marc,mbew,mard,t001l,t001w.

selection-screen begin of block b1 with frame title text-003.

parameters:p_bukrs type t001k-bukrs obligatory.

select-options:s_werks for t001k-bwkey no intervals no-extension obligatory,

                s_lgort for t001l-lgort.

selection-screen end of block b1.

selection-screen begin of block b2 with frame title text-004.

select-options:s_matnr for mara-matnr.

parameters:p_werks type t001k-bwkey obligatory.

selection-screen end of block b2.

data:it_marc type table of marc with header line,

       it_t001k type table of t001k with header line,

       it_mard type table of mard with header line,

       it_t001l type table of t001l with header line,

       it_mara type table of mara with header line,

       it_mbew type table of mbew with header line.

* BAPI related declaration

data: bapi_head   like bapimathead,

       bapi_makt   like bapi_makt,    "Material Description

       bapi_mara1  like bapi_mara,    "Client Data

       bapi_marax  like bapi_marax,

       bapi_marc1  like bapi_marc,    "Plant View

       bapi_marcx  like bapi_marcx,

       bapi_mard   like bapi_mard,    "Storage location view

       bapi_mardx  like bapi_mardx,

       bapi_mvke   like bapi_mvke,    "VALUATIONDATA

       bapi_mvkex  like bapi_mvkex,

       bapi_mbew   like bapi_mbew,    "Valuation Data

       bapi_mbewx  like bapi_mbewx,

       bapi_return like bapiret2.

start-of-selection.

   refresh:it_mara,it_marc,it_mard,it_t001l,it_t001k,it_mbew.

   clear:it_mara,it_marc,it_mard,it_t001l,it_t001k,it_mbew.

   select * from marc into table it_marc where matnr in s_matnr and werks = p_werks.

   select * from mbew into table it_mbew where matnr in s_matnr and bwkey = p_werks.

   select * from mard into table it_mard for all entries in it_marc where matnr = it_marc-matnr and werks = it_marc-werks.

   select * from mara into table it_mara where matnr in s_matnr.

   if it_marc[] is not initial.

     select * from t001k into table it_t001k where bukrs eq p_bukrs and bwkey in s_werks.

     if it_t001k[] is not initial.

       select * from t001l into table it_t001l for all entries in it_t001k where werks = it_t001k-bwkey.

     endif.

   endif.

   loop at it_marc.

     clear: it_mara,bapi_mara1,bapi_head,bapi_marc1,bapi_marcx.

     read table it_mara with key matnr = it_marc-matnr.

     if sy-subrc eq 0.

       call function 'CONVERSION_EXIT_MATN1_INPUT'

         exporting

           input  = it_mara-matnr

         importing

           output = it_mara-matnr.

       bapi_head-material    = it_mara-matnr.

       bapi_head-ind_sector  = it_mara-mbrsh.

       bapi_head-matl_type   = it_mara-mtart.

       bapi_head-purchase_view   = 'X'.

       bapi_head-storage_view    = 'X'.

       bapi_head-sales_view      = 'X'.

       bapi_head-account_view    = 'X'.

* MRP

       if it_marc-dismm is not initial.

         bapi_head-mrp_view        = 'X'.

         bapi_marc1-mrp_type = it_marc-dismm.

         bapi_marcx-mrp_type = 'X'.

         bapi_marc1-proc_type = it_marc-beskz.

         bapi_marcx-proc_type = 'X'.

       endif.

*Plant - Purchasing

       bapi_marc1-plant      = s_werks-low.

       bapi_marc1-pur_group  = it_marc-ekgrp.

       bapi_marc1-period_ind = it_marc-perkz.

       bapi_marc1-availcheck = it_marc-mtvfp.

       bapi_marc1-countryori = it_marc-herkl.

       bapi_marcx-plant      = s_werks-low.

       bapi_marcx-pur_group  = 'X'.

       bapi_marcx-period_ind = 'X'.

       bapi_marcx-availcheck = 'X'.

       bapi_marcx-countryori = 'X'.

*Valuation data

       clear it_mbew.

       read table it_mbew with key matnr = it_mara-matnr

                                    bwkey = it_marc-werks.

       if sy-subrc = 0.

         bapi_mbew-val_area    = s_werks-low.

         bapi_mbew-val_class   = it_mbew-bklas.

         bapi_mbew-price_ctrl  = it_mbew-vprsv.

         if bapi_mbew-price_ctrl = 'V'.

           bapi_mbew-moving_pr = it_mbew-verpr.

           bapi_mbewx-moving_pr   = 'X'.

         elseif bapi_mbew-price_ctrl = 'S'.

           bapi_mbew-std_price = it_mbew-stprs.

           bapi_mbewx-std_price   = 'X'.

         endif.

         bapi_mbewx-val_area    = s_werks-low.

         bapi_mbewx-val_class   = 'X'.

         bapi_mbewx-pr_ctrl_pp  = 'X'.

       endif.

       clear bapi_return.

       call function 'BAPI_MATERIAL_SAVEDATA'

         exporting

           headdata             = bapi_head

           plantdata            = bapi_marc1

           plantdatax           = bapi_marcx

*          STORAGELOCATIONDATA  = BAPI_MARD

*          STORAGELOCATIONDATAX = BAPI_MARDX

           valuationdata        = bapi_mbew

           valuationdatax       = bapi_mbewx

         importing

           return               = bapi_return.

* BAPI COMMIT & WAIT

       write😕 bapi_return-message.

       clear bapi_return.

       clear :bapi_head-purchase_view,bapi_head-account_view,bapi_head-mrp_view.

       loop at it_mard where matnr = it_mara-matnr and werks = it_marc-werks.

         bapi_mard-plant = s_werks-low.

         bapi_mard-stge_loc = it_mard-lgort.

         bapi_mardx-plant = s_werks-low.

         bapi_mardx-stge_loc = it_mard-lgort.

         call function 'BAPI_MATERIAL_SAVEDATA'

                 exporting

                   headdata             = bapi_head

*                  PLANTDATA            = BAPI_MARC1

*                  PLANTDATAX           = BAPI_MARCX

                   storagelocationdata  = bapi_mard

                   storagelocationdatax = bapi_mardx

*          VALUATIONDATA        = P_BAPI_MBEW

*          VALUATIONDATAX       = P_BAPI_MBEWX

                 importing

                   return               = bapi_return.

         write😕 bapi_return-message.

       endloop.

     endif.

     call function 'BAPI_TRANSACTION_COMMIT'

       exporting

         wait = '2'.

   endloop.

Can try with above code we have extended material to new company code , Plant and storage location

Cheers .

Hope it will help you

Read only

0 Likes
1,797

hello everyone,

thanks for the suggestions,they r very helpful.

here my client wants bdc program to extend material from one plant to another,

still i am facing the same problem in selection of views for the material to be extended,

in the template i am passing 'X' to the required views,but they r not selected when the

particular screen is processed,as suggested above i have checked vstpa and pstat they r

showing the already selected views when the material was created initially,when extending

i dont need all the views,i need only particular views for tht i hv used the below code

select single pstat from t134 into pstat

   where mtart = it-mtart.

   slen = strlen( pstat ).

   do slen times.

     b = 1.

     clear stat.

     move : pstat+a(b) to stat-cst .

*    stat-cst = pstat+a(b).

     append stat.

     add 1 to :a.

     clear b.

   enddo.

while preparing bdc data i am usin the below code

PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0070'.

       PERFORM BDC_FIELD       USING 'BDC_OKCODE'

                                     '=ENTR'.

       LOOP AT STAT WHERE CST = 'K'.

         PERFORM VCONCAT.

         TRANSLATE it-KZSEL_01_004 TO UPPER CASE.

         PERFORM BDC_FIELD       USING KZSEL "'X'.

                                 it-KZSEL_01_004.

         PERFORM VCONCAT.

         TRANSLATE it-kzsel_02_005 TO UPPER CASE.

         PERFORM BDC_FIELD       USING KZSEL "'X'.

*                                 it-KZSEL_01_004.

                                   it-KZSEL_02_005.

       ENDLOOP.

FORM VCONCAT .

   VIEWFLG = VIEWFLG + 1.

   if viewflg = 1 or viewflg = 2 .

*VIEWFLG = VIEWFLG + 1.

   KZSEL = 'MSICHTAUSW-KZSEL'.

   CONCATENATE KZSEL '(' VIEWFLG ')' INTO KZSEL.

   endif.

if viewflg = 3.

     viewflg = viewflg + 13.

    KZSEL = 'MSICHTAUSW-KZSEL'.

CONCATENATE KZSEL '(' VIEWFLG ')' INTO KZSEL.

*    viewflg = viewflg + 1.

*   KZSEL = 'MSICHTAUSW-KZSEL'.

*CONCATENATE KZSEL '(' VIEWFLG ')' INTO KZSEL.

endif.

   IF VIEWFLG = 16.

     PERFORM BDC_FIELD       USING 'BDC_OKCODE'

                                    '=P+'.

     PERFORM BDC_DYNPRO      USING 'SAPLMGMM' '0070'.

     PERFORM BDC_FIELD       USING 'BDC_CURSOR'

                                   'MSICHTAUSW-DYTXT(08)'.

     PERFORM BDC_FIELD       USING 'BDC_OKCODE'

                                   '=ENTR'.

endform.

if any problem in the above code pls help me.

its pretty urgent for me.

thanks

babu