Bapi or FM to create a downpayment document(F-47)

Hi,
Need an FM/BAPI to create an down payment document similar to F-47
Document type : KA
Spl G/L Acc Indicator : A
Account = Vendor No
Regards
Shiva

RFIDPT_ACC_DOCUMENT_POST_ADJ, conforme mapeamento dos campos abaixo:
T_ACCHD
Descrição do Campo
Tabela/Valor Fixo
Coluna
MANDT
Mandante do sistema
SY-MANDT
AWTYP
Operação de referência
BKPF
GLVOR
Ação de negócio
RFBU
TCODE
Código da transação
F-47/FBA6
BKTXT
Texto de cabeçalho do documento (código do aprovador)
USNAM
Nome do usuário
SY-UNAME
T_ACCIT
Descrição do Campo
Tabela/Valor Fixo
Coluna
MANDT
Mandante do sistema
SY-MANDT
POSNR
Número do item
Sequencial
BUKRS
Código da empresa
GJAHR
Ano do exercício fiscal
BUZEI
Número do item do documento
BLDAT
Data do documento
BUDAT
Data do lançamento
BLART
Tipo do documento
KA
XBLNR
Referência do documento
VORGN
Ação de negócio
AZAF
BUPLA
Local de negócio
UMSKZ
Código do razão especial
F
ZUMSK
Código de Razão Especial de destino
B
BSTAT
Status do documento
S
BSCHL
Chave de lançamento
39
SHKZG
Direção do movimento (D/C)
H
KOART
Tipo da conta: determina se aborda o livro Razão ou os livros auxiliares
K
LIFNR
Código do fornecedor
ZTERM
Condição de pagamento
C001
ZFBDT
Data base para pagamento
ZLSPR
Chave para o bloqueio de pagamento
W
EMPFB
Recebedor de pagamento/pagador
ZOUNR
Atribuição do item
SGTXT
Texto do item
PRCTR
Centro de lucro
PPRCTR
Centro de lucro do parceiro
KIDNO
Referência do pagamento
NEBTR
Valor do documento (+/-)
T_ACCCR
Descrição do Campo
Tabela/Valor Fixo
Coluna
MANDT
Mandante do sistema
SY-MANDT
POSNR
Número do item
Sequencial
WAERS
Código da moeda
BRL
WRBTR
Montante do item

Similar Messages

  • BAPI to create a billing document with reference to delivery or sales order

    Hi,
    Does anyone know any BAPI or function module that allows the creation of a billing document with reference to a sales order or to a delivery.
    Maybe the BAPI_BILLINGDOC_CREATEFROMDATA may be used to create a billing document with reference to a sales document, but i'm looking for a solution where I only need to indicate the number of the reference sales order or the reference delivery and maybe some few data more without the need of transfer all the items and conditions information.
    Thanks.
    Kind regards,
    Paulo Sousa

    Hello Paulo,
    To create a billing document based on a delivery use BAPI_BILLINGDOC_CREATEMULTIPLE. In table BILLINGDATAIN insert one line with the following data:
    REF_DOC = Delivery number
    REF_DOC_CA = 'J'
    If it runs fine, table SUCCESS will bring back useful data, like BILL_DOC (Billing document number).
    Regards,
    Joã

  • How to create an Accounting Document by calling BAPI

    Hai friends ,
    please tell me how to call this BAPI and fulfill all the parameters .. Please help me , I dont know the head and tail of it ...
    create an Accounting Document by calling BAPI  BAPI_ACC_DOCUMENT_POST
    Below is the step to fill the parameters for BAPI:
    Enter company code, invoice no, invoice date, document type, header text into DOCUMENTHEADER
    Enter customer, item text, company code, payment term into ACCOUNTRECEIVABLE
    Enter offset account, company code, document type, item text into ACCOUNTGL
    Enter currency type u201800u2019, currency, exchange rate, amount into CURRENCYAMOUNT. Please note there will be two rows in this table, one positive amount and one negative amount
    Call the BAPI to create the AR document. If p_check is checked, call the BAPI only without COMMIT and then do the message processing
    If p_check is initial, COMMIT the data to the database tables.
    Check the RETURN table after each BAPI, if no u2018Eu2019 message type found, output the document no. Otherwise, output the error messge to the screen with the message type u2018Eu2019.
    thanks in advance ...

    Hi,
    Check the link
    http://www.sapbrainsonline.com/sapinfo/tutorial.php?artid=617
    http://sap.ittoolbox.com/groups/technical-functional/sap-dev/bapi_acc_document_post-error-1973720
    http://delaynomore.spaces.live.com/blog/cns!D2BFFB84EDFE4189!528.entry
    http://sap4.com/wiki/index.php?title=BAPI_ACC_DOCUMENT_POST
    http://www.sapfans.com
    Anurodh

  • Creating a sales document using BAPI in web dynpro by uploading a file

    Hi ALL,
    Can some one help me how to create a sales document using  BAPI by uploading a file as input...Can someone  provide me a sample program....
    Thanks n Regards,
    Praveenn.
    Edited by: praveenn on Aug 23, 2011 12:42 PM

    Hi Sri,
    Thx for the response...
    Here is the code that i followed for creating a BAPI_SALESORDER_CREATE1 by uploading a text file as input.
    Just create a Attribute  in the VIEW CONTEXT of type String.
    method ONACTIONCREATE_SO .
    types : Begin of ty_data,
             sales_org  type vkorg,
             doc_type   type AUART,
             DISTR_CHAN type VTWEG,
             DIVISION   type spart,
             material   type matnr,
             partn_role type PARVW,
             PARTN_NUMB type kunnr,
           end of ty_data.
      DATA  :it_table TYPE  TABLE OF ty_data,
             i_data   TYPE  TABLE OF string,
             l_string TYPE string,
             wa_table TYPE ty_Data,
             l_xstring TYPE xstring,
             fields TYPE string_table,
             lv_field TYPE string.
    DATA: wa_order_header_in TYPE BAPISDHD1,
          it_order_items_in  TYPE TABLE OF BAPISDITM,
          wa_order_items_in  TYPE BAPISDITM,
          it_order_partners  TYPE TABLE OF BAPIPARNR,
          wa_order_partners  TYPE BAPIPARNR,
          it_return TYPE TABLE OF BAPIRET2,
          wa_return TYPE BAPIRET2.
    DATA : sales_doc type bapivbeln-vbeln.
    DATA:
       node_zfinal_node  TYPE REF TO if_wd_context_node,
       elem_zfinal_node  TYPE REF TO if_wd_context_element,
       stru_zfinal_node  TYPE if_main_view=>element_zfinal_node .
    get single attribute
      wd_context->get_attribute(
      EXPORTING
      name =  'DATASOURCE'
      IMPORTING
      value = l_xstring ).
      CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
        EXPORTING
          in_xstring = l_xstring
        IMPORTING
          out_string = l_string.
    SPLIT l_string  AT cl_abap_char_utilities=>newline INTO TABLE i_data.
      LOOP AT i_data INTO l_string.
       SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
        READ TABLE fields INTO lv_field INDEX 1.
        wa_table-sales_org = lv_field.
        READ TABLE fields INTO lv_field INDEX 2.
        wa_table-doc_type = lv_field.
        READ TABLE fields INTO lv_field INDEX 3.
        wa_table-DISTR_CHAN = lv_field.
        READ TABLE fields INTO lv_field INDEX 4.
        wa_table-DIVISION = lv_field.
        READ TABLE fields INTO lv_field INDEX 5.
        wa_table-material  = lv_field.
        READ TABLE fields INTO lv_field INDEX 6.
        wa_table-partn_role  = lv_field.
        READ TABLE fields INTO lv_field INDEX 7.
        wa_table-partn_numb  = lv_field.
    APPEND wa_table TO it_table.
      ENDLOOP.
    loop at it_table into wa_table.
    clear : wa_order_header_in.
    wa_order_header_in-sales_org   = wa_table-sales_org.
    wa_order_header_in-doc_type    = wa_table-doc_type.
    wa_order_header_in-distr_chan  = wa_table-distr_chan.
    wa_order_header_in-division    = wa_table-division.
    clear : wa_order_items_in.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = wa_table-material
    IMPORTING
       OUTPUT        = wa_order_items_in-material.
    *wa_order_items_in-req_qty  = wa_table-req_qty.
    append wa_order_items_in to it_order_items_in.
    clear : wa_order_partners.
    wa_order_partners-partn_role = wa_table-partn_role.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input         = wa_table-partn_numb
    IMPORTING
       OUTPUT        = wa_order_partners-partn_numb
    *wa_order_partners-partn_numb = wa_table-partn_numb.
    append wa_order_partners to it_order_partners.
    endloop.
    CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
      EXPORTING
      SALESDOCUMENTIN               =
        order_header_in               = wa_order_header_in
      ORDER_HEADER_INX              =
      SENDER                        =
      BINARY_RELATIONSHIPTYPE       =
      INT_NUMBER_ASSIGNMENT         =
      BEHAVE_WHEN_ERROR             =
      LOGIC_SWITCH                  =
      TESTRUN                       =
      CONVERT                       = ' '
    IMPORTING
       SALESDOCUMENT                 = sales_doc
      tables
       RETURN                        = it_return
       ORDER_ITEMS_IN                = it_order_items_in
      ORDER_ITEMS_INX               =
        order_partners                = it_order_partners.
      ORDER_SCHEDULES_IN            =
    get message manager
    DATA: l_current_controller TYPE REF TO if_wd_controller,
           l_message_manager    TYPE REF TO if_wd_message_manager.
           l_current_controller ?= wd_this->wd_get_api( ).
    DATA:  v_message_text TYPE string.
    When Sales Order is created commit the data
    IF NOT sales_doc IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
       EXPORTING wait = 'X'.
      CONCATENATE 'Sales Document' sales_doc 'has been created.' INTO v_message_text SEPARATED BY space.
    Report Success message
      CALL METHOD l_message_manager->report_success
      EXPORTING
      message_text = v_message_text.
      ELSE.
      v_message_text = 'Error Creating Sales Order'.
    Report Error message
    CALL METHOD l_message_manager->report_error_message
    EXPORTING
    message_text = v_message_text.
    ENDIF.
    endmethod.
    Edited by: praveenn on Aug 30, 2011 2:41 PM

  • FM/BAPI to create a accrual document in FBS1 ?

    Hi,
    Id any one aware of any BAPI or FM that can be used to create and accrual document through FBS1.
    Thanks,

    How about BAPI_USER_ACTGROUPS_ASSIGN ...?
    (Found searching SE37 with pattern "BAPIUSER" ...)
    <u>Take care</u>: when using an CUA you might need to use BAPI_USER_LOCACTGROUPS_ASSIGN (to assign roles in the CUA master system).

  • How to create shipment cost document through BAPI?

    Hi SAP Guru,
    My requirement is to create shipment cost document through BAPI.
    Is there any standard BAPI to create Shipment cost documents? If any buddy no please help me out.I am in client place i have find out the solution..
    Thanks & Regards,
    Pankaj Sinha

    Hi Pankaj,
    See the following link for more help.
    IDOC/BAPI for changing Shipment cost number/document
    Regards

  • Error while using BAPI  to create Goods Receipt Document

    Hello All,
        While using the bapi BAPI_GOODSMVT_CREATE to create  Goods receipt document ,the following error is encountered:-
    Error Message:FOR OBJECT XABBELEGNR,NUMBER RANGE INTERVAL DOES NOT EXIST OM36.
    Do we need to create a number range object ??If yes,how and where to create ?
    Thanks,
    Deepti.

    Hi Deepti!
    There is only a valid interval missing, not the whole object.
    Maintenance can be done via transaction SNRO, enter your object XABBELEGNR in entry screen. (Alternatively use transaction OMJ6).
    Push button 'Number Ranges' and 'Change Intervals'. Here you can define an interval.
    Regards,
    Christian

  • LSMW me51n, how to create one PR document for all the records in the  file

    HI all,
    I need to create LSMW for t-code me51n -Create Purchase Requisition. I`m using Bapi BUS2105, method CREATEFROMDATA, idoc message type PREQCR, basic type PREQCR03. The problem is that the LSMW is creating different idoc and different PR document for every record in the source file. My requirement is to create one PR document for one source file (Every source file is different Purchase Requisition) . I`m trying to do this with writing some code(global functions ) in the 'Mapping and conversion rules'  events - BEGINOF_TRANSACTION_, ENDOF_TRANSACTION__..., but i`m not very sure what exactly i`m doing .
    Please help me resolve this problem, any help will be appreciated .
    Best regards, Emil Milchev.

    Thank you for you answer.
    But I have found faster way of doing it - two source structures, one HEADER and ONE ITEM.
    HEADER: one empty text field and identificator for it.
    ITEM: everything else.
    Then everything was just fine, i`ve mapped the different IDOC segments by PREQ_ITEM fields (equal values in the source file : 10-10-10..., 20-20-20,.... etc.) and put all required fields for my LSMW
    SOURCE FIELDS:
    Z_ME51N_V2 - MASS_UPLOAD - CREATE create
    Source Fields
    UPFILE                    upload file
                IDENT                          C(010)    ident
                                               Identifing Field Content: header
                TEXT                           C(001)
                UPFILE2                   123
                    IDENT                          C(010)    ident
                                                   Identifing Field Content: item
                    BSART                          C(004)    Document type
                    BANFN                          C(010)    Purchase requisition number
                    BNFPO_FOR_MAP                  N(005)    Item number of purchase req. for MAPPING acc.
                    BNFPO                          N(005)    Item number of purchase requisition
                    KNTTP                          C(001)    Account assignment category
                    PSTYP                          C(001)    Item category in purchasing document
                    MATNR                          C(018)    Material Number
                    WERKS                          C(004)    Plant
                    LGORT                          C(004)    Storage Location
                    MENGE                          N(013)    Purchase requisition quantity
                    EKGRP                          C(003)    Purchasing group
                    KONNR                          C(010)    Number of principal purchase agreement
                    KTPNR                          N(005)    Item number of principal purchase agreement
                    LIFNR                          C(010)    Desired Vendor
                    FLIEF                          C(010)    Fixed Vendor
                    AFNAM                          C(012)    Name of requisitioner/requester
                    PREIS                          AMT4(011) Price in purchase requisition
                    ABLAD                          C(025)    Unloading Point
                    WEMPF                          C(012)    Goods Recipient
                    PS_POSID                       C(024)    Work Breakdown Structure Element (WBS Element)
                    KOSTL                          C(011)    COST_CTR v bapito ?
                    NAME1                          C(040)    Name1 - Name of an address
                    NAME2                          C(040)    Name2 - Name of an address 2
                    STREET                         C(060)    Street
                    DELIVERY_DATE                  C(008)    Date on which the goods are to be delivered
                    TEXT                           C(132)    item text
    STRUCTURE RELATIONS :
    Structure Relations
    E1PREQCR              Header segment                                               <<<< UPFILE  upload file
               E1BPEBANC             Transfer Structure: Create Requisition Item                  <<<< UPFILE2 123
               E1BPEBKN              Transfer Structure: Create/Display Requisition Acct Assgt    <<<< UPFILE2 123
               E1BPEBANTX            BAPI Purchase Requisition: Item Text                         <<<< UPFILE2 123
               E1BPESUHC             Communication Structure: Limits                              <<<< UPFILE2 123
               E1BPESUCC             Communication Structure: Contract Limits                     <<<< UPFILE2 123
               E1BPESLLC             Communication Structure: Create Service Line                 <<<< UPFILE2 123
               E1BPESKLC             Create Comm. Structure: Acct Assgt Distr. for Service Line   <<<< UPFILE2 123
               E1BPESLLTX            BAPI Services Long Text                                      <<<< UPFILE  upload file
               E1BPMERQADDRDELIVERY  PO Item: Address Structure BAPIADDR1 for Inbound Delivery    <<<< UPFILE2 123
                   E1BPMERQADDRDELIVERY1 PO Item: Address Structure BAPIADDR1 for Inbound Delivery    <<<< UPFILE2 123
               E1BPPAREX             Ref. Structure for BAPI Parameter EXTENSIONIN/EXTENSIONOUT   <<<< UPFILE2 123
    MAINTAIN FIELD MAPPING AND... :
    the MAPPING between two IDOC`s segments:
    In first segment:
    E1BPEBANC                      Transfer Structure: Create Requisition Item
             Fields
                 PREQ_NO                      Purchase requisition number
                                     Source:  UPFILE2-BANFN (Purchase requisition number)
                                     Rule :   Transfer (MOVE)
                                     Code:    E1BPEBANC-PREQ_NO = UPFILE2-BANFN.
                 PREQ_ITEM                    Item number of purchase requisition
                                     Source:  UPFILE2-BNFPO (Item number of purchase requisition)
                                     Rule :   Transfer (MOVE)
                                     Code:    E1BPEBANC-PREQ_ITEM = UPFILE2-BNFPO.
    In second segment :
    E1BPEBKN                       Transfer Structure: Create/Display Requisition Acct Assgt
               Fields
                   PREQ_NO                      Purchase requisition number
                   PREQ_ITEM                    Item number of purchase requisition
                                       Source:  UPFILE2-BNFPO_FOR_MAP (Item number of purchase req. for MAPPING
                                       Rule :   Transfer (MOVE)
                                       Code:    E1BPEBKN-PREQ_ITEM = UPFILE2-BNFPO_FOR_MAP.
    After that everything was OK .

  • BAPI_GOODSMVT_CREATE to create a material document for consumable goods

    Hi All,
    I am using a BAPi  (BAPI_GOODSMVT_CREATE) to create a material document using a PO. Please note that the PO contain no material number. It contains short text. The account assignment is being copied in to the MIGO from PO (when i am doing the process manually without BAPI). But when i am using the BAPI at that time i am getting an error as:
    E M7                   036 No goods receipt possible for purchase order 45XXXXXXXXXX 00010 .
    Logically this should not happen as  when i do it manually i am able to post MIGO.
    Under goods movement header i am giving :
    posting date
    doc date
    text
    goods movement code :
    01
    GOODSMVT_ITEM
    plant
    mov type
    po number
    vendor
    line item
    short text
    cost cenrtre
    order no(int ord no)
    mov indicator: B
    GL account
    base unit of measure
    Where i am going wrong?

    Hi Jurgen
    In response to my post where i wrote my observations :
    As you have suggested i have removed the account assignment objects and now i am not getting the error as mentioned in my post but at the same time i notice in export parameters  in the bapi the following things which was not present earlier.
    GOODSMVT_HEADRET                   50000xxxxx2014
    MATERIALDOCUMENT                    50000xxxxx
    MATDOCUMENTYEAR                     2014
    Now another thing is i am not getting any entry in return table.... which i should get. Please note that my test run contains no values(X).
    i think i am near to the solution. Could you suggest any more crucial points i might be missing?"
    for this i found out that there is a way to solve this issue. My concern was why the material document was not updating .  Well this is how SAP behaves.
    To update it we have to run simultaneously another fm " BAPI_TRANSACTION_COMMIT".  This will update it in the mseg table which in turn will reflect it PO history. So my requirement is answered and fulfilled.
    Thank you so much for the replies and cooperation.
    Thank you all.

  • FI - creating statistical posting documents like transaction F-38

    Hi to all !
    We are using R3 version 46C.
    I would like to find a way to create statistical posting documents like transaction
    F-38 without using batch input. Any function or BAPI existing for it ??
    Thanks,
    Yuval Kaduri
    at Cellcom Israel.

    Hi to all !
    We are using R3 version 46C.
    I would like to find a way to create statistical posting documents like transaction
    F-38 without using batch input. Any function or BAPI existing for it ??
    Thanks,
    Yuval Kaduri
    at Cellcom Israel.

  • Problem in creating an account document using BAPI_ACC_DOCUMENT_POST

    Hi Experts,
    I have a porblem while creating an account document from BAPI_ACC_DOCUMENT_POST.
    The problem is acc document is geeting posted and I am getting an document number for that bapi, but its not getting saved to data base and I am getting the following error message
    "Document 1900004327 3000 does not exist in fiscal year 2005
    Message no. F5A397
    System Response
    The required document either does not exist in the fiscal year or is still being posted.
    When the document is read, archived documents are also considered."
    Please sugggest...
    We are using ECC 6.0
    Thanks,
    Suma.

    Hi,
    this means that the posting is not open...
    try with 2008...
    or else ask ur financial consultatto check, whether the 2005 is open or not.
    u also try posting manually using FB01 with same entries u r using for this BAPI...so that u can track the error.
    Also use BAPI_TRAACTION_COMMIT after bapi post.
    check ur subsystem which u r passing for the BAPI..
    wa_general-assetsubno = '0000'. Is it 3000 or 0000
    Try using 0...
    Edited by: Sumi Vasu on May 14, 2008 8:13 AM

  • BAPI or FM to create SCD (VI01)

    Hi All,
        I am looking for a bapi or FM which can be used to create Shipment Cost Document.
    BAPI_SHIPMENT_CREATE - is to create shipment i.e. using VT01N
    BAPI_SHIPMENT_COST_ESTIMATE - is used for shipment cost estimation not creation.
    Regards,
    Leona

    Hi,
      I have used the standard FM and standard sub routines to create this custom BAPI. The order in which I have used them are as follows.
    SD_SCD_INITIALIZE - to Initialize
    SD_SCD_ITEMS_CREATE - to create line items automatically - as this will not work in my case so i have to use the below standard sub routien
    SD_SHIPMENT_PROTOCOL_STOP - to suppres the pop up.
      PERFORM scd_item_create(saplv54c) USING  ta_tvft
                                               ta_tvftk
                                               ta_tvfp
                                               u_shp_wa
                                               wa_vttsf-tsnum
                                               u_t180
                                               co_true
                                     CHANGING  c_scd_wa
                                               l_retcode.
    To create line items where item category is maintained as manual in SPRO
    SD_SCD_ITEM_CHANGE - to update the manual changes done in line item.
    SD_SCD_CHANGE  - to COPY the work area into scd internal table
    SD_SCDS_CHECK_COMPLETE
    SD_SCDS_SAVE
    Regards,
    Leona

  • BAPI or FM to create Vendor Master

    I need a BAPI or FM/API to create a vendor master.  Yes I know, there is BAPI_VENDOR_CREATE but it does not allow you to import any data.  Is there a BAPI/FM/API that creates a vendor master while allowing you to import data (like BAPI_MATERIAL_SAVEDATA for materials).
    Thanks,
    Davis

    Refer to the following and award points if useful.BAPI is like using standard function modules.We will populate the parameters and handle errors from that.See the code below which is vendor debit posting.You can get an idea by the following code.
    See the start of selection if this is confusing to you and understand the usage
                       TABLES
    TABLES: VBAK,
            ADR6,
            TRDYSE01CM.
                       INCLUDE
    INCLUDE ZZUTI_STD_HEADER_FOOTER. "Standard header and footer
    TYPES DECLARATION
    TYPES:
      BEGIN OF T_CRMEMO,
        VBELN TYPE VBAK-VBELN,
        POSNR TYPE VBAP-POSNR,
        ERDAT TYPE VBAK-ERDAT,
        AUART TYPE VBAK-AUART,
        AUGRU TYPE VBAK-AUGRU,
        WAERK TYPE VBAK-WAERK,
        VKORG TYPE VBAK-VKORG,
        VTWEG TYPE VBAK-VTWEG,
        SPART TYPE VBAK-SPART,
        VDATU TYPE VBAK-VDATU,
        BSTNK TYPE VBAK-BSTNK,
        BSARK TYPE VBAK-BSARK,
        BSTDK TYPE VBAK-BSTDK,
        AEDAT TYPE VBAK-AEDAT,
        BUKRS_VF TYPE VBAK-BUKRS_VF,
        MATNR TYPE VBAP-MATNR,
        ZMENG TYPE VBAP-ZMENG,
        ZIEME TYPE VBAP-ZIEME,
      END OF T_CRMEMO,
      BEGIN OF T_CRMEMO_CHANGE,
        VBELN(90) TYPE C,
        POSNR TYPE VBAP-POSNR,
        ERDAT TYPE VBAK-ERDAT,
        AUART TYPE VBAK-AUART,
        AUGRU TYPE VBAK-AUGRU,
        WAERK TYPE VBAK-WAERK,
        VKORG TYPE VBAK-VKORG,
        VTWEG TYPE VBAK-VTWEG,
        SPART TYPE VBAK-SPART,
        VDATU TYPE VBAK-VDATU,
        BSTNK TYPE VBAK-BSTNK,
        BSARK TYPE VBAK-BSARK,
        BSTDK TYPE VBAK-BSTDK,
        AEDAT TYPE VBAK-AEDAT,
        BUKRS_VF TYPE VBAK-BUKRS_VF,
        MATNR TYPE VBAP-MATNR,
        ZMENG TYPE VBAP-ZMENG,
        ZIEME TYPE VBAP-ZIEME,
      END OF T_CRMEMO_CHANGE,
      BEGIN OF T_MVKE,
        MATNR  TYPE MVKE-MATNR,
        VKORG  TYPE MVKE-VKORG,
        VTWEG  TYPE MVKE-VTWEG,
        MTPOS  TYPE MVKE-MTPOS,
      END OF T_MVKE,
      BEGIN OF T_ORDERS,
        VBELV   TYPE VBFA-VBELV,
        POSNV   TYPE VBFA-POSNV,
        VBELN   TYPE VBFA-VBELN,
        POSNN   TYPE VBFA-POSNN,
        VBTYP_N TYPE VBFA-VBTYP_N,
      END OF T_ORDERS,
      BEGIN OF T_EKPO,
        EBELN   TYPE EKKO-EBELN,
        EBELP   TYPE EKPO-EBELP,
        WAERS   TYPE EKKO-WAERS,
        MENGE   TYPE EKPO-MENGE,
        MEINS   TYPE EKPO-MEINS,
        NETPR   TYPE EKPO-NETPR,
        PEINH   TYPE EKPO-PEINH,
        mwskz   TYPE EKPO-mwskz,
        TXJCD   TYPE EKPO-TXJCD,
      END OF T_EKPO,
      BEGIN OF T_EKBE,
        EBELN   TYPE EKBE-EBELN,
        EBELP   TYPE EKBE-EBELP,
        ZEKKN   TYPE EKBE-ZEKKN,
        VGABE   TYPE EKBE-VGABE,
        GJAHR   TYPE EKBE-GJAHR,
        BELNR   TYPE EKBE-BELNR,
        BUZEI   TYPE EKBE-BUZEI,
      END OF T_EKBE,
      BEGIN OF T_RBKP,
        BELNR   TYPE RBKP-BELNR,
        GJAHR   TYPE RBKP-GJAHR,
        BLDAT   TYPE RBKP-BLDAT,
        BUDAT   TYPE RBKP-BUDAT,
        XBLNR   TYPE RBKP-XBLNR,
        LIFNR   TYPE RBKP-LIFNR,
        RMWWR   TYPE RBKP-RMWWR,
        WMWST1  TYPE RBKP-WMWST1,
        XRECH   TYPE RBKP-XRECH,
        STBLG   TYPE RBKP-STBLG,
      END OF T_RBKP,
      BEGIN OF T_CDHDR,
        OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
        OBJECTID   TYPE CDHDR-OBJECTID,
        CHANGENR   TYPE CDHDR-CHANGENR,
        UDATE      TYPE CDHDR-UDATE,
        UTIME      TYPE CDHDR-UTIME,
      END OF T_CDHDR,
      BEGIN OF T_CDPOS,
        OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
        OBJECTID   TYPE CDHDR-OBJECTID,
        CHANGENR   TYPE CDHDR-CHANGENR,
        TABNAME    TYPE CDPOS-TABNAME,
        TABKEY     TYPE CDPOS-TABKEY,
        FNAME      TYPE CDPOS-FNAME,
        CHNGIND    TYPE CDPOS-CHNGIND,
        VALUE_NEW  TYPE CDPOS-VALUE_NEW,
        VALUE_OLD  TYPE CDPOS-VALUE_OLD,
      END OF T_CDPOS,
      BEGIN OF T_CHANGE_DOCS,
        OBJECTCLAS TYPE CDHDR-OBJECTCLAS,
        OBJECTID   TYPE CDHDR-OBJECTID,
        CHANGENR   TYPE CDHDR-CHANGENR,
        UDATE      TYPE CDHDR-UDATE,
        UTIME      TYPE CDHDR-UTIME,
        TABNAME    TYPE CDPOS-TABNAME,
        TABKEY     TYPE CDPOS-TABKEY,
        FNAME      TYPE CDPOS-FNAME,
        CHNGIND    TYPE CDPOS-CHNGIND,
        VALUE_NEW  TYPE CDPOS-VALUE_NEW,
        VALUE_OLD  TYPE CDPOS-VALUE_OLD,
      END OF T_CHANGE_DOCS,
      BEGIN OF T_SUCCESS,
        crmemo    TYPE VBAK-vbeln,
        cmemo     TYPE VBAK-vbeln,
        orders    TYPE VBAK-vbeln,
        po        TYPE VBAK-vbeln,
        miro_no   TYPE VBAK-vbeln,
        text(20)  TYPE C,
      END OF T_SUCCESS,
      BEGIN OF T_ERROR,
        crmemo  TYPE VBAK-vbeln,
        cmemo     TYPE VBAK-vbeln,
        orders    TYPE VBAK-vbeln,
        po        TYPE VBAK-vbeln,
        miro_no   TYPE VBAK-vbeln,
        text(100) TYPE C,
      END OF T_ERROR.
                          WORKAREA DECLARATION
    DATA:
      WA_CRMEMO  TYPE T_CRMEMO,
      WA_CRMEMO_CHANGE TYPE T_CRMEMO_CHANGE,
      WA_MVKE    TYPE T_MVKE,
      WA_ORDERS  TYPE T_ORDERS,
      WA_CMEMO   TYPE  T_ORDERS,
      WA_PO      TYPE T_ORDERS,
      WA_EKPO    TYPE T_EKPO,
      WA_EKBE    TYPE T_EKBE,
      WA_EKBE_TEMP TYPE T_EKBE,
      WA_RBKP    TYPE T_RBKP,
      WA_RBKP_TMP TYPE T_RBKP,
      WA_CDHDR   TYPE T_CDHDR,
      WA_CDPOS   TYPE T_CDPOS,
      WA_CHANGE_DOCS TYPE T_CHANGE_DOCS,
      WA_CRMEMO_MR8M  TYPE T_CRMEMO,
      WA_SUCCESS TYPE T_SUCCESS,
      WA_ERROR   TYPE T_ERROR,
      WA_SUCCESS_MR8M TYPE T_SUCCESS,
      WA_ERROR_MR8M   TYPE T_ERROR.
    *--Work area for all the internal tables used for Sending Mail
    DATA :
      WA_OBJPACK TYPE SOPCKLSTI1,
      WA_OBJHEAD TYPE SOLISTI1,
      WA_OBJBIN TYPE SOLISTI1,
      WA_OBJTXT TYPE SOLISTI1,
      WA_RECLIST TYPE SOMLRECI1 .
    DATA:
    *-- Structure to hold Invoice Header Data
      x_docheader LIKE bapi_incinv_create_header,
    *-- Structure to hold Reversal Posting Data
      x_rev_post LIKE BAPI_INCINV_FLD.
                     INTERNAL TAABLE DECLARATION
    DATA:
      IT_CRMEMO      TYPE STANDARD TABLE OF T_CRMEMO   WITH HEADER LINE,
      IT_CRMEMO_CHANGE TYPE STANDARD TABLE OF T_CRMEMO_CHANGE WITH HEADER LINE,
      IT_MVKE        TYPE STANDARD TABLE OF T_MVKE     WITH HEADER LINE,
      IT_CRMEMO_MIRO TYPE STANDARD TABLE OF T_CRMEMO   WITH HEADER LINE,
      IT_CRMEMO_MR8M TYPE STANDARD TABLE OF T_CRMEMO   WITH HEADER LINE,
      IT_ORDERS      TYPE STANDARD TABLE OF T_ORDERS   WITH HEADER LINE,
      IT_CMEMO       TYPE STANDARD TABLE OF T_ORDERS   WITH HEADER LINE,
      IT_PO          TYPE STANDARD TABLE OF T_ORDERS   WITH HEADER LINE,
      IT_EKPO        TYPE STANDARD TABLE OF T_EKPO     WITH HEADER LINE,
      IT_EKBE        TYPE STANDARD TABLE OF T_EKBE     WITH HEADER LINE,
      IT_EKBE_TEMP    TYPE STANDARD TABLE OF T_EKBE    WITH HEADER LINE,
      IT_RBKP        TYPE STANDARD TABLE OF T_RBKP     WITH HEADER LINE,
      IT_CDHDR       TYPE STANDARD TABLE OF T_CDHDR    WITH HEADER LINE,
      IT_CDPOS       TYPE STANDARD TABLE OF T_CDPOS    WITH HEADER LINE,
      IT_CHANGE_DOCS TYPE STANDARD TABLE OF T_CHANGE_DOCS WITH HEADER LINE,
      IT_SUCCESS     TYPE STANDARD TABLE OF T_SUCCESS  WITH HEADER LINE,
      IT_ERROR       TYPE STANDARD TABLE OF T_ERROR    WITH HEADER LINE,
      IT_SUCCESS_MR8M TYPE STANDARD TABLE OF T_SUCCESS WITH HEADER LINE,
      IT_ERROR_MR8M  TYPE STANDARD TABLE OF T_ERROR    WITH HEADER LINE.
    *-- Internal table to hold Invoice Item Data
    DATA:BEGIN OF it_itemdata OCCURS 0.
           INCLUDE STRUCTURE bapi_incinv_create_item.
    DATA:END OF it_itemdata.
    *-- Internal table to hold Invoice Acct Assignment Data
    DATA:BEGIN OF it_ACCOUNTingdata OCCURS 0.
           INCLUDE STRUCTURE BAPI_INCINV_CREATE_ACCOUNT.
    DATA:END OF it_accountingdata.
    *-- Internal table to hold BAPI return data
    DATA: BEGIN OF it_return OCCURS 0.
            INCLUDE STRUCTURE bapiret2.  "Return Parameter.
    DATA: END OF it_return.
    *-- Internal table to hold BAPI return data
    DATA: BEGIN OF it_return_mr8m OCCURS 0.
            INCLUDE STRUCTURE bapiret2.  "Return Parameter.
    DATA: END OF it_return_mr8m.
    *--MAIL related Internal tables
    DATA: X_DOC_CHNG TYPE SODOCCHGI1,                      " document attributes
          IT_OBJPACK TYPE STANDARD TABLE OF SOPCKLSTI1,    " attachment table
          IT_OBJHEAD TYPE STANDARD TABLE OF SOLISTI1,      " object header table
          IT_OBJBIN TYPE STANDARD TABLE OF SOLISTI1,       " binary table
          IT_OBJTXT TYPE STANDARD TABLE OF SOLISTI1,       " object text
          IT_RECLIST TYPE STANDARD TABLE OF SOMLRECI1,     " mail recipients
          it_compressed_list TYPE STANDARD TABLE OF SOLI,
          it_pdf_list TYPE STANDARD TABLE OF TLINE,
          it_pdf  TYPE tline OCCURS 10 WITH HEADER LINE,
          it_html  TYPE solisti1   OCCURS 10  WITH HEADER LINE,
    *-- Internal table for MIME data (in CHAR format)
          it_temp   TYPE bapiqcmime OCCURS 10 WITH HEADER LINE,
    *-- Internal table for storing data
          it_mime(255) TYPE c OCCURS 10 WITH HEADER LINE.
    GLOBAL VARIABLES                                                     *
    DATA: V_PGM_ID      TYPE SY-REPID,                    " Program id
          v_zterm       TYPE lfb1-zterm,                  " Payment Terms
          v_text(75)    TYPE c,                           " To store error or success text
          v_itemno(6)   TYPE n,                           " To Increment Item No. for BAPI
          v_docnr       LIKE bapi_incinv_fld-inv_doc_no,  " For MIRO document number
          v_year1       LIKE bapi_incinv_fld-fisc_year,   " For MIRO Fiscal year
          v_spono       type TSP01-RQIDENT,               " For Spool No.
          v_type        type SOODK-OBJTP,                 " For Spool Type
          V_CRMEMO_QTY  TYPE VBAP-ZMENG,                  " For CR Memo Qty.
          V_LINE_AMOUNT TYPE EKPO-NETPR,                  " For CR Memo Item Qty.
          V_GROSSAMT    TYPE EKPO-NETPR,                  " For CR Memo Grand Qty.
          v_tax_per(3)  type n,                           " For CR Memo Tax amount %
          v_tax_amt     TYPE EKPO-NETPR,                  " For CR Memo Tax amount
          v_flag(1)     type c,                           " Flag to process fruther
          v_tot_s_mr8m  TYPE i,                           " For MR8M Success Records
          v_tot_e_mr8m  TYPE i,                           " For MR8M Error Records
          V_DATE        TYPE SY-DATUM,                    " For Sel. Screen Date
          V_DATE2(10)   TYPE C,                           " For EMail Date
          V_TIME(10)    TYPE C,                           " For EMail Time
          V_TIME2(10)   TYPE C,                           " For EMail Time
          V_INFO(100)   TYPE C,                           " For EMail Body Text
          V_TABLE_LINES TYPE SY-TABIX,                    " To Increment Email Count
          V_TEXT2       TYPE STRING   ,                   " For EMail Id text
          v_lines       TYPE i,                           " To Store PDF Lines
          v_temp(500)   TYPE c,                           " To Convert to 255 char format
          v_offset      TYPE p,                           " To Convert to 255 char format
          v_lineslen    TYPE i,                           " To Convert to 255 char format
          v_mimelen     TYPE i,                           " To Convert to 255 char format
          v_tabix       type sy-tabix.                    " To Convert to 255 char format
    CONSTANTS                                                            *
    CONSTANTS:
      C_X(1)            TYPE C          VALUE 'X',       " Constant X or Flag
      C_E(1)            TYPE C          VALUE 'E',       " For Error check
      c_v(1)            TYPE C          VALUE 'V',       " For PO Docs
      c_o(1)            TYPE C          VALUE 'O',       " For Order Docs
      c_c(1)            TYPE C          VALUE 'C',       " For Credit Memo Docs
      c_k(1)            TYPE C          VALUE 'K',       " For CR Memo Docs
      c_u(1)            TYPE C          VALUE 'U',       " For Change tables Update
      c_ali(3)          TYPE C          VALUE 'ALI',     " For ALI Format
      c_vbak(4)         TYPE C          VALUE 'VBAK',    " For Change docs table
      C_01(2)           TYPE C          VALUE '01',      " For Serial No. & Reversal Reason
      C_02(2)           TYPE C          VALUE '02',      " For Reversal Reason
      c_blart           TYPE bkpf-blart VALUE 'RE',      " Document type
      C_MTPOS           TYPE MVKE-MTPOS VALUE 'BANS',    " Item Category group
      C_AUGRU(5)        TYPE C          VALUE 'AUGRU',   " Reason Code
      C_0000500205(10)  TYPE C          VALUE '0000500205', " GL Account #
      C_VERKBELEG(9)    TYPE C          VALUE 'VERKBELEG'.  " For Object Class
    *-- Horizontal tab & line feed constants
    CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
    CONSTANTS:
      C_TAB  TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB,
      C_CR_LF TYPE C VALUE CL_ABAP_CHAR_UTILITIES=>CR_LF .
    SELECTION SCREEN
    *-- Select Optons
    SELECTION-SCREEN: BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-001.
      SELECT-OPTIONS: S_AUART FOR VBAK-AUART OBLIGATORY NO INTERVALS,
                                                         " Sales Document Type
                      S_AUGRU FOR VBAK-AUGRU OBLIGATORY NO INTERVALS,
                                                         " Order reason
                      S_ERDAT FOR VBAK-ERDAT OBLIGATORY.
                                        " Date on which the record was created
    SELECTION-SCREEN: END OF BLOCK B01.
    *-- Mail Sending Options
    SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-004.
      PARAMETERS:P_EMAIL AS CHECKBOX DEFAULT SPACE USER-COMMAND V_COM .
      PARAMETERS : P_MODE TYPE SO_ESCAPE   default 'U' MODIF ID US1.
      SELECT-OPTIONS: S_EMAIL FOR ADR6-SMTP_ADDR
                                          NO INTERVALS MODIF ID US2.
    SELECT-OPTIONS: S_EMAIL FOR TRDYSE01CM-USERNAME
                                         NO INTERVALS MODIF ID US2.
      SELECTION-SCREEN: BEGIN OF LINE.
        SELECTION-SCREEN: COMMENT 55(40) TEXT-019 MODIF ID US2.
      SELECTION-SCREEN: END OF LINE.
    SELECTION-SCREEN END OF BLOCK B2.
               WORK AREA for SELECT-OPTIONS
    DATA :  X_EMAIL LIKE S_EMAIL.   "Work area for EMAIL select-options
    INITIALIZATION
    INITIALIZATION.
    *-- Default values for Sales Document Type
      CLEAR S_AUART[].
      S_AUART-SIGN = 'I'.
      S_AUART-OPTION = 'EQ'.
      S_AUART-LOW = 'CR'.
      APPEND S_AUART.
      CLEAR S_AUART.
    *-- Default values for Date on which the record was created
      V_DATE = ( SY-DATUM - 1 ).
      CLEAR S_ERDAT[].
      S_ERDAT-SIGN = 'I'.
      S_ERDAT-OPTION = 'EQ'.
      S_ERDAT-LOW =  SY-DATUM.
      S_ERDAT-HIGH =  SY-DATUM.
      APPEND S_ERDAT.
      CLEAR S_ERDAT.
                       TOP OF PAGE                                       *
    TOP-OF-PAGE.
    *-- Displaying standard header.
      PERFORM std_top_of_page USING sy-title.
    A T  S E L E C T I O N   S C R E E N  O U T P U T
    *-- For modifying the selection screen layout
    AT SELECTION-SCREEN OUTPUT.
      PERFORM F_MODIFY_SCREEN.
                       AT SELECTION SCREEN.                              *
    AT SELECTION-SCREEN.
    *-- Subroutine to Validate selection screen fields
      PERFORM f_validate.
    START-OF-SELECTION                                                  *
    *START-OF-SELECTION.*
    **-- Fetch the Credit Memo Requests documents*
      *PERFORM F_GET_CREDIT_MEMO_REQUEST.*
      *IF NOT IT_CRMEMO[] IS INITIAL.*
    **-- Fetch Item Category Group*
        *PERFORM F_GET_MVKE_DOCS.*
    **-- Fetch Sales Order documents, PO Documents and Credit Memos*
        *PERFORM F_GET_SO_PO_DOCS.*
      *ENDIF.*
    **-- If Credit memo request internal table have an change records then*
       fetch the change documents from CDHDR and CDPOS*
      *IF NOT IT_CRMEMO_CHANGE[] IS INITIAL.*
    **-- Fetch Change Documents for CR Memos from CDHDR and CDPOS tables*
        *PERFORM F_GET_CHANGED_DOCS.*
      *ENDIF.*
    **-- Fetch Purchasing Document Item Details*
      *IF NOT IT_PO[] IS INITIAL.*
        *PERFORM F_GET_EKPO.*
      *ENDIF.*
    **-- Fetch MIRO Vendor based on the PO Details*
      IF NOT IT_EKPO[] IS INITIAL.
        PERFORM F_GET_VENDOR.
      ENDIF.
    END-OF-SELECTION                                                    *
      if v_flag is initial.
    *-- Process Vendor Debit Postings
        PERFORM F_PROCESS_MIRO.
    *-- Process Reversal Postings of Vendor Automatic Debits using TCODE MR8M
        PERFORM F_PROCESS_MR8M.
    *-- Send mail,if user enters Email id's and Email Mode is not initial
        IF P_EMAIL = C_X AND P_MODE IS NOT INITIAL AND S_EMAIL[] IS NOT INITIAL.
    *-- Get spool id
          perform f_spool_id.
    *-- EMail Logic
          PERFORM F_MAIL_LOGIC.
        ENDIF.
    *-- display the EMail RSCONN01 and Sussess and Error records of MIRO and MR8M
        perform f_display_report.
      else.
    *-- Else exit the process
        exit.
      endif.
    *&      Form  F_MODIFY_SCREEN
          A Form routine to modify the screen
    FORM F_MODIFY_SCREEN .
    *-- To Modify Mail Sending Options
      LOOP AT SCREEN.
        IF P_EMAIL = C_X.
          IF SCREEN-GROUP1 = 'US1' .
            SCREEN-INVISIBLE = 0.
            SCREEN-ACTIVE = 1.
            SCREEN-INPUT = 0.
            MODIFY SCREEN.
          ENDIF.
          IF SCREEN-GROUP2 = 'US2' .
            SCREEN-INVISIBLE = 0.
            SCREEN-ACTIVE = 1.
            MODIFY SCREEN.
          ENDIF.
        ELSEIF P_EMAIL = SPACE.
          IF SCREEN-GROUP1 = 'US1' .
            SCREEN-INVISIBLE = 1.
            SCREEN-ACTIVE = 0.
            MODIFY SCREEN.
          ENDIF.
          IF SCREEN-GROUP1 = 'US2' .
            SCREEN-INVISIBLE = 1.
            SCREEN-ACTIVE = 0.
            MODIFY SCREEN.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " F_MODIFY_SCREEN
    *&      Form  f_validate
          Validation of Selection-Screen Inputs
    FORM f_validate .
    *-- Validate Sales Document Type
      if not s_AUART[] is initial.
        select  AUART
          into s_AUART-low
          from TVAK up to 1 rows
          where AUART in s_AUART.
        endselect.
        if sy-subrc  0.
          message E000 with 'Invalid Sales Document Type'(e01) .
        endif.
      ENDIF.
    *-- Validate Order reason (reason for the business transaction)
      if not s_AUGRU[] is initial.
        select  AUGRU
          into s_AUGRU-low
          from TVAU up to 1 rows
          where AUGRU in s_AUGRU.
        endselect.
        if sy-subrc  0.
          message E000 with 'Invalid Order reason'(e02) .
        endif.
      endif.
    ENDFORM.                    " f_validate
    *&      Form  F_GET_CREDIT_MEMO_REQUEST
          Fetch Credit memo requests from VBAK & VBAP
    FORM F_GET_CREDIT_MEMO_REQUEST .
      SELECT A~VBELN
             B~POSNR
             A~ERDAT
             A~AUART
             A~AUGRU
             A~WAERK
             A~VKORG
             A~VTWEG
             A~SPART
             A~VDATU
             A~BSTNK
             A~BSARK
             A~BSTDK
             A~AEDAT
             A~BUKRS_VF
             B~MATNR
             B~ZMENG
             B~ZIEME
        INTO TABLE IT_CRMEMO
        FROM ( VBAK AS A
        INNER JOIN VBAP AS B ON AVBELN = BVBELN )
        WHERE ( A~ERDAT IN S_ERDAT
          OR  A~AEDAT IN S_ERDAT )
          AND A~AUART IN S_AUART.
      IF SY-SUBRC = 0.
        SORT IT_CRMEMO BY VBELN POSNR.
      ELSE.
        MESSAGE I000 WITH 'No Credit Memo Request selected'(002).
        v_flag = C_X.
        stop.
      ENDIF.
    ENDFORM.                    " F_GET_CREDIT_MEMO_REQUEST
    *&      Form  F_GET_MVKE_DOCS
          Fetch Sales Data for Material
    FORM F_GET_MVKE_DOCS .
      DATA: LV_TABIX TYPE SY-TABIX.
    *-- Fetch Sales Data for Material
      SELECT MATNR      " Material Number
             VKORG      " Sales Organization
             VTWEG      " Distribution Channel
             MTPOS      " Item category group from material master
        FROM MVKE       " Sales Data for Material
        INTO TABLE IT_MVKE
        FOR ALL ENTRIES IN IT_CRMEMO
        WHERE MATNR = IT_CRMEMO-MATNR
          AND VKORG = IT_CRMEMO-VKORG
          AND VTWEG = IT_CRMEMO-VTWEG.
      IF SY-SUBRC = 0.
        SORT IT_MVKE BY MATNR VKORG VTWEG MTPOS.
      ENDIF.
    *-- Validate Item category group if MVKE-MTOPS  'BANS' then ignore CM Request line item
      LOOP AT IT_CRMEMO INTO WA_CRMEMO.
        LV_TABIX = SY-TABIX.
        READ TABLE IT_MVKE INTO WA_MVKE WITH KEY MATNR = WA_CRMEMO-MATNR
                                                 VKORG = WA_CRMEMO-VKORG
                                                 VTWEG = WA_CRMEMO-VTWEG
                                                 MTPOS = C_MTPOS
                                                 BINARY SEARCH.
        IF SY-SUBRC  0.
          DELETE IT_CRMEMO INDEX LV_TABIX.    " Delete CR memo records
        ELSE.
    *-- Else check for credit memo request change date is not initial, and
      append those records to IT_CRMEMO_CHANGE internal table to retrive
      change documents
          IF NOT WA_CRMEMO-AEDAT IS INITIAL.
            WA_CRMEMO_CHANGE-VBELN = WA_CRMEMO-VBELN.
            WA_CRMEMO_CHANGE-POSNR = WA_CRMEMO-POSNR.
            WA_CRMEMO_CHANGE-ERDAT = WA_CRMEMO-ERDAT.
            WA_CRMEMO_CHANGE-AUART = WA_CRMEMO-AUART.
            WA_CRMEMO_CHANGE-AUGRU = WA_CRMEMO-AUGRU.
            WA_CRMEMO_CHANGE-WAERK = WA_CRMEMO-WAERK.
            WA_CRMEMO_CHANGE-VKORG = WA_CRMEMO-VKORG.
            WA_CRMEMO_CHANGE-VTWEG = WA_CRMEMO-VTWEG.
            WA_CRMEMO_CHANGE-SPART = WA_CRMEMO-SPART.
            WA_CRMEMO_CHANGE-VDATU = WA_CRMEMO-VDATU.
            WA_CRMEMO_CHANGE-BSTNK = WA_CRMEMO-BSTNK.
            WA_CRMEMO_CHANGE-BSARK = WA_CRMEMO-BSARK.
            WA_CRMEMO_CHANGE-BSTDK = WA_CRMEMO-BSTDK.
            WA_CRMEMO_CHANGE-AEDAT = WA_CRMEMO-AEDAT.
            WA_CRMEMO_CHANGE-BUKRS_VF = WA_CRMEMO-BUKRS_VF.
            WA_CRMEMO_CHANGE-MATNR = WA_CRMEMO-MATNR.
            WA_CRMEMO_CHANGE-ZMENG = WA_CRMEMO-ZMENG.
            WA_CRMEMO_CHANGE-ZIEME = WA_CRMEMO-ZIEME.
            APPEND WA_CRMEMO_CHANGE TO IT_CRMEMO_CHANGE.
            CLEAR WA_CRMEMO_CHANGE.
          ENDIF.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " F_GET_MVKE_DOCS
    *&      Form  F_GET_SO_PO_DOCS
          Fetch the Sales Order documents, PO documents, & Credit Memo
    FORM F_GET_SO_PO_DOCS.
    *-- Fetch Preceding sales orders based on the credit memo request
      SELECT VBELV
             POSNV
             VBELN
             POSNN
             VBTYP_N
        FROM VBFA
        INTO TABLE IT_ORDERS
        FOR ALL ENTRIES IN IT_CRMEMO
        WHERE VBELN = IT_CRMEMO-VBELN
          AND POSNN = IT_CRMEMO-POSNR
          AND VBTYP_N = C_K
          AND VBTYP_V = C_C.
      IF SY-SUBRC = 0.
        SORT IT_ORDERS BY VBELV POSNV.
    *-- Fetch Subsequent PO documents & Credit Memo based on the sales orders
        SELECT VBELV
               POSNV
               VBELN
               POSNN
               VBTYP_N
          FROM VBFA
          INTO TABLE IT_PO
          FOR ALL ENTRIES IN IT_ORDERS
          WHERE VBELV = IT_ORDERS-VBELV
            AND POSNV = IT_ORDERS-POSNV
            AND VBTYP_N IN (C_V,C_O)
            AND VBTYP_V = C_C.
        IF SY-SUBRC = 0.
          SORT IT_PO BY VBTYP_N.
    *-- Copy the IT_PO internal table contents to IT_CMEMO internal table
          IT_CMEMO[] = IT_PO[].
    *-- Delete PO documents from IT_CMEMO internal table
          DELETE IT_CMEMO WHERE VBTYP_N = C_V.
          SORT IT_CMEMO BY VBELN POSNN.
          IF IT_CMEMO[] IS INITIAL.
            MESSAGE I000 WITH 'No Credit Memo are available for CM Request'(003).
           v_flag = c_x.
           stop.
          ENDIF.
    *-- Delete Credit Memo documents from IT_PO internal table
          DELETE IT_PO WHERE VBTYP_N = C_O.
          SORT IT_PO BY VBELN POSNN.
        ENDIF.
      ENDIF.
    ENDFORM.                    " F_GET_SO_PO_DOCS
    *&      Form  F_GET_CHANGED_DOCS
          Fetch Change Documents for CR Memos from CDHDR and CDPOS tables
    FORM F_GET_CHANGED_DOCS .
    *-- Fetch Change Documents for CR Memos from CDHDR
      SELECT OBJECTCLAS
             OBJECTID
             CHANGENR
             UDATE
             UTIME
      FROM CDHDR
      INTO TABLE IT_CDHDR
      FOR ALL ENTRIES IN IT_CRMEMO_CHANGE
      WHERE OBJECTCLAS = C_VERKBELEG
        AND OBJECTID   = IT_CRMEMO_CHANGE-VBELN
       AND UDATE      = IT_CRMEMO_CHANGE-AEDAT
      IF SY-SUBRC = 0.
        SORT IT_CDHDR BY OBJECTCLAS OBJECTID CHANGENR.
    *-- Fetch Change Documents for CR Memos from CDPOS
        SELECT OBJECTCLAS
               OBJECTID
               CHANGENR
               TABNAME
               TABKEY
               FNAME
               CHNGIND
               VALUE_NEW
               VALUE_OLD
          FROM CDPOS
          INTO TABLE IT_CDPOS
          FOR ALL ENTRIES IN IT_CDHDR
          WHERE OBJECTCLAS = C_VERKBELEG
            AND OBJECTID   = IT_CDHDR-OBJECTID
            AND CHANGENR   = IT_CDHDR-CHANGENR
            AND TABNAME    = C_VBAK
            AND FNAME      = C_AUGRU
            AND CHNGIND    = C_U.
        IF SY-SUBRC = 0.
          SORT IT_CDPOS BY OBJECTCLAS OBJECTID CHANGENR.
        ENDIF.
      ENDIF.
    ENDFORM.                    " F_GET_CHANGED_DOCS
    *&      Form  F_GET_EKPO
          Fetch Purchasing Document Item Details
    FORM F_GET_EKPO .
    *-- Fetch Purchasing Document Item Details
      SELECT A~EBELN
             B~EBELP
             A~WAERS
             B~MENGE
             B~MEINS
             B~NETPR
             B~PEINH
             B~mwskz
             B~TXJCD
      INTO TABLE IT_EKPO
      FROM ( EKKO AS A
      INNER JOIN EKPO AS B ON AEBELN = BEBELN )
      FOR ALL ENTRIES IN IT_PO
      WHERE A~EBELN = IT_PO-VBELN
        AND B~EBELP = IT_PO-POSNN+1(5).
      IF SY-SUBRC = 0.
        SORT IT_EKPO BY EBELN EBELP.
      ENDIF.
    ENDFORM.                    " F_GET_EKPO
    *&      Form  F_GET_VENDOR
          Fetch MIRO Vendor details based on the PO Details
    FORM F_GET_VENDOR .
    DATA: LV_TABIX TYPE SY-TABIX.
    *-- Fetch History per Purchasing Document records for all the PO records
      SELECT EBELN
             EBELP
             ZEKKN
             VGABE
             GJAHR
             BELNR
             BUZEI
      FROM EKBE
      INTO TABLE IT_EKBE
      FOR ALL ENTRIES IN IT_EKPO
      WHERE EBELN = IT_EKPO-EBELN
        AND EBELP = IT_EKPO-EBELP
        AND VGABE = '2'.
       and STBLG = space.
      IF SY-SUBRC = 0.
        SORT IT_EKBE BY BELNR GJAHR.
    *-- Fetch the vendor details based on table IT_EKBE internal table
        SELECT BELNR
               GJAHR
               BLDAT
               BUDAT
               XBLNR
               LIFNR
               RMWWR
               WMWST1
               XRECH
               STBLG
        FROM RBKP
        INTO TABLE IT_RBKP
        FOR ALL ENTRIES IN IT_EKBE
        WHERE BELNR = IT_EKBE-BELNR
          AND GJAHR = IT_EKBE-GJAHR.
        IF SY-SUBRC = 0.
          SORT IT_RBKP BY BELNR GJAHR.
        ENDIF.
      ENDIF.
    *-- Sort PO History documents based on PO # and PO Item
      SORT IT_EKBE BY EBELN EBELP.
    *-- Copy the PO History documents into IT_EKBE_TEMP internal table
      IT_EKBE_TEMP[] = IT_EKBE[].
    *-- Delete PO History documents from IT_EKBE_TEMP internal table
      comparing with IT_RBKP where (STBLG) Reversal document number
      is initial
      LOOP AT IT_EKBE_TEMP INTO WA_EKBE_TEMP.
        LV_TABIX = SY-TABIX.
        READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
                                                 GJAHR = WA_EKBE_TEMP-GJAHR
                                                XRECH = SPACE
                                                 STBLG = SPACE.
        IF SY-SUBRC  0.
          DELETE IT_EKBE_TEMP INDEX LV_TABIX.
        ENDIF.
        CLEAR: WA_EKBE_TEMP, WA_RBKP.
      ENDLOOP.
    ENDFORM.                    " F_GET_VENDOR
    *&      Form  F_PROCESS_MIRO
          Process MIRO
    FORM F_PROCESS_MIRO .
      DATA:
        lv_itemno         TYPE i,
        lv_tabix          type sy-index,
        lc_check(1)       TYPE c VALUE 'X',
        V_FILL_ITEM,
        lv_rbkp_bldat type sy-datum.
      clear : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
      refresh : it_itemdata, it_accountingdata, IT_CRMEMO_MIRO, IT_CRMEMO_MR8M.
    *-- Copy all the CR Memo Docs and delete order reason not in S_AUGRU
      IT_CRMEMO_MR8M[] = IT_CRMEMO[].
    *-- Delete Reversal postings which are not in S_AUGRU
      DELETE IT_CRMEMO_MR8M WHERE AUGRU IN S_AUGRU.
    *-- Delete Reversal postings where AEDAT is initial
      DELETE IT_CRMEMO_MR8M where aedat is initial.
    *-- Delete order reason which are not in S_AUGRU
      DELETE IT_CRMEMO WHERE AUGRU NOT IN S_AUGRU.
    *-- Loop through the credit memo request records
      LOOP AT IT_CRMEMO INTO WA_CRMEMO.
        lv_tabix = sy-tabix.
    *-- If credit memo request change date is not initial then
      send change date (AEDAT) to lv_rbkp_bldat
        if not WA_CRMEMO-aedat is initial.
          lv_rbkp_bldat =  WA_CRMEMO-aedat.
        else.
    *-- If credit memo request change date is initial then
      send create date (ERDAT) to lv_rbkp_bldat
          lv_rbkp_bldat =  WA_CRMEMO-erdat.
        endif.
        READ TABLE IT_ORDERS INTO WA_ORDERS WITH KEY VBELN = WA_CRMEMO-VBELN
                                                     POSNN = WA_CRMEMO-POSNR.
        IF SY-SUBRC = 0.
          READ TABLE IT_PO INTO WA_PO WITH KEY VBELV = WA_ORDERS-VBELV
                                               POSNV = WA_ORDERS-POSNV.
          IF SY-SUBRC = 0.
            READ TABLE IT_EKPO INTO WA_EKPO WITH KEY EBELN = WA_PO-VBELN
                                                     EBELP = WA_PO-POSNN.
            IF SY-SUBRC = 0.
    *-- Read IT_EKBE_TEMP internal table which contains records which are not reversed
              READ TABLE IT_EKBE_TEMP INTO WA_EKBE_TEMP WITH KEY EBELN = WA_EKPO-EBELN
                                                                 EBELP = WA_EKPO-EBELP.
              IF SY-SUBRC = 0.
    *-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = 'X' ,
      check for invoice records for the correspnding CR Memo records
                READ TABLE IT_RBKP INTO WA_RBKP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
                                                         GJAHR = WA_EKBE_TEMP-GJAHR
                                                         XRECH = C_X.
                IF SY-SUBRC = 0.
    *-- Read IT_RBKP internal table with XRECH (Indicator: post invoice) = SPACE,
      and document date = CR Memo creation date
      and reference document number = PO number
                  READ TABLE IT_RBKP INTO WA_RBKP_TMP WITH KEY BELNR = WA_EKBE_TEMP-BELNR
                                                               GJAHR = WA_EKBE_TEMP-GJAHR
                                                               BLDAT = WA_CRMEMO-ERDAT
                                                               XRECH = ' '
                                                               XBLNR+0(10) = WA_EKBE_TEMP-ebeln.
                                                              STBLG = SPACE.
                  IF SY-SUBRC = 0.
                    CONTINUE.
                  ELSE.
    *-- Quantity Conversion (Get the Credit Memo Quantity by passing CMR unit per one PO unit)
                    perform f_quantity_conv.
    *-- Filling the Line items data
    *-- Incrementing the item no
                    lv_itemno = lv_itemno + 1.
                    v_itemno  = lv_itemno.
                    it_itemdata-invoice_doc_item  = v_itemno.
                    it_itemdata-po_number         = WA_ekPO-ebeln.
                    it_itemdata-po_item           = WA_EKPO-EBELP.
                    it_itemdata-tax_code          = WA_ekpo-mwskz.
                    it_itemdata-TAXJURCODE        = WA_ekpo-TXJCD.
    *-- Converting SAP amount to BAPI format by passing line item amount and currency
                    PERFORM f_currency_amount_sap_to_bapi USING    WA_EKPO-waers
                                                                   V_LINE_AMOUNT
                                                          CHANGING it_itemdata-item_amount .
                    it_itemdata-quantity          = ( WA_CRMEMO-ZMENG * V_CRMEMO_QTY ).
                    it_itemdata-po_unit           = WA_EKPO-MEINS.
                    APPEND it_itemdata.
    *-- Populate Account Assignment data
                    IT_ACCOUNTINGDATA-INVOICE_DOC_ITEM = v_itemno.
                    IT_ACCOUNTINGDATA-XUNPL       = space.
                    IT_ACCOUNTINGDATA-SERIAL_NO   = C_01.
                    IT_ACCOUNTINGDATA-TAX_CODE    = it_itemdata-tax_code.
                    IT_ACCOUNTINGDATA-TAXJURCODE  = it_itemdata-TAXJURCODE.
                    IT_ACCOUNTINGDATA-ITEM_AMOUNT = it_itemdata-item_amount.
                    IT_ACCOUNTINGDATA-QUANTITY    = it_itemdata-quantity.
                    IT_ACCOUNTINGDATA-PO_UNIT     = it_itemdata-po_unit.
                    IT_ACCOUNTINGDATA-GL_ACCOUNT  = C_0000500205.
                    append IT_ACCOUNTINGDATA.
                    clear IT_ACCOUNTINGDATA.
                    CLEAR it_itemdata.
                  endif.
                endif.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDIF.
    *-- At end of each credit memo request fill the header details of BAPI FM and
    *-- post the BAPI
        AT END OF VBELN.
          read table it_crmemo into wa_crmemo index lv_tabix.
    *-- Populate the document Header
    *-- Getting the header data for invoice
          x_docheader-invoice_ind  = space.
          x_docheader-doc_type     = c_blart.
          x_docheader-doc_date     = lv_rbkp_bldat.
          x_docheader-pstng_date   = lv_rbkp_bldat.
          x_docheader-ref_doc_no   = WA_RBKP-XBLNR.
          x_docheader-comp_code    = WA_CRMEMO-BUKRS_VF.
          x_docheader-CURRENCY     = WA_CRMEMO-WAERK.
          x_docheader-calc_tax_ind = lc_check.
    *-- Logic to find the Tax %
          v_tax_per = ( WA_RBKP-WMWST1 / ( WA_RBKP-RMWWR - WA_RBKP-WMWST1 ) ) * 100.
          v_tax_amt = ( V_GROSSAMT *  v_tax_per ) / 100.
          V_GROSSAMT =  ( V_GROSSAMT + v_tax_amt ).
          x_docheader-gross_amount = V_GROSSAMT.
          CLEAR:v_docnr, v_year1.
    *-- Calling BAPI to create PO invoice document
          CHECK NOT IT_ITEMDATA[] IS INITIAL.
          CALL FUNCTION 'BAPI_INCOMINGINVOICE_CREATE'
            EXPORTING
              headerdata       = x_docheader
            IMPORTING
              invoicedocnumber = v_docnr
              fiscalyear       = v_year1
            TABLES
              itemdata         = it_itemdata[]
              ACCOUNTingDATA    = it_ACCOUNTingDATA[]
             GLACCOUNTDATA    =
             taxdata          =
              return           = it_return.
    *-- Commit work
          IF NOT v_docnr IS INITIAL.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
              EXPORTING
                wait = 'X'.
    *-- Move the data to Success Internal Table
            wa_success-crmemo  = wa_crmemo-vbeln.
            wa_success-cmemo   = wa_cmemo-vbeln.
            wa_success-orders  = wa_orders-vbelv.
            wa_success-po      = wa_po-vbeln.
            wa_success-miro_no = v_docnr.
            wa_success-text    = 'MIRO is Posted'.
            append wa_success TO it_success.
            clear wa_success.
          ENDIF.
    *--   Read the values in the table IT_RETURN.
          CLEAR it_return.
          READ TABLE it_return INDEX 1.
      If message type is error then roll back the work
          IF it_return-type = C_E.
    *-- Roll back
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    *-- Move the data to Error Internal Table
            wa_error-crmemo = wa_crmemo-vbeln.
            wa_error-cmemo  = wa_cmemo-vbeln.
            wa_error-orders = wa_orders-vbelv.
            wa_error-po     = wa_po-vbeln.
            wa_error-text   = it_return-MESSAGE.
            append wa_error TO it_error.
            clear wa_error.
          ENDIF.
          refresh: it_return, it_itemdata, it_accountingdata.
          clear: V_GROSSAMT, it_return, it_itemdata, wa_crmemo, wa_orders, wa_po,
                 wa_ekpo, WA_EKBE_TEMP, wa_rbkp, wa_rbkp_tmp, v_docnr, v_year1, WA_SUCCESS,
                 WA_ERROR, it_accountingdata, v_tax_per, v_tax_amt, V_FILL_ITEM, lv_rbkp_bldat.
        ENDAT.
      ENDLOOP.
    ENDFORM.                    " F_PROCESS_MIRO
    *&      Form  f_quantity_conv
          Quantity Conversion
    FORM f_quantity_conv .
    *-- Quantity Conversion (Get the Credit Memo Quantity by passing CMR unit per one PO unit)
      CLEAR: V_LINE_AMOUNT, V_CRMEMO_QTY.
      call function 'MC_UNIT_CONVERSION'
        EXPORTING
          MATNR                = WA_CRMEMO-MATNR
          nach_meins           = WA_EKPO-MEINS
          von_meins            = WA_CRMEMO-ZIEME
        IMPORTING
          UMREF                = V_CRMEMO_QTY
        EXCEPTIONS
          CONVERSION_NOT_FOUND = 1
          MATERIAL_NOT_FOUND   = 2
          NACH_MEINS_MISSING   = 3
          OVERFLOW             = 4
          VON_MEINS_MISSING    = 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.
      ELSE.
        V_LINE_AMOUNT = ( V_CRMEMO_QTY  * WA_CRMEMO-ZMENG * WA_EKPO-peinh * WA_EKPO-NETPR ).
        V_GROSSAMT    = V_GROSSAMT + V_LINE_AMOUNT.
      ENDIF.
    ENDFORM.                    " f_quantity_conv
    *&      Form  f_currency_amount_sap_to_bapi
          SAP Amount to BAPI Amount
    FORM f_currency_amount_sap_to_bapi  USING    p_waers
                                                 p_kbetr
                                        CHANGING p_amt_doccur.
      DATA : lv_waers LIKE  tcurc-waers,
             lv_sapamount LIKE bapicurr-bapicurr,
             lv_bapi_amount LIKE bapicurr-bapicurr.
      lv_waers = p_waers.
      lv_sapamount = p_kbetr.
      CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_BAPI'
        EXPORTING
          currency    = lv_waers
          sap_amount  = lv_sapamount
        IMPORTING
          bapi_amount = lv_bapi_amount.
      p_amt_doccur = lv_bapi_amount.

  • Creating Move-Out Document by Program

    Hi,
    For an ISU Contract, I need to create Move-Out document programatically. Which BAPI or Function Module should I use regarding this purpose.
    I used BAPI_ISUMOVEOUT_CREATEFROMDATA to create Move-Out doc, but its generating it, but not updating them Contract. Even if I try to see the generated document in EC57, it gives an error that no document exists.
    Regards
    Pulokesh
    Edited by: Pulokesh Karmakar on Jul 12, 2010 4:29 PM

    Hi,
    you used a custom Web ADi integrator (XXFA_TEST).
    I think you have a grants problem, therefore with assigment of the system administrator, no problems exists.
    Have a look in the Web ADI Implementation Guide
    e.g. for R12.0.4 http://download.oracle.com/docs/cd/B40089_09/current/acrobat/120bneig.pdf
    Dirk

  • BAPI or RFC to create material

    Hi folks,
            Could any one tell me, if there is any BAPI or RFC to create Material in Material master....if so pls tel me the name and how to use the BAPI...thanks in advance,
                              santosh.

    HI CHECK OU THIS PROGRAM
    *& Report  ZBAPI_MATERIAL_SAVEDATA
    **& AUTHOR *
    *& PURPOSE : THIS REPORT USES BAPI MATERIAL SAVE DATA TO UPDATE AND CREATE
    *&           THE MATERIAL
    REPORT  ZBAPI_MATERIAL_SAVEDATA NO STANDARD PAGE HEADING MESSAGE-ID (ZHNC).
    TYPES:BEGIN OF TY_MAT,
           MATERIAL(4),
           IND_SECTOR(1),
           MATL_TYPE(4),
          BASIC_VIEW(1),*
          SALES_VIEW(1),*
          PURCHASE_VIEW(1),*
          STORAGE_VIEW(1),*
           MATL_GROUP(9),
           BASE_UOM(3),
           BASE_UOM_ISO(3),
          MATL_GROUP1(1),*
          BASE_UOM1(1),*
          BASE_UOM_ISO1(1),*
           PLANT(4),
           DEL_FLAG(1),
           PUR_GROUP(3),
           BASE_QTY(13),
          PLANT2(4),*
          DEL_FLAG5(1),*
          PUR_GROUP1(1),*
          BASE_QTY1(1),*
          PLANT3(4),*
           STGE_LOC(4),
           MRP_IND(1),
          PLANT4(4),*
          STGE_LOC1(4),*
          MRP_IND1(1),*
           SALES_ORG(4),
           DISTR_CHAN(2),
           DEL_FLAG1(1),
           MIN_ORDER(13),
          SALES_ORG1(4),*
          DISTR_CHAN1(2),*
          DEL_FLAG2(1),*
          MIN_ORDER1(1),*
           LANGU(2),
          MATL_DESC(40),
       END OF TY_MAT.
    DATA: IT_DATA TYPE TABLE OF TY_MAT,
          WA_DATA LIKE LINE  OF IT_DATA.
    *decalraing flag
    data: v_flag value ''.
    *DECLARING WORK AREAs  TO BE PASSED TO THE FUNCTION MODULE.
    DATA: BAPI_HEAD LIKE BAPIMATHEAD,
          BAPI_CLIENTDATA LIKE BAPI_MARA,
          BAPI_CLIENTDATAX LIKE BAPI_MARAX,
          BAPI_PLANTDATA LIKE BAPI_MARC,
          BAPI_PLANTDATAX LIKE  BAPI_MARCX,
          BAPI_STORAGELOCATIONDATA LIKE BAPI_MARD,
          BAPI_STORAGELOCATIONDATAX LIKE BAPI_MARDX,
          BAPI_SALESDATA LIKE BAPI_MVKE,
          BAPI_SALESDATAX LIKE BAPI_MVKEX,
          BAPI_MAKT LIKE BAPI_MAKT,
          BAPI_RETURN LIKE BAPIRET2.
    *INTERNAL TABLE TO HOLD THE MATERIAL DESCRIPTION
    DATA: BEGIN OF IT_MAKT OCCURS 0.
    INCLUDE STRUCTURE BAPI_MAKT.
    DATA END OF IT_MAKT.
    DATA:BEGIN OF IT_RET OCCURS 0.
    INCLUDE STRUCTURE BAPIRET2.
    DATA END OF IT_RET.
    *INTERNAL TABLE TO HOLD HEADER DATA
    DATA: IT_EXCEL TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE.
    *SELECTION-SCREEN ELEMENTS
    SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    PARAMETER: FNAME TYPE RLGRAP-FILENAME OBLIGATORY DEFAULT 'C:\Documents and Settings\Administrator\Desktop\MATMAS.XLS' .
    PARAMETERS: P_BEGCOL TYPE I DEFAULT 1 NO-DISPLAY,
                P_BEGROW TYPE I DEFAULT 1 NO-DISPLAY,
                P_ENDCOL TYPE I DEFAULT 100 NO-DISPLAY,
                P_ENDROW TYPE I DEFAULT 32000 NO-DISPLAY.
    SELECTION-SCREEN END OF BLOCK B1.
    *DECLARATION OF EXCELAL TABLE
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FNAME.
    PERFORM F_GET_FILE USING FNAME.
    START-OF-SELECTION.
    PERFORM F_XLS_ITAB USING FNAME
                       CHANGING IT_EXCEL.
    PERFORM F_MOVE_DATA.
    perform F_GET_DATA.
    *&      Form  F_GET_FILE
          text*
         -->P_FNAME  text*
         <--P_SY_SUBRC  text*
    FORM F_GET_FILE  USING    P_FNAME LIKE FNAME.
    CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
    EXPORTING
       PROGRAM_NAME        = SYST-REPID
       DYNPRO_NUMBER       = SYST-DYNNR
      FIELD_NAME          = ' '*
      STATIC              = ' '*
      MASK                = ' '*
      CHANGING
        FILE_NAME           = P_FNAME
    EXCEPTIONS*
      MASK_TOO_LONG       = 1*
      OTHERS              = 2*
    IF SY-SUBRC <> 0.
    MESSAGE E006(ZHNC).
    ENDIF.
    ENDFORM.                    " F_GET_FILE
    *&      Form  F_XLS_ITAB
          text*
         -->P_FNAME  text*
         <--P_IT_EXCEL  text*
    FORM F_XLS_ITAB  USING    P_FNAME
                     CHANGING P_IT_EXCEL.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        FILENAME                      = FNAME
        I_BEGIN_COL                   = P_BEGCOL
        I_BEGIN_ROW                   = P_BEGROW
        I_END_COL                     = P_ENDCOL
        I_END_ROW                     = P_ENDROW
      TABLES
        INTERN                        = IT_EXCEL
    EXCEPTIONS
       INCONSISTENT_PARAMETERS       = 1
       UPLOAD_OLE                    = 2
       OTHERS                        = 3
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO*
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.*
    ENDIF.
    ENDFORM.                    " F_XLS_ITAB
    *&      Form  F_MOVE_DATA
          text*
    -->  p1        text*
    <--  p2        text*
    FORM F_MOVE_DATA .
    DATA : LV_INDEX TYPE I.
    FIELD-SYMBOLS <FS>.
    *--- Sorting the internal table
    SORT IT_EXCEL BY ROW COL.
    CLEAR IT_EXCEL.
    LOOP AT IT_EXCEL.
    MOVE IT_EXCEL-COL TO LV_INDEX.
    *--- Assigning the each record to an internal table row
    ASSIGN COMPONENT LV_INDEX OF STRUCTURE WA_DATA TO <FS>.
    *--- Asigning the field value to a field symbol
    MOVE IT_EXCEL-VALUE TO <FS>.
    AT END OF ROW.
    APPEND WA_DATA TO IT_DATA.
    CLEAR WA_DATA.
    ENDAT.
    ENDLOOP.
    ENDFORM.                    " F_MOVE_DATA
    *&      Form  F_GET_DATA
          text*
    -->  p1        text*
    <--  p2        text*
    FORM F_GET_DATA .
    LOOP AT IT_DATA INTO WA_DATA.
    MOVE-CORRESPONDING WA_DATA  TO  BAPI_HEAD.
    BAPI_HEAD-BASIC_VIEW ='X'.
    BAPI_HEAD-SALES_VIEW ='X'.
    BAPI_HEAD-PURCHASE_VIEW ='X'.
    BAPI_HEAD-STORAGE_VIEW ='X'.
    MOVE-CORRESPONDING WA_DATA TO BAPI_CLIENTDATA.
    BAPI_CLIENTDATAX-MATL_GROUP = 'X'.
    BAPI_CLIENTDATAX-BASE_UOM = 'X'.
    BAPI_CLIENTDATAX-BASE_UOM_ISO = 'X'.
    MOVE-CORRESPONDING WA_DATA TO BAPI_PLANTDATA.
    BAPI_PLANTDATAX-PLANT = BAPI_PLANTDATA-PLANT.
    BAPI_PLANTDATAX-DEL_FLAG = 'X'.
    BAPI_PLANTDATAX-PUR_GROUP = 'X'.
    BAPI_PLANTDATAX-BASE_QTY = 'X'.
    MOVE-CORRESPONDING WA_DATA TO BAPI_STORAGELOCATIONDATA.
    BAPI_STORAGELOCATIONDATA-PLANT = BAPI_PLANTDATA-PLANT.
    BAPI_STORAGELOCATIONDATAX-PLANT = BAPI_STORAGELOCATIONDATA-PLANT.
    BAPI_STORAGELOCATIONDATAX-STGE_LOC = BAPI_STORAGELOCATIONDATA-STGE_LOC.
    BAPI_STORAGELOCATIONDATAX-MRP_IND = 'X'.
    MOVE-CORRESPONDING WA_DATA TO BAPI_SALESDATA.
    BAPI_SALESDATAX-SALES_ORG = BAPI_SALESDATA-SALES_ORG.
    BAPI_SALESDATAX-DISTR_CHAN = BAPI_SALESDATA-DISTR_CHAN.
    BAPI_SALESDATAX-DEL_FLAG = BAPI_SALESDATA-DEL_FLAG.
    BAPI_SALESDATAX-MIN_ORDER = 'X'.
    REFRESH IT_MAKT.
    IT_MAKT-LANGU = WA_DATA-LANGU.
    IT_MAKT-MATL_DESC = WA_DATA-MATL_DESC.
    APPEND IT_MAKT.
    CLEAR IT_RET.
    REFRESH IT_RET.
    PERFORM F_CALL_BAPI.
    READ TABLE IT_RET WITH KEY TYPE = 'S'.
    IF SY-SUBRC EQ 0.
    PERFORM F_BAPI_COMMIT.
    WRITE:/ 'MATERIAL CREATED OR UPDATED SUCESSFULLY WITH MATERIAL NO',WA_DATA-MATERIAL.
    ELSE.
    MESSAGE E000(ZHNC) WITH 'ERROR IN CREATING THE MATERIAL'.
    *WRITE: / 'ERROR IN CREATIN MATERIAL',IT_RET-MESSAGE.
    *PERFORM F_DOWNLOAD.
    ENDIF.
    *ENDIF.
    ENDLOOP.
    ENDFORM.                    " F_GET_DATA
    *&      Form  F_CALL_BAPI
          text*
    -->  p1        text*
    <--  p2        text*
    FORM F_CALL_BAPI .
    CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA'
      EXPORTING
        HEADDATA                   = BAPI_HEAD
       CLIENTDATA                 =  BAPI_CLIENTDATA
       CLIENTDATAX                =  BAPI_CLIENTDATAX
       PLANTDATA                  =  BAPI_PLANTDATA
       PLANTDATAX                 =  BAPI_PLANTDATAX
       STORAGELOCATIONDATA        =  BAPI_STORAGELOCATIONDATA
       STORAGELOCATIONDATAX       =  BAPI_STORAGELOCATIONDATAX
       SALESDATA                  =  BAPI_SALESDATA
       SALESDATAX                 =  BAPI_SALESDATAX
    IMPORTING
       RETURN                     =  IT_RET
    TABLES
       MATERIALDESCRIPTION        = IT_MAKT
      UNITSOFMEASURE             =*
      UNITSOFMEASUREX            =*
      INTERNATIONALARTNOS        =*
      MATERIALLONGTEXT           =*
      TAXCLASSIFICATIONS         =*
      RETURNMESSAGES             =*
      PRTDATA                    =*
      PRTDATAX                   =*
      EXTENSIONIN                =*
      EXTENSIONINX               =*
    APPEND IT_RET.
    ENDFORM.                    " F_CALL_BAPI
    *&      Form  F_BAPI_COMMIT
          text*
    -->  p1        text*
    <--  p2        text*
    FORM F_BAPI_COMMIT .
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING*
      WAIT         =*
    IMPORTING*
      RETURN        =*
    ENDFORM.                    " F_BAPI_COMMIT
    IF U WANT THE EXCEL FILE I CAN SEND U
    PLZ REWARD POINTS TO HELP ANSWERS

Maybe you are looking for

  • HP Pavilion Hard Drive Question

    Is there any way I can add a second hard drive to my HP Pavilion dv7-3165dvx laptop?  There's a second drive bay, but no connections.

  • I get an error message when trying to open the download disk.

    I need to reinstall photoshop cs5.  I have downloaded it, but cannot open the downloaded disk.  I get an error message saying it can't be opened due to it being "not recognized". The disk name is:  "Photoshop_12_1_LS1.dmg" Can anyone help me? Thanks.

  • Error when installing sap solution manager

    Dear all, When i am installing SAP solution manager (SAP SOLMAN 7.0 EHP1SR1 WINDOWS_X86_64), I meet the following error: An error occurred while processing option SAP Solution Manager 7.0 EhP1 > SAP Systems > MS SQL Server > Central System > Central

  • ACE: probe failing

    Hi, I've following probe configured: probe http probe1.test.com:10114   port 10114   interval 34   faildetect 17   passdetect interval 60   expect status 200 200   header Host header-value "hcmfincrp1.test.com"   open 1 and it is applied to serverfar

  • Urgent : Tracing required Datasource from a report

    Hi, I have to implement SD in BI, there is a TCODE given to me by the client that outputs a report (as per there requierment), Using the TCODE i have to activate the datasources and to transfer the data. The fields on the selection screen i am able t