This website is not affiliated with, sponsored by, or approved by SAP AG.

Function Module for MD61 - PIR Import Excel

Logistics : PP

Moderators: Snowy, thx4allthefish, Ha Tran

Function Module for MD61 - PIR Import Excel

Postby supersubra » Tue Aug 29, 2006 1:58 pm

can any body suggest me a way to upload data of Planned Independant Requirements from Excel sheet or any functional module related to this. I feel MD61 data entry should have better user interface. Or is there anyother easier Tcode to do that. Any help is appreciated.


Thanks in advance.
supersubra
 
Posts: 123
Joined: Tue Jan 10, 2006 2:53 am
Location: Coimbatore, India

Postby SAP4ME » Wed Aug 30, 2006 8:44 am

PIR upload is available in LSMW. If Txn LSMW does not work in your system, then you may have to first ask the Basis team to load it in your system, and add it to your authorization profile.
Thanks,
- SAP4ME
SAP4ME
 
Posts: 643
Joined: Thu Jul 14, 2005 3:03 pm
Location: South Carolina, USA

Postby q4u » Thu Aug 31, 2006 10:42 am

What is the LSMW object used for PIR?
q4u
 
Posts: 441
Joined: Wed Mar 08, 2006 7:02 am

Hhi

Postby dskumar2000 » Thu Sep 14, 2006 2:47 pm

Hi,
1. If you are aware of the Bapi.then it can be used.
2. A standard bapi is avialable inthe system which will hlep you to upload the data from excel into the SAP.
3. But you need to take the help of an abaper inwriting the code for this.

Reg
DSK
dskumar2000
 
Posts: 87
Joined: Sun May 14, 2006 9:35 am
Location: Michigan

Problem solved

Postby supersubra » Mon Sep 18, 2006 4:08 am

Using BAPI_REQUIREMENTS_CREATE I have completed the ABAP program. Thanks for all the replies.
supersubra
 
Posts: 123
Joined: Tue Jan 10, 2006 2:53 am
Location: Coimbatore, India

Re: Problem solved

Postby Fernando221 » Thu Dec 07, 2017 9:45 am

supersubra wrote:Using BAPI_REQUIREMENTS_CREATE I have completed the ABAP program. Thanks for all the replies.


First sorry to relive an old topic.

I have a requirement where I need to upload PIRs to MD61 from an Excel file. The selection screen must have some filters. I am already getting data returned from the bapis but I'm stuck at the selection screen filters. Could someone help?

My code

Code: Select all
REPORT  zpp_md61_upload NO STANDARD PAGE HEADING.

TYPE-POOLS : truxs .
TABLES: pbim, pbed.

TYPES : BEGIN OF t_excel_data ,    " structure for excel

          planno(12)  TYPE c ,    " req Plan no
          werks(4)    TYPE c ,   " Plant
          version(2)  TYPE c ,    " vrsion
          versact(1)  TYPE c ,    " vrsion act
          datve       TYPE datve ,    "data de
          datbe       TYPE datbe,     "data ate
          period      TYPE c,
          matnr(18)   TYPE c ,    " material
          date        TYPE pdatu ,    " data
          pquan(13)   TYPE c ,   " planned quantity
          req_type(4) TYPE c ,   " Requirement type

        END OF t_excel_data .



DATA: t_csv                 TYPE t_excel_data OCCURS 0
                         WITH HEADER LINE.

DATA : gs_req_item TYPE bapisitemr,
       gs_items    TYPE bapisshdin,
       gt_req_item TYPE TABLE OF bapisitemr,
       gt_items    TYPE TABLE OF bapisshdin.

DATA : gt_return LIKE bapiret1 OCCURS 0 WITH HEADER LINE.
DATA : gt_return1 LIKE bapiret1 OCCURS 0 WITH HEADER LINE.
DATA : gs_return TYPE bapiret1.

DATA: gs_excel_data TYPE t_excel_data, " work area for  excel data
      gt_excel_data TYPE TABLE OF t_excel_data, " internal dataa for excel data
      gt_raw_data   TYPE truxs_t_text_data .   " raw data .

DATA: gs_excel_data1 TYPE t_excel_data, " work area for  excel data
      gt_excel_data1 TYPE TABLE OF t_excel_data. " internal dataa for excel data

DATA v_file TYPE string.

"Declaração ALV
DATA gt_data TYPE REF TO data.
DATA gs_data TYPE REF TO data.

FIELD-SYMBOLS: <ft_data> TYPE STANDARD TABLE,
               <fs_data> TYPE any.

DATA: gr_table TYPE REF TO cl_salv_table.

"SELECTION-SCREEN

SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001 .
PARAMETERS : p_file TYPE rlgrap-filename OBLIGATORY.  " file name
SELECTION-SCREEN : END OF BLOCK b1 .

SELECTION-SCREEN : BEGIN OF BLOCK b2 WITH FRAME TITLE text-002 .
SELECT-OPTIONS: p_werks FOR pbim-werks,
           p_versb FOR pbim-versb,
           p_matnr FOR pbim-matnr,
           p_planno FOR pbim-pbdnr,
           p_date FOR pbed-pdatu.
SELECTION-SCREEN : END OF BLOCK b2 .

" f4 help event

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file .
  PERFORM f4_filename . "subroutine to perform f4 help


START-OF-SELECTION .

  PERFORM upload_excel . "subroutine to uplaod excel file .
  PERFORM req_create .   " subroutine for using bapi to update md61 .



*&---------------------------------------------------------------------*
*&      Form  F4_FILENAME
*&---------------------------------------------------------------------*

FORM f4_filename .

  CALL FUNCTION 'F4_FILENAME'  " function module to perform f4 help
    IMPORTING
      file_name = p_file.
  .


ENDFORM.                    " F4_FILENAME

*&---------------------------------------------------------------------*
*&      Form  UPLOAD_EXCEL
*&---------------------------------------------------------------------*

FORM upload_excel .

  v_file = p_file.

  TYPES truxs_t_text_data(4096) TYPE c OCCURS 0               .
  DATA: ti_raw  TYPE truxs_t_text_data                        .

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_tab_raw_data       = ti_raw
      i_filename           = p_file
    TABLES
      i_tab_converted_data = t_csv
    EXCEPTIONS
      error_message        = 4.

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

*  REFRESH gt_excel_data .
*  IF NOT p_file IS INITIAL .
*    CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
*      EXPORTING
*       I_FIELD_SEPERATOR    = 'X'
*        i_line_header        = 'X'
*        i_tab_raw_data       = gt_raw_data
*        i_filename           = v_file
*      TABLES
*        i_tab_converted_data = gt_excel_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.
*  ENDIF.

ENDFORM.                    " upload_excel



*&---------------------------------------------------------------------*
*&      Form  REQ_CREATE
*&---------------------------------------------------------------------*

FORM req_create .

* Constants for period indicator
*  CONSTANTS  : c_c TYPE c VALUE 'C',  " Calender Format
*               c_k TYPE c VALUE 'K',  " Calender Format
*               c_p TYPE c VALUE 'P',  " Period Format
*               c_d TYPE c VALUE 'D',  " day
*               c_m TYPE c VALUE 'M' . " month
*  CONSTANTS : c_1 TYPE c VALUE '1' ,  " Day
*              c_2 TYPE c VALUE '2' ,  " Week
*              c_3 TYPE c VALUE '3' ,  " Month
*              c_4 TYPE c VALUE '4' ,  " Posting period
*              c_5 TYPE c VALUE '5' .  " Planning Calender Period

  CONSTANTS: c_period     TYPE c VALUE 'T',
             c_reqtype(3) TYPE c VALUE 'LSF'.

  REFRESH : gt_items , gt_excel_data1 .

  gt_excel_data1[] = t_csv[].

  SORT gt_excel_data1 BY  planno werks matnr.

  DELETE ADJACENT DUPLICATES FROM gt_excel_data1 COMPARING planno werks matnr .

*  LOOP AT gt_excel_data1 INTO gs_excel_data1.

  LOOP AT t_csv INTO gs_excel_data.

*    CASE gs_excel_data-date_type.
*
*      WHEN c_c OR c_k OR c_p.
*        gs_excel_data-date_type = c_5.
*      WHEN c_d .
*        gs_excel_data-date_type = c_1.
*      WHEN c_m.
*        gs_excel_data-date_type = c_3.
*      WHEN OTHERS.
*        gs_excel_data-date_type = c_2.
*    ENDCASE.

    gs_excel_data-period = c_period.
    gs_excel_data-req_type = c_reqtype.

* Req Items

    gs_req_item-req_number = gs_excel_data-planno .  " Passing requirement Plan no to req items in Bapi from excel IT
    gs_req_item-plant = gs_excel_data-werks .        " Passing MAterial to req items in Bapi from excel IT
    gs_req_item-version   = '00' .                    " Version is always 00 .
    gs_req_item-vers_activ = gs_excel_data-versact.   " Versão ativa
    gs_req_item-material = gs_excel_data-matnr .     " Passing MAterial to req items in Bapi from excel IT
*   gs_req_item-version = gs_excel_data-version .
    gs_req_item-requ_type  = gs_excel_data-req_type . " Passing requirement type to req items in Bapi from excel IT

* line items
    gs_items-date_type = gs_excel_data-period .   " Periodo de planejamento, default = 'T'
*   gs_items-req_date = '20150113' .
*   gs_items-unit    =   gs_excel_data-meins .
    gs_items-req_qty =   gs_excel_data-pquan .      " Passing quantity to requirements_schedule_in in Bapi from excel IT
    gs_items-req_date =  gs_excel_data-date .       " Passing date  to requirements_schedule_in in Bapi from excel IT


    APPEND gs_req_item TO gt_req_item.
    APPEND gs_items TO gt_items .

    PERFORM filter_data.
    PERFORM create_change .  " Perform to create and change data in MD61 & MD62
    CLEAR :  gs_items , gs_excel_data , gt_items .
    CLEAR : gs_req_item , gt_items .
  ENDLOOP .

*    CLEAR : gs_excel_data1 .

*  ENDLOOP.
  PERFORM messages .   " Perform to display messages



ENDFORM.                    " REQ_CREATE

*&---------------------------------------------------------------------*
*&      Form filter_data
*&---------------------------------------------------------------------*

FORM filter_data.

  "READ TABLE gt_req_item INTO gt_req_item WITH KEY gs_req_item-plant = p_werks.

*  p_werks FOR pbim-werks,
*           p_versb FOR pbim-versb,
*           p_matnr FOR pbim-matnr,
*           p_planno FOR pbim-pbdnr,
*           p_date FOR pbed-pdatu.

*SELECT *
*    FROM ztbmm_preco_neg
*    INTO TABLE it_preco
*    WHERE fornecedor = p_lifnr
*      AND ano = p_ano
*      AND periodo = p_mes.


ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  CREATE_CHANGE
*&---------------------------------------------------------------------*


FORM create_change .

  CALL FUNCTION 'BAPI_REQUIREMENTS_CREATE'  " Bapi to Create Planned Independent Reqmts
    EXPORTING
      requirements_item        = gs_req_item
*     REQUIREMENT_PARAM        =
      do_commit                = 'X'
      update_mode              = 'X'
*     REFER_TYPE               = ' '
*     PROFILID                 = ' '
*   IMPORTING
*     MATERIAL                 =
*     PLANT                    =
*     REQUIREMENTSTYPE         =
*     VERSION                  =
*     REQMTSPLANNUMBER         =
*     MRP_AREA                 =
*     MATERIAL_EVG             =
*     REQ_PLAN_ID_EXT          =
*     REQ_SEGMENT              =
    TABLES
      requirements_schedule_in = gt_items
*     REQUIREMENTS_CHAR_IN     =
      return                   = gt_return.

*  gs_return-id = gt_return-id.
*  gs_return-number = gt_return-number.
*  gs_return-type = gt_return-type.
*  gs_return-message = gt_return-message.
*
*
*  APPEND gs_return TO gt_return1.

  READ TABLE gt_return INTO gt_return WITH KEY type = 'E' id = '6P' number = '011'.   " in case if the data already exists

  IF sy-subrc IS INITIAL.

    CALL FUNCTION 'BAPI_REQUIREMENTS_CHANGE'
      EXPORTING
        material                 = gs_req_item-material
        plant                    = gs_req_item-plant
        requirementstype         = gs_req_item-requ_type
        version                  = gs_req_item-version
        reqmtsplannumber         = gs_req_item-req_number
        vers_activ               = 'X'
      TABLES
        requirements_schedule_in = gt_items
        return                   = gt_return.


    READ TABLE gt_return INTO gt_return WITH KEY type = 'E' id = '6P' number = '012'.  " in case if the requirement is blocked

    IF sy-subrc IS INITIAL.

      WAIT UP TO 5 SECONDS.

      CALL FUNCTION 'BAPI_REQUIREMENTS_CHANGE'
        EXPORTING
          material                 = gs_req_item-material
          plant                    = gs_req_item-plant
          requirementstype         = gs_req_item-requ_type
          version                  = gs_req_item-version
          reqmtsplannumber         = gs_req_item-req_number
          vers_activ               = 'X'
        TABLES
          requirements_schedule_in = gt_items
          return                   = gt_return.

    ENDIF.
  ENDIF .
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.


ENDFORM.                    " CREATE_CHANGE

*&---------------------------------------------------------------------*
*&      Form  MESSAGES
*&---------------------------------------------------------------------*

FORM messages .

  IF gt_return IS  INITIAL .                   " Mensagem de sucesso

    MESSAGE 'Forecast foi criado com sucesso.' TYPE 'S' .

  ENDIF .

  IF gt_return IS NOT INITIAL .
    LOOP AT gt_return.                     " Mensagens de erro
      WRITE : /  gt_return-id ,
              10 gt_return-number ,
              20  gt_return-type ,
              30  gt_return-message
                                    .
    ENDLOOP .

  ENDIF.
ENDFORM.
Fernando221
 
Posts: 1
Joined: Fri Nov 10, 2017 1:28 pm


Return to Logistics PP

Who is online

Users browsing this forum: No registered users and 1 guest





This website is not affiliated with, sponsored by, or approved by SAP AG.