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

Material BOM Distribution (Modified by GSC-DD Team)



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



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Fri Apr 11, 2008 11:43 pm    Post subject: Material BOM Distribution (Modified by GSC-DD Team) Reply with quote

Code:
*&---------------------------------------------------------------------*
*& Report  ZRBDSEBOM                                                   *
*&                                                                     *
*&---------------------------------------------------------------------*
*& distribution of material bom                                        *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZRBDSEBOM NO STANDARD PAGE HEADING LINE-SIZE 132.

********************************************************************
* This program is a front-end to RBDSEBOM which provides the following
* functionality:
* (1) Reduces number of input parameters to four
* (2) Requires entries for plant, BOM usage, and logical system name
* (3) A check is made for each material to see if it already exists on
*     the target system.  If so, then no BOMs are transferred.
*
* Written by Rohit Gupta on January 8th, 2001
********************************************************************

********************************************************************
* Change History:
*
*{   INSERT         S13K900053                                        1
* 020702 add RFC call to obtain receiving system permission
*}   INSERT
********************************************************************

********************************************************************
* Future Enhancements:
* -> Use text-symbols instead of hard-coded text
********************************************************************

* Tables

TABLES: MARA, MAST, T001W.


* Constants

* Message indicating material does not exist
constants: MATERIAL_DOES_NOT_EXIST type i value '305'.

* Maximum number of materials that can be sent at once
CONSTANTS: MAX_BOMS type i value 10.


* Data declarations

* Internal table for specified materials
DATA: begin of i_materials occurs 5,
        matnr like mara-matnr,
      end of i_materials.

* Variables for BAPI to check if material exists
DATA: deletion_flag like BAPIMATALL-DEL_FLAG,
      bapi_return1   like bapireturn1.
DATA: bapi_return2 like bapiret2 occurs 1 with header line.

* Flag to indicate if any material already exists on target system
DATA: material_does_not_exist_flag type i value 0.

* Flag to indicate if any BOM already exists on target system
DATA: bom_exists_flag type i value 0.

* Number of lines in internal table
DATA: number_of_lines type i.

* Number of lines returned from database
DATA: count type i.
*{   INSERT         S13K900053                                        2
data gv_rfc_target_permit type char3. " 7/1/2 result of permission check
*}   INSERT


* Input parameters

SELECT-OPTIONS: sel_mat for mast-matnr obligatory matchcode object mat1,
                sel_wrk for mast-werks no-display,
                sel_anw for mast-stlan no-display.

PARAMETERS:     p_wrk like mast-werks obligatory,
                p_anw like mast-stlan obligatory,
                p_logsys like tbdlst-logsys obligatory.


********************************************************************
* For now we'll first screen all BOMs and exit if any of them
* already exist in the target system.  Eventually can modify so
* that it only creates those that do not exist, and outputs an error
* message for those that do exist.
********************************************************************

START-OF-SELECTION.
*{   INSERT         S13K900053                                        1
* 020702 receiving system permission check

  CALL FUNCTION 'ZMD_XFR_CHECK' destination p_logsys
   IMPORTING
     EV_PERMISSION       = gv_rfc_target_permit
   EXCEPTIONS
     OTHERS              = 1.

  if sy-subrc ne 0.
    write: / 'Unable to get permission from target system.'.
*           / 'Possible RFC connection problem, or the required',
*             'function module ZMD_XFR_CHECK',
*           / 'has not been installed on the target system'.
    exit.
  elseif gv_rfc_target_permit ne 'YES'.
    Write: 'Sending permission denied by target system'.
    exit.
  endif.


*}   INSERT

* First verify at least one of the specified BOMs exist
select count( * ) into count
                    from mast where matnr in sel_mat and
                                    werks = p_wrk and
                                    stlan = p_anw.
if count eq 0.
  write text-001.
  exit.
elseif count gt MAX_BOMS.
  write: 'Number of specified BOMs exceeds limit of', MAX_BOMS.
  exit.
endif.

select matnr from mara into table i_materials where matnr in sel_mat.

if sy-subrc ne 0.
  write: 'No valid materials specified'.
  exit.
else.
  loop at i_materials.

* Check to see if material exists
    CALL FUNCTION 'BAPI_MATERIAL_EXISTENCECHECK'
      DESTINATION p_logsys
      EXPORTING
        MATERIAL            = i_materials-matnr
      IMPORTING
        DELETION_FLAG       = deletion_flag
        RETURN              = bapi_return1.

* Output appropriate message
    if bapi_return1-number eq MATERIAL_DOES_NOT_EXIST.
      write: / 'Material', i_materials-matnr, 'does not exist',
             'in target system'.
      material_does_not_exist_flag = 1.
    else.
      write bapi_return1-message.
    endif.

* Check to see if BOM exists
    CALL FUNCTION 'BAPI_MAT_BOM_EXISTENCE_CHECK'
      DESTINATION p_logsys
      EXPORTING
        MATERIAL              = i_materials-matnr
        PLANT                 = p_wrk
        BOMUSAGE              = p_anw
*       VALID_FROM_DATE       =
*       VALID_TO_DATE         =
      TABLES
        RETURN                = bapi_return2.
          .
* Output appropriate message
    describe table bapi_return2 lines number_of_lines.
    if number_of_lines eq 0.
      write: / 'BOM', i_materials-matnr, '/', p_wrk, '/',
             p_anw, 'already exists in target system'.
      bom_exists_flag = 1.
    endif.

  endloop.

* Exit processing if any material already exists on back-end system
  if material_does_not_exist_flag eq 1.
    write: /.
    write: / 'Cannot continue processing because at least one',
           'of the materials does not exist on target system'.
    exit.
  endif.

* Exit processing if any BOM already exists on back-end system
  if bom_exists_flag eq 1.
    write: /.
    write: / 'Cannot continue processing because at least one',
           'of the BOMs already exists on target system'.
    exit.
  endif.
endif.


********************************************************************
* Now call RBDSEBOM (transaction BD30) program with parameters.
********************************************************************

* Set value for plant
move:  'I' to sel_wrk-sign,
       'EQ' to sel_wrk-option,
       p_wrk to sel_wrk-low.
append sel_wrk.

* Set value for BOM usage
move:  'I' to sel_anw-sign,
       'EQ' to sel_anw-option,
       p_anw to sel_anw-low.
append sel_anw.

submit RBDSEBOM
       with sel_mat in sel_mat
       with sel_wrk in sel_wrk
       with sel_anw in sel_anw
       with p_logsys = p_logsys.


*Selection texts
*----------------------------------------------------------
* P_ANW         BOM usage
* P_LOGSYS         Logical system
* P_WRK         Plant
* SEL_MAT         Material


Code:

FUNCTION ZMD_XFR_CHECK.
*"----------------------------------------------------------------------
*"*"Local interface:
*"  EXPORTING
*"     VALUE(EV_PERMISSION) TYPE  CHAR3
*"----------------------------------------------------------------------

* c campbell cleveland basis 7/1/02

* Each master data transfer program must call this FM at the target RFC
* before sending data. If the call fails or returns NO, no data is to be
* sent to that target RFC.

* This FUGR object should only be transported from S1O (APO) or S13 (R3)
* where it will always be coded as NO. It should be repaired at the
* target system to accept inbound data (return LC_YES below).

* This receiving-side security will safeguard against such possibilities
* as incorrect RFC destination tables on the sending system. The FM
* technique was deemed more difficult for a casual user to circumvent
* than a "softer" control such as a table-based parameter.

constants: lc_yes type char3 value 'YES',
           lc_no  type char3 value 'NO'.

ev_permission = lc_no. " <== repair this to YES to grant permission...

ENDFUNCTION.
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 -> PP 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.