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: 

about bapi with help of example

Former Member
0 Kudos
208

about bapi with help of example plz dont give links.

5 REPLIES 5

Former Member
0 Kudos
99

Hi,

BAPI is RFC enables FM that can be accessed by

NON-SAP system. it is part of BOR(Business Object

Repository) . BAPI can be viewed using BAPI

transaction.

RFC FM should be released to be part of BOR.

Example

CALL FUNCTION 'ZBAPI_AR_ACC_GETKEYDATEBALANCE'

EXPORTING

COMPANYCODE = IT_GROUP-BUKRS

CUSTOMER = IT_GROUP-KUNNR

KEYDATE = P_BAL

BALANCESPGLI = GC_X

NOTEDITEMS = GC_X

TABLES

KEYBALANCE = IT_BALANCE

EXCEPTIONS

OTHERS = 1.

Regards

amole

anversha_s
Active Contributor
0 Kudos
99

hi,

bapi for mm01

REPORT Z_BAPI_MAT.

**********************************************************************

  • STRUCTURE DECLARATIONS *

**********************************************************************

TABLES: BAPIMATHEAD, "Headerdata

BAPI_MARA, "Clientdata

BAPI_MARAX, "Clientdatax

BAPI_MARC, "Plantdata

BAPI_MARCX, "Plantdatax

BAPI_MAKT, "Material description

BAPIRET2. "Return messages

DATA:V_FILE TYPE STRING.

DATA:

BEGIN OF LSMW_MATERIAL_MASTER,

MATNR(018) TYPE C, "Material number

MTART(004) TYPE C, "Material type

MBRSH(001) TYPE C, "Industry sector

WERKS(004) TYPE C, "Plant

MAKTX(040) TYPE C, "Material description

DISMM(002) TYPE C, "Extra Field Added In the Program as itsrequired

MEINS(003) TYPE C, "Base unit of measure

MATKL(009) TYPE C, "Material group

SPART(002) TYPE C, "Division

LABOR(003) TYPE C, "Lab/office

PRDHA(018) TYPE C, "Product hierarchy

MSTAE(002) TYPE C, "X-plant matl status

MTPOS_MARA(004) TYPE C, "Gen item cat group

BRGEW(017) TYPE C, "Gross weight

GEWEI(003) TYPE C, "Weight unit

NTGEW(017) TYPE C, "Net weight

GROES(032) TYPE C, "Size/Dimensions

MAGRV(004) TYPE C, "Matl grp pack matls

BISMT(018) TYPE C, "Old material number

WRKST(048) TYPE C, "Basic material

PROFL(003) TYPE C, "DG indicator profile

KZUMW(001) TYPE C, "Environmentally rlvt

BSTME(003) TYPE C, "Order unit

VABME(001) TYPE C,

EKGRP(003) TYPE C, "Purchasing group

XCHPF(001) TYPE C, "Batch management

EKWSL(004) TYPE C, "Purchasing key value

WEBAZ(003) TYPE C, "GR processing time

MFRPN(040) TYPE C, "Manufacturer part number

MFRNR(010) TYPE C, "Manufacturer number

VPRSV(001) TYPE C, "Price control indicator

STPRS(015) TYPE C, "Standard price

BWPRH(014) TYPE C, "Commercial price1

BKLAS(004) TYPE C, "Valuation class

END OF LSMW_MATERIAL_MASTER.

**********************************************************************

  • INTERNAL TABLE DECLARATIONS *

**********************************************************************

*to store the input data

DATA:

BEGIN OF it_matmaster OCCURS 0.

INCLUDE STRUCTURE LSMW_MATERIAL_MASTER.

DATA:

END OF it_matmaster.

*for material description

DATA:BEGIN OF IT_MATERIALDESC OCCURS 0.

INCLUDE STRUCTURE BAPI_MAKT .

DATA:END OF IT_MATERIALDESC.

*to return messages

DATA:BEGIN OF IT_RETURN OCCURS 0.

INCLUDE STRUCTURE BAPIRET2.

DATA:END OF IT_RETURN.

************************************************************************

  • SELECTION SCREEN

************************************************************************

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-002.

PARAMETERS:P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN END OF BLOCK B1 .

************************************************************************

  • AT SELECTION SCREEN

************************************************************************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = 'P_FILE'

IMPORTING

FILE_NAME = P_FILE.

**********************************************************************

  • TO UPLOAD THE DATA *

**********************************************************************

START-OF-SELECTION.

V_FILE = P_FILE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = V_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = IT_MATMASTER

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

**********************************************************************

  • DATA POPULATIONS *

**********************************************************************

LOOP AT IT_MATMASTER.

BAPIMATHEAD-MATERIAL = IT_MATMASTER-MATNR.

BAPIMATHEAD-IND_SECTOR = IT_MATMASTER-Mbrsh.

BAPIMATHEAD-MATL_TYPE = IT_MATMASTER-Mtart.

BAPIMATHEAD-BASIC_VIEW = 'X'.

BAPIMATHEAD-PURCHASE_VIEW = 'X'.

BAPIMATHEAD-ACCOUNT_VIEW = 'X'.

BAPI_MARA-MATL_GROUP = IT_MATMASTER-MATKL.

BAPI_MARA-OLD_MAT_NO = IT_MATMASTER-BISMT.

BAPI_MARA-BASE_UOM = IT_MATMASTER-MEINS.

BAPI_MARA-BASIC_MATL = IT_MATMASTER-WRKST.

BAPI_MARA-MFR_NO = IT_MATMASTER-MFRNR.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-OLD_MAT_NO = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

BAPI_MARAX-BASIC_MATL = 'X'.

BAPI_MARAX-MFR_NO = 'X'.

BAPI_MARC-PLANT = IT_MATMASTER-WERKS.

BAPI_MARC-PUR_GROUP = IT_MATMASTER-EKGRP.

BAPI_MARCX-PLANT = IT_MATMASTER-WERKS.

BAPI_MARCX-PUR_GROUP = 'X'.

IT_MATERIALDESC-LANGU = 'EN'.

IT_MATERIALDESC-MATL_DESC = IT_MATMASTER-MAKTX.

append IT_materialdesc.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'

EXPORTING

headdata = BAPIMATHEAD

CLIENTDATA = BAPI_MARA

CLIENTDATAX = BAPI_MARAx

PLANTDATA = BAPI_MARc

PLANTDATAX = BAPI_MARcx

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

  • VALUATIONDATA =

  • VALUATIONDATAX =

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA =

  • SALESDATAX =

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

  • FLAG_ONLINE = ' '

  • FLAG_CAD_CALL = ' '

IMPORTING

RETURN = IT_RETURN

TABLES

MATERIALDESCRIPTION = IT_MATERIALDESC

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

  • RETURNMESSAGES =

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

WRITE:/ IT_RETURN-TYPE,

2 IT_RETURN-ID,

22 IT_RETURN-NUMBER,

25 IT_RETURN-MESSAGE.

  • IT_RETURN-LOG_NO,

  • IT_RETURN-LOG_MSG_NO,

  • IT_RETURN-MESSAGE_V1,

  • IT_RETURN-MESSAGE_V2,

  • IT_RETURN-MESSAGE_V3,

  • IT_RETURN-MESSAGE_V4,

  • IT_RETURN-PARAMETER,

  • IT_RETURN-ROW,

  • IT_RETURN-FIELD,

  • IT_RETURN-SYSTEM.

ENDLOOP.

if hlped pls rwd points

anver

Former Member
0 Kudos
99

With the correct customizing (order types, etc...) the following BAPI will create a PM order for you.

Naturally the master data is also required to be created in SAP (Technical objects, Work places, etc...)



*&---------------------------------------------------------------------*
*& Report  Z_BAPI_ALM_ORDER_MAINTAIN_TEST                              *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  z_bapi_alm_order_maintain_test.

TABLES: mara,
        resb.                               "anyagfoglalások táblája

DATA: it_methods LIKE STANDARD TABLE OF bapi_alm_order_method,
      wa_methods LIKE LINE OF it_methods.

DATA: it_header LIKE STANDARD TABLE OF bapi_alm_order_headers_i,
      wa_header LIKE LINE OF it_header.

DATA: it_operation LIKE STANDARD TABLE OF bapi_alm_order_operation,
      wa_operation LIKE LINE OF it_operation.

DATA: it_component LIKE STANDARD TABLE OF bapi_alm_order_component,
      wa_component LIKE LINE OF it_component.

DATA: it_component_up LIKE
                      STANDARD TABLE OF bapi_alm_order_component_up,
      wa_component_up LIKE LINE OF it_component_up.

DATA: et_numbers LIKE STANDARD TABLE OF bapi_alm_numbers,
      wa_numbers LIKE LINE OF et_numbers.

DATA: et_extension_in LIKE STANDARD TABLE OF bapiparex,
      wa_extension_in LIKE LINE OF et_extension_in.

DATA: et_return LIKE STANDARD TABLE OF bapiret2,
      wa_return LIKE LINE OF et_return.

DATA: it_resb LIKE STANDARD TABLE OF resb,
      wa_resb LIKE LINE OF it_resb.

DATA: lv_commit TYPE i.

PARAMETERS: p_test AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_create RADIOBUTTON GROUP rg1 DEFAULT 'X'.
SELECTION-SCREEN COMMENT 4(30) text-rcr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: p_change RADIOBUTTON GROUP rg1.
SELECTION-SCREEN COMMENT 4(30) text-rch.
PARAMETERS: p_aufnr LIKE aufk-aufnr MEMORY ID anr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
PARAMETERS: p_compon AS CHECKBOX DEFAULT 'X'.
PARAMETERS: p_partn AS CHECKBOX DEFAULT 'X'.

START-OF-SELECTION.

  IF p_aufnr IS INITIAL.
    MOVE '007321002921' TO p_aufnr.
  ENDIF.

  PERFORM it_methods_fill.
  PERFORM it_header_fill.
  PERFORM it_operation_fill.
  IF p_compon = 'X'.
    PERFORM it_component_fill.
  ENDIF.

  REFRESH et_numbers.

  break zaladev.

  CALL FUNCTION 'Z_BAPI_ALM_ORDER_MAINTAIN'
    TABLES
      it_methods             = it_methods
      it_header              = it_header
*   IT_HEADER_UP           =
*   IT_HEADER_SRV          =
*   IT_HEADER_SRV_UP       =
*   IT_USERSTATUS          =
*   IT_PARTNER             =
*   IT_PARTNER_UP          =
      it_operation           = it_operation
*   IT_OPERATION_UP        =
*   IT_RELATION            =
*   IT_RELATION_UP         =
      it_component           = it_component
      it_component_up        = it_component_up
*   IT_TEXT                = it_text
*   IT_TEXT_LINES          =
      extension_in           = et_extension_in
      et_return              = et_return
      et_numbers             = et_numbers.

  CLEAR lv_commit.
  LOOP AT et_return INTO wa_return.
    IF wa_return-type = 'S' AND NOT wa_return-message_v2 IS INITIAL.
      IF p_test IS INITIAL.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
        lv_commit = 1.
      ENDIF.
      EXIT.
    ENDIF.
  ENDLOOP.

  IF lv_commit IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  ENDIF.

  break zaladev.


*&---------------------------------------------------------------------*
*&      Form  it_methods_fill
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM it_methods_fill.

  IF p_create = 'X'.                               "LÉTREHOZÁS

    MOVE '1' TO wa_methods-refnumber.
    MOVE 'HEADER' TO wa_methods-objecttype.
    MOVE 'CREATE' TO wa_methods-method.
    MOVE '%00000000001' TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

    MOVE '1' TO wa_methods-refnumber.
    MOVE 'OPERATION' TO wa_methods-objecttype.
    MOVE 'CREATE' TO wa_methods-method.
    MOVE '%000000000010010' TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

    MOVE '2' TO wa_methods-refnumber.
    MOVE 'OPERATION' TO wa_methods-objecttype.
    MOVE 'CREATE' TO wa_methods-method.
    MOVE '%000000000010020' TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

    MOVE '3' TO wa_methods-refnumber.
    MOVE 'OPERATION' TO wa_methods-objecttype.
    MOVE 'CREATE' TO wa_methods-method.
    MOVE '%0000000000100200010' TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

    MOVE '4' TO wa_methods-refnumber.
    MOVE 'OPERATION' TO wa_methods-objecttype.
    MOVE 'CREATE' TO wa_methods-method.
    MOVE '%0000000000100200020' TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

    IF p_compon = 'X'.

      MOVE 1 TO wa_methods-refnumber.
      MOVE 'COMPONENT' TO wa_methods-objecttype.
      MOVE 'CREATE' TO wa_methods-method.
      MOVE '%00000000001' TO wa_methods-objectkey.
      APPEND wa_methods TO it_methods.

      MOVE 2 TO wa_methods-refnumber.
      MOVE 'COMPONENT' TO wa_methods-objecttype.
      MOVE 'CREATE' TO wa_methods-method.
      MOVE '%00000000001' TO wa_methods-objectkey.
      APPEND wa_methods TO it_methods.

    ENDIF.

    MOVE '1' TO wa_methods-refnumber.
    MOVE '' TO wa_methods-objecttype.
    MOVE 'SAVE' TO wa_methods-method.
    MOVE '%00000000001' TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

  ELSE.                                            "MÓDOSÍTÁS

    MOVE '1' TO wa_methods-refnumber.
    MOVE 'HEADER' TO wa_methods-objecttype.
    MOVE 'CHANGE' TO wa_methods-method.
    MOVE p_aufnr TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

    IF p_compon = 'X'.

      MOVE 1 TO wa_methods-refnumber.
      MOVE 'COMPONENT' TO wa_methods-objecttype.
      MOVE 'CHANGE' TO wa_methods-method.
      MOVE p_aufnr TO wa_methods-objectkey.
      APPEND wa_methods TO it_methods.

      MOVE 2 TO wa_methods-refnumber.
      MOVE 'COMPONENT' TO wa_methods-objecttype.
      MOVE 'CHANGE' TO wa_methods-method.
      MOVE p_aufnr TO wa_methods-objectkey.
      APPEND wa_methods TO it_methods.

      MOVE 3 TO wa_methods-refnumber.
      MOVE 'COMPONENT' TO wa_methods-objecttype.
      MOVE 'DELETE' TO wa_methods-method.
      MOVE p_aufnr TO wa_methods-objectkey.
      APPEND wa_methods TO it_methods.

    ENDIF.

    MOVE '1' TO wa_methods-refnumber.
    MOVE '' TO wa_methods-objecttype.
    MOVE 'SAVE' TO wa_methods-method.
    MOVE p_aufnr TO wa_methods-objectkey.
    APPEND wa_methods TO it_methods.

  ENDIF.

ENDFORM.                    " it_methods_fill

*&---------------------------------------------------------------------*
*&      Form  it_header_fill
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM it_header_fill .

  IF p_create = 'X'.                               "LÉTREHOZÁS

    MOVE '%00000000001' TO wa_header-orderid.
    MOVE 'D210' TO wa_header-order_type.           "rendelésfajta
    MOVE '2000' TO wa_header-planplant.            "tervez&#337; gyár
    MOVE '19' TO wa_header-mn_wk_ctr.              "fel.munkahely
    MOVE '2000' TO wa_header-plant.                "fel.munkahely gyára
    MOVE 'CUV-SZV-CSUR-ATEM-I...' TO wa_header-funct_loc. "m&#369;sz.hely
    MOVE '' TO wa_header-equipment.                "berendezés
    MOVE '' TO wa_header-material.                 "anyagszám
*    MOVE '' TO wa_header-LOC_WK_CTR.               "fel.munkahely
*    MOVE '' TO wa_header-LOC_COMP_CODE.            "vállalat
*    MOVE sy-datum TO wa_header-START_DATE.         "kezdés dátuma
*    MOVE sy-datum TO wa_header-FINISH_DATE.        "befejezés dátuma
*    MOVE '' TO wa_header-BASICSTART.               "kezdés id&#337;pontja
*   MOVE '' TO wa_header-BASIC_FIN.                "befejezés id&#337;pontja
    MOVE 'Teszt szöveg 1' TO wa_header-short_text.  "szöveg
    APPEND wa_header TO it_header.

  ELSE.                                            "MÓDOSÍTÁS

    MOVE p_aufnr TO wa_header-orderid.
    MOVE 'CUV-SZV-CSUR-ATEM-II..' TO wa_header-funct_loc. "m&#369;sz.hely
    MOVE 'Teszt szöveg módosítva 2' TO wa_header-short_text.  "szöveg
    APPEND wa_header TO it_header.

  ENDIF.

ENDFORM.                    " it_header_fill

*&---------------------------------------------------------------------*
*&      Form  it_operation_fill
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM it_operation_fill .

  IF p_create = 'X'.                                "LÉTREHOZÁS

    MOVE 10 TO wa_operation-activity.             "m&#369;velet
    MOVE ''     TO wa_operation-sub_activity.         "al-m&#369;velet
    MOVE 'PM01'     TO wa_operation-control_key.         "vezérl&#337; kulcs
*    MOVE '19'   TO wa_operation-WORK_CNTR.            "munkahely
*    MOVE '2000' TO wa_operation-PLANT.                "gyár
    MOVE ''     TO wa_operation-standard_text_key.    "mintakulcs
    MOVE 'M&#369;velet leírása 1.sor' TO wa_operation-description."leírás
    MOVE ''     TO wa_operation-vendor_no.            "szállító
*    MOVE 3      TO wa_operation-quantity.             "mennyiség
*    MOVE 'KG'   TO wa_operation-base_uom.             "menny.egys.
*    MOVE 500    TO wa_operation-PRICE.                "ár
*    MOVE 1      TO wa_operation-PRICE_UNIT.           "áregység
*    MOVE 'HUF'  TO wa_operation-CURRENCY.             "pénznem
*    MOVE ''     TO wa_operation-PERS_NO.              "törzsszám
    MOVE 10      TO wa_operation-work_activity.        "m&#369;velet munkája
*    MOVE 'KG'   TO wa_operation-UN_WORK.              "m&#369;velet munkája
    MOVE 2      TO wa_operation-number_of_capacities.  "szüks. kapacitás
    APPEND wa_operation TO it_operation.

    MOVE 20 TO wa_operation-activity.             "m&#369;velet
    MOVE ''     TO wa_operation-sub_activity.         "al-m&#369;velet
    MOVE 'PM01'     TO wa_operation-control_key.         "vezérl&#337; kulcs
*    MOVE '19'   TO wa_operation-WORK_CNTR.            "munkahely
*    MOVE '2000' TO wa_operation-PLANT.                "gyár
    MOVE ''     TO wa_operation-standard_text_key.    "mintakulcs
    MOVE 'M&#369;velet leírása 2.sor' TO wa_operation-description."leírás
    MOVE ''     TO wa_operation-vendor_no.            "szállító
*    MOVE 5      TO wa_operation-quantity.             "mennyiség
*    MOVE 'KG'   TO wa_operation-base_uom.             "menny.egys.
*    MOVE 500    TO wa_operation-PRICE.                "ár
*    MOVE 1      TO wa_operation-PRICE_UNIT.           "áregység
*    MOVE 'HUF'  TO wa_operation-CURRENCY.             "pénznem
*    MOVE ''     TO wa_operation-PERS_NO.              "törzsszám
    MOVE 5      TO wa_operation-work_activity.        "m&#369;velet munkája
*    MOVE 'KG'   TO wa_operation-UN_WORK.              "m&#369;velet munkája
    MOVE 1      TO wa_operation-number_of_capacities.  "szüks. kapacitás
    APPEND wa_operation TO it_operation.

    MOVE 20 TO wa_operation-activity.             "m&#369;velet
    MOVE 10     TO wa_operation-sub_activity.         "al-m&#369;velet
    MOVE 'PM01'     TO wa_operation-control_key.         "vezérl&#337; kulcs
*    MOVE '19'   TO wa_operation-WORK_CNTR.            "munkahely
*    MOVE '2000' TO wa_operation-PLANT.                "gyár
    MOVE ''     TO wa_operation-standard_text_key.    "mintakulcs
    MOVE 'Alm&#369;velet leírása 2/1.sor' TO wa_operation-description."leírás
    MOVE ''     TO wa_operation-vendor_no.            "szállító
*    MOVE 5      TO wa_operation-quantity.             "mennyiség
    MOVE 'KG'   TO wa_operation-base_uom.             "menny.egys.
*    MOVE 500    TO wa_operation-PRICE.                "ár
*    MOVE 1      TO wa_operation-PRICE_UNIT.           "áregység
*    MOVE 'HUF'  TO wa_operation-CURRENCY.             "pénznem
*    MOVE ''     TO wa_operation-PERS_NO.              "törzsszám
    MOVE 2      TO wa_operation-work_activity.        "m&#369;velet munkája
*    MOVE 'KG'   TO wa_operation-UN_WORK.              "m&#369;velet munkája
    MOVE 1      TO wa_operation-number_of_capacities.  "szüks. kapacitás
    APPEND wa_operation TO it_operation.

    MOVE 20 TO wa_operation-activity.             "m&#369;velet
    MOVE 20     TO wa_operation-sub_activity.         "al-m&#369;velet
    MOVE 'PM01'     TO wa_operation-control_key.         "vezérl&#337; kulcs
*    MOVE '19'   TO wa_operation-WORK_CNTR.            "munkahely
*    MOVE '2000' TO wa_operation-PLANT.                "gyár
    MOVE '11'     TO wa_operation-standard_text_key.    "mintakulcs
    MOVE 'Alm&#369;velet leírása 2/2.sor' TO wa_operation-description."leírás
    MOVE ''     TO wa_operation-vendor_no.            "szállító
    MOVE 5      TO wa_operation-quantity.             "mennyiség
    MOVE 'KG'   TO wa_operation-base_uom.             "menny.egys.
*    MOVE 500    TO wa_operation-PRICE.                "ár
*    MOVE 1      TO wa_operation-PRICE_UNIT.           "áregység
*    MOVE 'HUF'  TO wa_operation-CURRENCY.             "pénznem
*    MOVE ''     TO wa_operation-PERS_NO.              "törzsszám
    MOVE 3      TO wa_operation-work_activity.        "m&#369;velet munkája
*    MOVE 'KG'   TO wa_operation-UN_WORK.              "m&#369;velet munkája
    MOVE 1      TO wa_operation-number_of_capacities.  "szüks. kapacitás
    APPEND wa_operation TO it_operation.

  ELSE.                                            "MÓDOSÍTÁS

  ENDIF.

ENDFORM.                    " it_operation_fill

*&---------------------------------------------------------------------*
*&      Form  it_component_fill
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM it_component_fill.

  IF p_create = 'X'.                                   "LÉTREHOZÁS

    MOVE '0010'            TO wa_component-item_number.
    MOVE '000000023336110300' TO wa_component-material.   "cikkszám
    MOVE '2000'        TO wa_component-plant.      "gyár
    MOVE '0001'        TO wa_component-stge_loc.   "raktár
    MOVE 1             TO wa_component-requirement_quantity. "felh.m.
    MOVE '0020'        TO wa_component-activity.   "m&#369;velet
    APPEND wa_component TO it_component.

    MOVE '0020'         TO wa_component-item_number.
    MOVE '000000095000001900' TO wa_component-material.   "cikkszám
    MOVE '2000'         TO wa_component-plant.      "gyár
    MOVE ''             TO wa_component-stge_loc.   "raktár
    MOVE 2              TO wa_component-requirement_quantity. "felh.m.
    MOVE '0020'         TO wa_component-activity.   "m&#369;velet
    MOVE 'N'            TO wa_component-item_cat.   "tételtípus
    MOVE '0000000014'   TO wa_component-vendor_no.   "szállító
    APPEND wa_component TO it_component.

  ELSE.                                                "MÓDOSÍTÁS

    SELECT * FROM resb
      INTO TABLE it_resb
      WHERE aufnr EQ p_aufnr.
    IF sy-subrc = 0.
      READ TABLE it_resb INTO wa_resb
        WITH KEY aufnr = p_aufnr.
      MOVE wa_resb-rsnum TO wa_component-reserv_no.
    ELSE.
      CLEAR wa_component-reserv_no.
    ENDIF.

    MOVE '0010'            TO wa_component-item_number.
    MOVE '0001'        TO wa_component-res_item.
*    MOVE '000000023336110400' TO wa_component-material.   "cikkszám
*    MOVE '2000'        TO wa_component-plant.      "gyár
*    MOVE '0001'        TO wa_component-stge_loc.   "raktár
    MOVE 6             TO wa_component-requirement_quantity. "felh.m.
    MOVE '0020'        TO wa_component-activity.   "m&#369;velet
    APPEND wa_component TO it_component.

    MOVE 'X' TO wa_component_up-requirement_quantity.
    MOVE 'X' TO wa_component_up-activity.
    APPEND wa_component_up TO it_component_up.

    MOVE '0020'            TO wa_component-item_number.
    MOVE '0002'        TO wa_component-res_item.
*    MOVE '000000095000001800' TO wa_component-material.   "cikkszám
*    MOVE '2000'        TO wa_component-plant.      "gyár
*    MOVE '0001'        TO wa_component-stge_loc.   "raktár
    MOVE 6             TO wa_component-requirement_quantity. "felh.m.
    MOVE '0010'        TO wa_component-activity.   "m&#369;velet
    APPEND wa_component TO it_component.

*    MOVE 'X' TO wa_component_up-material.
    MOVE 'X' TO wa_component_up-requirement_quantity.
    MOVE 'X' TO wa_component_up-activity.
    APPEND wa_component_up TO it_component_up.


    MOVE '0030'            TO wa_component-item_number.
    MOVE '000000023336110400' TO wa_component-material.   "cikkszám
    MOVE '2000'        TO wa_component-plant.      "gyár
    MOVE '0001'        TO wa_component-stge_loc.   "raktár
    MOVE 7             TO wa_component-requirement_quantity. "felh.m.
    MOVE '0020'        TO wa_component-activity.   "m&#369;velet
    APPEND wa_component TO it_component.

  ENDIF.

ENDFORM.                    " it_component_fill

Former Member
0 Kudos
99

hi,

u can check this example also

BAPI_GOODSMVT_CREATE to post Goods Movement

The following is an abap program making used of the BAPI function BAPI_GOODSMVT_CREATE to do Goods Receipts for Purchase Order after importing the data from an external system.

*

  • BAPI TO Upload Inventory Data

*

  • GMCODE Table T158G - 01 - MB01 - Goods Receipts for Purchase Order

  • 02 - MB31 - Goods Receipts for Prod Order

  • 03 - MB1A - Goods Issue

  • 04 - MB1B - Transfer Posting

  • 05 - MB1C - Enter Other Goods Receipt

  • 06 - MB11

*

  • Domain: KZBEW - Movement Indicator

  • Goods movement w/o reference

  • B - Goods movement for purchase order

  • F - Goods movement for production order

  • L - Goods movement for delivery note

  • K - Goods movement for kanban requirement (WM - internal only)

  • O - Subsequent adjustment of "material-provided" consumption

  • W - Subsequent adjustment of proportion/product unit material

*

report zbapi_goodsmovement.

parameters: p-file like rlgrap-filename default

'c:\sapdata\TEST.txt'.

parameters: e-file like rlgrap-filename default

'c:\sapdata\gdsmvterror.txt'.

parameters: xpost like sy-datum default sy-datum.

data: begin of gmhead.

include structure bapi2017_gm_head_01.

data: end of gmhead.

data: begin of gmcode.

include structure bapi2017_gm_code.

data: end of gmcode.

data: begin of mthead.

include structure bapi2017_gm_head_ret.

data: end of mthead.

data: begin of itab occurs 100.

include structure bapi2017_gm_item_create.

data: end of itab.

data: begin of errmsg occurs 10.

include structure bapiret2.

data: end of errmsg.

data: wmenge like iseg-menge,

errflag.

data: begin of pcitab occurs 100,

ext_doc(10), "External Document Number

mvt_type(3), "Movement Type

doc_date(8), "Document Date

post_date(8), "Posting Date

plant(4), "Plant

material(18), "Material Number

qty(13), "Quantity

recv_loc(4), "Receiving Location

issue_loc(4), "Issuing Location

pur_doc(10), "Purchase Document No

po_item(3), "Purchase Document Item No

del_no(10), "Delivery Purchase Order Number

del_item(3), "Delivery Item

prod_doc(10), "Production Document No

scrap_reason(10), "Scrap Reason

upd_sta(1), "Update Status

end of pcitab.

call function 'WS_UPLOAD'

exporting

filename = p-file

filetype = 'DAT'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = pcitab

  • EXCEPTIONS

  • FILE_OPEN_ERROR = 1

  • FILE_READ_ERROR = 2

  • NO_BATCH = 3

  • GUI_REFUSE_FILETRANSFER = 4

  • INVALID_TYPE = 5

  • OTHERS = 6

.

if sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

exit.

endif.

gmhead-pstng_date = sy-datum.

gmhead-doc_date = sy-datum.

gmhead-pr_uname = sy-uname.

gmcode-gm_code = '01'. "01 - MB01 - Goods Receipts for Purchase Order

loop at pcitab.

itab-move_type = pcitab-mvt_type.

itab-mvt_ind = 'B'.

itab-plant = pcitab-plant.

itab-material = pcitab-material.

itab-entry_qnt = pcitab-qty.

itab-move_stloc = pcitab-recv_loc.

itab-stge_loc = pcitab-issue_loc.

itab-po_number = pcitab-pur_doc.

itab-po_item = pcitab-po_item.

concatenate pcitab-del_no pcitab-del_item into itab-item_text.

itab-move_reas = pcitab-scrap_reason.

append itab.

endloop.

loop at itab.

write:/ itab-material, itab-plant, itab-stge_loc,

itab-move_type, itab-entry_qnt, itab-entry_uom,

itab-entry_uom_iso, itab-po_number, itab-po_item,

pcitab-ext_doc.

endloop.

call function 'BAPI_GOODSMVT_CREATE'

exporting

goodsmvt_header = gmhead

goodsmvt_code = gmcode

  • TESTRUN = ' '

  • IMPORTING

goodsmvt_headret = mthead

  • MATERIALDOCUMENT =

  • MATDOCUMENTYEAR =

tables

goodsmvt_item = itab

  • GOODSMVT_SERIALNUMBER =

return = errmsg

.

clear errflag.

loop at errmsg.

if errmsg-type eq 'E'.

write:/'Error in function', errmsg-message.

errflag = 'X'.

else.

write:/ errmsg-message.

endif.

endloop.

if errflag is initial.

commit work and wait.

if sy-subrc ne 0.

write:/ 'Error in updating'.

exit.

else.

write:/ mthead-mat_doc, mthead-doc_year.

perform upd_sta.

endif.

endif.

----


  • FORM UPD_STA *

----


  • ........ *

----


form upd_sta.

loop at pcitab.

pcitab-upd_sta = 'X'.

modify pcitab.

endloop.

call function 'WS_DOWNLOAD'

exporting

filename = p-file

filetype = 'DAT'

  • IMPORTING

  • FILELENGTH =

tables

data_tab = pcitab

  • EXCEPTIONS

  • FILE_OPEN_ERROR = 1

  • FILE_READ_ERROR = 2

  • NO_BATCH = 3

  • GUI_REFUSE_FILETRANSFER = 4

  • INVALID_TYPE = 5

  • OTHERS = 6

.

endform.

*--- End of Program

Regards,

Naveen

Former Member
0 Kudos
99

one more example phani,

BAPI to Copy Materials from one Plant to Another

*

  • Copy Materials from one Plant to Another

  • First run GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

  • Second run UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

  • Check data in Excel before Second run

REPORT ZBAPIMM01 LINE-SIZE 255 NO STANDARD PAGE HEADING

LINE-COUNT 065(001).

TABLES: T001L, "Storage Locations

MARA, "General Material Data

MAKT, "Material Descriptions

MBEW, "Material Valuation

MARC. "Plant Data for Material

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_MBEW1 LIKE BAPI_MBEW, "Accounting View

BAPI_MBEWX LIKE BAPI_MBEWX,

BAPI_RETURN LIKE BAPIRET2.

DATA: BEGIN OF INT_MAKT OCCURS 100.

INCLUDE STRUCTURE BAPI_MAKT.

DATA: END OF INT_MAKT.

DATA: BEGIN OF INT_MAT OCCURS 100,

WERKS(4), "Plant

MTART(4), "Material type

MATNR(18), "Material number

MATKL(9) , "Material group

MBRSH(1), "Industry sector

MEINS(3), "Base unit of measure

GEWEI(3), "Weight Unit

SPART(2), "Division

EKGRP(3), "Purchasing group

VPRSV(1), "Price control indicator

STPRS(12), "Standard price

PEINH(3), "Price unit

SPRAS(2), "Language key

MAKTX(40), "Material description

END OF INT_MAT.

SELECT-OPTIONS:

PLANT FOR MARC-WERKS OBLIGATORY MEMORY ID PLT,

MATERIAL FOR MARA-MATNR MEMORY ID MAT,

MATLTYPE FOR MARA-MTART MEMORY ID MTY,

DIVISION FOR MARA-SPART MEMORY ID DIV.

PARAMETERS: F_FILE LIKE RLGRAP-FILENAME

DEFAULT 'C:\DATA\ZMATERIAL.XLS' MEMORY ID F_FILE,

GETDATA AS CHECKBOX, "Tick to download materials data to local harddisk

UPDDATA AS CHECKBOX. "Tick to update date to Materials Master

IF GETDATA = 'X'.

PERFORM DOWNLOAD_DATA.

PERFORM DOWNLOAD_FILE.

ENDIF.

IF UPDDATA = 'X'.

PERFORM UPLOAD_FILE.

PERFORM UPDATE_MM.

ENDIF.

FORM DOWNLOAD_DATA.

SELECT * FROM MARC WHERE LVORM EQ ' '

AND WERKS IN PLANT

AND MATNR IN MATERIAL.

CLEAR MARA.

SELECT SINGLE * FROM MARA WHERE MATNR = MARC-MATNR.

CHECK MATLTYPE.

CHECK DIVISION.

CLEAR MBEW.

SELECT SINGLE * FROM MBEW WHERE MATNR = MARC-MATNR

AND BWKEY = MARC-WERKS.

CLEAR MAKT.

SELECT SINGLE * FROM MAKT WHERE SPRAS = 'EN'

AND MATNR = MARC-MATNR.

WRITE:/ MARC-WERKS, "Plant

MARA-MTART, "Material type

MARA-MATNR, "Material number

MARA-MATKL, "Material group

MARA-MBRSH, "Industry sector

MARA-MEINS, "Base unit of measure

MARA-GEWEI, "Weight Unit

MARA-SPART, "Division

MARC-EKGRP, "Purchasing group

MBEW-VPRSV, "Price control indicator

MBEW-STPRS, "Standard price

MBEW-PEINH, "Price unit

MAKT-SPRAS, "Language key

MAKT-MAKTX. "Material description

INT_MAT-WERKS = MARC-WERKS. "Plant

INT_MAT-MTART = MARA-MTART. "Material type

INT_MAT-MATNR = MARA-MATNR. "Material number

INT_MAT-MATKL = MARA-MATKL. "Material group

INT_MAT-MBRSH = MARA-MBRSH. "Industry sector

INT_MAT-MEINS = MARA-MEINS. "Base unit of measure

INT_MAT-GEWEI = MARA-GEWEI. "Weight Unit

INT_MAT-SPART = MARA-SPART. "Division

INT_MAT-EKGRP = MARC-EKGRP. "Purchasing group

INT_MAT-VPRSV = MBEW-VPRSV. "Price control indicator

INT_MAT-STPRS = MBEW-STPRS. "Standard price

INT_MAT-PEINH = MBEW-PEINH. "Price unit

INT_MAT-SPRAS = MAKT-SPRAS. "Language key

INT_MAT-MAKTX = MAKT-MAKTX. "Material description

APPEND INT_MAT.

CLEAR INT_MAT.

ENDSELECT.

ENDFORM.

FORM DOWNLOAD_FILE.

call function 'WS_DOWNLOAD'

EXPORTING

FILENAME = F_FILE

FILETYPE = 'DAT'

  • FILETYPE = 'WK1'

tables

data_tab = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Download Successfully to your local harddisk'.

SKIP.

ENDIF.

ENDFORM.

FORM UPLOAD_FILE.

call function 'WS_UPLOAD'

EXPORTING

FILENAME = F_FILE

FILETYPE = 'DAT'

  • FILETYPE = 'WK1'

tables

data_tab = INT_MAT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_WRITE_ERROR = 2

INVALID_FILESIZE = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10.

IF SY-SUBRC = 0.

FORMAT COLOR COL_GROUP.

WRITE:/ 'Data Upload Successfully from your local harddisk'.

SKIP.

ENDIF.

ENDFORM.

FORM UPDATE_MM.

LOOP AT INT_MAT.

  • Header

BAPI_HEAD-MATERIAL = INT_MAT-MATNR.

BAPI_HEAD-IND_SECTOR = INT_MAT-MBRSH.

BAPI_HEAD-MATL_TYPE = INT_MAT-MTART.

BAPI_HEAD-BASIC_VIEW = 'X'.

BAPI_HEAD-PURCHASE_VIEW = 'X'.

BAPI_HEAD-ACCOUNT_VIEW = 'X'.

  • Material Description

REFRESH INT_MAKT.

INT_MAKT-LANGU = INT_MAT-SPRAS.

INT_MAKT-MATL_DESC = INT_MAT-MAKTX.

APPEND INT_MAKT.

  • Client Data - Basic

BAPI_MARA1-MATL_GROUP = INT_MAT-MATKL.

BAPI_MARA1-BASE_UOM = INT_MAT-MEINS.

BAPI_MARA1-UNIT_OF_WT = INT_MAT-GEWEI.

BAPI_MARA1-DIVISION = INT_MAT-SPART.

BAPI_MARAX-MATL_GROUP = 'X'.

BAPI_MARAX-BASE_UOM = 'X'.

BAPI_MARAX-UNIT_OF_WT = 'X'.

BAPI_MARAX-DIVISION = 'X'.

  • Plant - Purchasing

BAPI_MARC1-PLANT = INT_MAT-WERKS.

BAPI_MARC1-PUR_GROUP = INT_MAT-EKGRP.

BAPI_MARCX-PLANT = INT_MAT-WERKS.

BAPI_MARCX-PUR_GROUP = 'X'.

  • Accounting

BAPI_MBEW1-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEW1-PRICE_CTRL = INT_MAT-VPRSV.

BAPI_MBEW1-STD_PRICE = INT_MAT-STPRS.

BAPI_MBEW1-PRICE_UNIT = INT_MAT-PEINH.

BAPI_MBEWX-VAL_AREA = INT_MAT-WERKS.

BAPI_MBEWX-PRICE_CTRL = 'X'.

BAPI_MBEWX-STD_PRICE = 'X'.

BAPI_MBEWX-PRICE_UNIT = 'X'.

WRITE:/ BAPI_HEAD, BAPI_MARC1.

call function 'BAPI_MATERIAL_SAVEDATA'

exporting

HEADDATA = BAPI_HEAD

CLIENTDATA = BAPI_MARA1

CLIENTDATAX = BAPI_MARAX

PLANTDATA = BAPI_MARC1

PLANTDATAX = BAPI_MARCX

  • FORECASTPARAMETERS =

  • FORECASTPARAMETERSX =

  • PLANNINGDATA =

  • PLANNINGDATAX =

  • STORAGELOCATIONDATA =

  • STORAGELOCATIONDATAX =

VALUATIONDATA = BAPI_MBEW1

VALUATIONDATAX = BAPI_MBEWX

  • WAREHOUSENUMBERDATA =

  • WAREHOUSENUMBERDATAX =

  • SALESDATA = BAPI_MVKE1

  • SALESDATAX = BAPI_MVKEX

  • STORAGETYPEDATA =

  • STORAGETYPEDATAX =

IMPORTING

RETURN = BAPI_RETURN

TABLES

MATERIALDESCRIPTION = INT_MAKT

  • UNITSOFMEASURE =

  • UNITSOFMEASUREX =

  • INTERNATIONALARTNOS =

  • MATERIALLONGTEXT =

  • TAXCLASSIFICATIONS =

  • RETURNMESSAGES =

  • PRTDATA =

  • PRTDATAX =

  • EXTENSIONIN =

  • EXTENSIONINX =

.

IF BAPI_RETURN-TYPE = 'E'.

WRITE:/ 'Error Message ', BAPI_RETURN.

ENDIF.

ENDLOOP.

ENDFORM.

*---End of Program

Regards,

Naveen