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

BAPI

Former Member
0 Likes
1,251

hi,

Iam working on BAPI. i dont know how to use that. can any body send any sample reports or sample programs on BAPI.

chandu

10 REPLIES 10
Read only

Former Member
0 Likes
1,121

Hai Chandra Babu

Go through the following Document for BAPI

Bapi to create customer master

-


BAPI_CUSTOMER_CREATEFROMDATA

BAPI_CUSTOMER_CREATEFROMDATA1

Or you can use FM SD_CUSTOMER_MAINTAIN_ALL

what is BAPI?

BAPI stands for Business API(Application Program Interface).

I have answered this question before..

A BAPI is remotely enabled function module ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..

You can make your function module remotely enabled in attributes of Function module but

A BAPI are standard SAP function modules provided by SAP for remote access. Also they are part of Businees Objest Repository(BOR).

BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA. in this case u only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.

The following standardized BAPIs are provided:

Reading instances of SAP business objects

GetList ( ) With the BAPI GetList you can select a range of object key values, for example, company codes and material numbers.

The BAPI GetList() is a class method.

GetDetail() With the BAPI GetDetail() the details of an instance of a business object type are retrieved and returned to the calling program. The instance is identified via its key. The BAPI GetDetail() is an instance method. BAPIs that can create, change or delete instances of a business object type

The following BAPIs of the same object type have to be programmed so that they can be called several times within one transaction. For example, if, after sales order 1 has been created, a second sales order 2 is created in the same transaction, the second BAPI call must not affect the consistency of the sales order 2. After completing the transaction with a COMMIT WORK, both the orders are saved consistently in the database.

Create( ) and CreateFromData! ( )

The BAPIs Create() and CreateFromData() create an instance of an SAP business object type, for example, a purchase order. These BAPIs are class methods.

Change( )

The BAPI Change() changes an existing instance of an SAP business object type, for example, a purchase order. The BAPI Change () is an instance method.

Delete( ) and Undelete( ) The BAPI Delete() deletes an instance of an SAP business object type from the database or sets a deletion flag.

The BAPI Undelete() removes a deletion flag. These BAPIs are instance methods.

Cancel ( ) Unlike the BAPI Delete(), the BAPI Cancel() cancels an instance of a business object type. The instance to be cancelled remains in the database and an additional instance is created and this is the one that is actually canceled. The Cancel() BAPI is an instance method.

Add<subobject> ( ) and Remove<subobject> ( ) The BAPI Add<subobject> adds a subobject to an existing object inst! ance and the BAPI and Remove<subobject> removes a subobject from an object instance. These BAPIs are instance methods.

Check these Links out

http://searchsap.techtarget.com/ateQuestionNResponse/0,289625,sid21_cid558752_tax293481,00.html

http://www.sap-img.com/abap/interview-question-on-bapi-rfc-abap-objects-tables.htm

http://www.sap-img.com/fu033.htm

http://www.sap-img.com/abap/ale-bapi.htm

Please check out this thread..

Also refer to the following links..

www.sappoint.com/abap/bapiintro.pdf

www.sap-img.com/bapi.htm

www.sap-img.com/abap/bapi-conventions.htm

www.planetsap.com/Bapi_main_page.htm

www.sapgenie.com/abap/bapi/index.htm

Checkout !!

http://searchsap.techtarget.com/originalContent/0,289142,sid21_gci948835,00.html

http://techrepublic.com.com/5100-6329-1051160.html#

http://www.sap-img.com/bapi.htm

http://www.sap-img.com/abap/bapi-conventions.htm

http://www.sappoint.com/abap/bapiintro.pdf

Java Connector(JCO) can call not only BAPI's but also the function modules which are remotely enabled..

BAPI's as i said earlier are remotely enabled function modules..

Hence, JCO can call also BAPI's(n not only BAPI's as u mentioned).

Check the following Example Code

U need to give the step_nr, item_nr, cond_count and cond_type so the correct conditon will be updated. If no condition exists for the given parameters, a new condition will be created.

U can find these parameters for a particular condition type in table KONV.

&----


*& Form saveTransactionJOCR

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM saveTransactionJOCR .

data: salesdocument like BAPIVBELN-VBELN,

order_header_inx like bapisdh1x,

order_header_in like bapisdh1,

return type standard table of bapiret2 with header line,

conditions_in type standard table of bapicond with header line,

conditions_inx type standard table of bapicondx with header line,

logic_switch like BAPISDLS,

step_nr like conditions_in-cond_st_no,

item_nr like conditions_in-itm_number,

cond_count like conditions_in-cond_count,

cond_type like conditions_in-cond_type.

salesdocument = wa_order_information-VBELN.

LOGIC_SWITCH-COND_HANDL = 'X'.

order_header_inx-updateflag = 'U'.

  • conditions

clear conditions_in[].

clear conditions_inx[].

clear: step_nr,

item_nr,

cond_count,

cond_type.

step_nr = '710'.

item_nr = '000000'.

cond_count = '01'.

cond_type = 'ZCP2'.

CONDITIONS_IN-ITM_NUMBER = item_nr.

conditions_in-cond_st_no = step_nr.

CONDITIONS_IN-COND_COUNT = cond_count.

CONDITIONS_IN-COND_TYPE = cond_type.

CONDITIONS_IN-COND_VALUE = 666.

CONDITIONS_IN-CURRENCY = 'EUR'.

append conditions_in.

CONDITIONS_INX-ITM_NUMBER = item_nr.

conditions_inx-cond_st_no = step_nr.

CONDITIONS_INX-COND_COUNT = cond_count.

CONDITIONS_INX-COND_TYPE = cond_type.

CONDITIONS_INX-UPDATEFLAG = 'U'.

CONDITIONS_INX-COND_VALUE = 'X'.

CONDITIONS_INX-CURRENCY = 'X'.

append conditions_inx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

EXPORTING

SALESDOCUMENT = salesdocument

ORDER_HEADER_IN = order_header_in

ORDER_HEADER_INX = order_header_inx

LOGIC_SWITCH = logic_switch

TABLES

RETURN = return

CONDITIONS_IN = conditions_in

CONDITIONS_INX = conditions_inx

.

if return-type ne 'E'.

commit work and wait.

endif.

ENDFORM. " saveTransactionJOCR

Thanks & regards

Sreenivasulu P

Read only

Former Member
0 Likes
1,121
Read only

Former Member
0 Likes
1,121

Take a look here

http://www.sap-img.com/abap/bapi-goodsmvt-create-to-post-goods-movement.htm

Regards,

Ravi

Note : Please close the thread if the question is answered

Read only

Former Member
0 Likes
1,121

Hi,

Check the code...

REPORT Z_MAT_UPLOAD .

*TO CREATE MATERIAL USING BAPI.

**********************************************************************
*                STRUCTURE  DECLARATIONS                             *
**********************************************************************

TABLES: BAPIMATHEAD,  "Headerdata
        BAPI_MARA,    "Clientdata
        BAPI_MARAX,   "Clientdatax
        BAPI_MARC,    "Plantdata
        BAPI_MARCX,   "Plantdatax
        BAPI_MAKT,    "Material description
        BAPI_MBEW,    "VALUATION DATA
        BAPI_MBEWX,
        BAPI_MARM,
        BAPI_MARMX,
        bapi_mean,
        BAPIRET2.     "Return messages

DATA:V_FILE TYPE STRING.   "input data file



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
    bwkey(004) type c,

  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.

*FOR gross wt
data: begin of it_uom occurs 0.
      include structure BAPI_MARM.
data:end of it_uom.

DATA: BEGIN OF IT_UOMX OCCURS 0.
      INCLUDE STRUCTURE BAPI_MARMX.
DATA:END OF IT_UOMX.

data:begin of it_mean occurs 0.
     include structure bapi_mean.
data:end of it_mean.

DATA:BEGIN OF IT_MLTX OCCURS 0.
     INCLUDE STRUCTURE BAPI_MLTX.
DATA:END OF IT_MLTX.
*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.

*ELSE.
*DELETE IT_MATMASTER INDEX 1.
ENDIF.

**********************************************************************
*                DATA POPULATIONS                                    *
**********************************************************************


LOOP AT  IT_MATMASTER.
*HEADER DATA
  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'.
*CLIENTDATA
  BAPI_MARA-MATL_GROUP = IT_MATMASTER-MATKL.
  BAPI_MARA-DIVISION = IT_MATMASTER-SPART.
  BAPI_MARA-DSN_OFFICE = IT_MATMASTER-LABOR.
  BAPI_MARA-PROD_HIER = IT_MATMASTER-PRDHA.
  BAPI_MARA-PUR_STATUS = IT_MATMASTER-MSTAE.
  BAPI_MARA-ITEM_CAT = IT_MATMASTER-MTPOS_MARA.
  BAPI_MARA-NET_WEIGHT = IT_MATMASTER-NTGEW.
*  BAPI_MARA-PO_UNIT = 'KG'.
*  BAPI_MARA-UNIT_OF_WT_ISO = 'KG'.
  BAPI_MARA-UNIT_OF_WT = 'KG'.
*  BAPI_MARA-PACK_VO_UN = 'KG'.
*  BAPI_MARA-BASE_UOM_ISO = 'KG'.
  bapi_mara-size_dim = it_matmaster-groes.
  BAPI_MARA-MAT_GRP_SM = IT_MATMASTER-MAGRV.
  BAPI_MARA-OLD_MAT_NO = IT_MATMASTER-BISMT.
  BAPI_MARA-BASE_UOM = IT_MATMASTER-MEINS.
  BAPI_MARA-BASIC_MATL = IT_MATMASTER-WRKST.
  BAPI_MARA-HAZMATPROF = IT_MATMASTER-PROFL.
  BAPI_MARA-ENVT_RLVT = IT_MATMASTER-KZUMW.
  BAPI_MARA-PO_UNIT = IT_MATMASTER-BSTME.
  BAPI_MARA-VAR_ORD_UN = IT_MATMASTER-VABME.
  BAPI_MARA-PUR_VALKEY = IT_MATMASTER-EKWSL.
  BAPI_MARA-MANU_MAT = IT_MATMASTER-MFRPN.
  BAPI_MARA-MFR_NO = IT_MATMASTER-MFRNR.
  BAPI_MARAX-MATL_GROUP = 'X'.
  BAPI_MARAX-DIVISION = 'X'.
  BAPI_MARAX-DSN_OFFICE = 'X'.
  BAPI_MARAX-PROD_HIER = 'X'.
  BAPI_MARAX-PUR_STATUS = 'X'.
  BAPI_MARAX-ITEM_CAT = 'X'.
  BAPI_MARAX-NET_WEIGHT = 'X'.
  BAPI_MARAX-UNIT_OF_WT = 'X'.
*  BAPI_MARAX-UNIT_OF_WT_ISO = 'X'.
  bapi_maraX-size_dim = 'X'.
  BAPI_MARAX-MAT_GRP_SM = 'X'.
  BAPI_MARAX-OLD_MAT_NO = 'X'.
  BAPI_MARAX-BASE_UOM = 'X'.
  BAPI_MARAX-BASE_UOM_ISO = 'X'.
  BAPI_MARAX-BASIC_MATL = 'X'.
  BAPI_MARAX-MFR_NO = 'X'.
  BAPI_MARAX-HAZMATPROF = 'X'.
  BAPI_MARAX-ENVT_RLVT = 'X'.
  BAPI_MARAX-PO_UNIT = 'X'.
*  BAPI_MARAX-PACK_VO_UN = 'X'.
  BAPI_MARAX-VAR_ORD_UN = 'X'.
  BAPI_MARAX-PUR_VALKEY = 'X'.
  BAPI_MARAX-MANU_MAT = 'X'.
  BAPI_MARAX-MFR_NO = 'X'.

*PLANT DATA

  BAPI_MARC-PLANT = IT_MATMASTER-WERKS.
  BAPI_MARC-PUR_GROUP = IT_MATMASTER-EKGRP.
  BAPI_MARC-BATCH_MGMT = IT_MATMASTER-XCHPF.
  BAPI_MARC-GR_PR_TIME = IT_MATMASTER-WEBAZ.
  BAPI_MARCX-PLANT = IT_MATMASTER-WERKS.
  BAPI_MARCX-PUR_GROUP = 'X'.
  BAPI_MARCX-BATCH_MGMT = 'X'.
  BAPI_MARCX-GR_PR_TIME = 'X'.

*VALUATION DATA
  BAPI_MBEW-PRICE_CTRL = IT_MATMASTER-VPRSV.
  BAPI_MBEW-STD_PRICE = IT_MATMASTER-STPRS.
  BAPI_MBEW-COMMPRICE1 = IT_MATMASTER-BWPRH.
  BAPI_MBEW-VAL_AREA = IT_MATMASTER-BWKEY.
  BAPI_MBEW-VAL_CLASS = IT_MATMASTER-BKLAS.
  BAPI_MBEWX-PRICE_CTRL = 'X'.
  BAPI_MBEWX-STD_PRICE = 'X'.
  BAPI_MBEWX-COMMPRICE1 = 'X'.
  BAPI_MBEWX-VAL_AREA = IT_MATMASTER-BWKEY.
  BAPI_MBEWX-VAL_CLASS = 'X'.
  IT_MATERIALDESC-LANGU = 'EN'.
  IT_MATERIALDESC-MATL_DESC = IT_MATMASTER-MAKTX.
  append IT_materialdesc.
  IT_UOM-GROSS_WT = IT_MATMASTER-BRGEW.
  IT_UOM-ALT_UNIT = 'KG'.
  IT_UOM-ALT_UNIT_ISO = 'KG'.
    IT_UOM-UNIT_OF_WT = IT_MATMASTER-GEWEI.
    APPEND IT_UOM.
  IT_UOMX-GROSS_WT = 'X'.
  IT_UOMX-ALT_UNIT = 'KG'.
  IT_UOMX-ALT_UNIT_ISO = 'KG'.
  IT_UOMX-UNIT_OF_WT = 'X'.


  APPEND IT_UOMX.

  it_mean-unit = 'KD3'.
  append it_mean.

  it_mltx-langu = 'E'.
  it_mltx-text_name = it_matmaster-matnr.
  APPEND IT_MLTX.
  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              = BAPI_MBEW
     VALUATIONDATAX             = BAPI_MBEWX
*     WAREHOUSENUMBERDATA        =
*     WAREHOUSENUMBERDATAX       =
*     SALESDATA                  =
*     SALESDATAX                 =
*     STORAGETYPEDATA            =
*     STORAGETYPEDATAX           =
*     FLAG_ONLINE                = ' '
*     FLAG_CAD_CALL              = ' '
   IMPORTING
     RETURN                     = IT_RETURN
   TABLES
     MATERIALDESCRIPTION        = IT_MATERIALDESC
     UNITSOFMEASURE             = IT_UOM
     UNITSOFMEASUREX            = IT_UOMX
     INTERNATIONALARTNOS        = it_mean
*     MATERIALLONGTEXT           = IT_MLTX
*     TAXCLASSIFICATIONS         =
*     RETURNMESSAGES             =
*     PRTDATA                    =
*     PRTDATAX                   =
*     EXTENSIONIN                =
*     EXTENSIONINX               =
            .

read table it_return with key TYPE = 'S'.
if sy-subrc = 0.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*   EXPORTING
*     WAIT          =
*   IMPORTING
*     RETURN        =
            .
*else.
*
*CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
** IMPORTING
**   RETURN        =
*          .
*
endif.

 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.

Regards

vijay

Read only

Former Member
0 Likes
1,121

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,

Subhasish

Read only

Former Member
0 Likes
1,121

Hi,

Check this code for creating a business partner..

  • Creating Business Partner

CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'

EXPORTING

partnercategory = lc_2 "Organization

partnergroup = lc_par_grp "Internal no. assignment

centraldata = wa_centraldata

centraldataorganization = wa_centraldataorg

addressdata = wa_addressdata

IMPORTING

businesspartner = lv_customer

TABLES

return = lit_return1.

  • Binary search not used as no. of records are less than 15

READ TABLE lit_return1 INTO wa_return1 WITH KEY type = gc_error.

IF sy-subrc = 0.

CLEAR lv_customer.

CONCATENATE text-008 wa_return1-message INTO lv_err_desc

SEPARATED BY space.

Regards,

Tanveer.

<b>Please mark helpful answers</b>

Read only

Former Member
0 Likes
1,121

hi friends,

thanks to everyone. now i got it. if i have doubts i get back to all.

chandu

Read only

0 Likes
1,121

Hi,

Please appreciate the time spent by each of the people who have answered your question. Please mark the helpful answers and close the thread.

Regards,

Ravi

Read only

Former Member
0 Likes
1,121

hi friends,

thanks to everyone. now i got it. if i have doubts i get back to all.

chandu