Skip to Content
0
Aug 30, 2012 at 04:12 PM

Not able to populate the line item no. 1, 2 ,3..using BAPI_REQUISITION_CREATE

113 Views

Hi Experts,

I am trying to create PO in the interface in which data is sent from external system to create PR.

However problem is I am not able to populate the lineitem number as 1, 2 ,3...

Even if I pass the value as 1, 2 ,3....The PR created has line item numbers as 10, 20 ,30...

Could you please let me know what can be the issue.

Data:

gt_pr_crea TYPE STANDARD TABLE OF bapiebanc,

gt_pr_crea2 TYPE STANDARD TABLE OF bapiebkn,

gt_pr_crea3 TYPE STANDARD TABLE OF bapiebantx,

gwa_pr_crea TYPE bapiebanc,

gwa_pr_crea2 TYPE bapiebkn,

gwa_pr_crea3 TYPE bapiebantx,

LOOP AT gt_pr_data INTO gwa_pr_data.

* check PR data for AMP system
CLEAR lv_partner.
CASE gwa_pr_data-purchase_requisition+0(1).
WHEN lc_p.
CLEAR lv_partner.
lv_partner = 'SYS1'(t03).
WHEN lc_a.
CLEAR lv_partner.
lv_partner = 'SYS2'(t04).
WHEN lc_f.
CLEAR lv_partner.
lv_partner = 'SYS3'(t05).
ENDCASE.
* check PR data for

IF gwa_pr_data-purchase_requisition+0(1) = lc_p.
* read material master data for material type ZIEN / NLAG
READ TABLE gt_mara
INTO gwa_mara
WITH KEY matnr = gwa_pr_data-material.

IF sy-subrc = 0.
IF gwa_mara-mtart EQ lc_zien OR
gwa_mara-mtart EQ lc_nlag.
ELSE.
CLEAR gwa_log_message.
gwa_log_message-type = lc_e.
CONCATENATE gwa_mara-mtart
text-008
INTO lv_message1
SEPARATED BY space.
gwa_log_message-message = lv_message1.
gwa_log_message-id = 'ZF_MSG'(011).
gwa_log_message-number = 004.
APPEND gwa_log_message TO gt_log_message.
* reject the PR and give error message
CONTINUE.
ENDIF.
ENDIF.
ENDIF.

* check flag PR created or not
CLEAR gwa_eban.
READ TABLE gt_eban INTO gwa_eban WITH KEY banfn = gwa_pr_data-purchase_requisition.
IF sy-subrc NE 0.
*--Remove the Purchase Requisition number as it is generated internally
gwa_pr_crea-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_crea-preq_item = gwa_pr_data-item_on_requisition.

gwa_pr_crea-doc_type = gwa_pr_data-document_type.
gwa_pr_crea-pur_group = gwa_pr_data-purchasing_group.
gwa_pr_crea-created_by = gwa_pr_data-requisitioner.
gwa_pr_crea-preq_name = gwa_pr_data-requisitioner.
gwa_pr_crea-short_text = gwa_pr_data-shorttext.
gwa_pr_crea-material = gwa_pr_data-material.

gwa_pr_crea-plant = gwa_pr_data-plant.
gwa_pr_crea-store_loc = gwa_pr_data-storage_location.
gwa_pr_crea-mat_grp = gwa_pr_data-material_group.
gwa_pr_crea-quantity = gwa_pr_data-quantity_requested.
gwa_pr_crea-unit = gwa_pr_data-unitof_measure.
gwa_pr_crea-deliv_date = gwa_pr_data-deliverydate.
gwa_pr_crea-rel_date = sy-datum.
gwa_pr_crea-acctasscat = gwa_pr_data-acct_assignment_cat.
gwa_pr_crea-price_unit = gwa_pr_data-valuation_price.
APPEND gwa_pr_crea TO gt_pr_crea.
*-- read gt_glacc to get G/L account
READ TABLE gt_glacc INTO gwa_glacc WITH KEY mat_grp = gwa_pr_data-material_group.
IF sy-subrc = 0.
gwa_pr_crea2-g_l_acct = gwa_glacc-gl_acc.
ENDIF.

gwa_pr_crea2-serial_no = gwa_pr_data-sr_nofor_acct_assnment.
gwa_pr_crea2-order_no = gwa_pr_data-internal_order.
gwa_pr_crea2-co_area = text-001.
APPEND gwa_pr_crea2 TO gt_pr_crea2.
* item_note.
READ TABLE gt_textid INTO gwa_textid WITH KEY tdid = lc_b01.
IF sy-subrc = 0.
gwa_pr_crea3-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_crea3-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_crea3-text_line = gwa_textid-tdtext.
gwa_pr_crea3-text_id = gwa_textid-tdid.
APPEND gwa_pr_crea3 TO gt_pr_crea3.
CLEAR gwa_pr_crea3.
ENDIF.
* deliverytext.
READ TABLE gt_textid INTO gwa_textid WITH KEY tdid = lc_b02.
IF sy-subrc = 0.
*--Remove the Purchase Requisition number as it is generated internally
gwa_pr_crea3-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_crea3-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_crea3-text_line = gwa_textid-tdtext.
gwa_pr_crea3-text_id = gwa_textid-tdid.
APPEND gwa_pr_crea3 TO gt_pr_crea3.
CLEAR gwa_pr_crea3.
ENDIF.
* item_text.
READ TABLE gt_textid INTO gwa_textid WITH KEY tdid = lc_b03.
IF sy-subrc = 0.
*--Remove the Purchase Requisition number as it is generated internally
gwa_pr_crea3-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_crea3-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_crea3-text_line = gwa_textid-tdtext.
gwa_pr_crea3-text_id = gwa_textid-tdid.
APPEND gwa_pr_crea3 TO gt_pr_crea3.
CLEAR gwa_pr_crea3.
ENDIF.
* move data to change bapi structure
ELSE.
gwa_pr_chan-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_chan-pur_group = gwa_pr_data-purchasing_group.
gwa_pr_chan-material = lv_matnr_out.
gwa_pr_chan-plant = gwa_pr_data-plant.
gwa_pr_chan-store_loc = gwa_pr_data-storage_location.
gwa_pr_chan-matl_group = gwa_pr_data-material_group.
gwa_pr_chan-preq_name = gwa_pr_data-requisitioner.
gwa_pr_chan-short_text = gwa_pr_data-shorttext.
gwa_pr_chan-quantity = gwa_pr_data-quantity_requested.
gwa_pr_chan-unit = gwa_pr_data-unitof_measure.
gwa_pr_chan-preq_date = gwa_pr_data-requisition_date.
gwa_pr_chan-deliv_date = gwa_pr_data-deliverydate.
gwa_pr_chan-acctasscat = gwa_pr_data-acct_assignment_cat.
gwa_pr_chan-prio_urgency = gwa_pr_data-requirement_urgency.
gwa_pr_chan-price_unit = gwa_pr_data-valuation_price.
gwa_pr_chan-rel_date = sy-datum.
APPEND gwa_pr_chan TO gt_pr_chan.
* serial no
gwa_pr_chan2-preq_item = gwa_pr_data-item_on_requisition.
*-- read gt_glacc to get G/L account
READ TABLE gt_glacc INTO gwa_glacc WITH KEY mat_grp = gwa_pr_data-material_group.
IF sy-subrc = 0.
gwa_pr_chan2-gl_account = gwa_glacc-gl_acc.
ENDIF.
gwa_pr_chan2-quantity = gwa_pr_data-quantity_requested.
gwa_pr_chan2-serial_no = gwa_pr_data-sr_nofor_acct_assnment.
gwa_pr_chan2-orderid = gwa_pr_data-internal_order.
APPEND gwa_pr_chan2 TO gt_pr_chan2.
* purchase doc category
gwa_pr_chan4-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_chan4-doc_type = gwa_pr_data-document_type.
gwa_pr_chan4-pur_group = gwa_pr_data-purchasing_group.
gwa_pr_chan4-material = lv_matnr_out.
gwa_pr_chan4-plant = gwa_pr_data-plant.
gwa_pr_chan4-store_loc = gwa_pr_data-storage_location.
gwa_pr_chan4-quantity = gwa_pr_data-quantity_requested.
gwa_pr_chan4-unit = gwa_pr_data-unitof_measure.
gwa_pr_chan4-deliv_date = gwa_pr_data-deliverydate.
gwa_pr_chan4-price_unit = gwa_pr_data-valuation_price.
gwa_pr_chan4-doc_cat = gwa_pr_data-purchase_doc_category.
APPEND gwa_pr_chan4 TO gt_pr_chan4.

* item_note.
READ TABLE gt_textid INTO gwa_textid WITH KEY tdid = lc_b01.
IF sy-subrc = 0.
gwa_pr_chan3-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_chan3-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_chan3-text_line = gwa_textid-tdtext.
gwa_pr_chan3-text_id = gwa_textid-tdid.
APPEND gwa_pr_chan3 TO gt_pr_chan3.
CLEAR gwa_pr_chan3.
ENDIF.

* deliverytext.
READ TABLE gt_textid INTO gwa_textid WITH KEY tdid = lc_b02.
IF sy-subrc = 0.
gwa_pr_chan3-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_chan3-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_chan3-text_line = gwa_textid-tdtext.
gwa_pr_chan3-text_id = gwa_textid-tdid.
APPEND gwa_pr_chan3 TO gt_pr_chan3.
CLEAR gwa_pr_chan3.
ENDIF.

* item_text.
READ TABLE gt_textid INTO gwa_textid WITH KEY tdid = lc_b03.
IF sy-subrc = 0.
gwa_pr_chan3-preq_no = gwa_pr_data-purchase_requisition.
gwa_pr_chan3-preq_item = gwa_pr_data-item_on_requisition.
gwa_pr_chan3-text_line = gwa_textid-tdtext.
gwa_pr_chan3-text_id = gwa_textid-tdid.
APPEND gwa_pr_chan3 TO gt_pr_chan3.
CLEAR gwa_pr_chan3.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.

*----Get The Create and Change PR data out of Loop.
*--Create PR Data
IF gt_pr_crea[] IS NOT INITIAL AND
gt_pr_crea2[] IS NOT INITIAL AND
gt_pr_crea3[] IS NOT INITIAL.

* call bapi for creation of Purchase requisition
CALL FUNCTION 'BAPI_REQUISITION_CREATE'
* As PR number generated by std.internally
* IMPORTING
* number = lv_pr_num
TABLES
requisition_items = gt_pr_crea
requisition_account_assignment = gt_pr_crea2
requisition_item_text = gt_pr_crea3
return = gt_return.
* get error record in file
CLEAR gwa_return.
LOOP AT gt_return INTO gwa_return.
IF gwa_return-type = lc_e.
gwa_error-prnum = gwa_pr_data-purchase_requisition.
gwa_error-lin_num = lv_line.
gwa_error-msg = gwa_return-message.
APPEND gwa_error TO gt_error.
CLEAR: gwa_error,gwa_return.
ELSE.
gwa_error-prnum = gwa_pr_data-purchase_requisition.
gwa_error-lin_num = lv_line.
gwa_error-msg = gwa_return-message.
APPEND gwa_error TO gt_error_s.
CLEAR: gwa_error,gwa_return.
ENDIF.
ENDLOOP.

IF gt_error[] IS NOT INITIAL.
CLEAR lv_error_no.
DESCRIBE TABLE gt_error LINES lv_error_no.
ENDIF.

IF gt_error_s[] IS NOT INITIAL.
CLEAR lv_success_no.
DESCRIBE TABLE gt_error LINES lv_success_no.
ENDIF.

CLEAR: gt_pr_crea[],
gt_pr_crea2[],
gt_pr_crea3[],
gwa_pr_crea,
gt_return.
ENDIF.

ENDLOOP