Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Re: BAPI_PO_CHANGE

Former Member
0 Likes
1,150

Hi Expert,

I am uploading data from excel into me23n transaction code the field in my excel sheet are  PO NUMBER, ITEM,CC,DEL DATE,QTY. this are the field

i am uploading from excel into my internal table and then using bapi i want to update the me23n tcode i have written the below code

How to write the bapi for the below code bcz i am not familiar with bapi.

   *&---------------------------------------------------------------------*
*& Report  ZR_MM_PO_UPLOAD_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_MM_PO_UPLOAD_REPORT NO STANDARD PAGE HEADING MESSAGE-ID zz.

type-pools: truxs.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .
*PARAMETERS: p_stmt RADIOBUTTON GROUP grp DEFAULT 'X',
*            p_util RADIOBUTTON GROUP grp.
PARAMETERS: p_file TYPE rlgrap-filename LOWER CASE OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*************** Structure declaration****************

Types: Begin of ty_final,
       ebeln(15) type c,          " po number
       ebelp(2) type c,           " item
       ebtyp(15) type c,          " conformation category
       eindt(18) type c,          " Delivery date
       menge(15) type c,          " quantity
       end of ty_final.

************* work arae and internal table declaration*****************

data: wa_final type ty_final,
      it_final type STANDARD TABLE OF ty_final.
data: wa_output type ty_final,
      it_output type STANDARD TABLE OF ty_final.


*************** data declaration****************

data: ex_tab_raw_data TYPE truxs_t_text_data.


Refresh: it_final.
*********** AT SELECTION-SCREEN EVENT

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

******* select excel file to upload*********
PERFORM select_excel_file.


********* copy xls file to internal table & process the internal table*******

  PERFORM copy_csv_2_it_final.
  PERFORM process_it_final.

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

   DATA : ex_file_table TYPE filetable,
         ex_rc TYPE i,
         ex_tab_raw_data TYPE truxs_t_text_data.
  REFRESH ex_file_table[].
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            =  'Select File: '
      default_extension       =  '*.XLS'
*    DEFAULT_FILENAME        =
*    FILE_FILTER             =
*    INITIAL_DIRECTORY       =
      multiselection          =  ' '
    CHANGING
      file_table              =  ex_file_table
      rc                      =  ex_rc
*    USER_ACTION             =
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      OTHERS                  = 4          .

  READ TABLE ex_file_table INTO p_file INDEX 1.

*  PERFORM convert_2_lower_case.

  IF p_file NP '*.xls' AND p_file NP '*.xlsx' AND p_file NP '*.csv'.    " '*.xls'
    MESSAGE i032(z1).    "Choose a valid file
    CLEAR: p_file.
  ENDIF.

  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.                    " SELECT_EXCEL_FILE


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

  REFRESH it_final.
  CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
    EXPORTING
    I_FIELD_SEPERATOR          = 'X'
     I_LINE_HEADER              = 'X'
      I_TAB_RAW_DATA             = ex_tab_raw_data
    I_FILENAME                 = p_file
    TABLES
      I_TAB_CONVERTED_DATA       = it_final
*   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.                    " COPY_CSV_2_IT_FINAL
*&---------------------------------------------------------------------*
*&      Form  PROCESS_IT_FINAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PROCESS_IT_FINAL .

   clear wa_final.
  refresh: it_final.
  loop at it_final into wa_final.
    clear wa_output.
    move wa_final-ebeln to wa_output-ebeln.
    move wa_final-ebelp to wa_output-ebelp.
    move wa_final-ebtyp to wa_output-ebtyp.
    move wa_final-eindt to wa_output-eindt.
    move wa_final-menge to wa_output-menge.
    append wa_output to it_output.

  endloop.

  sort it_output by ebeln.
  DELETE ADJACENT DUPLICATES FROM it_output COMPARING ebeln ebelp.


ENDFORM.                    " PROCESS_IT_FINAL

Regards,

Am

Moderator Message: Please search before posting your question. Thread locked.





Message was edited by: Suhas Saha

Hi Expert,

I am uploading data from excel into me23n transaction code the field in my excel sheet are  PO NUMBER, ITEM,CC,DEL DATE,QTY. this are the field

i am uploading from excel into my internal table and then using bapi i want to update the me23n tcode i have written the below code

How to write the bapi for the below code bcz i am not familiar with bapi.

   *&---------------------------------------------------------------------*
*& Report  ZR_MM_PO_UPLOAD_REPORT
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZR_MM_PO_UPLOAD_REPORT NO STANDARD PAGE HEADING MESSAGE-ID zz.

type-pools: truxs.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .
*PARAMETERS: p_stmt RADIOBUTTON GROUP grp DEFAULT 'X',
*            p_util RADIOBUTTON GROUP grp.
PARAMETERS: p_file TYPE rlgrap-filename LOWER CASE OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.

*************** Structure declaration****************

Types: Begin of ty_final,
       ebeln(15) type c,          " po number
       ebelp(2) type c,           " item
       ebtyp(15) type c,          " conformation category
       eindt(18) type c,          " Delivery date
       menge(15) type c,          " quantity
       end of ty_final.

************* work arae and internal table declaration*****************

data: wa_final type ty_final,
      it_final type STANDARD TABLE OF ty_final.
data: wa_output type ty_final,
      it_output type STANDARD TABLE OF ty_final.


*************** data declaration****************

data: ex_tab_raw_data TYPE truxs_t_text_data.


Refresh: it_final.
*********** AT SELECTION-SCREEN EVENT

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

******* select excel file to upload*********
PERFORM select_excel_file.


********* copy xls file to internal table & process the internal table*******

  PERFORM copy_csv_2_it_final.
  PERFORM process_it_final.

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

   DATA : ex_file_table TYPE filetable,
         ex_rc TYPE i,
         ex_tab_raw_data TYPE truxs_t_text_data.
  REFRESH ex_file_table[].
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            =  'Select File: '
      default_extension       =  '*.XLS'
*    DEFAULT_FILENAME        =
*    FILE_FILTER             =
*    INITIAL_DIRECTORY       =
      multiselection          =  ' '
    CHANGING
      file_table              =  ex_file_table
      rc                      =  ex_rc
*    USER_ACTION             =
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      OTHERS                  = 4          .

  READ TABLE ex_file_table INTO p_file INDEX 1.

*  PERFORM convert_2_lower_case.

  IF p_file NP '*.xls' AND p_file NP '*.xlsx' AND p_file NP '*.csv'.    " '*.xls'
    MESSAGE i032(z1).    "Choose a valid file
    CLEAR: p_file.
  ENDIF.

  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.                    " SELECT_EXCEL_FILE


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

  REFRESH it_final.
  CALL FUNCTION 'TEXT_CONVERT_CSV_TO_SAP'
    EXPORTING
    I_FIELD_SEPERATOR          = 'X'
     I_LINE_HEADER              = 'X'
      I_TAB_RAW_DATA             = ex_tab_raw_data
    I_FILENAME                 = p_file
    TABLES
      I_TAB_CONVERTED_DATA       = it_final
*   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.                    " COPY_CSV_2_IT_FINAL
*&---------------------------------------------------------------------*
*&      Form  PROCESS_IT_FINAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM PROCESS_IT_FINAL .

   clear wa_final.
  refresh: it_final.
  loop at it_final into wa_final.
    clear wa_output.
    move wa_final-ebeln to wa_output-ebeln.
    move wa_final-ebelp to wa_output-ebelp.
    move wa_final-ebtyp to wa_output-ebtyp.
    move wa_final-eindt to wa_output-eindt.
    move wa_final-menge to wa_output-menge.
    append wa_output to it_output.

  endloop.

  sort it_output by ebeln.
  DELETE ADJACENT DUPLICATES FROM it_output COMPARING ebeln ebelp.


ENDFORM.                    " PROCESS_IT_FINAL

Regards,

Am

Moderator Message: Please search before posting your question. Thread locked.





Message was edited by: Suhas Saha

6 REPLIES 6
Read only

jitendra_it
Active Contributor
0 Likes
1,029

Hi Antha,

Below link will help you in using the BAPI for PO change.

http://wiki.sdn.sap.com/wiki/display/HOME/Abap+code+on+BAPI+PO+Change

Many Thanks,

Jitendra

Read only

0 Likes
1,029

This message was moderated.

Read only

0 Likes
1,029

you can read following link:

<external link removed>

Message was edited by: Suhas Saha

Read only

yogendra_bhaskar
Contributor
0 Likes
1,029

Do u wanna use bapi for update , change or display ?

for me23n u can use BAPI_PO_GETDETAIL1.

pass the PO no. in BAPIMEPOHEADER-PO_NUMBER

Read only

0 Likes
1,029

Hi Bhasker,

My requirement is iam uploading data from excel and from excel it should be updated to me23n tcode for that i have written code as u seen in the above i want bapi how to update this

i.e i dont know how to use bapi in my report pls can u have look into this.

Am

Read only

0 Likes
1,029

hi AM ,

just add the following code :

LOOP AT it_output INTO wa_output.

      

     data : po_items TYPE STANDARD TABLE OF BAPIEKPO.

        CALL FUNCTION 'BAPI_PO_GETDETAIL'

          EXPORTING

            purchaseorder                    = wa_output-ebeln

*          ITEMS                            = 'X'

*          ACCOUNT_ASSIGNMENT               = ' '

*          SCHEDULES                        = ' '

*          HISTORY                          = ' '

*          ITEM_TEXTS                       = ' '

*          HEADER_TEXTS                     = ' '

*          SERVICES                         = ' '

*          CONFIRMATIONS                    = ' '

*          SERVICE_TEXTS                    = ' '

*          EXTENSIONS                       = ' '

*        IMPORTING

*          PO_HEADER                        =

*          PO_ADDRESS                       =

*        TABLES

*          PO_HEADER_TEXTS                  =

           PO_ITEMS                         = PO_ITEMS

*          PO_ITEM_ACCOUNT_ASSIGNMENT       =

*          PO_ITEM_SCHEDULES                =

*          PO_ITEM_CONFIRMATIONS            =

*          PO_ITEM_TEXTS                    =

*          PO_ITEM_HISTORY                  =

*          PO_ITEM_HISTORY_TOTALS           =

*          PO_ITEM_LIMITS                   =

*          PO_ITEM_CONTRACT_LIMITS          =

*          PO_ITEM_SERVICES                 =

*          PO_ITEM_SRV_ACCASS_VALUES        =

*          RETURN                           =

*          PO_SERVICES_TEXTS                =

*          EXTENSIONOUT                     =

                 

ENDLOOP.

You will have the po item detail in table PO_ITEMS