SAP AND ABAP TIPS AND FACTS

Showing posts with label BAPI. Show all posts
Showing posts with label BAPI. Show all posts

Thursday, June 19, 2008

SAP MRP List Function Module

SAP MRP List Function Module

To get a MRP list similar to SAP Transaction MD05 you can use the following Function Module.

SAP ABAP Function Module to get MRP list

MD_MRP_LIST_API

The above mentioned Function Module gives MRP List output. For more details on the outputted list please check the following

OutPut Parameters

Structure
MDPS                              Item in MRP document
MDEZ                              Individual lines of the MRP elements
MDSU                             Total lines for MRP elements

Input Parameters

PLSCN                           Planning scenario in long-term planning
MATNR                         Material Number
WERKS                          Plant
BERID                           MRP area
AFIBZ                            Name of display filter
LIFNR                            Vendor Number

Related Tables

MDKP                             Header Data for MRP Document
MDTB                             MRP table
MDTC                             Aggregated MRP table items
T457T                             Description of MRP elements

Related Transaction Code MD05
_____________________________________________________

Please find the code below.

REPORT ZEX_MRPLIST .


Parameter: p_matnr like MARC-MATNR,
           p_werks like MARC-WERKS.


Data: st_MT61D like MT61D,
      st_MDKP  like MDKP,
      int_MDPS TYPE TABLE OF MDPS,
      int_MDEZ TYPE TABLE OF MDEZ,
      int_MDSU TYPE TABLE OF MDSU.


CALL FUNCTION 'MD_MRP_LIST_API'
  EXPORTING
*   PLSCN                          =
    MATNR                          = p_matnr
    WERKS                          = p_werks
*   BERID                          =
*   AFIBZ                          =
*   SINFG                          = 'X'
*   LIFNR                          =
*   AFHOR                          =
*   DTNUM                          =
*   INPER                          =
*   DISPLAY_LIST_MDPSX             =
*   DISPLAY_LIST_MDEZX             =
*   DISPLAY_LIST_MDSUX             =
 IMPORTING
   E_MT61D                        = st_MT61D
   E_MDKP                         = st_MDKP
 TABLES
   MDPSX                          = int_MDPS
   MDEZX                          = int_MDEZ
   MDSUX                          = int_MDSU
 EXCEPTIONS
  MRP_LIST_NOT_FOUND             = 1
   MATERIAL_PLANT_NOT_FOUND       = 2
   ERROR                          = 3
   OTHERS                         = 4
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

Wednesday, June 18, 2008

SAP Availability Check BAPI/Function Module

SAP Availability Check BAPI/Function Module

If you need to check the availability of a Material using a program, then you can make use of the following BAPI.

SAP Availability check BAPI
BAPI_MATERIAL_AVAILABILITY
__________________________________

This BAPI returns the Available quantity.

The code given below shows how to call this BAPI. The import parameters of this BAPI are

Material
Plant
Unit
________________________


REPORT ZEX_AVAILIBILITYCHK .

Parameter: p_matnr like BAPIMATVP-MATNR,
           p_werks like BAPIMATVP-WERKS,
           p_unit  like BAPIADMM-UNIT.

*Data: int_wmdvsx like BAPIWMDVS occurs 0 with header line,
*      int_wmdvex like BAPIWMDVE occurs 0 with header line.

Data: int_wmdvsx  type table of bapiwmdvs with header line,
      int_wmdvex  type table of bapiwmdve with header line,
      d_WKBST like BAPICM61V-WKBST.



           CALL FUNCTION 'BAPI_MATERIAL_AVAILABILITY'
             EXPORTING
               PLANT                    = p_werks
               MATERIAL                 = p_matnr
               UNIT                     = p_unit
*              CHECK_RULE               =
*              STGE_LOC                 =
*              BATCH                    =
*              CUSTOMER                 =
*              DOC_NUMBER               =
*              ITM_NUMBER               =
*              WBS_ELEM                 =
*              STOCK_IND                =
*              DEC_FOR_ROUNDING         =
*              DEC_FOR_ROUNDING_X       =
*              READ_ATP_LOCK            =
*              READ_ATP_LOCK_X          =
            IMPORTING
*              ENDLEADTME               =
               AV_QTY_PLT               = d_WKBST
*              DIALOGFLAG               =
*              RETURN                   =
             TABLES
               WMDVSX                   = int_wmdvsx
               WMDVEX                   = int_wmdvex
                     .


Write:/ d_WKBST.

 If sy-subrc = 0.

 endif.


Saturday, June 14, 2008

SAP BAPI Sales Order Simulate

SAP BAPI Sales Order Simulate

In SAP before creating a sales order there is a way to simulate it using a BAPI.  This can be done using the following BAPI.

SAP ABAP BAPI to Simulate a Sales Order.

BAPI_SALESORDER_SIMULATE

This is very useful in case you want to check the Availability and Pricing. The parameters obtained are given below.

BAPIITEMEX                     Communication Fields: Issue SD Document Item: WWW
BAPISDHEDU                    Struture of VBEP (Sales Document: Schedule Line Data)
BAPICOND                       Communication Fields for Maintaining Conditions in the Order
BAPIINCOMP                    Communication Fields: Incompletion


Find the code below.

Note: This is very similar to Sales Order Create BAPI 'BAPI_SALESORDER_CREATEFROMDAT1' but in this case the actual Sales Order is not created instead a simulation is carried out.

REPORT ZEX_SALORDSIMULATE.


*-------------------------Data Declaration-----------------------------*
Data: st_BAPISDHEAD like BAPISDHEAD, " Sales Order Header Data
      ta_BAPIITEMIN like BAPIITEMIN occurs 0 with header line, " Ln item
      ta_BAPIPARTNR like BAPIPARTNR occurs 0 with header line, " Partner
      int_BAPIITEMEX like BAPIITEMEX occurs 0 with header line,
      int_BAPISDHEDU like BAPISDHEDU occurs 0 with header line,
      int_BAPICOND like BAPICOND occurs 0 with header line,
      int_BAPIINCOMP like BAPIINCOMP occurs 0 with header line,
      d_BAPIRETURN1 like BAPIRETURN.          " Bapi return msg

* Move the data to create sales order in the repective parameters------*
move: 'TA' to st_BAPISDHEAD-DOC_TYPE,     " Sales document type
      '15493'     to st_BAPISDHEAD-PURCH_NO_C,
      '00010'     to ta_BAPIITEMIN-ITM_NUMBER,
      'Y-351'     to ta_BAPIITEMIN-MATERIAL,
      '1100'      to ta_BAPIITEMIN-PLANT,
      '1'         to ta_BAPIITEMIN-REQ_QTY,
      'AG'        to ta_BAPIPARTNR-PARTN_ROLE,  " Sold to Party
      '0000007777'   to ta_BAPIPARTNR-PARTN_NUMB.
* Append the internal tables-------------------------------------------*
       append ta_BAPIPARTNR.
       clear ta_BAPIPARTNR.
       append ta_BAPIITEMIN.
       clear ta_BAPIITEMIN.
* Move ship to party---------------------------------------------------*
       move: 'RG'    to ta_BAPIPARTNR-PARTN_ROLE, " Ship to party
             '0000007777'   to ta_BAPIPARTNR-PARTN_NUMB.
* Append the internal tables-------------------------------------------*
       append ta_BAPIPARTNR.
       clear ta_BAPIPARTNR.

* Call BAPI to SIMULATE the Order

      CALL FUNCTION 'BAPI_SALESORDER_SIMULATE'
        EXPORTING
          ORDER_HEADER_IN           = st_BAPISDHEAD
*         CONVERT_PARVW_AUART       = ' '
       IMPORTING
*         SALESDOCUMENT             =
*         SOLD_TO_PARTY             =
*         SHIP_TO_PARTY             =
*         BILLING_PARTY             =
         RETURN                    = d_BAPIRETURN1
        TABLES
         ORDER_ITEMS_IN            = ta_BAPIITEMIN
         ORDER_PARTNERS            = ta_BAPIPARTNR
*         ORDER_SCHEDULE_IN         =
         ORDER_ITEMS_OUT           = int_BAPIITEMEX
*         ORDER_CFGS_REF            =
*         ORDER_CFGS_INST           =
*         ORDER_CFGS_PART_OF        =
*         ORDER_CFGS_VALUE          =
*         ORDER_CFGS_BLOB           =
*         ORDER_CCARD               =
*         ORDER_CCARD_EX            =
         ORDER_SCHEDULE_EX         = int_BAPISDHEDU
         ORDER_CONDITION_EX        = int_BAPICOND
         ORDER_INCOMPLETE          = int_BAPIINCOMP
*         MESSAGETABLE              =
*         EXTENSIONIN               =
*         PARTNERADDRESSES          =
                .

IF SY-SUBRC = 0.

ENDIF.




Thursday, June 12, 2008

SAP BAPI List of BAPIS in the System

SAP BAPI List of BAPIS in the System

To get a list of all the BAPIs in the system the following BAPI can be used.

BAPI_MONITOR_GETLIST
____________________________

The following Parameters should be passed to the above mentioned BAPI

Object type
Release /Reference Release to Display
Display Potential BAPIs
Display New BAPIs in Release
Display BAPIs from Previous Releases
Release Status of BAPIs
Release Status of Function Modules
________________________________________________________________

The BAPI returns a table with the following information.

Object type, Object name, Method name of BAPI, Function module name, Application component ID, Release at creation, Author, Last changed on, Last changed by, R/3 System, name of R/3 System, Application area or BAPI Work Group reponsible, Interface object type, Release status of BAPI methods, Release status of function module, Release in which object type was set as obsolete, Documentation on function module exists, Documentation for business object exists, Message type, Object type component, Description.

Example:

REPORT ZEX_BAPI_GETLIST .

* Parameters-----------------------------------------------------------*
Parameter: p_ojtpe like BAPIMONIT-OBJTYPE default '*',
           p_rel like BAPIMONIT-CREA_REL default SY-SAPRL,
           p_poten like BAPIMONIT-OPTSEL default ' ',
           p_newbp like BAPIMONIT-OPTSEL default 'X',
           p_oldbp like BAPIMONIT-OPTSEL default 'X',
           p_relbp like BAPIMONIT-OPTSEL default '*',
           p_relfun like BAPIMONIT-FUNCREL default '*'.

* Data Declaration-----------------------------------------------------*
Data: d_ret like BAPIRET2.

* Internal Table Declaration-------------------------------------------*
Data: int_comsel like BAPIMONCOM occurs 0 with header line,
      int_orgBP  like BAPISRCSYS occurs 0 with header line,
      int_selbap like BAPIMONSTR occurs 0 with header line.


* Function Call--------------------------------------------------------*
CALL FUNCTION 'BAPI_MONITOR_GETLIST'
 EXPORTING
   OBJECTTYPE              = p_ojtpe
   SHOW_RELEASE            = p_rel
   BAPIS_POTENTIAL         = p_poten
   BAPIS_NEW               = p_newbp
   BAPIS_OLD               = p_oldbp
   RELEASED_BAPI           = p_relbp
   RELEASED_FUNC           = p_relfun
 IMPORTING
   RETURN                  = d_ret
 TABLES
   COMPONENTS2SELECT       = int_comsel
   SYSTEMS2SELECT          = int_orgBP
   BAPILIST                = int_selbap
          .

 if sy-subrc = 0.

 endif.


Thursday, June 5, 2008

SAP ABAP BAPI Material EDIT

SAP ABAP BAPI Material EDIT

If you wish to edit a Material, you can use the following BAPI.

BAPI_MATERIAL_EDIT

The above mentioned BAPI makes use of CALL TRANSACTION MM02 or MM42 to edit the MATERIAL. The selection of the appropriate transaction is made based on the entered material. The table MAW1 is checked for the existence of material, if the material exists in MAW1 then the transaction MM02 is called else transaction MM42 is called.

 
 BAPI_MATERIAL_EDIT in turn calls the following function modules.

BAPI_MATERIAL_EXISTENCECHECK and
CONVERSION_EXIT_MATN1_OUTPUT

The user is then presented with the change material screen either for MM02 or MM42.

The code below shows the values of the input parameters for the BAPI  BAPI_MATERIAL_EDI

REPORT ZEX_CHANGEMAT .

Parameters: p_matnr like BAPIMATALL-MATERIAL,
            p_fscrn like BAPIMATALL-SKIP_1ST_SCREEN.

Data: d_ret like BAPIRET1.


           CALL FUNCTION 'BAPI_MATERIAL_EDIT'
             EXPORTING
               MATERIAL             = p_matnr
              SKIP_1ST_SCREEN       = p_fscrn
            IMPORTING
              RETURN                = d_ret
                     .



if sy-subrc = 0.

endif.


Monday, June 2, 2008

SAP ABAP Creating a Material using a BAPI Part 2

SAP ABAP Creating a Material using a BAPI Part 2

In part 1
SAP ABAP Creating a Material using a BAPI Part 1 we have seen how to get the next Material Number. In this Part we will see the parameters that need to be passed for creating the actual Material. For simplicity let us keep the number of parameters to minimum. We will just pass the mandatory fields as per the system that I am using. Please note that you need to pass the Material Number Obtained in the previous Part. Also make sure that you run the following BAPIs in the Order shown below.

To create a Material in SAP using a BAPI you need to use the following 2 BAPIs

BAPI_MATERIAL_GETINTNUMBER
_______________________________________________
Pass the Material Number obtained
from the above BAPI to the following BAPI

_______________________________________________
BAPI_MATERIAL_SAVEDATA
_______________________________________________


Find the code below.

REPORT ZEX_SAVEMATERIAL .

Parameters: p_matype like BAPIMATDOA-MATL_TYPE,
            p_indsr like BAPIMATDOA-IND_SECTOR,
            p_reqnum like BAPIMATALL-REQ_NUMBERS.

Data: d_ret like BAPIRETURN1,
      d_ret2 like BAPIRET2.

Data: int_matnum type BAPIMATINR occurs 0 with header line,
      int_matdesc type BAPI_MAKT occurs 0 with header line.

Data: st_headdata like BAPIMATHEAD,
      st_clientdata like BAPI_MARA,
      st_clientx like BAPI_MARAX.

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
     EXPORTING
          MATERIAL_TYPE    = p_matype
          INDUSTRY_SECTOR  = p_indsr
          REQUIRED_NUMBERS = p_reqnum
     IMPORTING
          RETURN           = d_ret
     TABLES
          MATERIAL_NUMBER  = int_matnum.

if sy-subrc = 0.
endif.

loop at int_matnum.
  st_headdata-MATERIAL = int_matnum-MATERIAL.
endloop.

int_matdesc-langu ='E'.
int_matdesc-langu_iso = 'E'.
int_matdesc-matl_desc = 'Material 1'.
append int_matdesc.
clear int_matdesc.

st_headdata-ind_sector = 'C'.
st_headdata-matl_type = 'HAWA'.

st_clientdata-MATL_GROUP = '001'.
st_clientdata-BASE_UOM = 'BT'.
st_clientdata-BASE_UOM_ISO = 'BT'.

st_clientx-MATL_GROUP ='X'.
st_clientx-BASE_UOM = 'X'.
st_clientx-BASE_UOM_ISO = 'X'.


CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
  EXPORTING
    HEADDATA                   = st_headdata
   CLIENTDATA                  = st_clientdata
   CLIENTDATAX                 = st_clientx
*             PLANTDATA                  =
*             PLANTDATAX                 =
*             FORECASTPARAMETERS         =
*             FORECASTPARAMETERSX        =
*             PLANNINGDATA               =
*             PLANNINGDATAX              =
*             STORAGELOCATIONDATA        =
*             STORAGELOCATIONDATAX       =
*             VALUATIONDATA              =
*             VALUATIONDATAX             =
*             WAREHOUSENUMBERDATA        =
*             WAREHOUSENUMBERDATAX       =
*             SALESDATA                  =
*             SALESDATAX                 =
*             STORAGETYPEDATA            =
*             STORAGETYPEDATAX           =
*             FLAG_ONLINE                = ' '
*             FLAG_CAD_CALL              = ' '
*             NO_DEQUEUE                 = ' '
 IMPORTING
   RETURN                     = d_ret2
 TABLES
   MATERIALDESCRIPTION        = int_matdesc
*             UNITSOFMEASURE             =
*             UNITSOFMEASUREX            =
*             INTERNATIONALARTNOS        =
*             MATERIALLONGTEXT           =
*             TAXCLASSIFICATIONS         =
*             RETURNMESSAGES             =
*             PRTDATA                    =
*             PRTDATAX                   =
*             EXTENSIONIN                =
*             EXTENSIONINX               =
          .

If sy-subrc = 0.
Endif.





SAP ABAP Creating a Material using a BAPI Part 1

SAP ABAP Creating a Material using a BAPI

In SAP ABAP you can create a Material using a BAPI. To do so you first need to get the Next Material Number. This can be obtained by using the following BAPI.

To create a Material in SAP using a BAPI you need to use the following 2 BAPIs

BAPI_MATERIAL_GETINTNUMBER
BAPI_MATERIAL_SAVEDATA

If you are suing the transaction MM01 to create a Material, you can see the Material Number being assigned automatically. If you have not noticed this please run the transaction MM01 and enter the values in the initial screen. After hitting enter you will see the Material Number appear in the next screen automatically.

Let us now see the parameters that need to be passed to the BAPI BAPI_MATERIAL_GETINTNUMBER.

The Mandatory Parameters that need to be passed to the BAPI are as follows.

Material Type
Industry Sector
Required Numbers

Enter the desired values and generate the Next Material Number. Once you obtain the Material Number, you then need to pass this number to the following BAPI.

BAPI to create Material in SAP

BAPI_MATERIAL_SAVEDATA

The following program demonstrates the BAPI BAPI_MATERIAL_GETINTNUMBER

REPORT ZEX_GETMATNUM .

Parameters: p_matype like BAPIMATDOA-MATL_TYPE,
            p_indsr like BAPIMATDOA-IND_SECTOR,
            p_reqnum like BAPIMATALL-REQ_NUMBERS.

Data: d_ret like BAPIRETURN1.

Data: int_matnum type BAPIMATINR occurs 0.

CALL FUNCTION 'BAPI_MATERIAL_GETINTNUMBER'
  EXPORTING
    MATERIAL_TYPE          = p_matype
   INDUSTRY_SECTOR         = p_indsr
   REQUIRED_NUMBERS        = p_reqnum
 IMPORTING
   RETURN                  = d_ret
  TABLES
    MATERIAL_NUMBER        = int_matnum
          .

          if sy-subrc = 0.

          endif.

I have used the following Parameters:

Material Type            HAWA
Industry Sector         C
Required Numbers     1

See Also: SAP ABAP Creating a Material using a BAPI Part 2
____________________________________________________________________________________________________________________________________________________________________


Saturday, May 31, 2008

SAP BAPI for displaying Material Data

SAP BAPI for displaying Material Data

If you wish to display Material data related to Material General Data, Material Plant Data and Material Valuation Data then you can use the following BAPI. This BAPI displays the above mentioned data for a Material.

BAPI/Function Module to display Material Data / Display Material Data BAPI/Function Module

BAPI_MATERIAL_GET_DETAIL

This BAPI has 4 input parameters

Material  (Mandatory)
Plant
Valuation Area
Valuation Type

Please find the code below.

REPORT ZEX_GETMATDET .

Parameters: p_matnr like BAPIMATDET-MATERIAL,
            p_werks like BAPIMATALL-PLANT,
            p_valara like BAPIMATALL-VAL_AREA,
            p_valtyp like BAPIMATALL-VAL_TYPE.


Data: st_matgendata like BAPIMATDOA,
      st_matplantdat like BAPIMATDOC,
      st_matvaldat like BAPIMATDOBEW,
      d_return like BAPIRETURN.


CALL FUNCTION 'BAPI_MATERIAL_GET_DETAIL'
  EXPORTING
   MATERIAL                   = p_matnr
   PLANT                       = p_werks
   VALUATIONAREA               = p_valara
   VALUATIONTYPE               = p_valtyp
 IMPORTING
   MATERIAL_GENERAL_DATA       = st_matgendata
   RETURN                      = d_return
   MATERIALPLANTDATA           = st_matplantdat
   MATERIALVALUATIONDATA       = st_matvaldat .

   If sy-subrc = 0.

   endif.


Important Transactions related to Material Management

Create General

MM01 Immediate
MM11 Schedule
____________________________________________

Create Special

MMR1 Raw Material
MMB1 Semi finished  Product
MMF1 Finished Product
MMI1 Operating Supplies
MMH1 Trading Goods
MMU1 Non Valuated Material
MMN1 Non Stock Material
MMV1 Packaging
MMl1 Empties
MMS1 Services
MMk1 Configurable Material
MMP1 Maintenance Assembly
MMW1 Competitor Product
MMG1 Returnable Packaging
______________________________________________

Change

MM02 Immediately
MM12 Schedule
MM13 Active
______________________________________________

Display

MMO3 Current
MM19 Display at Key Date




 

 



SAP function Module to get vendor Bank Details

SAP function Module to get vendor Bank Details

If you wish to extract the bank details of a particular vendor then you can use the following BAPI.

BAPI/Function Module  for vendor bank details extraction

BAPI_VENDOR_GETDETAIL


Please find below the code to extract vendor Bank Details.

REPORT ZEX_CUSTOMERBANK .


Parameters: p_kunnr like BAPICUSTOMER_ID-CUSTOMER,
            p_bukrs like BAPICUSTOMER_ID-COMP_CODE.

Data: ty_knbk type knbk,
      ty_custadd type BAPICUSTOMER_04,
      ty_custgendet type BAPICUSTOMER_KNA1,
      ty_custcompdet type BAPICUSTOMER_05,
      d_ret         like BAPIRET1.

Data: wa_custadd like ty_custadd,
      wa_custgendet like ty_custgendet,
      wa_custcompdet like ty_custcompdet.

Data: int_knbk like ty_knbk occurs 0.

CALL FUNCTION 'BAPI_CUSTOMER_GETDETAIL2'
  EXPORTING
    CUSTOMERNO                  = p_kunnr
   COMPANYCODE                  = p_bukrs
 IMPORTING
   CUSTOMERADDRESS              = wa_custadd
   CUSTOMERGENERALDETAIL        = wa_custgendet
   CUSTOMERCOMPANYDETAIL        = wa_custcompdet
   RETURN                       = d_ret
 TABLES
   CUSTOMERBANKDETAIL           = int_knbk      .

   if sy-subrc = 0.

   Endif.



Related Topics:

Read Vendor



Thursday, May 29, 2008

SAP BAPI To Get Customer Bank Details

SAP BAPI To Get Customer Bank Details

In case you wish to extract the Bank Data for a particular customer, you can use the following BAPI. This BAPI extracts the Customer's Address, General Data, Company Code Data and the Bank Details.

SAP ABAP to get customer Bank Details   
BAPI_CUSTOMER_GETDETAIL2

For reference please find below the transaction codes to Create/Change/Display a customer

XD01 Create Customer Complete
XD02 Change Customer Complete
XD03 Display Customer Complete

VD01 Create Customer Sales and Distribution
VD02 Change Customer Sales and Distribution
VD03 Display Customer Sales and Distribution


Also Find below the tables related to the BAPI BAPI_CUSTOMER_GETDETAIL2

KNBK-Customer Master (Bank Details)
ADRC- Addresses (central address admin.)
KNA1-General Data in Customer Master
KNB1-Customer Master (Company Code)

The following code extracts the above mentioned details from the SAP R/3 System

REPORT ZEX_CUSTOMERBANK .


Parameters: p_kunnr like BAPICUSTOMER_ID-CUSTOMER,
            p_bukrs like BAPICUSTOMER_ID-COMP_CODE.

Data: ty_knbk type knbk,
      ty_custadd type BAPICUSTOMER_04,
      ty_custgendet type BAPICUSTOMER_KNA1,
      ty_custcompdet type BAPICUSTOMER_05,
      d_ret         like BAPIRET1.

Data: wa_custadd like ty_custadd,
      wa_custgendet like ty_custgendet,
      wa_custcompdet like ty_custcompdet.


Data: int_knbk like ty_knbk occurs 0.


CALL FUNCTION 'BAPI_CUSTOMER_GETDETAIL2'
  EXPORTING
    CUSTOMERNO                  = p_kunnr
   COMPANYCODE                  = p_bukrs
 IMPORTING
   CUSTOMERADDRESS              = wa_custadd
   CUSTOMERGENERALDETAIL        = wa_custgendet
   CUSTOMERCOMPANYDETAIL        = wa_custcompdet
   RETURN                       = d_ret
 TABLES
   CUSTOMERBANKDETAIL           = int_knbk      .


   if sy-subrc = 0.

   Endif.

SAP ABAP BAPI to Read Customer Data

SAP ABAP BAPI to Read Customer Data

In case you wish to read the customer data you can use the following BAPI, it retrieves the Customer Master (Company Code) Data and the General Data in Customer Master.

SAP ABAP BAPI to Read Customer Master Data
CUSTOMER_READ

You need to pass the Customer Number and the Company Code. See the example given below.


REPORT ZEX_CUSTOMERREAD .

Parameters: p_bukrs like KNB1-BUKRS,
            p_kunnr like KNA1-KUNNR.


Data: ty_kna1 type kna1,
      ty_knb1 type knb1.

Data: int_kna1 like ty_kna1,
      int_knb1 like ty_knb1.

CALL FUNCTION 'CUSTOMER_READ'
  EXPORTING
    I_BUKRS         = p_bukrs
    I_KUNNR         = p_kunnr
 IMPORTING
   E_KNA1          = int_Kna1
   E_KNB1          = int_knb1
 EXCEPTIONS
   NOT_FOUND       = 1
   OTHERS          = 2
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.


Wednesday, May 14, 2008

Purchase Order BAPI SAP ABAP

Purchase Order BAPI SAP ABAP

If you wish to transfer Purchase Order related Data to SAP, you can do so by using the following BAPI.

BAPI_PO_CREATE

Many a times there is a requirement to transfer purchase order data from a third party to SAP, it can be done by the following methods.

1) BAPI
3) BDC
3) EDI

This this tutorial we will see how to create a Purchase Order using the above mentioned BAPI.

Please note that if you wish to create Real Time Purchase Orders from an external system into SAP R/3 then you need to use either the JCO connector, .NET connector or XI. The example below shows creation of a single purchase order, if you have data required to create purchase orders then you first need to upload it into an internal table and then pass the table to the BAPI.

Please find the code below to create a Purchase order using the BAPI BAPI_PO_CREATE

REPORT ZEX_POCREATE .



Data: int_pohead like BAPIEKKOC,
      int_poitem like BAPIEKPOC occurs 0 with header line,
      int_posched like BAPIEKET occurs 0 with header line,
      int_ret like BAPIRETURN occurs 0 with header line.
Data: d_purchord like BAPIEKKOC-PO_NUMBER.

Move: 'NB' to int_pohead-DOC_TYPE,
      '1000' to int_pohead-PURCH_ORG,
      '001' to int_pohead-PUR_GROUP,
      '0000001234' to int_pohead-vendor,


      '00010' to int_poitem-po_item,
      'Material' to int_poitem-material,
      'Material' to int_poitem-pur_mat,
      '1000' to int_poitem-plant,


      '00010' to int_posched-PO_ITEM,
      '20080531' to int_posched-DELIV_DATE,
      '2'        to int_posched-QUANTITY.


Append int_poitem.
Clear int_poitem.
APPEND int_posched.
CLEAR int_posched.

CALL FUNCTION 'BAPI_PO_CREATE'
  EXPORTING
   PO_HEADER                        = int_pohead
*   PO_HEADER_ADD_DATA               =
*   HEADER_ADD_DATA_RELEVANT         =
*   PO_ADDRESS                       =
    SKIP_ITEMS_WITH_ERROR            = 'X'
*   ITEM_ADD_DATA_RELEVANT           =
 IMPORTING
   PURCHASEORDER                     = d_purchord
  TABLES
    PO_ITEMS                         = int_poitem
*   PO_ITEM_ADD_DATA                 =
    PO_ITEM_SCHEDULES                = int_posched
*   PO_ITEM_ACCOUNT_ASSIGNMENT       =
*   PO_ITEM_TEXT                     =
    RETURN                           = int_ret
*   PO_LIMITS                        =
*   PO_CONTRACT_LIMITS               =
*   PO_SERVICES                      =
*   PO_SRV_ACCASS_VALUES             =
*   PO_SERVICES_TEXT                 =
*   PO_BUSINESS_PARTNER              =
*   EXTENSIONIN                      =
*   POADDRDELIVERY                   =
          .

If sy-subrc = 0.
  Write:/ 'Purchase Order Number is', d_purchord.
endif.




ABAP TIPS

PREVIOUS                  NEXT                    RANDOM

 ABAP TIPS


Since your web browser does not support JavaScript, here is a non-JavaScript version of the image slideshow:

 ABAP TIPS
Always specify your conditions in the Where-clause instead of checking them yourself with check statements. The database system can then use an index (if possible) and the network load is considerably less.


 ABAP TIPS
For all frequently used Select statements, try to use an index. You always use an index if you specify (a generic part of) the index fields concatenated with logical Ands in the Select statement's Where clause. Note that complex Where clauses are poison for the statement optimizer in any database system.


 ABAP TIPS
If there exists at least one row of a database table or view with a certain condition, use the Select Single statement instead of a Select-Endselect-loop. Select Single requires one communication with the database system, whereas Select-Endselect needs two.


 ABAP TIPS
It is always faster to use the Into Table version of a Select statement than to use Append statements.


 ABAP TIPS
To read data from several logically connected tables use a join instead of nested Select statements. Network load is considerably less.


 ABAP TIPS
If you want to find the maximum, minimum, sum and average value or the count of a database column, use a select list with aggregate functions instead of computing the aggregates yourself. Network load is considerably less.


 ABAP TIPS
If you process your data only once, use a Select-Endselect-loop instead of collecting data in an internal table with Select Into Table. Internal table handling takes up much more space.


 ABAP TIPS
Use a select list or a view instead of Select * , if you are only interested in specific columns of the table. Network load is considerably less.


 ABAP TIPS
For all frequently used, read-only tables, try to use SAP buffering. Network load is considerably less.


 ABAP TIPS
Whenever possible, use array operations instead of single-row operations to modify your database tables. Frequent communication between the application program and database system produces considerable overhead.


 ABAP TIPS
Whenever possible, use column updates instead of single-row updates to update your database tables. Network load is considerably less.


 ABAP TIPS
Instead of using nested Select loops or FOR ALL ENTRIES it is often possible to use subqueries. Network load is considerably less.


 ABAP TIPS
Use the special operators CO, CA, CS, instead of programming the operations yourself. If ABAP/4 statements are executed per character on long strings, CPU consumption can rise substantially.


 ABAP TIPS
Some function modules for string manipulation have become obsolete and should be replaced by ABAP/4 statements or functions: STRING_CONCATENATE... -> CONCATENATE, STRING_SPLIT... -> SPLIT, STRING_LENGTH -> strlen(), STRING_CENTER -> WRITE...TO...CENTERED, STRING_MOVE_RIGHT -> WRITE...TO...RIGHT-JUSTIFIED


 ABAP TIPS
Use the CONCATENATE statement instead of programming a string concatenation of your own.


 ABAP TIPS
If you want to delete the leading spaces in a string, use the ABAP/4 statement SHIFT...LEFT DELETING LEADING... .Other constructions (with CN and SHIFT...BY SY-FDPOS PLACES, with CONDENSE if possible, with CN and ASSIGN CLA+SY-FDPOS(LEN) ...) are not as fast. In any case, avoid using SHIFT inside a WHILE-loop!


 ABAP TIPS
Use the SPLIT statement instead of programming a string split yourself.


 ABAP TIPS
Use the strlen( ) function to restrict the DO loop to the relevant part of the field, e.g. when determinating a check-sum.


 ABAP TIPS
Use "CLEAR f WITH val" whenever you want to initialize a field with a value different from the field's type-specific initial value.


 ABAP TIPS
Try to keep the table ordered and use binary search or used a table of type SORTED TABLE. If TAB has n entries, linear search runs in O( n ) time, whereas binary search takes only O( log2( n ) ).


 ABAP TIPS
A dynamic key access is slower than a static one, since the key specification must be evaluated at runtime. However, for large tables the costs are dominated by number of comparison needed to locate the entry.


 ABAP TIPS
If you need to access an internal table with different keys repeatedly, keep your own secondary indices.With a secondary index, you can replace a linear search with a binary search plus an index access.


 ABAP TIPS
LOOP ... WHERE is faster than LOOP/CHECK because LOOP ... WHERE evaluates the specified condition internally. As with any logical expressions, the performance is better if the operands of a comparison share a common type. The performance can be further enhanced if LOOP ... WHERE is combined with FROM i1 and/or TO i2, if possible.


Always use Pretty Printer and Extended Program Check before releasing the code. Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive.

Ole Automation Part1
Ole Automation Part 2
Processing Blocks in ABAP
Simple ABAP Report
ALV Grid - Changing Colors
ALV Report Example
Creating Variants For ABAP Reports
Recording BDC using Transaction
Sales Document Flow in ABAP
User Exits in SAP SD
SAP ABAP Naming Standards
SAP SD Tables
SAP ABAP Data Dictionary Tables
MM Important Transaction Codes in SAP
Passing g Data From One ABAP Program to Another
ABAP Compute Add Collect and Append
SAP ABAP Determining Attributes of Data
SAP ABAP Editor Icons
BAPI for Displaying Material Data
BAPI to get customer bank details
EDI Outbound Process
SAP EDI Process Overview
Function Module for Vendor Bank details
SAP IDOC
Creating a Valid Password in SAP
SAP BADIs Introduction
SAP ABAP MACROS
POP UP function Module to Confirm and Save Data
Select Options
BAPI for availability check
String to Numerical
SAP Goods Movement Process
Getting a List of Plants for a Material
SAP R3 Clients Concept
ABAP Adobe Forms
Authorization Object Tables
SAP Industry Specific Solutions

Sap Scripts and SmartForms Bar Codes
Standard Reports and Sap Scripts
Important Standard Reports in SAP
Abap Tricks and Tips
Bapi Sales Order
BAPI Purchase Order
Creating Function Modules in SAP
Creating Tables in SAP
Finding User Exits in SAP
Function Module Create Text and Read Text
Important Transaction Codes in SAP
ABAP Function Module for Submitting a Program
ABAP Game Tic Tac Toe
ABAP Internal Table To Excel Sheet
ABAP Function Module to create Directory
Different Types of Menus in SAP
Function Modules in SAP to check Loged in Users
ABAP Function Module for Adding Days to Dates
Call a Transaction From a Remote System
SAP MM simple Procurement Cycle
BAPI Material EDIT
Finding Decimal Places in Currency
Getting negative sign before a number in ABAP
Program Editor Lock Unlock
Restricting Select Options
List of BAPIs in the system
SAP Function Module Scramble a String
LSMW
POP up table contents on the screen
SAP R3 Bookmarking Websites
Stock Requirements List Function Module
Retail Transaction Codes
ABAP Debugger Break Points
ABAP Debugger WatchPoints
Drill Down Reports Concept
Creating a HOT SPOT
Interactive Programs and Hide Technique
String Concatenate
Get Week of the Year
SAP ABAP to Add Days to a Date
Add Months to a Date
Get Month in the Year
Display Clock

ABAP Code For Progress BAR
ABAP Function Module For Caluclator
ABAP Function Module For Calender
Displaying Messages in ABAP
Function Module Pop Up To Confirm
Conversion Routines in SAP
SAP ABAP Authorization
SAP ABAP Module Pool Tutorial
SAP ABAP RFC

Finding Path to SAP Transaction in Menu
SAP Purchasing Documents
SAP and ABAP Shortcuts
Logical Databases
Advantages of Logical Databases
Copy to Clipboard
BAPI Create Material
Finding and Running Programs in ABAP
Program Syntax Check and Extended Syntax Check
Select Options upper lower case
BAPI Sales Order Simulate
Get PLANT and Description for a Material
MRP List Function Module
Production Planning and Controlling
Applications in SAP R3
Tool Based Reports
Important Transaction Codes in SAP
SAP Stock per Bin
Pop Up a Calender
Module to Read a File
Module to Reverse A String
Run an Executable Program with Parameters
Program for POP up Screen
Printing Selection Parameters for a Report
Uploading and DownLoading a Report
SAP ABAP Version Management
SAP ABAP Short Cuts
List of Important System Variables

ABAP MACROS
ABAP Calling a File Selector
Some Important Function Modules
ABAP String Operations

ABAP Function Module to Check Validity of Date
Transfer Internal Table Contents to a File

SAP ABAP Program Types
BAPI to Read Customer Data
Checking Validity of Date
Download to Application Server
ABAP Debugger Breakpoint and Watchpoint
BAPI to get Company Code Details
Creating Material Using BAPI part 2
Generating a Valid Password
Logical Databases Structure
Making Fields OBligatory in Selection Screen
ABAP Views
Getting a Company Code for a Plant
Importing contents of Clipboard in SAP
Getting a Plant for a Material
Plant Material and Storage Location
SAP Production Planning Standard Reports
NetWeaver Components
Supported Databases and Operating Systems