Application Development 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: 

Reg : bapi

former_member585865
Contributor
0 Kudos

Hi All,

Am currently working in 4.6b version i have an requirement to upload purchase order creation i.e stock transport order using BAPI. I just want to know how to simulate purchase order before upload in bapi,and if error occurs how can i say that particular line item is error in purchase order creation.But i know that we can simulate in BAPI_PO_CREATE1 in ECC 6.0 how can i achieve in 4.6 version.

am using the function module :BAPI_PO_CREATE

my upload file format :

Material

Quantity

Plant

Storage Location

Delivery Date

4 REPLIES 4

former_member210123
Active Participant
0 Kudos

Hi,

DATA : l_ponumber LIKE ekpo-ebeln,

l_msgty TYPE c,

l_msgid(2) TYPE c,

l_msgno(3) TYPE c,

l_msgtx(100) TYPE c,

l_errflag TYPE c.

DATA : BEGIN OF tl_bapireturn OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA : END OF tl_bapireturn.

*C-- Data declarations for type of subc / serial nos

data: begin of lt_disub_sertab occurs 0,

ebelp like ekpo-ebelp, " PO Item #

sernr like e1rmsno-sernr, " PO Item Serial #

end of lt_disub_sertab.

data: begin of lt_disub_poitem occurs 0,

ebelp like ekpo-ebelp, " PO Item #

serru like ekpo-serru, " Sub contracting Type

anzsn like ekpo-anzsn, " No. of Ser # (= Item Qty)

disub_sobkz like ekpo-disub_sobkz,

disub_pspnr like ekpo-disub_pspnr,

disub_kunnr like ekpo-disub_kunnr,

disub_vbeln like ekpo-disub_vbeln,

disub_posnr like ekpo-disub_posnr,

disub_owner like ekpo-disub_owner,

end of lt_disub_poitem.

*C-- End of data declarations for type of subc / serial nos

CLEAR: l_ponumber.

CLEAR: tl_bapireturn.

REFRESH: tl_bapireturn.

*C-- Handling Type of SubC / Serial Nos

clear lt_disub_poitem.

refresh lt_disub_poitem.

loop at t_po_item

where po_number = t_po_header-po_number.

lt_disub_poitem-ebelp = t_po_item-po_item.

lt_disub_poitem-serru = '1'.

lt_disub_poitem-anzsn = t_po_item-quantity.

append lt_disub_poitem.

clear lt_disub_poitem.

endloop.

Serial Numbers

clear lt_disub_sertab.

refresh lt_disub_sertab.

loop at t_po_itemseril

where po_number = t_po_header-po_number.

lt_disub_sertab-ebelp = t_po_itemseril-po_item.

lt_disub_sertab-sernr = t_po_itemseril-serno.

append lt_disub_sertab.

clear lt_disub_sertab.

endloop.

Export Internal tables to Memory.

export: lt_disub_poitem to memory id 'disub_item',

lt_disub_sertab to memory id 'disub_sertab'.

*C-- End of handling Type of SubC / Serial Nos

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

POHEADER = t_bapi_poheader

POHEADERX = t_bapi_poheaderx

POADDRVENDOR = t_bapi_poaddrvendor

TESTRUN = p_trun

MEMORY_UNCOMPLETE =

MEMORY_COMPLETE =

POEXPIMPHEADER = t_bapi_poexpimpheader

POEXPIMPHEADERX = t_bapi_poexpimpheaderx

VERSIONS =

NO_MESSAGING =

NO_MESSAGE_REQ =

NO_AUTHORITY =

NO_PRICE_FROM_PO =

IMPORTING

EXPPURCHASEORDER = l_ponumber

EXPHEADER =

EXPPOEXPIMPHEADER =

TABLES

RETURN = tl_bapireturn

POITEM = t_bapi_poitem

POITEMX = t_bapi_poitemx

POADDRDELIVERY =

POSCHEDULE = t_bapi_poschedule

POSCHEDULEX = t_bapi_poschedulex

POACCOUNT = t_bapi_poaccount

POACCOUNTPROFITSEGMENT =

POACCOUNTX = t_bapi_poaccountx

POCONDHEADER =

POCONDHEADERX =

POCOND =

POCONDX =

POLIMITS = t_bapi_polimits

POCONTRACTLIMITS =

POSERVICES =

POSRVACCESSVALUES =

POSERVICESTEXT =

EXTENSIONIN =

EXTENSIONOUT =

POEXPIMPITEM = t_bapi_poexpimpitem

POEXPIMPITEMX = t_bapi_poexpimpitemx

POTEXTHEADER = t_bapi_potextheader

POTEXTITEM =

ALLVERSIONS =

POPARTNER =

NFMETALLITMS =

.

IF p_trun IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT =

IMPORTING

RETURN =

.

ENDIF.

*C-- Write messages

WRITE: / 'PO Number: '(012), t_po_header-po_number.

CLEAR l_errflag.

LOOP AT tl_bapireturn.

CLEAR: l_msgty, l_msgid, l_msgno, l_msgtx.

l_msgty = tl_bapireturn-type.

l_msgid = tl_bapireturn-id.

l_msgno = tl_bapireturn-number.

l_msgtx = tl_bapireturn-message.

WRITE: / l_msgty, l_msgid, l_msgno, l_msgtx.

IF l_msgty EQ 'E'.

l_errflag = 'X'.

ENDIF. " l_msgty EQ 'E'

ENDLOOP.

Former Member
0 Kudos

hai.

check this.

REPORT zpo_bapi_purchord_tej.

----


  • DATA DECLARATIONS *

----


TYPE-POOLS slis.

TYPES: BEGIN OF ty_table,

v_legacy(8),

vendor TYPE bapimepoheader-vendor,

purch_org TYPE bapimepoheader-purch_org,

pur_group TYPE bapimepoheader-pur_group,

material TYPE bapimepoitem-material,

quantity(13),

delivery_date TYPE bapimeposchedule-delivery_date,

net_price(23),

plant TYPE bapimepoitem-plant,

END OF ty_table.

TYPES: BEGIN OF ty_alv,

v_legs(8),

success(10),

v_legf(8),

END OF ty_alv.

TYPES: BEGIN OF ty_alv1,

v_legf1(8),

v_msg(500),

END OF ty_alv1.

*-----Work area declarations.

DATA: x_table TYPE ty_table,

x_header TYPE bapimepoheader,

x_headerx TYPE bapimepoheaderx,

x_item TYPE bapimepoitem,

x_itemx TYPE bapimepoitemx,

x_sched TYPE bapimeposchedule,

x_schedx TYPE bapimeposchedulx,

x_commatable(255),

x_alv TYPE ty_alv,

x_alv1 TYPE ty_alv1,

x_alv2 TYPE ty_alv1.

*-----Internal table declarations.

DATA: it_table TYPE TABLE OF ty_table,

it_commatable LIKE TABLE OF x_commatable,

it_item TYPE TABLE OF bapimepoitem,

it_itemx TYPE TABLE OF bapimepoitemx,

it_sched TYPE TABLE OF bapimeposchedule,

it_schedx TYPE TABLE OF bapimeposchedulx,

it_alv TYPE TABLE OF ty_alv,

it_alv1 TYPE TABLE OF ty_alv1,

it_alv2 TYPE TABLE OF ty_alv1.

DATA: po_number TYPE bapimepoheader-po_number,

x_return TYPE bapiret2,

it_return TYPE TABLE OF bapiret2,

v_file TYPE string,

v_temp(8),

v_succsount TYPE i VALUE 0,

v_failcount TYPE i VALUE 0,

v_total TYPE i.

DATA: v_temp1(5) TYPE n VALUE 0.

DATA: x_event TYPE slis_t_event,

x_fieldcat TYPE slis_t_fieldcat_alv,

x_list_header TYPE slis_t_listheader,

x_event1 LIKE LINE OF x_event,

x_layout1 TYPE slis_layout_alv,

x_variant1 TYPE disvariant,

x_repid2 LIKE sy-repid.

DATA : it_fieldcat TYPE TABLE OF slis_t_fieldcat_alv.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK v_b1 WITH FRAME.

*-----To fetch the flat file.

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK v_b1.

----


  • AT SELECTION-SCREEN *

----


AT SELECTION-SCREEN.

IF p_file IS INITIAL.

MESSAGE text-001 TYPE 'E'.

ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*-----To use F4 help to find file path.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

v_file = p_file.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

PERFORM gui_upload.

LOOP AT it_table INTO x_table.

PERFORM header_details.

v_temp = x_table-v_legacy.

LOOP AT it_table INTO x_table WHERE v_legacy = v_temp.

PERFORM lineitem.

PERFORM schedule.

ENDLOOP.

DELETE it_table WHERE v_legacy = v_temp.

PERFORM bapicall.

MOVE po_number TO x_alv-success.

APPEND x_alv TO it_alv.

CLEAR x_alv.

*-----To clear the item details in internal table after the operation for a header.

REFRESH: it_item,

it_itemx,

it_sched,

it_schedx.

CLEAR: v_temp1.

ENDLOOP.

v_total = v_succsount + v_failcount.

PERFORM display_alv.

----


  • FORM GUI_UPLOAD *

----


FORM gui_upload .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

TABLES

data_tab = it_commatable

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17

.

IF sy-subrc = 0.

*-----To fetch the comma seperated flat file into an internal table.

LOOP AT it_commatable INTO x_commatable.

IF x_commatable IS NOT INITIAL.

SPLIT x_commatable AT ',' INTO

x_table-v_legacy

x_table-vendor

x_table-purch_org

x_table-pur_group

x_table-material

x_table-quantity

x_table-delivery_date

x_table-net_price

x_table-plant.

APPEND x_table TO it_table.

ENDIF.

CLEAR x_table.

ENDLOOP.

ENDIF.

ENDFORM. " gui_upload

----


  • FORM HEADER_DETAILS *

----


FORM header_details .

MOVE 'NB' TO x_header-doc_type.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_table-vendor

IMPORTING

output = x_table-vendor

.

MOVE x_table-vendor TO x_header-vendor.

MOVE x_table-purch_org TO x_header-purch_org.

MOVE x_table-pur_group TO x_header-pur_group.

x_headerx-doc_type = 'X'.

x_headerx-vendor = 'X'.

x_headerx-purch_org = 'X'.

x_headerx-pur_group = 'X'.

ENDFORM. " header_details

----


  • FORM LINEITEM *

----


FORM lineitem .

v_temp1 = v_temp1 + 10.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_temp1

IMPORTING

output = v_temp1.

MOVE v_temp1 TO x_item-po_item.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_table-material

IMPORTING

output = x_table-material.

MOVE x_table-material TO x_item-material.

MOVE x_table-quantity TO x_item-quantity.

MOVE x_table-net_price TO x_item-net_price.

MOVE x_table-plant TO x_item-plant.

x_itemx-po_item = v_temp1.

x_itemx-material = 'X'.

x_itemx-quantity = 'X'.

x_itemx-net_price = 'X'.

x_itemx-plant = 'X'.

APPEND x_item TO it_item.

APPEND x_itemx TO it_itemx.

CLEAR: x_item, x_itemx.

ENDFORM. " lineitem1

----


  • FORM SCHEDULE *

----


FORM schedule .

MOVE x_table-delivery_date TO x_sched-delivery_date.

MOVE v_temp1 TO x_sched-po_item.

x_schedx-delivery_date = 'X'.

x_schedx-po_item = v_temp1.

APPEND x_sched TO it_sched.

APPEND x_schedx TO it_schedx.

CLEAR: x_sched, x_schedx.

ENDFORM. " schedule

----


  • FORM BAPICALL *

----


FORM bapicall .

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = x_header

poheaderx = x_headerx

IMPORTING

exppurchaseorder = po_number

TABLES

return = it_return

poitem = it_item

poitemx = it_itemx

poschedule = it_sched

poschedulex = it_schedx.

IF po_number IS NOT INITIAL.

v_succsount = v_succsount + 1.

MOVE x_table-v_legacy TO x_alv-v_legs.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSE.

v_failcount = v_failcount + 1.

MOVE x_table-v_legacy TO x_alv-v_legf.

MOVE x_table-v_legacy TO x_alv1-v_legf1.

LOOP AT it_return INTO x_return.

IF x_alv1-v_msg IS INITIAL.

MOVE x_return-message TO x_alv1-v_msg.

ELSE.

CONCATENATE x_alv1-v_msg x_return-message INTO x_alv1-v_msg SEPARATED BY space.

ENDIF.

ENDLOOP.

APPEND x_alv1 TO it_alv1.

CLEAR x_alv1.

ENDIF.

ENDFORM. " bapicall

----


  • FORM DISPLAY_ALV *

----


FORM display_alv .

PERFORM x_list_header.

PERFORM build_fieldcat CHANGING x_fieldcat.

x_repid2 = sy-repid.

x_event1-name = 'TOP_OF_PAGE'.

x_event1-form = 'TOP_OF_PAGE'.

APPEND x_event1 TO x_event.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = x_repid2

is_layout = x_layout1

it_fieldcat = x_fieldcat

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

i_save = 'A'

is_variant = x_variant1

it_events = x_event

TABLES

t_outtab = it_alv

EXCEPTIONS

program_error = 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. " display_master_data

----


  • FORM USER_COMMAND *

----


FORM user_command USING ucomm LIKE sy-ucomm selfield

TYPE slis_selfield.

READ TABLE it_alv INTO x_alv INDEX selfield-tabindex.

CLEAR : x_alv2,it_alv2[].

LOOP AT it_alv1 INTO x_alv1 WHERE v_legf1 = x_alv-v_legf.

x_alv2 = x_alv1.

APPEND x_alv2 TO it_alv2 .

ENDLOOP.

DATA : it_fieldcat TYPE slis_t_fieldcat_alv.

DATA : x3_fieldcat LIKE LINE OF it_fieldcat.

CLEAR : x3_fieldcat,it_fieldcat[].

CLEAR x3_fieldcat.

x3_fieldcat-col_pos = '1'.

x3_fieldcat-fieldname = 'V_LEGF1'.

x3_fieldcat-reptext_ddic = text-111.

x3_fieldcat-ref_tabname = 'IT_ALV2'.

APPEND x3_fieldcat TO it_fieldcat.

CLEAR x3_fieldcat.

CLEAR x3_fieldcat.

x3_fieldcat-col_pos = '1'.

x3_fieldcat-fieldname = 'V_MSG'.

x3_fieldcat-reptext_ddic = text-112.

x3_fieldcat-ref_tabname = 'IT_ALV2'.

APPEND x3_fieldcat TO it_fieldcat.

CLEAR x3_fieldcat.

x_layout1-colwidth_optimize = 'X'.

x_layout1-zebra = 'X'.

IF it_alv2[] IS NOT INITIAL.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = x_repid2

is_layout = x_layout1

it_fieldcat = it_fieldcat

i_save = 'A'

i_callback_top_of_page = 'TOP'

is_variant = x_variant1

it_events = x_event

TABLES

t_outtab = it_alv2

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDIF.

ENDFORM.

----


  • FORM USER_COMMAND *

----


FORM top.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = 'Commentry'.

ENDFORM.

----


  • FORM BUILD_FIELDCAT *

----


FORM build_fieldcat CHANGING et_fieldcat TYPE slis_t_fieldcat_alv.

DATA: x1_fieldcat TYPE slis_fieldcat_alv.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '1'.

x1_fieldcat-fieldname = 'V_LEGS'.

x1_fieldcat-reptext_ddic = text-108.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '2'.

x1_fieldcat-fieldname = 'SUCCESS'.

x1_fieldcat-key = 'X'.

x1_fieldcat-reptext_ddic = text-109.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '3'.

x1_fieldcat-fieldname = 'V_LEGF'.

x1_fieldcat-key = 'X'.

x1_fieldcat-reptext_ddic = text-110.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

ENDFORM. " build_fieldcat

----


  • FORM BUILD_LIST_HEADER *

----


FORM x_list_header.

DATA: x_list_header1 TYPE slis_listheader.

*-----List Header: type H

CLEAR x_list_header1 .

x_list_header1-typ = 'H'.

x_list_header1-info = text-105.

APPEND x_list_header1 TO x_list_header.

*-----List Key: type S

x_list_header1-typ = 'S'.

x_list_header1-key = text-106.

x_list_header1-info = v_total.

APPEND x_list_header1 TO x_list_header.

*-----List Key: Type S

CLEAR x_list_header1 .

x_list_header1-typ = 'S'.

x_list_header1-key = text-107.

x_list_header1-info = v_succsount.

APPEND x_list_header1 TO x_list_header.

ENDFORM. " build_list_header

----


  • FORM TOP_OF_PAGE *

----


FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = x_list_header.

ENDFORM. " TOP_OF_PAGE

regards.

sowjanya.b

Former Member
0 Kudos

hi

hope it will help you.

Pls reward if help.

REPORT zpo_bapi_purchord_tej.

----


  • DATA DECLARATIONS *

----


TYPE-POOLS slis.

TYPES: BEGIN OF ty_table,

v_legacy(8),

vendor TYPE bapimepoheader-vendor,

purch_org TYPE bapimepoheader-purch_org,

pur_group TYPE bapimepoheader-pur_group,

material TYPE bapimepoitem-material,

quantity(13),

delivery_date TYPE bapimeposchedule-delivery_date,

net_price(23),

plant TYPE bapimepoitem-plant,

END OF ty_table.

TYPES: BEGIN OF ty_alv,

v_legs(8),

success(10),

v_legf(8),

END OF ty_alv.

TYPES: BEGIN OF ty_alv1,

v_legf1(8),

v_msg(500),

END OF ty_alv1.

*-----Work area declarations.

DATA: x_table TYPE ty_table,

x_header TYPE bapimepoheader,

x_headerx TYPE bapimepoheaderx,

x_item TYPE bapimepoitem,

x_itemx TYPE bapimepoitemx,

x_sched TYPE bapimeposchedule,

x_schedx TYPE bapimeposchedulx,

x_commatable(255),

x_alv TYPE ty_alv,

x_alv1 TYPE ty_alv1,

x_alv2 TYPE ty_alv1.

*-----Internal table declarations.

DATA: it_table TYPE TABLE OF ty_table,

it_commatable LIKE TABLE OF x_commatable,

it_item TYPE TABLE OF bapimepoitem,

it_itemx TYPE TABLE OF bapimepoitemx,

it_sched TYPE TABLE OF bapimeposchedule,

it_schedx TYPE TABLE OF bapimeposchedulx,

it_alv TYPE TABLE OF ty_alv,

it_alv1 TYPE TABLE OF ty_alv1,

it_alv2 TYPE TABLE OF ty_alv1.

DATA: po_number TYPE bapimepoheader-po_number,

x_return TYPE bapiret2,

it_return TYPE TABLE OF bapiret2,

v_file TYPE string,

v_temp(8),

v_succsount TYPE i VALUE 0,

v_failcount TYPE i VALUE 0,

v_total TYPE i.

DATA: v_temp1(5) TYPE n VALUE 0.

DATA: x_event TYPE slis_t_event,

x_fieldcat TYPE slis_t_fieldcat_alv,

x_list_header TYPE slis_t_listheader,

x_event1 LIKE LINE OF x_event,

x_layout1 TYPE slis_layout_alv,

x_variant1 TYPE disvariant,

x_repid2 LIKE sy-repid.

DATA : it_fieldcat TYPE TABLE OF slis_t_fieldcat_alv.

----


  • SELECTION-SCREEN *

----


SELECTION-SCREEN BEGIN OF BLOCK v_b1 WITH FRAME.

*-----To fetch the flat file.

PARAMETERS: p_file TYPE rlgrap-filename.

SELECTION-SCREEN END OF BLOCK v_b1.

----


  • AT SELECTION-SCREEN *

----


AT SELECTION-SCREEN.

IF p_file IS INITIAL.

MESSAGE text-001 TYPE 'E'.

ENDIF.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*-----To use F4 help to find file path.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file.

v_file = p_file.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

PERFORM gui_upload.

LOOP AT it_table INTO x_table.

PERFORM header_details.

v_temp = x_table-v_legacy.

LOOP AT it_table INTO x_table WHERE v_legacy = v_temp.

PERFORM lineitem.

PERFORM schedule.

ENDLOOP.

DELETE it_table WHERE v_legacy = v_temp.

PERFORM bapicall.

MOVE po_number TO x_alv-success.

APPEND x_alv TO it_alv.

CLEAR x_alv.

*-----To clear the item details in internal table after the operation for a header.

REFRESH: it_item,

it_itemx,

it_sched,

it_schedx.

CLEAR: v_temp1.

ENDLOOP.

v_total = v_succsount + v_failcount.

PERFORM display_alv.

----


  • FORM GUI_UPLOAD *

----


FORM gui_upload .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = v_file

filetype = 'ASC'

TABLES

data_tab = it_commatable

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

no_authority = 6

unknown_error = 7

bad_data_format = 8

header_not_allowed = 9

separator_not_allowed = 10

header_too_long = 11

unknown_dp_error = 12

access_denied = 13

dp_out_of_memory = 14

disk_full = 15

dp_timeout = 16

OTHERS = 17

.

IF sy-subrc = 0.

*-----To fetch the comma seperated flat file into an internal table.

LOOP AT it_commatable INTO x_commatable.

IF x_commatable IS NOT INITIAL.

SPLIT x_commatable AT ',' INTO

x_table-v_legacy

x_table-vendor

x_table-purch_org

x_table-pur_group

x_table-material

x_table-quantity

x_table-delivery_date

x_table-net_price

x_table-plant.

APPEND x_table TO it_table.

ENDIF.

CLEAR x_table.

ENDLOOP.

ENDIF.

ENDFORM. " gui_upload

----


  • FORM HEADER_DETAILS *

----


FORM header_details .

MOVE 'NB' TO x_header-doc_type.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_table-vendor

IMPORTING

output = x_table-vendor

.

MOVE x_table-vendor TO x_header-vendor.

MOVE x_table-purch_org TO x_header-purch_org.

MOVE x_table-pur_group TO x_header-pur_group.

x_headerx-doc_type = 'X'.

x_headerx-vendor = 'X'.

x_headerx-purch_org = 'X'.

x_headerx-pur_group = 'X'.

ENDFORM. " header_details

----


  • FORM LINEITEM *

----


FORM lineitem .

v_temp1 = v_temp1 + 10.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = v_temp1

IMPORTING

output = v_temp1.

MOVE v_temp1 TO x_item-po_item.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = x_table-material

IMPORTING

output = x_table-material.

MOVE x_table-material TO x_item-material.

MOVE x_table-quantity TO x_item-quantity.

MOVE x_table-net_price TO x_item-net_price.

MOVE x_table-plant TO x_item-plant.

x_itemx-po_item = v_temp1.

x_itemx-material = 'X'.

x_itemx-quantity = 'X'.

x_itemx-net_price = 'X'.

x_itemx-plant = 'X'.

APPEND x_item TO it_item.

APPEND x_itemx TO it_itemx.

CLEAR: x_item, x_itemx.

ENDFORM. " lineitem1

----


  • FORM SCHEDULE *

----


FORM schedule .

MOVE x_table-delivery_date TO x_sched-delivery_date.

MOVE v_temp1 TO x_sched-po_item.

x_schedx-delivery_date = 'X'.

x_schedx-po_item = v_temp1.

APPEND x_sched TO it_sched.

APPEND x_schedx TO it_schedx.

CLEAR: x_sched, x_schedx.

ENDFORM. " schedule

----


  • FORM BAPICALL *

----


FORM bapicall .

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = x_header

poheaderx = x_headerx

IMPORTING

exppurchaseorder = po_number

TABLES

return = it_return

poitem = it_item

poitemx = it_itemx

poschedule = it_sched

poschedulex = it_schedx.

IF po_number IS NOT INITIAL.

v_succsount = v_succsount + 1.

MOVE x_table-v_legacy TO x_alv-v_legs.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSE.

v_failcount = v_failcount + 1.

MOVE x_table-v_legacy TO x_alv-v_legf.

MOVE x_table-v_legacy TO x_alv1-v_legf1.

LOOP AT it_return INTO x_return.

IF x_alv1-v_msg IS INITIAL.

MOVE x_return-message TO x_alv1-v_msg.

ELSE.

CONCATENATE x_alv1-v_msg x_return-message INTO x_alv1-v_msg SEPARATED BY space.

ENDIF.

ENDLOOP.

APPEND x_alv1 TO it_alv1.

CLEAR x_alv1.

ENDIF.

ENDFORM. " bapicall

----


  • FORM DISPLAY_ALV *

----


FORM display_alv .

PERFORM x_list_header.

PERFORM build_fieldcat CHANGING x_fieldcat.

x_repid2 = sy-repid.

x_event1-name = 'TOP_OF_PAGE'.

x_event1-form = 'TOP_OF_PAGE'.

APPEND x_event1 TO x_event.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = x_repid2

is_layout = x_layout1

it_fieldcat = x_fieldcat

i_callback_user_command = 'USER_COMMAND'

i_callback_top_of_page = 'TOP_OF_PAGE'

i_save = 'A'

is_variant = x_variant1

it_events = x_event

TABLES

t_outtab = it_alv

EXCEPTIONS

program_error = 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. " display_master_data

----


  • FORM USER_COMMAND *

----


FORM user_command USING ucomm LIKE sy-ucomm selfield

TYPE slis_selfield.

READ TABLE it_alv INTO x_alv INDEX selfield-tabindex.

CLEAR : x_alv2,it_alv2[].

LOOP AT it_alv1 INTO x_alv1 WHERE v_legf1 = x_alv-v_legf.

x_alv2 = x_alv1.

APPEND x_alv2 TO it_alv2 .

ENDLOOP.

DATA : it_fieldcat TYPE slis_t_fieldcat_alv.

DATA : x3_fieldcat LIKE LINE OF it_fieldcat.

CLEAR : x3_fieldcat,it_fieldcat[].

CLEAR x3_fieldcat.

x3_fieldcat-col_pos = '1'.

x3_fieldcat-fieldname = 'V_LEGF1'.

x3_fieldcat-reptext_ddic = text-111.

x3_fieldcat-ref_tabname = 'IT_ALV2'.

APPEND x3_fieldcat TO it_fieldcat.

CLEAR x3_fieldcat.

CLEAR x3_fieldcat.

x3_fieldcat-col_pos = '1'.

x3_fieldcat-fieldname = 'V_MSG'.

x3_fieldcat-reptext_ddic = text-112.

x3_fieldcat-ref_tabname = 'IT_ALV2'.

APPEND x3_fieldcat TO it_fieldcat.

CLEAR x3_fieldcat.

x_layout1-colwidth_optimize = 'X'.

x_layout1-zebra = 'X'.

IF it_alv2[] IS NOT INITIAL.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = x_repid2

is_layout = x_layout1

it_fieldcat = it_fieldcat

i_save = 'A'

i_callback_top_of_page = 'TOP'

is_variant = x_variant1

it_events = x_event

TABLES

t_outtab = it_alv2

EXCEPTIONS

program_error = 1

OTHERS = 2.

ENDIF.

ENDFORM.

----


  • FORM USER_COMMAND *

----


FORM top.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = 'Commentry'.

ENDFORM.

----


  • FORM BUILD_FIELDCAT *

----


FORM build_fieldcat CHANGING et_fieldcat TYPE slis_t_fieldcat_alv.

DATA: x1_fieldcat TYPE slis_fieldcat_alv.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '1'.

x1_fieldcat-fieldname = 'V_LEGS'.

x1_fieldcat-reptext_ddic = text-108.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '2'.

x1_fieldcat-fieldname = 'SUCCESS'.

x1_fieldcat-key = 'X'.

x1_fieldcat-reptext_ddic = text-109.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

x1_fieldcat-col_pos = '3'.

x1_fieldcat-fieldname = 'V_LEGF'.

x1_fieldcat-key = 'X'.

x1_fieldcat-reptext_ddic = text-110.

x1_fieldcat-ref_tabname = 'IT_ALV'.

APPEND x1_fieldcat TO et_fieldcat.

CLEAR x1_fieldcat.

ENDFORM. " build_fieldcat

----


  • FORM BUILD_LIST_HEADER *

----


FORM x_list_header.

DATA: x_list_header1 TYPE slis_listheader.

*-----List Header: type H

CLEAR x_list_header1 .

x_list_header1-typ = 'H'.

x_list_header1-info = text-105.

APPEND x_list_header1 TO x_list_header.

*-----List Key: type S

x_list_header1-typ = 'S'.

x_list_header1-key = text-106.

x_list_header1-info = v_total.

APPEND x_list_header1 TO x_list_header.

*-----List Key: Type S

CLEAR x_list_header1 .

x_list_header1-typ = 'S'.

x_list_header1-key = text-107.

x_list_header1-info = v_succsount.

APPEND x_list_header1 TO x_list_header.

ENDFORM. " build_list_header

----


  • FORM TOP_OF_PAGE *

----


FORM top_of_page.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = x_list_header.

ENDFORM. " TOP_OF_PAGE

former_member585865
Contributor
0 Kudos

Hi All,

Just tell me how to simulate purchase order using the function module or some other logic i don't need the code just tell me logic its enough,

just read my question carefully and answer yar.