Bdc to me21n

Hi is it possible to write bdc for me21n
i m try it but it int trnasfer data
Moderator Message: Vague question.
Edited by: kishan P on Dec 13, 2010 8:30 PM

Hi Sandeep,
Please use standard Bapi for creating purchase order using the Enjoy Transaction. BAPI_PO_CREATE1.
Your previous thread, title "bapi to create PO", will give you the details.
Regards
Bhanu

Similar Messages

  • BDC for ME21N Transaction

    Dear All,
    I have a requirement to create PO using transaction ME21N. I had written a code to create PO using BDC for transaction ME21. But the user wants it to be modified to ME21N. The user wants the PO created in the foreground like the one i created fro ME21. But is it possible to use BDC for ME21N or is there any other way i can change the BAPI to foreground processing like in BDC?
    Regards,
    Karthik

    Hi Raghavender,
    This is a report to display and validate the RFQ's. And once the user selects the RFQ and clicks on Create PO from RFQ push button, it should go to transaction 'ME21N' with values from RFQ. ( similar to what we do in ME21N, when we drag RFQ from the documents overview and drop it into cart, the values are populated). I want the similar functionality to happen when the user clicks on clicks on Create PO push button. But it should happen only in the foreground and not background.
    Regards,
    Karthik

  • BDC for ME21N (Flat file format)

    Hello,
         I have to write a BDC for ME21N(stock transfer).... Someone pls give me the format of flat file... we need separate files for header and items or only one file is enough??? pls someone send me the format and code......
    my email id is [email protected]
    Thanks in advance...
    Regards,
    Maya.

    Hi
    see this and do accordingly
    REPORT zmm_bdcp_purchaseorderkb02
    NO STANDARD PAGE HEADING LINE-SIZE 255.
    Declaring internal tables *
    *-----Declaring line structure
    DATA : BEGIN OF it_dummy OCCURS 0,
    dummy(255) TYPE c,
    END OF it_dummy.
    *-----Internal table for line items
    DATA : BEGIN OF it_idata OCCURS 0,
    ematn(18), "Material Number.
    menge(13), "Qyantity.
    netpr(11), "Net Price.
    werks(4), "Plant.
    ebelp(5), "Item Number.
    END OF it_idata.
    *-----Deep structure for header data and line items
    DATA : BEGIN OF it_me21 OCCURS 0,
    lifnr(10), "Vendor A/c No.
    bsart(4), "A/c Type.
    bedat(8), "Date of creation of PO.
    ekorg(4), "Purchasing Organisation.
    ekgrp(3), "Purchasing Group.
    x_data LIKE TABLE OF it_idata,
    END OF it_me21.
    DATA : x_idata LIKE LINE OF it_idata.
    DATA : v_delimit VALUE ','.
    DATA : v_indx(3) TYPE n.
    DATA : v_fnam(30) TYPE c.
    DATA : v_count TYPE n.
    DATA : v_ne TYPE i.
    DATA : v_ns TYPE i.
    *include bdcrecx1.
    INCLUDE zmm_incl_purchaseorderkb01.
    Search help for file *
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    CALL FUNCTION 'F4_FILENAME'
    EXPORTING
    program_name = syst-cprog
    dynpro_number = syst-dynnr
    IMPORTING
    file_name = p_file.
    START-OF-SELECTION.
    To upload the data into line structure *
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
    filename = p_file
    filetype = 'DAT'
    TABLES
    data_tab = it_dummy.
    Processing the data from line structure to internal tables *
    REFRESH:it_me21.
    CLEAR :it_me21.
    LOOP AT it_dummy.
    IF it_dummy-dummy+0(01) = 'H'.
    v_indx = v_indx + 1.
    CLEAR it_idata.
    REFRESH it_idata.
    CLEAR it_me21-x_data.
    REFRESH it_me21-x_data.
    SHIFT it_dummy.
    SPLIT it_dummy AT v_delimit INTO it_me21-lifnr
    it_me21-bsart
    it_me21-bedat
    it_me21-ekorg
    it_me21-ekgrp.
    APPEND it_me21.
    ELSEIF it_dummy-dummy+0(01) = 'L'.
    SHIFT it_dummy.
    SPLIT it_dummy AT v_delimit INTO it_idata-ematn
    it_idata-menge
    it_idata-netpr
    it_idata-werks
    it_idata-ebelp.
    APPEND it_idata TO it_me21-x_data.
    MODIFY it_me21 INDEX v_indx.
    ENDIF.
    ENDLOOP.
    To open the group *
    PERFORM open_group.
    To populate the bdcdata table for header data *
    LOOP AT it_me21.
    v_count = v_count + 1.
    REFRESH it_bdcdata.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0100',
    ' ' 'BDC_CURSOR' 'EKKO-LIFNR',
    ' ' 'BDC_OKCODE' '/00',
    ' ' 'EKKO-LIFNR' it_me21-lifnr,
    ' ' 'RM06E-BSART' it_me21-bsart,
    ' ' 'RM06E-BEDAT' it_me21-bedat,
    ' ' 'EKKO-EKORG' it_me21-ekorg,
    ' ' 'EKKO-EKGRP' it_me21-ekgrp,
    ' ' 'RM06E-LPEIN' 'T'.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
    ' ' 'BDC_CURSOR' 'RM06E-EBELP',
    ' ' 'BDC_OKCODE' '/00'.
    MOVE 1 TO v_indx.
    *-----To populate the bdcdata table for line item data
    LOOP AT it_me21-x_data INTO x_idata.
    CONCATENATE 'EKPO-EMATN(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-ematn.
    CONCATENATE 'EKPO-MENGE(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-menge.
    CONCATENATE 'EKPO-NETPR(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-netpr.
    CONCATENATE 'EKPO-WERKS(' v_indx ')' INTO v_fnam.
    PERFORM subr_bdc_table USING ' ' v_fnam x_idata-werks.
    v_indx = v_indx + 1.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
    ' ' 'BDC_CURSOR' 'RM06E-EBELP',
    ' ' 'BDC_OKCODE' '/00'.
    ENDLOOP.
    PERFORM subr_bdc_table USING: 'X' 'SAPMM06E' '0120',
    ' ' 'BDC_CURSOR' 'RM06E-EBELP',
    ' ' 'BDC_OKCODE' '=BU'.
    PERFORM bdc_transaction USING 'ME21'.
    ENDLOOP.
    PERFORM close_group.
    End of selection event *
    END-OF-SELECTION.
    IF session NE 'X'.
    *-----To display the successful records
    WRITE :/10 text-001. "Sucess records
    WRITE :/10 SY-ULINE(20).
    SKIP.
    IF it_sucess IS INITIAL.
    WRITE :/ text-002.
    ELSE.
    WRITE :/ text-008, "Total number of Succesful records
    35 v_ns.
    SKIP.
    WRITE:/ text-003, "Vendor Number
    17 text-004, "Record number
    30 text-005. "Message
    ENDIF.
    LOOP AT it_sucess.
    WRITE:/4 it_sucess-lifnr,
    17 it_sucess-tabix CENTERED,
    30 it_sucess-sucess_rec.
    ENDLOOP.
    SKIP.
    *-----To display the erroneous records
    WRITE:/10 text-006. "Error Records
    WRITE:/10 SY-ULINE(17).
    SKIP.
    IF it_error IS INITIAL.
    WRITE:/ text-007. "No error records
    ELSE.
    WRITE:/ text-009, "Total number of erroneous records
    35 v_ne.
    SKIP.
    WRITE:/ text-003, "Vendor Number
    17 text-004, "Record number
    30 text-005. "Message
    ENDIF.
    LOOP AT it_error.
    WRITE:/4 it_error-lifnr,
    17 it_error-tabix CENTERED,
    30 it_error-error_rec.
    ENDLOOP.
    REFRESH it_sucess.
    REFRESH it_error.
    ENDIF.
    CODE IN INCLUDE.
    Include ZMM_INCL_PURCHASEORDERKB01
    DATA: it_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    DATA: it_MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
    DATA: E_GROUP_OPENED.
    *-----Internal table to store sucess records
    DATA:BEGIN OF it_sucess OCCURS 0,
    msgtyp(1) TYPE c,
    lifnr LIKE ekko-lifnr,
    tabix LIKE sy-tabix,
    sucess_rec(125),
    END OF it_sucess.
    DATA: g_mess(125) type c.
    *-----Internal table to store error records
    DATA:BEGIN OF it_error OCCURS 0,
    msgtyp(1) TYPE c,
    lifnr LIKE ekko-lifnr,
    tabix LIKE sy-tabix,
    error_rec(125),
    END OF it_error.
    Selection screen
    SELECTION-SCREEN BEGIN OF LINE.
    PARAMETERS session RADIOBUTTON GROUP ctu. "create session
    SELECTION-SCREEN COMMENT 3(20) text-s07 FOR FIELD session.
    SELECTION-SCREEN POSITION 45.
    PARAMETERS ctu RADIOBUTTON GROUP ctu. "call transaction
    SELECTION-SCREEN COMMENT 48(20) text-s08 FOR FIELD ctu.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 3(20) text-s01 FOR FIELD group.
    SELECTION-SCREEN POSITION 25.
    PARAMETERS group(12). "group name of session
    SELECTION-SCREEN COMMENT 48(20) text-s05 FOR FIELD ctumode.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS ctumode LIKE ctu_params-dismode DEFAULT 'N'.
    "A: show all dynpros
    "E: show dynpro on error only
    "N: do not display dynpro
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 48(20) text-s06 FOR FIELD cupdate.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS cupdate LIKE ctu_params-updmode DEFAULT 'L'.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 3(20) text-s03 FOR FIELD keep.
    SELECTION-SCREEN POSITION 25.
    PARAMETERS: keep AS CHECKBOX. "' ' = delete session if finished
    "'X' = keep session if finished
    SELECTION-SCREEN COMMENT 48(20) text-s09 FOR FIELD e_group.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS e_group(12). "group name of error-session
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 51(17) text-s03 FOR FIELD e_keep.
    SELECTION-SCREEN POSITION 70.
    PARAMETERS: e_keep AS CHECKBOX. "' ' = delete session if finished
    "'X' = keep session if finished
    SELECTION-SCREEN END OF LINE.
    PARAMETERS:p_file LIKE rlgrap-filename.
    at selection screen *
    AT SELECTION-SCREEN.
    group and user must be filled for create session
    IF SESSION = 'X' AND
    GROUP = SPACE. "OR USER = SPACE.
    MESSAGE E613(MS).
    ENDIF.
    create batchinput session *
    FORM OPEN_GROUP.
    IF SESSION = 'X'.
    SKIP.
    WRITE: /(20) 'Create group'(I01), GROUP.
    SKIP.
    *----open batchinput group
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    CLIENT = SY-MANDT
    GROUP = GROUP
    USER = sy-uname.
    WRITE:/(30) 'BDC_OPEN_GROUP'(I02),
    (12) 'returncode:'(I05),
    SY-SUBRC.
    ENDIF.
    ENDFORM. "OPEN_GROUP
    end batchinput session *
    FORM CLOSE_GROUP.
    IF SESSION = 'X'.
    *------close batchinput group
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),
    (12) 'returncode:'(I05),
    SY-SUBRC.
    ELSE.
    IF E_GROUP_OPENED = 'X'.
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    WRITE: /.
    WRITE: /(30) 'Fehlermappe wurde erzeugt'(I06).
    ENDIF.
    ENDIF.
    ENDFORM. "CLOSE_GROUP
    Start new transaction according to parameters *
    FORM BDC_TRANSACTION USING TCODE TYPE ANY.
    DATA: L_SUBRC LIKE SY-SUBRC.
    *------batch input session
    IF SESSION = 'X'.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    TCODE = TCODE
    TABLES
    DYNPROTAB = it_BDCDATA.
    WRITE: / 'BDC_INSERT'(I03),
    TCODE,
    'returncode:'(I05),
    SY-SUBRC,
    'RECORD:',
    SY-INDEX.
    ELSE.
    REFRESH it_MESSTAB.
    CALL TRANSACTION TCODE USING it_BDCDATA
    MODE CTUMODE
    UPDATE CUPDATE
    MESSAGES INTO it_MESSTAB.
    L_SUBRC = SY-SUBRC.
    WRITE: / 'CALL_TRANSACTION',
    TCODE,
    'returncode:'(I05),
    L_SUBRC,
    'RECORD:',
    SY-INDEX.
    ENDIF.
    Message handling for Call Transaction *
    perform subr_mess_hand using g_mess.
    *-----Erzeugen fehlermappe
    IF L_SUBRC <> 0 AND E_GROUP <> SPACE.
    IF E_GROUP_OPENED = ' '.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
    CLIENT = SY-MANDT
    GROUP = E_GROUP
    USER = sy-uname
    KEEP = E_KEEP.
    E_GROUP_OPENED = 'X'.
    ENDIF.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
    TCODE = TCODE
    TABLES
    DYNPROTAB = it_BDCDATA.
    ENDIF.
    REFRESH it_BDCDATA.
    ENDFORM. "BDC_TRANSACTION
    Form subr_bdc_table *
    text
    -->P_0220 text *
    -->P_0221 text *
    -->P_0222 text *
    FORM subr_bdc_table USING VALUE(P_0220) TYPE ANY
    VALUE(P_0221) TYPE ANY
    VALUE(P_0222) TYPE ANY.
    CLEAR it_bdcdata.
    IF P_0220 = ' '.
    CLEAR it_bdcdata.
    it_bdcdata-fnam = P_0221.
    it_bdcdata-fval = P_0222.
    APPEND it_bdcdata.
    ELSE.
    it_bdcdata-dynbegin = P_0220.
    it_bdcdata-program = P_0221.
    it_bdcdata-dynpro = P_0222.
    APPEND it_bdcdata.
    ENDIF.
    ENDFORM. " subr_bdc_table
    Form subr_mess_hand *
    text *
    -->P_G_MESS text *
    FORM subr_mess_hand USING P_G_MESS TYPE ANY.
    LOOP AT IT_MESSTAB.
    CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
    ID = it_messtab-msgid
    LANG = it_messtab-msgspra
    NO = it_messtab-msgnr
    v1 = it_messtab-msgv1
    v2 = it_messtab-msgv2
    IMPORTING
    MSG = P_G_MESS
    EXCEPTIONS
    OTHERS = 0.
    CASE it_messtab-msgtyp.
    when 'E'.
    it_error-error_rec = P_G_MESS.
    it_error-lifnr = it_me21-lifnr.
    it_error-tabix = v_count.
    APPEND IT_ERROR.
    when 'S'.
    it_sucess-sucess_rec = P_G_MESS.
    it_sucess-lifnr = it_me21-lifnr.
    it_sucess-tabix = v_count.
    APPEND IT_SUCESS.
    endcase.
    ENDLOOP.
    Describe table it_sucess lines v_ns.
    Describe table it_error lines v_ne.
    ENDFORM. " subr_mess_hand
    Regards
    Anji

  • Creation of PO using BDC with ME21N - Urgent

    Hi All,
    My requirement is to create a Purchase Order using BDC. I'm using ME21N for BDC. I did recording and using that recording I wrote a program for BDC. BDC table is populated correctly, but while calling ME21N using call transaction, program is cuming back to the selection screen, without creating PO. And sy-subrc value after call transaction is '0'. Please let me know the problem.
    Thanks in Advance.
    Siva Sankar.

    Hi,
    Put a break point after the call transaction statement(i.e, put break point on sy-subrc check)
    and then check the message table.
    if call transaction is suceessfull u will find a success messages in the I_messages table.
    Regards,
    Sriram

  • BDC for ME21n

    Hi All,
    I need to create a BDC program for the creation of purchase orders using tcode ME21n.
    I have Header data & Item data to upload while creating the purchase order.
    How to handle the uploading of header data & item data.
    How should we code the program & how the flatfile should be designed.
    Regards,
    Sudhir

    Hi
    Here I am giving you a sample code..where we need to create PO's from Z table...
    Regarding the structure of the flat file, it is purely based on the client and the functional team.. they will know better which fields are to be filled. So, you have to sit with the functional guy and do the recording using SHDB tcode and then decide with the flat file.
    *& Report  ZZPO_BDC
    REPORT  ZZPO_BDC no standard page heading line-size 255.
    tables: zzpo_staging.
    DATA  id type string..
    DATA: fnam(20) type c,
           matnr type bstmg.
    data: quan(13) type c,
          netpr(15) type c,
          qty(13) type c,
          gp(15) type c.
    DATA  idx type string.
    data: i_bdcdata like bdcdata occurs 1 with header line,
          i_msg like bdcmsgcoll occurs 1 with header line.
    DATA  W_STR type string.
    DATA: IT_STAGING TYPE STANDARD TABLE OF ZZPO_STAGING WITH HEADER LINE,
          ti_staging type standard table of zzpo_staging with header line,
          KT_STAGING TYPE STANDARD TABLE OF ZZPO_STAGING WITH HEADER LINE.
    *CALL FUNCTION 'BDC_OPEN_GROUP'
    * EXPORTING
    *   CLIENT                    = SY-MANDT
    *   DEST                      = 'zzpo'
    *   GROUP                     =  'zzpo'
    **   HOLDDATE                  = FILLER8
    *   KEEP                      = 'X'
    *   USER                      =  sy-uname
    **   RECORD                    = FILLER1
    **   PROG                      = SY-CPROG
    **   DCPFM                     = '%'
    **   DATFM                     = '%'
    ** IMPORTING
    **   QID                       =
    ** EXCEPTIONS
    **   CLIENT_INVALID            = 1
    **   DESTINATION_INVALID       = 2
    **   GROUP_INVALID             = 3
    **   GROUP_IS_LOCKED           = 4
    **   HOLDDATE_INVALID          = 5
    **   INTERNAL_ERROR            = 6
    **   QUEUE_ERROR               = 7
    **   RUNNING                   = 8
    **   SYSTEM_LOCK_ERROR         = 9
    **   USER_INVALID              = 10
    **   OTHERS                    = 11
    *IF SY-SUBRC <> 0.
    ** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    **         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    start-of-selection.
    *perform open_group.
      SELECT * FROM ZZPO_STAGING INTO TABLE IT_STAGING.
      select * from zzpo_staging into table ti_staging.
      SELECT * fROM ZZPO_STAGING INTO TABLE KT_sTAGING.
        delete adjacent duplicates from it_staging comparing vendor docdate.
      loop at IT_STAGING.
        perform bdc_dynpro      using 'SAPMM06E' '0100'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'EKKO-EKGRP'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '/00'.
        perform bdc_field       using 'EKKO-LIFNR'
                                       IT_STAGING-vendor.
        perform bdc_field       using 'RM06E-BSART'
                                      'NB'.
        perform bdc_field       using 'RM06E-BEDAT'
                                       IT_STAGING-docdate.
        perform bdc_field       using 'EKKO-EKORG'
                                       IT_STAGING-purorg.
        perform bdc_field       using 'EKKO-EKGRP'
                                       IT_STAGING-purgrp.
        perform bdc_field       using 'RM06E-LPEIN'
                                      'T'.
    *  endloop.
        perform bdc_dynpro      using 'SAPMM06E' '0120'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'RM06E-EPSTP(01)'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=DETA'.
        perform bdc_dynpro      using 'SAPMM06E' '0120'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'EKPO-WERKS(01)'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '/00'.
        move 1 to id.
        loop at TI_STAGING WHERE VENDOR = IT_STAGING-VENDOR AND DOCDATE = IT_STAGING-DOCDATE.
          concatenate 'RM06E-EPSTP(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-itmcategory.
          concatenate 'EKPO-KNTTP(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-accassignment.
          concatenate 'EKPO-EMATN(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-material.
          concatenate 'EKPO-TXZ01(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-shortxt.
          quan = ti_staging-poqty.
          concatenate 'EKPO-MENGE(0' id ')' into fnam.
          perform bdc_field       using fnam quan.
          concatenate 'RM06E-EEIND(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-deliverydate.
          netpr = ti_staging-netpr.
          concatenate 'EKPO-NETPR(0' id ')' into fnam.
          perform bdc_field       using fnam netpr.
          concatenate 'EKPO-MATKL(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-mategroup.
          concatenate 'EKPO-WERKS(0' id ')' into fnam.
          perform bdc_field       using fnam TI_STAGING-plant.
          ID = ID + 1.
        ENDLOOP.
    *    perform bdc_dynpro      using 'SAPMM06E' '0111'.
    *    perform bdc_field       using 'BDC_CURSOR'
    *                                  'EKPO-MENGE'.
    *    perform bdc_field       using 'BDC_OKCODE'
    *                                  '/00'.
    *perform bdc_field       using 'EKPO-KNTTP'
    *                              'N'.
    *perform bdc_field       using 'EKPO-TXZ01'
    *                              'Office Supplies'.
    *perform bdc_field       using 'EKPO-MENGE'
    *                              '2'.
    *    perform bdc_field       using 'EKPO-SPINF'
    *                                  'B'.
    *    perform bdc_field       using 'EKPO-BPUMN'
    *                                  '1'.
    *    perform bdc_field       using 'EKPO-BPUMZ'
    *                                  '1'.
    *    perform bdc_field       using 'EKPO-PRSDR'
    *                                  'X'.
    *perform bdc_field       using 'RM06E-EEIND'
    *                              '06/24/2008'.
    *perform bdc_field       using 'RM06E-LPEIN'
    *                              'D'.
    *    perform bdc_field       using 'EKPO-WEPOS'
    *                                  'X'.
    *    perform bdc_field       using 'EKPO-REPOS'
    *                                  'X'.
        loop at TI_STAGING where vendor = it_staging-vendor and docdate = it_staging-docdate.
          perform bdc_dynpro      using 'SAPMM06E' '0511'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '=ENTE'.
          perform bdc_field       using 'EKKN-SAKTO'
                                         TI_STAGING-glaccount.
          perform bdc_field       using 'BDC_CURSOR'
                                        'DKACB-FMORE'.
          perform bdc_field       using 'DKACB-FMORE'
                                        'X'.
          perform bdc_dynpro      using 'SAPLKACB' '0002'.
          perform bdc_field       using 'BDC_CURSOR'
                                        'COBL-VORNR'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '=ENTE'.
          perform bdc_field       using 'COBL-NPLNR'
                                         TI_STAGING-networkid.
          perform bdc_field       using 'COBL-VORNR'
                                         TI_STAGING-activity.
    *    perform bdc_dynpro      using 'SAPMM06E' '0120'.
    *    perform bdc_field       using 'BDC_CURSOR'
    *                                  'RM06E-EPSTP(02)'.
    *    perform bdc_field       using 'BDC_OKCODE'
    *                                  '=DETA'.
    *    perform bdc_field       using 'RM06E-EBELP'
    *                                  '10'.
    *    perform bdc_dynpro      using 'SAPMM06E' '0120'.
    *    perform bdc_field       using 'BDC_CURSOR'
    *                                  'EKPO-WERKS(02)'.
    *    perform bdc_field       using 'BDC_OKCODE'
    *                                  '/00'.
    *    perform bdc_field       using 'RM06E-EBELP'
    *                                  '10'.
    *perform bdc_field       using 'RM06E-EPSTP(02)'
    *                              'd'.
    *perform bdc_field       using 'EKPO-KNTTP(02)'
    *                              'n'.
    *perform bdc_field       using 'EKPO-TXZ01(02)'
    *                              'adage artwork'.
    *perform bdc_field       using 'EKPO-MENGE(02)'
    *                              '                1'.
    *perform bdc_field       using 'RM06E-EEIND(02)'
    *                              '06242008'.
    *perform bdc_field       using 'EKPO-MATKL(02)'
    *                              'm1'.
    *perform bdc_field       using 'EKPO-WERKS(02)'
    *                              'a001'.
    *    perform bdc_field       using 'BDC_OKCODE'
    *                                  '/00'.
          perform bdc_dynpro      using 'SAPMM06E' '0111'.
          perform bdc_field       using 'BDC_CURSOR'
                                        'EKPO-MENGE'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '/00'.
    *    perform bdc_field       using 'EKPO-MATKL'
    *                                  'M1'.
    *    perform bdc_field       using 'EKPO-TXZ01'
    *                                   wa_jtab-j4.
    *    perform bdc_field       using 'EKPO-PRSDR'
    *                                  'X'.
    *    perform bdc_field       using 'RM06E-EEIND'
    *                                   wa_jtab-j6.
          perform bdc_field       using 'RM06E-LPEIN'
                                        'D'.
          perform bdc_field       using 'EKPO-WEPOS'
                                        'X'.
          perform bdc_field       using 'EKPO-UEBTK'
                                        'X'.
          perform bdc_field       using 'EKPO-WEBRE'
                                        'X'.
          perform bdc_field       using 'BDC_OKCODE'
                                       '/00'.
          perform bdc_field       using 'BDC_OKCODE'
                                         '=ENTE'.
          move 1 to idx.
          perform bdc_dynpro      using 'SAPLMLSP' '0200'.
          perform bdc_field       using 'BDC_OKCODE'
                                       '/00'.
          perform bdc_field       using 'BDC_OKCODE'
                                         '=ENTE'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '/00'.
          perform bdc_field       using 'RM11P-HEADTEXT'
                                          'adage'.
          perform bdc_field       using  'BDC_CURSOR' 'ESLL-TBTWR(01)'.
          perform bdc_field       using 'RM11P-NEW_ROW'
                                         '10'.
    *      concatenate 'ESLL-KTEXT1(0' idx ')' into fnaml.
    *      perform bdc_field       using fnaml wa_ktab-k1.
    *      concatenate 'ESLL-MENGE(0' idx ')' into fnaml.
    *      perform bdc_field       using fnaml wa_ktab-k2.
    *      concatenate 'ESLL-MEINS(0' idx ')' into fnaml.
    *      perform bdc_field       using fnaml wa_ktab-k3.
    *      concatenate 'ESLL-TBTWR(0' idx ')' into fnaml.
    *      perform bdc_field       using fnaml wa_ktab-k4.
    *      IDX = IDX + 1.
    *      loop at KT_STAGING where vendor = it_staging-vendor and docdate = it_staging-docdate and itmcategory is not initial.
            IF TI_STAGING-ITMCATEGORY IS NOT INITIAL.
            qty = ti_staging-serqty.
            gp  = ti_staging-sergrossprice.
            perform bdc_field       using 'ESLL-KTEXT1(01)' TI_STAGING-sertext.
            perform bdc_field       using 'ESLL-MENGE(01)'  qty.
            perform bdc_field       using 'ESLL-MEINS(01)'  TI_STAGING-seruom.
            perform bdc_field      using 'ESLL-TBTWR(01)'   gp.
    *    endloop.
    *    move 1 to cnt.
    *    loop at KT_STAGING WHERE VENDOR = IT_STAGING-VENDOR AND DOCDATE = IT_STAGING-DOCDATE and itmcategory is not initial.
            perform bdc_dynpro      using 'SAPLMLSK' '0200'.
            perform bdc_field       using 'BDC_CURSOR'
                                          'RM11K-VORNR(01)'.
            perform bdc_field       using 'BDC_OKCODE'
                                          '/00'.
            perform bdc_field       using 'VRTKZ1'
                                          'X'.
    *      concatenate 'ESKN-SAKTO(0' IDX ')' into fnamk.
    *      perform bdc_field       using fnam wa_ktab-k5.
    *      concatenate 'ESKN-NPLNR(0' IDX ')' into fnamk.
    *      perform bdc_field       using fnam wa_ktab-k6.
    *      concatenate 'RM11K-VORNR(0' IDX ')' into fnamk.
    *      perform bdc_field       using fnam wa_ktab-k7.
    *      cnt = cnt + 1.
            PERFORM BDC_FIELD USING 'ESKN-SAKTO(01)' TI_STAGING-serglaccount.
            PERFORM BDC_FIELD USING 'ESKN-NPLNR(01)' TI_STAGING-sernetwork.
            PERFORM BDC_FIELD USING 'RM11K-VORNR(01)' TI_STAGING-seractivity.
    *      endloop.
          perform bdc_dynpro      using 'SAPLKACB' '0002'.
          perform bdc_field       using 'BDC_CURSOR'
                                        'COBL-NPLNR'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '=ENTE'.
          perform bdc_field       using 'COBL-NPLNR'
                                         kt_STAGING-sernetwork.
          perform bdc_field       using 'COBL-VORNR'
                                         kt_STAGING-seractivity.
          perform bdc_dynpro      using 'SAPLMLSK' '0200'.
          perform bdc_field       using 'BDC_CURSOR'
                                        'ESLL-INTROW'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '/00'.
          perform bdc_field       using 'VRTKZ1'
                                        'X'.
        perform bdc_dynpro      using 'SAPMM06E' '0200'.
        perform bdc_field       using 'BDC_CURSOR'
                                  'RM06E-EBELP'.
        perform bdc_field       using 'BDC_OKCODE'
                                  '=BACK'.
        perform bdc_dynpro      using 'SAPLMLSP' '0200'.
        perform bdc_field       using 'BDC_OKCODE'
                                         '=SAV'.
      ELSE.
        perform bdc_dynpro      using 'SAPMM06E' '0100'.
        perform bdc_field       using 'BDC_OKCODE'
                                         '=SAV'.
      ENDIF.
    endloop.
    *perform bdc_field       using 'RM11P-HEADTEXT'
    *                              'adage artwork'.
    *    perform bdc_field       using 'BDC_CURSOR'
    *                                  'ESLL-KTEXT1(01)'.
    *perform bdc_field       using 'RM11P-NEW_ROW'
    *                              '10'.
    *perform bdc_transaction using 'ME21'.
    CALL TRANSACTION 'ME21' USING I_BDCDATA MODE 'A' messages into i_msg.
    *clear: kt_staging,ti_staging,it_staging,i_bdcdata.
      endloop.
    *    CALL FUNCTION 'BDC_INSERT'
    *     EXPORTING
    *       TCODE                  = 'ME21'
    **    POST_LOCAL             = NOVBLOCAL
    **    PRINTING               = NOPRINT
    **    SIMUBATCH              = ' '
    **    CTUPARAMS              = ' '
    *      TABLES
    *        DYNPROTAB              = I_BDCDATA
    **  EXCEPTIONS
    **    INTERNAL_ERROR         = 1
    **    NOT_OPEN               = 2
    **    QUEUE_ERROR            = 3
    **    TCODE_INVALID          = 4
    **    PRINTING_INVALID       = 5
    **    POSTING_INVALID        = 6
    **    OTHERS                 = 7
    *    IF SY-SUBRC <> 0.
    *      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *    ENDIF.
    *Using Call Transaction Statement Call the transaction in back ground mode/fore ground mode
      LOOP AT I_MSG.
        CALL FUNCTION 'FORMAT_MESSAGE'
         EXPORTING
           ID              = I_MSG-MSGID
           LANG            = SY-LANGU
           NO              = I_MSG-MSGNR
           V1              = I_MSG-MSGV1
           V2              = I_MSG-MSGV2
           V3              = I_MSG-MSGV3
           V4              = I_MSG-MSGV4
         IMPORTING
           MSG             = W_STR
    *  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.
        WRITE:/ i_msg-msgnr,w_str.
      endloop.
    *  CALL FUNCTION 'BDC_CLOSE_GROUP'.
    *** EXCEPTIONS
    ***   NOT_OPEN          = 1
    ***   QUEUE_ERROR       = 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.
    *perform close_group.
    *        Start new screen                                              *
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR I_BDCDATA.
      I_BDCDATA-PROGRAM  = PROGRAM.
      I_BDCDATA-DYNPRO   = DYNPRO.
      I_BDCDATA-DYNBEGIN = 'X'.
      APPEND I_BDCDATA.
    ENDFORM.                    "BDC_DYNPRO
    *        Insert field                                                  *
    FORM BDC_FIELD USING FNAM FVAL.
    *  IF FVAL <> SPACE.
      CLEAR I_BDCDATA.
      I_BDCDATA-FNAM = FNAM.
      I_BDCDATA-FVAL = FVAL.
      APPEND I_BDCDATA.
    *  ENDIF.
    ENDFORM.                    "BDC_FIELD

  • Me21n Bdc

    Hello Expert i am making a bdc for ME21n, to make a purchase order net price is compulsary for material
    or you can say m21n has two subscreen/table control,
    How Can i Handle it

    Hi,
    if user is directly using the transaction ME21N then you can use the the exit method.
    if you are trying to create the PO in the background by uploading the PO details using the text or excel sheet then you can use the BAPI BAPI_PO_CRATE1  to create the PO.
    you can check the data present in the file in the amount field  before passing the data to the BAPI and if it is not populated pass the error message on the screen.

  • ME21N cannot run in the background - BDC

    Hi all,
    i had created a program using BDC to create PO via tcode, ME21N.
    When i run my program online, nothing happens.
    But when i schedule my program as batch job, the CNTRL_ERROR on exception error occurred.
    I inform to my basis team. they insisted that ME21N BDC cannot run in batch job.
    Pls kindly advice.
    tks in advance to all those contribute.

    BDC for ME21N Transaction
    using BDC for ME21N
    Need BDC program for ME21n
    Re: Creation of PO using BDC with ME21N - Urgent
    Reward points..

  • Bdc programing

    Hi,
    i am new to bdc.in my req.. they asked me to change bapi function module and i want replace with bdc. i want to do recording for ME21n or ME21 Tcode and bdc Session method.plz let me know the process by step by step.if any one have code for this send me.for every 1000 line items i want to crate session.
    my input file type:
    rectyp      type  char1,            " Type of Record indicator - H /T / D
             ebeln       type  ebeln,            " Purchasing Document Number
             bukrs       type zlegacy_company,   " Company Code
             ekgrp       type  bkgrp,            " Purchasing Group
             bsart(6),                           " Purchasing Document Type
             ekorg       type  ekorg,            " Purchasing Organization
             lifnr       type  elifn,            " Vendor Account Number
             bedat       type  ebdat,            " Purchasing Document Date
             ebelp       type  ebelp,            " Item Number of Purchasing Documen
             knttp       type  knttp,            " Account Assignment Category
             matkl       type  matkl,            " Material Group
             werks       type  werks,            " Plant
             txz01       type  txz01,            " Short Text
             menge(13)   type  c,                " Purchase Order Quantity
             meins       type  bstme,            " Purchase Order Unit of Measure
             netpr(16)   type   c,               " Net Price in Purchasing Document
             peinh(5)    type    c,              " Price Unit
             bprme       type  bbprm,            " Order Price Unit (Purchasing)
             eeind       type  datum,            " Delivery Date
             mwskz       type  mwskz,            " Sales Tax Code
             saknr       type  saknr,            " Cost Element
             prctr(15),                          " Profit Center
             po_number   type ebeln,             " PO Number
             bwart       type bwart,             " Movement type
             po_item     type ebelp,             " PO Line Item
             bldat       type bldat,             " Document Date
             lfsnr       type lfsnr,             " Delivery Note
             frbnr       type frbnr,             " Bill of Laden
             bktxt       type bktxt,             " Header Text
             erfmg(13)   type c,
    thanks,
    ankitha

    Hi Ankitha,
    Its not possible to use BDC for ME21N, becos this is Enjoy Tcode. Better create program using BAPI_PO_CREATE1 Bapi.
    if u want here is the code with bapi.....
    FORM create_sto .
    REFRESH: i_errpo, i_error.
    CLEAR: w_header, i_errpo, i_error, v_success, v_error.
    LOOP AT i_header_sa INTO w_header.
    CLEAR: w_errpo, w_poheaderx, w_exppurchaseorder, w_expheader,
    w_return, w_poitem, w_poitemx, w_poschedule, w_poschedulex,
    i_return, w_poitem, w_poitemx, i_poschedule, i_poschedulex.
    REFRESH: i_return, i_poitem, i_poitemx, i_poschedule, i_poschedulex.
    *--Fill Header
    w_poheader-po_number = w_header-ebeln.
    w_poheader-doc_type = 'ZU'.
    *--The supplying plant is mapped based on the recieving plant in from the ZCA_CONV_UTILITY.
    The conversion is based on the new values of the recieving plant and storage location
    v_value_old = w_header-bukrs.
    PERFORM convert TABLES i_values
    USING 'BUKRS'
    v_value_old
    CHANGING v_value_new.
    w_poheader-comp_code = v_value_new(4).
    w_poheader-pur_group = w_header-ekgrp.
    CLEAR: v_value_old, v_value_new.
    v_value_old = w_header-ekorg.
    PERFORM convert TABLES i_values
    USING 'EKORG'
    v_value_old
    CHANGING v_value_new.
    WRITE w_header-aedat+4(2) TO v_po_date(2).
    WRITE w_header-aedat6(2) TO v_po_date2(2).
    WRITE w_header-aedat(4) TO v_po_date+4(4).
    w_poheader-purch_org = v_value_new(4).
    w_poheader-vendor = w_header-lifnr.
    w_poheader-creat_date = v_po_date.
    w_poheader-item_intvl = w_header-pincr.
    w_poheader-langu = w_header-spras.
    w_poheader-subitemint = w_header-upinc.
    w_poheader-vper_start = w_header-kdatb.
    w_poheader-vper_end = w_header-kdate.
    w_poheader-warranty = w_header-gwldt.
    w_poheader-ref_1 = w_header-ihrez.
    w_poheader-sales_pers = w_header-verkf.
    w_poheader-our_ref = w_header-unsez.
    w_poheader-telephone = w_header-telf1.
    w_poheaderx-po_number = 'X'.
    w_poheaderx-doc_type = 'X'.
    w_poheaderx-suppl_plnt = 'X'.
    w_poheaderx-comp_code = 'X'.
    w_poheaderx-pur_group = 'X'.
    w_poheaderx-purch_org = 'X'.
    w_poheaderx-vendor = 'X'.
    w_poheaderx-creat_date = 'X'.
    w_poheaderx-item_intvl = 'X'.
    w_poheaderx-langu = 'X'.
    w_poheaderx-subitemint = 'X'.
    w_poheaderx-vper_start = 'X'.
    w_poheaderx-vper_end = 'X'.
    w_poheaderx-warranty = 'X'.
    w_poheaderx-ref_1 = 'X'.
    w_poheaderx-sales_pers = 'X'.
    w_poheaderx-our_ref = 'X'.
    w_poheaderx-telephone = 'X'.
    CLEAR: w_item, v_poitem.
    LOOP AT i_item INTO w_item WHERE ebeln EQ w_header-ebeln.
    CLEAR: w_zmm_cordlog,
    v_split,
    w_matnr.
    READ TABLE i_zmm_cordlog INTO w_zmm_cordlog WITH KEY ponumber = w_item-ebeln
    poitem = w_item-ebelp.
    IF sy-subrc EQ 0.
    *--If file is processed earlier, rollback work.
    IF NOT w_zmm_cordlog-mdoc561 IS INITIAL. "STO has to be processed for 561 Goods Mvmt
    w_errortab-ponumber = w_item-ebeln.
    w_errortab-poitem = w_item-ebelp.
    w_errortab-message = text-051. "Process STO for 561 Goods Mvmt.
    APPEND w_errortab TO i_errortab.
    ADD 1 TO v_error.
    CLEAR w_errortab.
    PERFORM error_pos.
    CONTINUE.
    ELSE.
    IF NOT w_zmm_cordlog-eccpo IS INITIAL. "STO already exists
    w_errortab-ponumber = w_item-ebeln.
    w_errortab-poitem = w_item-ebelp.
    w_errortab-eccpo = w_zmm_cordlog-eccpo.
    w_errortab-eccpoitem = w_zmm_cordlog-eccpoitem.
    w_errortab-message = text-052. "STO already created, record skipped
    APPEND w_errortab TO i_errortab.
    ADD 1 TO v_error.
    CLEAR w_errortab.
    PERFORM error_pos.
    CONTINUE.
    ENDIF.
    ENDIF.
    ENDIF.
    CLEAR w_mard.
    SELECT SINGLE * FROM mard INTO w_mard
    WHERE matnr EQ w_item-matnr
    AND werks EQ w_item-werks
    AND lgort EQ w_item-lgort.
    IF sy-subrc <> 0.
    w_itmerror-ponumber = w_item-ebeln.
    w_itmerror-poitem = w_item-ebelp.
    CONCATENATE w_item-matnr w_item-werks w_item-lgort text-044
    INTO w_itmerror-message SEPARATED BY space.
    APPEND w_itmerror TO i_itmerror.
    ADD 1 TO v_error.
    CONTINUE.
    ENDIF.
    *--Plant and Storage location conversion
    CLEAR: v_value_old, i_values[], v_value_new.
    CONCATENATE w_item-werks w_item-lgort INTO v_value_old.
    PERFORM convert TABLES i_values
    USING 'WERKSLGORT'
    v_value_old
    CHANGING v_value_new.
    w_item-werks = v_value_new+0(4).
    w_item-lgort = v_value_new+4(4).
    *--The converted recieving plant will be the same as the supplying plant in the new system
    and the supplying storage location would be OW01.
    w_poheader-suppl_plnt = w_item-werks.
    *--Fill item
    w_poitem-po_item = w_item-ebelp.
    w_poitem-material = w_item-matnr.
    w_poitem-plant = w_item-werks.
    w_poitem-stge_loc = w_item-lgort.
    w_poitem-po_unit = w_item-meins.
    PERFORM get_valuation_type USING w_item-matnr
    w_item-werks
    w_item-lgort
    CHANGING w_poitem-val_type.
    IF w_item-matnr CP '*-R'.
    SPLIT w_item-matnr AT '-R' INTO w_item-matnr v_split.
    ELSEIF w_item-matnr CP '*-D'.
    SPLIT w_item-matnr AT '-D' INTO w_item-matnr v_split.
    ENDIF.
    SELECT SINGLE matnr INTO w_matnr
    FROM mara
    WHERE matnr = w_item-matnr.
    IF sy-subrc NE 0.
    w_errortab-ponumber = w_item-ebeln.
    w_errortab-poitem = w_item-ebelp.
    CONCATENATE w_item-matnr 'Does not exist in the MARC table'
    INTO w_errortab-message.
    ADD 1 TO v_error.
    CONTINUE.
    ENDIF.
    w_poitem-matl_group = w_item-matkl.
    w_poitem-item_cat = w_item-pstyp.
    w_poitem-acctasscat = w_item-knttp.
    w_poitem-reminder1 = w_item-mahn1.
    w_poitem-conf_ctrl = w_item-bstae.
    w_poitem-ackn_reqd = w_item-kzabs.
    w_poitem-quantity = w_item-menge.
    w_poitem-reminder2 = w_item-mahn2.
    w_poitem-acknowl_no = w_item-labnr.
    w_poitem-reminder3 = w_item-mahn3.
    w_poitem-trackingno = w_item-bednr.
    w_poitem-gr_pr_time = w_item-webaz.
    w_poitem-under_dlv_tol = w_item-untto.
    w_poitem-qual_insp = w_item-insmk.
    w_poitem-over_dlv_tol = w_item-uebto.
    w_poitem-unlimited_dlv = w_item-uebtk.
    w_poitem-no_more_gr = w_item-elikz.
    w_poitem-shipping = w_item-evers.
    w_poitem-period_ind_expiration_date = ' '.
    APPEND w_poitem TO i_poitem.
    w_poitemx-po_item = w_poitem-po_item.
    w_poitemx-po_itemx = 'X'.
    w_poitemx-material = 'X'.
    w_poitemx-plant = 'X'.
    w_poitemx-stge_loc = 'X'.
    w_poitemx-po_unit = 'X'.
    w_poitemx-val_type = 'X'.
    w_poitemx-matl_group = 'X'.
    w_poitemx-item_cat = 'X'.
    w_poitemx-acctasscat = 'X'.
    w_poitemx-reminder1 = 'X'.
    w_poitemx-conf_ctrl = 'X'.
    w_poitemx-ackn_reqd = 'X'.
    w_poitemx-quantity = 'X'.
    w_poitemx-reminder2 = 'X'.
    w_poitemx-acknowl_no = 'X'.
    w_poitemx-reminder3 = 'X'.
    w_poitemx-trackingno = 'X'.
    w_poitemx-gr_pr_time = 'X'.
    w_poitemx-under_dlv_tol = 'X'.
    w_poitemx-qual_insp = 'X'.
    w_poitemx-over_dlv_tol = 'X'.
    w_poitemx-unlimited_dlv = 'X'.
    w_poitemx-no_more_gr = 'X'.
    w_poitemx-shipping = 'X'.
    w_poitemx-period_ind_expiration_date = 'X'.
    APPEND w_poitemx TO i_poitemx.
    CLEAR w_poitemx.
    CLEAR: w_slines, v_scheditem.
    LOOP AT i_slines INTO w_slines WHERE ebeln EQ w_item-ebeln
    AND ebelp EQ w_item-ebelp.
    *--Fill Schedule lines for PO
    w_poschedule-po_item = w_item-ebelp.
    w_poschedule-sched_line = w_slines-etenr.
    w_poschedule-del_datcat_ext = ' '.
    w_poschedule-delivery_date = w_slines-eindt.
    w_poschedule-quantity = w_slines-menge.
    APPEND w_poschedule TO i_poschedule.
    CLEAR w_poschedule.
    w_poschedulex-po_item = w_item-ebelp.
    w_poschedulex-sched_line = w_slines-etenr.
    w_poschedulex-po_itemx = 'X'.
    w_poschedulex-sched_linex = 'X'.
    w_poschedulex-del_datcat_ext = 'X'.
    w_poschedulex-delivery_date = 'X'.
    w_poschedulex-quantity = 'X'.
    APPEND w_poschedulex TO i_poschedulex.
    CLEAR w_poschedulex.
    CLEAR w_slines.
    ENDLOOP.
    CLEAR: w_poitem,
    w_item.
    ENDLOOP.
    SORT: i_poitem, i_poitemx, i_poschedule, i_poschedulex.
    *--If the import data to BAPI is empty, then raise a message to check the Material Error file for
    any PO items which are skipped.
    The PO in error is also moved to the error file for reprocessing.
    IF w_poheader IS INITIAL OR
    i_poitem[] IS INITIAL.
    CLEAR: w_poheader, w_poheaderx, i_return[], i_poitem, i_poitem[].
    CONTINUE.
    ENDIF.
    *--BAPI call for PO creation
    CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
    poheader = w_poheader
    poheaderx = w_poheaderx
    testrun = p_test
    IMPORTING
    exppurchaseorder = w_exppurchaseorder
    expheader = w_expheader
    TABLES
    return = i_return
    poitem = i_poitem
    poitemx = i_poitemx
    poschedule = i_poschedule
    poschedulex = i_poschedulex.
    *--Commit the transaction if a success message is returned, else rollback work.
    Update the legacy PO and items in the ZMM_CORDLOG table
    start of modification
    WAIT UP TO time SECONDS.
    end of modification
    IF NOT i_return[] IS INITIAL.
    LOOP AT i_return INTO w_return.
    *--Read the error messages
    IF w_return-type = 'E'.
    w_errortab-ponumber = w_header-ebeln.
    w_errortab-doctype = w_poheader-doc_type.
    w_errortab-supplplnt = w_poheader-suppl_plnt.
    w_errortab-vendor = w_poheader-vendor.
    w_errortab-eccpo = w_expheader-po_number.
    w_errortab-message = w_return-message(73).
    APPEND w_errortab TO i_errortab.
    ADD 1 TO v_error.
    ROLLBACK WORK.
    ELSEIF w_return-type = 'S'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    wait = 'X'
    EXCEPTIONS
    OTHERS = 1.
    IF sy-subrc EQ 0.
    v_success = v_success + 1.
    CLEAR w_poitem.
    LOOP AT i_poitem INTO w_poitem.
    w_zmm_cordlog-ponumber = w_poheader-po_number.
    w_zmm_cordlog-poitem = w_poitem-po_item.
    w_zmm_cordlog-doctype = w_poheader-doc_type.
    w_zmm_cordlog-supplplnt = w_poheader-suppl_plnt.
    w_zmm_cordlog-vendor = w_poheader-vendor.
    w_zmm_cordlog-eccpo = w_poheader-po_number.
    w_zmm_cordlog-eccpoitem = w_poitem-po_item.
    w_zmm_cordlog-message = w_return-message(73).
    MODIFY zmm_cordlog FROM w_zmm_cordlog. "Modify DB table
    CLEAR w_zmm_cordlog.
    w_errpo-ebeln = w_poheader-po_number.
    w_errpo-ebelp = w_poitem-po_item.
    APPEND w_errpo TO i_errpo.
    CLEAR w_errpo.
    ENDLOOP.
    ENDIF.
    ENDIF.
    ENDLOOP.
    CALL FUNCTION 'DEQUEUE_ALL'.
    ENDIF.
    CLEAR: w_header,
    w_poheader,
    w_poheaderx.
    CALL FUNCTION 'DEQUEUE_ALL'.
    ENDLOOP.
    IF NOT i_errpo[] IS INITIAL.
    *--Separate error records (all records for any PO in error).
    PERFORM create_error_file TABLES i_header_sa.
    *--Write data to Application Server
    IF NOT i_error[] IS INITIAL.
    OPEN DATASET p_error FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
    IF sy-subrc NE 0.
    MESSAGE e398 WITH text-023 space space space.
    ENDIF.
    LOOP AT i_error INTO w_error.
    TRANSFER w_error TO p_error.
    ENDLOOP.
    ENDIF.
    ENDIF.
    COMMIT WORK.
    ENDFORM. " create_sto
    some other example code with bapi.. for ME21N
    use BAPI_PO_CREATE1.
    check this Sample code,
    REPORT  zpo_create                              .
    PARAMETERS: p-file LIKE rlgrap-filename DEFAULT
                              'c:\demo3.txt'.
    DATA: BEGIN OF itab OCCURS 0,
      line(1000),
      END OF itab.
    DATA l_item(5) TYPE n.
    TABLES : zerror.
    DATA lcounter(3) TYPE n.
    DATA : l_errflag.
    DATA : l_po_header LIKE bapimepoheader.
    DATA : l_po_headerx LIKE bapimepoheaderx.
    DATA : t_po_account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE.
    DATA : t_po_accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.
    DATA : l_new_po(10), l_last_po(10).
    DATA : l_purchaseorder LIKE bapimepoheader-po_number.
    *DATA : L_HEADER LIKE BAPIMEPOHEADER STRUCTURE BAPIMEPOHEADER.
    DATA : BEGIN OF t_po_items OCCURS 0.
            INCLUDE STRUCTURE bapimepoitem.
    DATA : END OF t_po_items.
    DATA : BEGIN OF t_po_itemsx OCCURS 0.
            INCLUDE STRUCTURE bapimepoitemx.
    DATA : END OF t_po_itemsx.
    DATA : BEGIN OF t_return OCCURS 0.
            INCLUDE STRUCTURE bapiret2.
    DATA : END OF t_return.
    CLEAR : l_po_header.
    CALL FUNCTION 'WS_UPLOAD'
      EXPORTING
        filename                = p-file
        filetype                = 'DAT'
      TABLES
        data_tab                = itab
      EXCEPTIONS
        file_open_error         = 1
        file_read_error         = 2
        no_batch                = 3
        gui_refuse_filetransfer = 4
        invalid_type            = 5
        OTHERS                  = 6.
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      EXIT.
    ENDIF.
    LOOP  AT itab.
      IF itab-line(1) EQ 'K'.
        l_new_po = itab-line(10).
        IF l_last_po NE  l_new_po AND l_last_po NE space.
          PERFORM create_po.
          PERFORM refresh_table.
        ENDIF.
        IF itab-line+13(2) EQ '40'.
          PERFORM append_header.
        ENDIF.
        IF itab-line+13(2) EQ '81'.
          PERFORM append_item.
        ENDIF.
        l_last_po = l_new_po.
      ENDIF.
    ENDLOOP.
    IF sy-subrc EQ 0.
      PERFORM create_po.
      PERFORM refresh_table.
    ENDIF.
    *&      Form  CREATE_PO
    PO Create
    -->  p1        text
    <--  p2        text
    FORM create_po .
      CLEAR : l_purchaseorder.
      CALL FUNCTION 'BAPI_PO_CREATE1'
        EXPORTING
          poheader                     = l_po_header
         poheaderx                    = l_po_headerx
        POADDRVENDOR                 =
        TESTRUN                      =
        MEMORY_UNCOMPLETE            =
        MEMORY_COMPLETE              =
        POEXPIMPHEADER               =
        POEXPIMPHEADERX              =
        VERSIONS                     =
        NO_MESSAGING                 =
        NO_MESSAGE_REQ               =
        NO_AUTHORITY                 =
        NO_PRICE_FROM_PO             =
       IMPORTING
         exppurchaseorder             = l_purchaseorder
        EXPHEADER                    =
        EXPPOEXPIMPHEADER            =
       TABLES
         return                       = t_return
         poitem                       = t_po_items
         poitemx                      = t_po_itemsx
        POADDRDELIVERY               =
        POSCHEDULE                   =
        POSCHEDULEX                  =
         poaccount                    = t_po_account
        POACCOUNTPROFITSEGMENT       =
         poaccountx                   = t_po_accountx
        POCONDHEADER                 =
        POCONDHEADERX                =
        POCOND                       =
        POCONDX                      =
        POLIMITS                     =
        POCONTRACTLIMITS             =
        POSERVICES                   =
        POSRVACCESSVALUES            =
        POSERVICESTEXT               =
        EXTENSIONIN                  =
        EXTENSIONOUT                 =
        POEXPIMPITEM                 =
        POEXPIMPITEMX                =
        POTEXTHEADER                 =
        POTEXTITEM                   =
        ALLVERSIONS                  =
        POPARTNER                    =
      l_errflag = space.
      lcounter  = 1.
      LOOP AT t_return .
        IF t_return-type = 'E'.
          l_errflag = 'X'.
          GET TIME.
          PERFORM append_error.
        ENDIF.
        WRITE : /1 t_return-message.
      ENDLOOP.
      IF l_errflag EQ space.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
    WAIT =
    IMPORTING
    RETURN =
      ENDIF.
    ENDFORM.                    " CREATE_PO
    *&      Form  APPEND_HEADER
    PO Header print
    -->  p1        text
    <--  p2        text
    FORM append_header .
      l_po_header-comp_code = '1000'." Company Code
      l_po_header-doc_type = 'NB'. " Order Typr BSART
      l_po_header-creat_date = sy-datum. " P.O Dt - BEDAT
    *CONCATENATE '0000' ITAB+72(6) INTO L_PO_HEADER-VENDOR .
      l_po_header-vendor = itab-line+71(6).
    *L_PO_HEADER-VENDOR = ITAB+72(6)    " 'ABC'. "Vendor - EKKO-LIFNR
      IF itab-line(4) NE 'K034'.
        l_po_header-purch_org = '2000'. " Purch. Org - EKKO-EKORG
        l_po_header-pur_group = 'F01'. " Purch Group - EKKO-EKGRP
      ELSE.
        l_po_header-purch_org = '1000'. " Purch. Org - EKKO-EKORG
        l_po_header-pur_group = '001'. " Purch Group - EKKO-EKGRP
      ENDIF.
      l_po_header-currency_iso = 'USD'. " Currency Default field for Enjoy
      l_po_header-ref_1       = itab-line+1(9).
    *L_PO_HEADER-DOC_CAT = 'F'. " Account Assign Cat EKPO-KNTTP
    *_PO_HEADER-CREATED_BY = SY-UNAME.
      CLEAR : l_po_headerx.
      l_po_headerx-po_number = 'X'.
      l_po_headerx-comp_code = 'X'." Company Code
      l_po_headerx-doc_type = 'X'. " Order Typr BSART
      l_po_headerx-vendor = 'X'. "Vendor - EKKO-LIFNR
      l_po_headerx-purch_org = 'X'. " Purch. Org - EKKO-EKORG
      l_po_headerx-pur_group = 'X'. " Purch Group - EKKO-EKGRP
      l_po_headerx-currency_iso = 'X'. " Currency Default field for Enjoy
      l_po_headerx-ref_1       = 'X'.
    ENDFORM.                    " APPEND_HEADER
    *&      Form  APPEND_ITEM
    Material Number and Item print
    -->  p1        text
    <--  p2        text
    FORM append_item .
    PO Line Items
      l_item = l_item + 10.
      t_po_items-po_item = l_item.
    *T_PO_ITEMS-PO_ITEM = '00010'." Line Item No - EKPO-EBELP
    *T_PO_ITEMS-SHORT_TEXT = 'KSR TEXT'." Line Item TEXT
      CONCATENATE  '00000000' itab-line+32(10) INTO t_po_items-material.
    *T_PO_ITEMS-MATERIAL = '000000000000000043'. " Material No - EKPO-EMATN
      CONCATENATE  '00000000' itab-line+32(10) INTO t_po_items-ematerial.
      t_po_items-plant = '2001'. " Plant - EKPO-WERKS
      t_po_items-quantity = '1.000'.
      t_po_items-net_price = '10.00'. " EKPO-NETPR
      t_po_items-price_unit = '10 '.
    *T_PO_ITEMS-TAX_CODE = 'A2'.
      IF  itab-line+0(4) EQ 'K034'.
        t_po_items-acctasscat = 'R'.
        t_po_items-plant = '1001'.
        t_po_account-po_item = l_item.
        t_po_account-profit_ctr = 'BR034'.
        t_po_account-gl_account = '0000135075'.
    T_PO_ACCOUNT-CO_AREA  = '1000'.
        APPEND t_po_account.
        CLEAR t_po_account.
        t_po_accountx-po_item = l_item.
        t_po_accountx-profit_ctr = 'X'.
        t_po_accountx-gl_account = 'X'.
    T_PO_ACCOUNTX-CO_AREA  = 'X'.
        APPEND t_po_accountx.
        CLEAR t_po_accountx.
      ENDIF.
      APPEND t_po_items.
      CLEAR t_po_items.
      t_po_itemsx-po_item = l_item.
      t_po_itemsx-po_itemx = 'X'.
      t_po_itemsx-acctasscat = 'X'.
      t_po_itemsx-material = 'X'.
      t_po_itemsx-ematerial = 'X'.
      t_po_itemsx-plant = 'X'.
      t_po_itemsx-quantity = 'X'.
      t_po_itemsx-net_price = 'X'.
      t_po_itemsx-price_unit = 'X'.
    *T_PO_ITEMSX-TAX_CODE = 'X'.
      APPEND t_po_itemsx.
      CLEAR t_po_itemsx.
    Second Line Item
    ENDFORM.                    " APPEND_ITEM
    *&      Form  REFRESH_TABLE
          text
    -->  p1        text
    <--  p2        text
    FORM refresh_table .
      REFRESH : t_po_items, t_po_itemsx.
      CLEAR l_item.
    ENDFORM.                    " REFRESH_TABLE
    *&      Form  append_error
          text
    -->  p1        text
    <--  p2        text
    FORM append_error .
      MOVE : sy-datum TO zerror-zdate,
              sy-uzeit TO zerror-ztime,
              itab+3(5) TO zerror-document_no,
              t_return-message    TO zerror-message.
      lcounter =  lcounter + 1.
      zerror-counter = lcounter .
      zerror-rec_type = itab-line(1).
      MODIFY zerror. CLEAR zerror.
      COMMIT WORK.
    ENDFORM.                    " append_error
    ~~Guduri
    Mark the helpful answers
            NAVEEN KUMAR GUDURI

  • Me21 and me21n

    what is the diff?
    is it possible to write the bdc for me21n?

    Hi Mohan,
    ME21 is for creating PO.
    ME21 is like all in one for PO.
    Its not recommended to do  BDC for ME21N transaction(or for that matter any enjoy transactions).
    Its created based on Java and Activex Controls.
    Instead use the <b>BAPI_PO_CREATE1</b>. You can find sample code for creating PO using <b>BAPI_PO_CREATE1</b> in this link.
    Re: BDC for ME21N
    Regards,
    Arun Sambargi.

  • Enjoy purchase order transaction

    Hi All,
    Can anybody tell me how get idea on Enjoy Purchase Order.
    ie, how to update it ie, using bapi.
    Can anybody explain it in detail.
    regards,
    phaneendra.

    Hi,
    Check reply from vijay babu using BAPI_PO_CREATE1
    BDC for ME21N
    Regards

  • Printing Purchase Orders after they have been created using BAPI_PO_CREATE1

    Hi
    We have a requirement to develop a Z program to to alloow certain users to create and print "special" dummy Purchase Orders (PO).
    Using BAPI_PO_CREATE1 I have been able to create the PO no problem.  But how on earth do you get them to physically print out ?
    BAPI_PO_CREATE1 is meant to be an alternative to ME21N. In ME21N you can create a "PO message" which is actually a print output of the PO) and have it sent to the spool, depending on config. However, you can't use BDC with ME21N.
    I expected the BAPI to have some sort of table/structure to pass print parameters that emulated ME21N's  PO message, but there is none.
    Anybody done this ?
    cheers Hugh

    Well, if you had your PO output configured to print immediately when the PO is created, then the BAPI call would result in a printout.
    But if you don't want to always print a PO when a new document is created, you could set up a new output type for 'print immediately' and then attach a condition in the output configuration that checks if a certain criterion is met (so for instance if the PO was created via the BAPI), and only if this condition is met would the processing continue.
    That way, you could keep the current PO output process (on request only), and have a conditional output that'd only be processed for POs created by the BAPI.

  • Bdc notes for mm01 & me21n

    hi gurus,
      i want  notes for creating materials and to create purchase order using bdc and to upload some datas using that recording from datas in note pad or any external file with screen shots. if any body sent to it ll be very useful to me...
    thanks in advance
    arun

    Hi,
    check the codes for mm01 and me21n.
    mm01
    report ZBHMAT no standard page heading line-size 255.
    DATA:BEGIN OF ITAB OCCURS 0,
         MATNR LIKE RMMG1-MATNR,
         MBRSH LIKE RMMG1-MBRSH,
         MTART LIKE RMMG1-MTART,
         KZSEL LIKE MSICHTAUSW-KZSEL,
         WERKS LIKE RMMG1-WERKS,
         VKORG LIKE RMMG1-VKORG,
         VTWEG LIKE RMMG1-VTWEG,
         MAKTX LIKE MAKT-MAKTX,
         MEINS LIKE MARA-MEINS,
         SKTOF LIKE MVKE-SKTOF,
         TAXKM LIKE MG03STEUER-TAXKM,
         GEWEI LIKE MARA-GEWEI,
         MTVFP LIKE MARC-MTVFP,
         TRAGR LIKE MARA-TRAGR,
         LADGR LIKE MARC-LADGR,
    END OF ITAB.
    DATA BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = 'C:/BHARAT/MAT.TXT'
       FILETYPE                      = 'ASC'
      TABLES
        DATA_TAB                      = ITAB.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
       CLIENT                    = SY-MANDT
       GROUP                     = 'MATERIAL'
       KEEP                      = 'X'
       USER                      = SY-UNAME
       PROG                      = SY-CPROG.
    LOOP AT ITAB.
    perform bdc_dynpro      using 'SAPLMGMM' '0060'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RMMG1-MATNR'.
    perform bdc_field       using 'RMMG1-MATNR'
                                  ITAB-MATNR.
    perform bdc_field       using 'RMMG1-MBRSH'
                                  ITAB-MBRSH.
    perform bdc_field       using 'RMMG1-MTART'
                                  ITAB-MTART.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_dynpro      using 'SAPLMGMM' '0070'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MSICHTAUSW-KZSEL(04)'.
    perform bdc_field       using 'MSICHTAUSW-KZSEL(04)'
                                  ITAB-KZSEL.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=ENTR'.
    perform bdc_dynpro      using 'SAPLMGMM' '0080'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RMMG1-WERKS'.
    perform bdc_field       using 'RMMG1-WERKS'
                                  ITAB-WERKS.
    perform bdc_field       using 'RMMG1-VKORG'
                                  ITAB-VKORG.
    perform bdc_field       using 'RMMG1-VTWEG'
                                  ITAB-VTWEG.
    perform bdc_field       using 'BDC_OKCODE'
                                  'ENTR'.
    perform bdc_dynpro      using 'SAPLMGMM' '4000'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MAKT-MAKTX'.
    perform bdc_field       using 'MAKT-MAKTX'
                                  ITAB-MAKTX.
    perform bdc_field       using 'MARA-MEINS'
                                  ITAB-MEINS.
    perform bdc_field       using 'MVKE-SKTOF'
                                  ITAB-SKTOF.
    perform bdc_field       using 'MG03STEUER-TAXKM(01)'
                                  ITAB-TAXKM.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_dynpro      using 'SAPLMGMM' '4200'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MAKT-MAKTX'.
    perform bdc_field       using 'MAKT-MAKTX'
                                  ITAB-MAKTX.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_dynpro      using 'SAPLMGMM' '4000'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MAKT-MAKTX'.
    perform bdc_field       using 'MAKT-MAKTX'
                                  ITAB-MAKTX.
    perform bdc_field       using 'MARA-MEINS'
                                  ITAB-MEINS.
    perform bdc_field       using 'MVKE-SKTOF'
                                  ITAB-SKTOF.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_dynpro      using 'SAPLSPO1' '0300'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=YES'.
    perform bdc_dynpro      using 'SAPLMGMM' '4000'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MAKT-MAKTX'.
    perform bdc_field       using 'MAKT-MAKTX'
                                  ITAB-MAKTX.
    perform bdc_field       using 'MARA-MEINS'
                                  ITAB-MEINS.
    perform bdc_field       using 'MARA-GEWEI'
                                  ITAB-GEWEI.
    perform bdc_field       using 'MARC-MTVFP'
                                  ITAB-MTVFP.
    perform bdc_field       using 'MARA-TRAGR'
                                  ITAB-TRAGR.
    perform bdc_field       using 'MARC-LADGR'
                                  ITAB-LADGR.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_dynpro      using 'SAPLSPO1' '0300'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=YES'.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
       TCODE                  = 'MM01'
      TABLES
        DYNPROTAB              = BDCTAB.
    REFRESH BDCTAB.
    ENDLOOP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCTAB.
      BDCTAB-PROGRAM  = PROGRAM.
      BDCTAB-DYNPRO   = DYNPRO.
      BDCTAB-DYNBEGIN = 'X'.
      APPEND BDCTAB.
    ENDFORM.
    FORM BDC_FIELD USING FNAM FVAL.
        CLEAR BDCTAB.
        BDCTAB-FNAM = FNAM.
        BDCTAB-FVAL = FVAL.
        APPEND BDCTAB.
    ENDFORM.
    me21n
    report ZBH_PURORDER no standard page heading line-size 255.
    PARAMETERS:P_FILE LIKE IBIPPARMS-PATH.
    DATA FILENAME TYPE STRING.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
    CALL FUNCTION 'F4_FILENAME'
       EXPORTING
          program_name  = sy-cprog
          dynpro_number = sy-dynnr
       IMPORTING
          file_name     = P_FILE.
    START-OF-SELECTION.
    FILENAME = P_FILE.
    DATA:BEGIN OF XTAB OCCURS 0,
    TYP,
    DES(255) TYPE C,
    END OF XTAB.
    DATA:BEGIN OF ITAB OCCURS 0,
    SUPERFIELD LIKE MEPO_TOPLINE-SUPERFIELD,
    EKORG LIKE MEPO1222-EKORG,
    EKGRP LIKE MEPO1222-EKGRP,
    BUKRS LIKE MEPO1222-BUKRS,
    END OF ITAB.
    DATA:BEGIN OF JTAB OCCURS 0,
    N(4) TYPE C,
    EMATN LIKE MEPO1211-EMATN,
    MENGE(13) TYPE C,
    NETPR(13) TYPE C,
    NAME1 LIKE MEPO1211-NAME1,
    END OF JTAB.
    DATA:BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
    DATA:DELIMITER VALUE '*'.
    DATA A TYPE I.
    DATA M(4) TYPE N.
    DATA L_FNAM(30) TYPE C.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        FILENAME                      = FILENAME
       FILETYPE                      = 'ASC'
      TABLES
        DATA_TAB                      = XTAB.
    LOOP AT XTAB.
    IF XTAB-TYP = 'H'.
      SPLIT XTAB-DES AT DELIMITER INTO ITAB-SUPERFIELD ITAB-EKORG ITAB-EKGRP
      ITAB-BUKRS.
      JTAB-N = JTAB-N + 1.
      APPEND ITAB.
    ELSEIF XTAB-TYP = 'I'.
      SPLIT XTAB-DES AT DELIMITER INTO JTAB-EMATN JTAB-MENGE JTAB-NETPR
      JTAB-NAME1.
    APPEND JTAB.
    ENDIF.
    ENDLOOP.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
       CLIENT                    = SY-MANDT
       GROUP                     = 'PORDER'
       KEEP                      = 'X'
       USER                      = SY-UNAME.
    LOOP AT ITAB.
    A = SY-TABIX.
    REFRESH BDCTAB.
    perform bdc_dynpro      using 'SAPLMEGUI' '0014'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MEPO_TOPLINE-SUPERFIELD'.
    perform bdc_field       using 'MEPO_TOPLINE-BSART'
                                  'NB'.
    perform bdc_field       using 'MEPO_TOPLINE-SUPERFIELD'
                                  ITAB-SUPERFIELD.
    perform bdc_field       using 'MEPO_TOPLINE-BEDAT'
                                  '09.02.2007'.
    perform bdc_field       using 'DYN_6000-LIST'
                                  '                                      1'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=MEV4000BUTTON'.
    perform bdc_dynpro      using 'SAPLMEGUI' '0014'.
    perform bdc_field       using 'MEPO_TOPLINE-BSART'
                                  'NB'.
    perform bdc_field       using 'MEPO_TOPLINE-SUPERFIELD'
                                  ITAB-SUPERFIELD.
    perform bdc_field       using 'MEPO_TOPLINE-BEDAT'
                                  '09.02.2007'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MEPO1222-EKORG'.
    perform bdc_field       using 'MEPO1222-EKORG'
                                  ITAB-EKORG.
    perform bdc_field       using 'MEPO1222-EKGRP'
                                  ITAB-EKGRP.
    perform bdc_field       using 'MEPO1222-BUKRS'
                                  ITAB-BUKRS.
    perform bdc_field       using 'DYN_6000-LIST'
                                  '                                      1'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=MEV4001BUTTON'.
    perform bdc_dynpro      using 'SAPLMEGUI' '0014'.
    perform bdc_field       using 'MEPO_TOPLINE-BSART'
                                  'NB'.
    perform bdc_field       using 'MEPO_TOPLINE-SUPERFIELD'
                                  ITAB-SUPERFIELD.
    perform bdc_field       using 'MEPO_TOPLINE-BEDAT'
                                  '09.02.2007'.
    perform bdc_field       using 'MEPO1222-EKORG'
                                  ITAB-EKORG.
    perform bdc_field       using 'MEPO1222-EKGRP'
                                 ITAB-EKGRP.
    perform bdc_field       using 'MEPO1222-BUKRS'
                                 ITAB-BUKRS.
    M = 1.
    LOOP AT JTAB.
    IF JTAB-N = A.
    WRITE:/ JTAB.
    CONCATENATE 'MEPO1211-EMATN(' M ')' INTO L_FNAM.
    perform bdc_field       using 'BDC_CURSOR'
                                  L_FNAM.
    perform bdc_field       using L_FNAM
                                  JTAB-EMATN.
    CONCATENATE 'MEPO1211-MENGE(' M ')' INTO L_FNAM.
    perform bdc_field       using L_FNAM
                                  JTAB-MENGE.
    CONCATENATE 'MEPO1211-NETPR(' M ')' INTO L_FNAM.
    perform bdc_field       using L_FNAM
                                  JTAB-NETPR.
    CONCATENATE 'MEPO1211-NAME1(' M ')' INTO L_FNAM.
    perform bdc_field       using L_FNAM
                                  JTAB-NAME1.
    M = M + 1.
    ENDIF.
    ENDLOOP.
    perform bdc_field       using 'DYN_6000-LIST'
                                  '                                      1'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_dynpro      using 'SAPLMEGUI' '0014'.
    perform bdc_field       using 'MEPO_TOPLINE-BSART'
                                  'NB'.
    perform bdc_field       using 'MEPO_TOPLINE-SUPERFIELD'
                                  ITAB-SUPERFIELD.
    perform bdc_field       using 'MEPO_TOPLINE-BEDAT'
                                  '09.02.2007'.
    perform bdc_field       using 'MEPO1222-EKORG'
                                  ITAB-EKORG.
    perform bdc_field       using 'MEPO1222-EKGRP'
                                  ITAB-EKGRP.
    perform bdc_field       using 'MEPO1222-BUKRS'
                                  ITAB-BUKRS.
    perform bdc_field       using 'DYN_6000-LIST'
                                  '                                      1'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'MEPO1319-MATKL'.
    perform bdc_field       using 'MEPO1319-SPINF'
                                  'X'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=MESAVE'.
    CALL FUNCTION 'BDC_INSERT'
    EXPORTING
       TCODE                  = 'ME21N'
      TABLES
        DYNPROTAB              = BDCTAB.
    ENDLOOP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCTAB.
      BDCTAB-PROGRAM  = PROGRAM.
      BDCTAB-DYNPRO   = DYNPRO.
      BDCTAB-DYNBEGIN = 'X'.
      APPEND BDCTAB.
    ENDFORM.
    FORM BDC_FIELD USING FNAM FVAL.
        CLEAR BDCTAB.
        BDCTAB-FNAM = FNAM.
        BDCTAB-FVAL = FVAL.
        APPEND BDCTAB.
    ENDFORM.
    FLAT FILE:
    H1171611000001*1000
    ICPU116000*1000
    ILEY BOARD1010000*1000
    IMOUSE66000*1000
    H1171711000001*1000
    ICPU580000*1000
    H1171701000001*1000
    IMOUSE33000*1000
    ILEY BOARD1010000*1000
    rgds,
    bharat.

  • ME21 / ME21N BDC Codes

    Hi All,
    while recording( in ME21) atlast im gettin an error like netprice is grtr than 0, eventhough netprice is positive value only,
    while using me21n, cant craete prog, dunno why,
    im getin hectic with this one,
    I need code for ME21 / ME21N (purchase order create),
    plz anyone help me,
    thanks in advance,
    hema.p

    hi
    check this code
    report zgmimm_me21 no standard page heading line-size 255.
    tables: t100.
    type-pools: truxs.
    types: begin of i_upload,
            lifnr    like ekko-lifnr,         "Vendor Number
            bukrs    like ekko-bukrs,         "Order type
            bedat    like ekko-bedat,         "Purchase Order Date
            ekorg    like ekko-ekorg,         "Purchasing organization
            ausnr    like ekko-ausnr,         "Purchase order
            ekgrp    like ekko-ekgrp,         "Purchasing group
            eddat    like ekko-bedat,         "Delivery date
            werks    like ekpo-werks,         "Plant
            lgort    like ekpo-lgort,         "Storage location
            zterm    like ekko-zterm,         "Payment terms
            ematn    like ekpo-ematn,         "Material
            menge    like ekpo-menge,         "PO Quantity
            lewed    like ekpo-lewed,          "Latest GR Date
          end of i_upload.
    data: begin of i_input occurs 0,
          pbg(10) type c,
          bldat(07) type c,         "001
         BLDAT like BKPF-BUDAT,
          hkont(10) type c,
          kostl(10) type c,
          wrbtr(11) type c,
          dbcrflag(01) type c,
           sgtxt(32) type c,
       end of i_input.
    data: v_counter(2) type n.
    data: v_mod        type i.
    data: v_ebelp      like ekpo-ebelp.
    data: v_fname(132) type c.
    data: v_fname1(132) type c.
    data: v_tabix      like sy-tabix.
    data : ws_text(200) type c.
    data : wa_mag(1).
    data: begin of int_msg occurs 0,
           cnt type i,
           massage(1) type c,
           text(200) type c,
          end of int_msg.
    data : begin of i_final occurs 0,
            lifnr    like ekko-lifnr,         "Vendor Number
            bukrs    like ekko-bukrs,         "Order type
            bedat(10),
            ekorg    like ekko-ekorg,         "Purchasing organization
            ausnr    like ekko-ausnr,         "Purchase order
            ekgrp    like ekko-ekgrp,         "Purchasing group
            eddat(10),
            werks    like ekpo-werks,         "Plant
            lgort    like ekpo-lgort,         "Storage location
            zterm    like ekko-zterm,         "Payment terms
            ematn    like ekpo-ematn,         "Material
            menge    type char15,             "PO Quantity
            lewed(10),
            TAX_CODE type mwskz,
            GR_BASEDIV,
          end of i_final.
    data: it_datatab type standard table of i_upload,
          wa_datatab type i_upload.
    data: it_raw type truxs_t_text_data.
    data: begin of bdcdata occurs 0.
            include structure bdcdata.
    data: end of bdcdata.
    data: begin of messtab occurs 0.
            include structure bdcmsgcoll.
    data: end of messtab.
    data: begin of t_input occurs 0.
            include structure i_input.
    data:  end of t_input.
    data: begin of i_local_output occurs 0,
             text(2800) type c,
          end of i_local_output.
    data: begin of i_error occurs 0.
            include structure i_input.
    data:    text(50) type c.
    data: end of i_error.
    data : _datum1(10).
    data :  t_datum1(10).
    data:  msgno like sy-msgno,
           msgid like sy-msgid,
           msgty like sy-msgty,
           message like message.
    *Data : TEXT(50) Type c value 'File Shoud be in Excel Format'.
    data: wa_head     type bapimepoheader,
          wa_headx    type bapimepoheaderx,
          i_return    type bapiret2            occurs 0 with header line,
          i_item      type bapimepoitem        occurs 0 with header line,
          i_itemx     type bapimepoitemx       occurs 0 with header line,
          i_sch       type bapimeposchedule    occurs 0 with header line,
          i_schx      type bapimeposchedulx    occurs 0 with header line.
                  SELECTION SCREEN
    parameters: p_file type  rlgrap-filename obligatory modif id app.
               Write : /3 Text.
             START OF SELECTION
    at selection-screen on value-request for p_file.
      call function 'F4_FILENAME'
           exporting
                field_name = 'P_FILE'
           importing
                file_name  = p_file.
    start-of-selection.
      perform data_from_excel_to_sap.
      perform pass_data_to_final_int_tab.
    perform fill_bdc_data.
      perform fill_bapi_parameters.
      perform call_po_create_bapi.
    *&      Form  DATA_FROM_EXCEL_TO
          text
    -->  p1        text
    <--  p2        text
    form data_from_excel_to_sap.
      call function 'TEXT_CONVERT_XLS_TO_SAP'
          exporting
        I_FIELD_SEPERATOR        =
            i_line_header            =  'X'
            i_tab_raw_data           =  it_raw       " WORK TABLE
            i_filename               =  p_file
          tables
            i_tab_converted_data     = it_datatab[]    "ACTUAL DATA
         exceptions
            conversion_failed        = 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.
    endform.                    " DATA_FROM_EXCEL_TO
    *&      Form  PASS_DATA_TO_FINAL_INTERNAL_TA
          text
    -->  p1        text
    <--  p2        text
    form pass_data_to_final_int_tab.
      loop at it_datatab into wa_datatab.
        move wa_datatab-lifnr to i_final-lifnr.  "Vendor Number
        move wa_datatab-bukrs to i_final-bukrs.  "Order type
        move wa_datatab-bedat to i_final-bedat.  "Purchase Order Date
        concatenate i_final-bedat6(2) '.' i_final-bedat4(2) '.20'
                         i_final-bedat+2(2) into _datum1.
        i_final-bedat = _datum1.
        move wa_datatab-ekorg to i_final-ekorg.  "Purchasing organization
        move wa_datatab-ausnr to i_final-ausnr.  "Purchase order
        move wa_datatab-ekgrp to i_final-ekgrp.  "Purchasing group
        move wa_datatab-eddat to i_final-eddat.  "Delivery date
        concatenate i_final-eddat6(2) '.' i_final-eddat4(2) '.20'
                         i_final-eddat+2(2) into _datum1.
        i_final-eddat = _datum1.
        move wa_datatab-werks to i_final-werks.  "Plant
        move wa_datatab-lgort to i_final-lgort.  "Storage location
        move wa_datatab-zterm to i_final-zterm.  "Payment terms
        move wa_datatab-ematn to i_final-ematn.  "Material
        move wa_datatab-menge to i_final-menge.  "PO Quantity
        move wa_datatab-lewed to i_final-lewed.  "Latest GR Date
    ***Value Hard coaded considering this Program is only for Import.
        I_FINAL-TAX_CODE   = 'V0'.
        I_FINAL-GR_BASEDIV = ' '.
        concatenate i_final-lewed6(2) '.' i_final-lewed4(2) '.20'
                         i_final-lewed+2(2) into _datum1.
        i_final-lewed = _datum1.
        append i_final.
      endloop.
    endform.                    " PASS_DATA_TO_FINAL_INTERNAL_TA
    *&      Form  FILL_BDC_DATA
          text
    -->  p1        text
    <--  p2        text
    form fill_bdc_data.
      read table i_final index 1.
      perform f0510_bdcdata using :
                 'X'          'SAPMM06E'   '0100',
                 ' '          'BDC_CURSOR' 'RM06E-MATKL',
                 ' '          'BDC_OKCODE' '=KOPF',
                 ' '          'EKKO-LIFNR'  i_final-lifnr,
                 ' '          'RM06E-BSART' i_final-bukrs,
                 ' '          'RM06E-BEDAT' i_final-bedat,
                 ' '          'RM06E-BSTNR' i_final-ausnr,
                 ' '          'EKKO-EKORG'  i_final-ekorg,
                 ' '          'EKKO-EKGRP'  i_final-ekgrp,
                 ' '          'RM06E-EEIND' i_final-eddat,
                 ' '          'RM06E-LPEIN' 'T',
                 ' '          'RM06E-WERKS' i_final-werks,
                 ' '          'RM06E-LGORT' i_final-lgort.
      perform f0510_bdcdata using :
                 'X'          'SAPMM06E'   '0101',
                 ' '          'BDC_OKCODE' '=AB',
                 ' '          'EKKO-ZTERM' i_final-zterm.
      move: '01' to v_counter.
      loop at i_final.
        move: sy-tabix to v_tabix.
        concatenate 'EKPO-EMATN(' v_counter ')' into v_fname.
        concatenate 'EKPO-MENGE(' v_counter ')' into v_fname1.
        perform f0510_bdcdata using :
                   'X'           'SAPMM06E'    '0120',
                   ' '           'BDC_OKCODE'  '=DETZ',
                ' '           'RM06E-EBELP' '5',
                   ' '           v_fname       i_final-ematn,
                   ' '           v_fname1      i_final-menge.
        perform f0510_bdcdata using :
                        'X'            'SAPMM06E'   '0112',
                        ' '            'BDC_CURSOR' 'EKPO-LEWED',
                        ' '            'BDC_OKCODE' '/00',
                        ' '            'EKPO-LEWED' i_final-lewed,
                        ' '            'EKPO-PRDAT' i_final-bedat.
                      ' '            'EKPO-IPRKZ' 'D'.
        v_mod = v_counter mod 5.
        if v_mod eq 0.
          clear v_ebelp.
          move: v_tabix to v_ebelp.
          perform f0510_bdcdata using :
                     'X'           'SAPMM06E'    '0120',
                     ' '           'BDC_OKCODE'  '/00',
                     ' '           'RM06E-EBELP'  v_ebelp.
          v_counter = '02'.
        else.
          v_counter = v_counter + 1.
        endif.
      endloop.
    loop at i_final.
       clear: v_fname.
       v_counter = sy-tabix.
       v_ebelp = sy-tabix.
       concatenate 'RM06E-TCSELFLAG(' '01' ')' into v_fname.
       perform f0510_bdcdata using :
                       'X'             'SAPMM06E'    '0120',
                       ' '             'RM06E-EBELP' v_ebelp,
                       ' '             'BDC_OKCODE'  '/00'.
       perform f0510_bdcdata using :
                       'X'             'SAPMM06E'    '0120',
                       ' '             'BDC_CURSOR'  'RM06E-BSTPO(01)',
                       ' '             'BDC_OKCODE'  '=DETZ',
                        ' '             'RM06E-EBELP' v_ebelp,
                       ' '             v_fname       'X'.
       perform f0510_bdcdata using :
                       'X'            'SAPMM06E' '0112',
                       ' '            'BDC_CURSOR'  'EKPO-LEWED',
                       ' '            'BDC_OKCODE' '/00',
                       ' '            'EKPO-PLIFZ' '91',
                       ' '            'EKPO-GEWEI' 'KG',
                       ' '            'EKPO-PRDAT' i_final-bedat,
                       ' '            'EKPO-IPRKZ' 'D',
                       ' '            'EKPO-LEWED' i_final-lewed.
    endloop.
      perform f0510_bdcdata using :
                  'X'          'SAPMM06E' '0120',
                  ' '          'BDC_CURSOR' 'RM06E-BSTPO(10)',
                  ' '          'BDC_OKCODE' '=BU',
                  ' '          'RM06E-EBELP' '1'.
      perform f0510_bdcdata using :
               'X'        'SAPLSPO1'   '0300',
               ' '        'BDC_OKCODE' '=YES'.
      call transaction 'ME21' using bdcdata messages into messtab
                          mode 'A' update 'S'.
      perform f000_process_errors.
      clear: bdcdata, messtab.
      refresh: bdcdata, messtab.
      loop at int_msg.
        write:/ int_msg-text.
      endloop.
    endform.                    " FILL_BDC_DATA
    *&      Form  F0510_BDCDATA
          text
         -->dynbegin   text
         -->name       text
         -->value      text
    form f0510_bdcdata using    value(dynbegin)
                          value(name)
                          value(value).
      if dynbegin = 'X'.
        clear bdcdata.
        move: name to bdcdata-program,
             value to bdcdata-dynpro,
               'X' to bdcdata-dynbegin.
        append bdcdata.
      else.
        clear bdcdata.
        move: name to bdcdata-fnam,
              value to bdcdata-fval.
        append bdcdata.
      endif.
    endform.                    " F0510_BDCDATA
    *&      Form  F000_PROCESS_ERRORS
          text
    -->  p1        text
    <--  p2        text
    form f000_process_errors.
      loop at messtab.
        clear t100.
        select single * from t100 where sprsl = messtab-msgspra
                                  and   arbgb = messtab-msgid
                                  and   msgnr = messtab-msgnr.
        ws_text = t100-text.
        wa_mag  = messtab-msgtyp.
        if ws_text cs '&1'.
          replace '&1' with messtab-msgv1 into ws_text.
          replace '&2' with messtab-msgv2 into ws_text.
          replace '&3' with messtab-msgv3 into ws_text.
          replace '&4' with messtab-msgv4 into ws_text.
        else.
          replace '&' with messtab-msgv1 into ws_text.
          replace '&' with messtab-msgv2 into ws_text.
          replace '&' with messtab-msgv3 into ws_text.
          replace '&' with messtab-msgv4 into ws_text.
        endif.
        condense ws_text.
        move ws_text to int_msg-text.
        move wa_mag to int_msg-massage.
        append int_msg.
      endloop.
      delete int_msg where massage = 'W'.
    endform.                    " F000_PROCESS_ERRORS
    *&      Form  fill_bapi_parameters
          Subroutine to fill BAPI Parameters
    form fill_bapi_parameters.
      clear: wa_head, wa_headx, i_return, i_item, i_itemx, i_sch, i_schx.
      perform fill_bapi_header.
      perform fill_bapi_items.
    endform.                    " fill_bapi_parameters
    *&      Form  fill_bapi_header
          Subroutine to fill the bapi header
    form fill_bapi_header.
      read table i_final index 1.
      check sy-subrc eq 0.
      move: i_final-ausnr          to wa_head-po_number,
            i_final-bukrs          to wa_head-doc_type,
            i_final-zterm          to wa_head-pmnttrms,
            i_final-ekorg          to wa_head-purch_org,
            i_final-ekgrp          to wa_head-pur_group,
            'FOB'                  to wa_head-incoterms1,
            'Free On Board'        to wa_head-incoterms2.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
           exporting
                input  = i_final-lifnr
           importing
                output = i_final-lifnr.
      move:         i_final-lifnr  to wa_head-vendor.
      concatenate i_final-bedat+6(4)
                  i_final-bedat+3(2)
                  i_final-bedat(2) into wa_head-doc_date.
      move: 'X'                    to wa_headx-po_number,
            'X'                    to wa_headx-doc_type,
            'X'                    to wa_headx-vendor,
            'X'                    to wa_headx-pmnttrms,
            'X'                    to wa_headx-purch_org,
            'X'                    to wa_headx-pur_group,
            'X'                    to wa_headx-doc_date,
            'X'                    to wa_headx-incoterms1,
            'X'                    to wa_headx-incoterms2.
    endform.                    " fill_bapi_header
    *&      Form  fill_bapi_items
          Subroutine to fill the bapi items
    form fill_bapi_items.
      loop at i_final.
        call function 'CONVERSION_EXIT_ALPHA_INPUT'
             exporting
                  input  = i_final-ematn
             importing
                  output = i_final-ematn.
        move: sy-tabix          to i_item-po_item,
              i_final-ematn     to i_item-material,
              i_final-werks     to i_item-plant,
              i_final-lgort     to i_item-stge_loc,
              i_final-menge     to i_item-quantity.
                I_ITEM-TAX_CODE   = I_FINAL-TAX_CODE.
                I_ITEM-GR_BASEDIV = I_FINAL-GR_BASEDIV.
        concatenate i_final-lewed+6(4)
                    i_final-lewed+3(2)
                    i_final-lewed(2) into i_item-gr_to_date.
        move: sy-tabix          to i_itemx-po_item,
              'X'               to i_itemx-po_itemx,
              'X'               to i_itemx-material,
              'X'               to i_itemx-plant,
              'X'               to i_itemx-stge_loc,
              'X'               to i_itemx-quantity,
              'X'               to i_itemx-gr_to_date.
        move: 'X'     TO        i_itemx-TAX_CODE ,
              'X'     TO        i_itemx-GR_BASEDIV.
        append: i_item, i_itemx.
        move: sy-tabix          to i_sch-po_item,
              '0001'            to i_sch-sched_line,
              'D'               to i_sch-del_datcat_ext.
            i_final-menge     to i_sch-quantity.
        concatenate i_final-eddat(2)
                    i_final-eddat+3(2)
                    i_final-eddat+6(4) into i_sch-delivery_date.
        move: sy-tabix          to i_schx-po_item,
              '0001'            to i_schx-sched_line,
              'X'               to i_schx-po_itemx,
              'X'               to i_schx-sched_linex,
            'X'               to i_schx-quantity,
              'X'               to i_schx-delivery_date,
              'X'               to i_schx-del_datcat_ext.
        append: i_sch, i_schx.
      endloop.
    endform.                    " fill_bapi_items
    *&      Form  call_po_create_bapi
          Subroutine to call PO CREATE BAPI
    form call_po_create_bapi.
      call function 'BAPI_PO_CREATE1'
           exporting
                poheader    = wa_head
                poheaderx   = wa_headx
           tables
                return      = i_return
                poitem      = i_item
                poitemx     = i_itemx
                poschedule  = i_sch
                poschedulex = i_schx.
      read table i_return with key type = 'S'
                                   id   = '06'
                                   number = '017'.
      if sy-subrc eq 0.
        call function 'BAPI_TRANSACTION_COMMIT'
             exporting
                  wait = 'X'.
        write:/ i_return-message.
      else.
        delete i_return where type = 'S'.
        delete i_return where type = 'I'.
        delete i_return where type = 'W'.
        write:/ 'Following Errors occured in PO Creation:'.
        skip.
        loop at i_return.
          write:/ i_return-message.
        endloop.
      endif.
    endform.                    " call_po_create_bapi
    thanks
    sitaram

  • Doubt in uploading purchase order data using BDC

    Hi friends,
    how to upload purchase order data.
    1) In both BDC and BAPI which one is preferable?
    2) for suppose if it is through BDC,  how to use? what are the transactions that we can use(SHDB, ME21N,ME21)?
    3) To execute the job in background, is it possible for both call transaction and session method.
    Thanks in advance
    Sreenivas k

    It really depends on the number of records you have. Still for a set of 5,000 records my answer to your questions will be:
    1) In both BDC and BAPI which one is preferable?  - <b>Go with BDC</b>
    2) for suppose if it is through BDC, how to use? what are the transactions that we can use(SHDB, ME21N,ME21)? - <b>Yes, its SHDB for recording, SE38 for abap program and ME21 for PO. Avoid SAP Enjoy transactions for recording as you may end up having problems wiht it.</b>
    3) To execute the job in background, is it possible for both call transaction and session method. - <b>If you use call transaction method then you have to schedule the job to run in background or simply run it through F9 instead of F8. In case of session method you can chose to process the session in background. However  I would suggest you go with BDC Session method for this.</b>
    - Guru
    Reward points for helpful answers

  • How to transfer data in A tableview control in transaction ME21n

    Dear friends,
    I m new in the field of SAP ABAP.
    And right now i m trying to transfer the data in a tableview control in transaction ME21n. I've recorded the sequence of mandatory fields in transaction ME21n but, when i try to transfer the data using BDC call transaction method the order of manadatory fields change.
    I m trying to transfer data from text file.
    If anybody has a solution to this problem please tell me how to sort out this.
    Thanks in advance.

    Hi Vivek,
    Welcome to SDN.
    BDC solution will not work with transaction ME21N.
    ME21N is an enjoy SAP transaction which has a lot of new objects that BDC can not call/use.
    Please use transaction ME21 instead of ME21N.
    Hope this will help.
    Regards,
    Ferry Lianto
    Please reward points in helpful.

Maybe you are looking for