Application Development 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: 

BDC To Update Safety time in MRP View.

Former Member
0 Kudos

Hi Experts,

I have a small issue,

Program to update u201C Safety time/act.covu201D (MARC-SHZET) -MRP 2 view

Program will have a selection screen with the following parameters:

1) Plant (WERKS) Default (blank = ALL plants)

2) Date (SPMON) Default = Current Month + 1

Program will need to update u201CSafety time/act.covu201D (MARC-SHZET) from S976

Target Daysu2019 supply (REICZ).

The program will join records from S976 version = u201CA00u201D and SPMON = current month +1 (default from selection screen) with MARC. The join will be on plant (WERKS) and material (MATNR).

Update the MARC-SHZET field with the value in S976-REICZ.

If REICZ > 99 make the value in MARC-SHZET = 99.

For the Above issue i wrote the program as below , but it is not updating the safety time please check it adn if any one got the solution or coding please revert me.

&----


*& Report ZR_SFTYTIMEUPD *

*& *

&----


REPORT ZR_SFTYTIMEUPD .

tables: s976,

marc.

data : begin of it_s976 occurs 0,

vrsio type s976-vrsio, "Version number in the information

"structure

spmon type s976-spmon, "Period to analyze - month

werks type s976-werks, "Plant

matnr type s976-matnr, "Material Number

reicz type s976-reicz, "Target range of coverage (target

"days'supply)

end of it_s976.

DATA: BEGIN OF it_marc OCCURS 0.

INCLUDE STRUCTURE marc.

DATA: END OF it_marc.

data: lv_date1 type sy-datum,

lv_date2 type sy-datum,

lv_month(2) type n,

lv_year(4) type n.

data:it_bdcdata like bdcdata occurs 0 with header line.

data:it_messtab like bdcmsgcoll occurs 0 with header line.

data: v_mode.

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

select-options: s_spmon for s976-spmon,

s_werks for s976-werks,

s_matnr for s976-matnr.

selection-screen: end of block b1.

initialization.

concatenate sy-datum0(4) sy-datum4(2) into lv_date1.

lv_month = sy-datum+4(2).

lv_year = sy-datum+0(4).

do 1 times.

lv_month = lv_month + 1.

if lv_month gt 12.

lv_month = 1.

lv_year = lv_year + 1.

endif.

enddo.

concatenate lv_year lv_month into lv_date2.

s_spmon-low = lv_date1.

s_spmon-high = lv_date2.

s_spmon-option = 'BT'.

s_spmon-sign = 'I'.

append s_spmon.

clear s_spmon.

start-of-selection.

select vrsio

spmon

werks

matnr

reicz

into table it_s976 from s976

where vrsio = 'A00'

and spmon in s_spmon

and werks in s_werks.

if sy-subrc = 0.

SORT it_s976 by spmon werks matnr.

endif.

if it_s976[] is not initial.

select *

into table it_marc from marc

for all entries in it_s976

where matnr = it_s976-matnr

and werks = it_s976-werks.

endif.

if sy-subrc = 0.

SORT it_marc BY werks matnr.

endif.

loop at it_s976.

read table it_marc with key werks = it_s976-werks

matnr = it_s976-matnr.

if sy-subrc = 0.

if it_s976-reicz > 99.

it_marc-shzet = 99.

else.

it_marc-shzet = it_s976-reicz .

endif.

**-- Initial Screen

perform bdc_dynpro using 'SAPLMGMM' '0060'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-MATNR'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RMMG1-MATNR'

it_marc-matnr.

**-- Pop up materials view

perform bdc_dynpro using 'SAPLMGMM' '0070'.

perform bdc_field using 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(13)'.

perform bdc_field using 'MSICHTAUSW-KZSEL(13)'

'X'.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

**-- Pop Plant entry screen

perform bdc_dynpro using 'SAPLMGMM' '0080'.

perform bdc_field using 'BDC_CURSOR'

'RMMG1-WERKS'.

perform bdc_field using 'RMMG1-WERKS'

it_marc-WERKS.

perform bdc_field using 'BDC_OKCODE'

'=ENTR'.

**-- Second screen

perform bdc_dynpro using 'SAPLMGMM' '3000'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

*perform bdc_field using 'MAKT-MAKTX'

  • it_marc-MAKTX.

*perform bdc_field using 'MARC-BESKZ'

  • it_marc-BESKZ.

*perform bdc_field using 'MARC-LGPRO'

  • it_marc-LGPRO.

*perform bdc_field using 'MARC-LGFSB'

  • it_marc-LGFSB.

*perform bdc_field using 'MARC-FHORI'

  • it_marc-FHORI.

perform bdc_field using 'MARC-SHZET'

it_marc-shzet.

perform bdc_dynpro using 'SAPLSPO1' '0300'.

perform bdc_field using 'BDC_OKCODE'

'=yes'.

*perform bdc_transaction using 'MM02'.

endif.

call transaction 'MM02' using it_bdcdata

mode 'A'

messages into it_messtab.

clear it_marc.

endloop.

&----


*& Form BDC_DYNPRO

&----


  • BDC screens information

----


form bdc_dynpro using program dynpro.

clear it_bdcdata.

it_bdcdata-program = program.

it_bdcdata-dynpro = dynpro.

it_bdcdata-dynbegin = 'X'.

append it_bdcdata.

clear it_bdcdata.

endform. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • BDC fields information

----


form bdc_field using fnam fval.

clear it_bdcdata.

it_bdcdata-fnam = fnam.

it_bdcdata-fval = fval.

append it_bdcdata.

clear it_bdcdata.

endform. " BDC_FIELD

Thanks & Regards,

Prasad.T

3 REPLIES 3

Former Member
0 Kudos

Hi Parasad,

Since u called the batch in mode A ("call transaction 'MM02' using it_bdcdata mode 'A' ") u should see all the screens when u run it. What happens then? does it reach the right screen? is there a value in the field u wish to update?

If not, we will get a hint of what's wrong.

Another option is to use a bapi - which is much "safer".

U can use bapi_material_savedata:

data: my_headdata type bapimathead,

my_plantdata type bapi_marc,

my_plantdatax type bapi_marcx,

my_return_tab type table of bapiret2.

my_headdata-material = <your material number>.

my_headdata-mrpview = 'X'.

my_plantdata-plant = <your plant - it_marc-WERKS?>.

my_plantdata-safetytime = S976-REICZ <or any other value>.

my_plantdatax-plant = <your plant - it_marc-WERKS?>.

my_plantdatax-safetytime = 'X'.

call function 'BAPI_material_savedat'

exporting

headdata = my_headdata

plantdata = my_plantdata

plantdatax = my_plantdatax

importing

return = my_return_tab.

And that's it. It should work always, but just to be safe u can check the return table for errors.

Note that in the materials view screen u choose the 13th view (" perform bdc_field using 'MSICHTAUSW-KZSEL(13)'

'X'. " - this marks line 13) - in different material types the MRP 2 view might in a different line (different material types have different possible view list and not all materials have all their views already defined. in each of these cases MRP 2 view might appear in a different line) and then your bdc won't work. For those reasons i recommend working with the bapi - u can see it's quite easy.

If u still want to stay with the bdc, follow the screens to see what's wrong and we'll try fixing it...

Pls reward points if helpful.

Igal

0 Kudos

Hai Igal Anav,

The program is not working perfectly. It is just running in that loop only.

Iam in confusion. If you have the solution please reply me the coding by using BAPI.

Thanks for your reply.

Thanks & Regards,

Prasad.T

0 Kudos

Hi Prasad,

I tried changing ur code in my system. But unfortunately we dont have S976 table;)

First mistake: Where r u refreshing ur BDC and messages internal tables? Refresh these tables just before first perform inside loop


  loop at it_s976.
    read table it_marc  with key werks = it_s976-werks
                                  matnr = it_s976-matnr.
    if sy-subrc = 0.
      if it_s976-reicz > 99.
        it_marc-shzet = 99.
      else.
        it_marc-shzet = it_s976-reicz .
      endif.

**-- Initial Screen
*REFRESH: it_bdcdata[], it_messtab[].*
      perform bdc_dynpro      using 'SAPLMGMM' '0060'.
      perform bdc_field       using 'BDC_CURSOR'
                                    'RMMG1-MATNR'.
      perform bdc_field       using 'BDC_OKCODE'
                                    '/00'.
      perform bdc_field       using 'RMMG1-MATNR'
                                    it_marc-MATNR.

Second mistake: Where r u processing error records?

After calling transaction check messages table. If u have any error then display those records in output/Create session for those.

It seems problem lies with ur recording also. If u carefully observe this piece of code


**-- Pop up materials view
      perform bdc_dynpro      using 'SAPLMGMM' '0070'.
      perform bdc_field       using 'BDC_CURSOR'
                                    'MSICHTAUSW-DYTXT(13)'.
      perform bdc_field       using 'BDC_OKCODE'
                                    '=ENTR'.
      perform bdc_field       using 'MSICHTAUSW-KZSEL(13)'
                                     'X'.

Here u r always selecting the view which lies in 13th position. Here is the problem. For one material u may have ur required view in 13th position and for other it may be in another position.

So ur BDC will fail.

What u have to do is do a fresh recording. Go to MM02 select Basic data view which will be there in first position for all the materials. press enter. Now from here select ur required view and fill in all the data. Now change ur code as per ur new BDC. Ideally it will work.

Thanks,

Vinod.