SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BAPI_REQUISITION_CREATE



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы -> BAPI
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Mon Oct 18, 2010 5:28 pm    Post subject: BAPI_REQUISITION_CREATE Reply with quote

BAPI_REQUISITION_CREATE - Create Purchase Requisition

Source: http://wiki.sdn.sap.com/wiki/display/ABAP/BAPI_REQUISITION_CREATE

Purpose: This BAPI is used to create Purchase Requisitions (PRs).There are different scenarios to create the PRs depends on the requirements. I will be focusing here to create different service item because problems occur when you create PRs with services using this BAPI.

Purchase Requisitions for services can be of two types:

With and without master - Single account assignment.
With and without master- Multiple account assignment
There is one more type of PRs for services i.e. WITH LIMIT. But here I will be focusing on above two types.

Technical Information: This BAPI is having two importing parameters, they are:

SKIP_ITEMS_WITH_ERROR & AUTOMATIC_SOURCE.

Do not consider any of them while calling the BAPI in your code. we can skip both of them as they are not mandatory.

Scenario: To upload Mass PRs for services from legacy systems to 6.0. The data was to be uploaded through a spread sheet having all the required fields to create Service Purchase Requisition. This is also helpful for creation of individual Service PR also.

Some of the fields (from different structures used in BAPI) whose sequencing and value initialization is to be done very logically otherwise the service line item will not get created. They are 'SERIAL_NO', 'LINE_NO', 'EXT_LINE', and 'PCKG_NO'. For every new PR number initialize 'SERIAL_NO' to '01', 'LINE_NO' to '1', 'EXT_LINE' to '10', 'ITEM_NO' = '00001' and 'PCKG_NO' to '0000000001'. This can be done by declaring different variables for those fields and then initializing the values like:

Code:

at new preqno.

      v_accasserial_no = 01.
      v_req_services_line_no = 1.
      v_req_services_ext_line = 10.

* Package No initializtion to create the Service line item in the PR

      v_packno = 0000000001.
      v_item_no = '00001'.


At every new line item of the PR, populate the table 'REQUISITION_ITEMS' which contains the item data, as shown below:

Code:
      requisition_items-doc_type = i_in2-pr_type.
      requisition_items-preq_no = i_in2-preqno.
      requisition_items-acctasscat = i_in2-acctass.
      requisition_items-pur_group = i_in2-pur_grp.
      requisition_items-plant = i_in2-plant.
      requisition_items-deliv_date = i_in2-del_date.
      requisition_items-item_cat_ext = i_in2-itemca.
      requisition_items-short_text = i_in2-matdesc.
      requisition_items-mat_grp = i_in2-matgrp.
      requisition_items-trackingno = i_in2-trackno.
      requisition_items-preq_name  = i_in2-afnam.
      requisition_items-pckg_no = v_packno.
      requisition_items-distrib = '2'.
      requisition_items-part_inv = '2'.
      requisition_items-preq_item = v_item_no.
      v_item_no = v_item_no + v_item_no .
      append requisition_items.

Field 'DISTRIB' needs to be populated in case of Multiple account assignment along with 'PART_INV'. For more details check the data element documentation for both.

After that populate the table 'REQUISITION_ACCOUNT_ASSIGNMENT'. In this table two fields needs to be populated carefully, they are 'SERIAL_NO' & 'PREQ_ITEM'. This can be done as:

Code:
requisition_account_assignment-serial_no = v_accasserial_no. "(declared above)
requisition_account_assignment-preq_item = requisition_items-preq_item.


While populating the table 'REQUISITION_SERVICES' we will have to take a look on under given logic.

Each line item of the PR will link with a logical header in 'REQUISITION_SERVICES', which we can not see but until and unless we will provide the proper header there will not be any creation of a single SERVICE line item.

This can be done as:

* To Populate the header data for Requisition Services. Every unique PR line item
* should have different header data which internally links to multiple service line
* item.

Code:
    at new preqitem.
      requisition_services-pckg_no = requisition_items-pckg_no.
      requisition_services-subpckg_no = requisition_services-pckg_no + 1.
      requisition_services-ext_line = 0.
      requisition_services-line_no = v_req_services_line_no.
      requisition_services-short_text = i_in2-matdesc.
      append requisition_services.
    endat.


Remember that this header should get populated only once for one line item of PR.

In case of single or multiple service line item we can populate the required table like this:


Code:
*Populate the requisition services table for multiple service requisition.
    requisition_services-pckg_no = requisition_items-pckg_no + 1.
    requisition_services-subpckg_no = 0.
    requisition_services-ext_line = requisition_services-ext_line + v_req_services_ext_line.
    requisition_services-line_no = requisition_services-line_no + '0000000001'.
    requisition_services-short_text = i_in2-srtext.
    requisition_services-gr_price = i_in2-preq_price.
    requisition_services-quantity = i_in2-quantity.

    call function 'CONVERSION_EXIT_CUNIT_INPUT'
      exporting
        input    = i_in2-unit
        language = sy-langu
      importing
        output   = i_in2-unit.

    requisition_services-base_uom = i_in2-unit.
    v_packno = v_packno + requisition_services-pckg_no.
"(Above line is very important, else there will be improper output)
    append requisition_services.

After doing all the above work properly we need to populate the table 'REQUISITION_SRV_ACCASS_VALUES' which acts as a Value/Link to Service Account Assignment.


Code:
* Populate the requisition service access value table.
    requisition_srv_accass_values-pckg_no = requisition_services-pckg_no.
    requisition_srv_accass_values-line_no = requisition_services-line_no.
    requisition_srv_accass_values-serno_line = requisition_account_assignment-serial_no.
    requisition_srv_accass_values-serial_no = requisition_srv_accass_values-serno_line.
    requisition_srv_accass_values-percentage = '100'.
    append requisition_srv_accass_values.


If we have the requirement to populate long text for each service line item, we can do it as:


Code:
* Populate the service long text.
    requisition_services_text-pckg_no = requisition_services-pckg_no.
    requisition_services_text-line_no = requisition_srv_accass_values-line_no.
    requisition_services_text-text_id = 'LLTX'.
    requisition_services_text-format_col = '*'.
"(This is done if the long text is more than 132 chars, as the BAPI has limitation of 132 chars.)
    call function 'CONVERT_STRING_TO_TABLE'
      exporting
        i_string         = i_in2-ser_ltext
        i_tabline_length = 132
      tables
        et_table         = it_outlines.

    loop at it_outlines.
      requisition_services_text-text_line = it_outlines.
      append requisition_services_text.
    endloop.
    refresh it_outlines[].
    clear:it_outlines.

"Now all the required tables are populated properly, we just need to call the BAPI.

Code:
    at end of  preqitem.
      at end of preqno.
        call function 'BAPI_REQUISITION_CREATE'
          importing
            number                         = prno
          tables
            requisition_items              = requisition_items
            requisition_account_assignment = requisition_account_assignment
            requisition_services           = requisition_services
            requisition_srv_accass_values  = requisition_srv_accass_values
            requisition_services_text      = requisition_services_text
            return                         = i_return.

       read table i_return with key type = 'E'.
        if sy-subrc <> 0 .
*Function called for commit
          call function 'BAPI_TRANSACTION_COMMIT'
            exporting
              wait = 'X'.
        else.
          call function 'BAPI_TRANSACTION_ROLLBACK'.
        endif.

We can cross check the created PR by TCODE: ME53N.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы -> BAPI All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.