Skip to Content
0
Oct 23, 2019 at 07:09 AM

what we do for uploading a multiple line item in bapi.

168 Views

i have a bapi =====>

KKPI_BDC_COSTING_CREATE

i write a code for it.

SPAN { font-family: "Courier New"; font-size: 10pt; color: #000000; background: #FFFFFF; } .L0S31 { font-style: italic; color: #808080; } .L0S32 { color: #3399FF; } .L0S33 { color: #4DA619; } .L0S52 { color: #0000FF; } .L0S55 { color: #800080; } .L0S70 { color: #808080; }

TYPES:BEGIN OF ty_file,
line(1000) TYPE c,
v_fin1 TYPE MATNR,
END OF ty_file.



DATA : it_file TYPE STANDARD TABLE OF ty_file INITIAL SIZE 1,
wa_file TYPE ty_file,
it_fin TYPE STANDARD TABLE OF ty_fin INITIAL SIZE 1,
wa_fin TYPE ty_fin.

DATA : it_return TYPE STANDARD TABLE OF bapiret2 INITIAL SIZE 1,
wa_return TYPE bapiret2.

DATA :input_data TYPE kkpi_transfer_data_line,
table_control_line TYPE rk70l.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS p_path TYPE localfile.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
* FIELD_NAME = ' '
IMPORTING
file_name = p_path.

AT SELECTION-SCREEN.
IF p_path IS INITIAL.
MESSAGE text-002 TYPE 'E'.
ELSE.
IF p_path CP '*.TXT' OR
p_path CP '*.txt'.
ELSE.
MESSAGE text-003 TYPE 'E'.
ENDIF.
ENDIF.

START-OF-SELECTION.

DATA: p_file1 TYPE string.
p_file1 = p_path.

CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file1
TABLES
data_tab = it_file
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.
* Implement suitable error handling here
ENDIF.

END-OF-SELECTION.
DATA : t_input_data TYPE kkpi_transfer_data.

DATA : v_klvar TYPE ck_klvar,
v_matnr TYPE matnr,
v_werks TYPE werks_d,
v_losgr(100) TYPE c,
v_tvers TYPE ck_tvers,
v_kadat TYPE ck_abdat,
v_bidat TYPE ck_bidat,
v_posnr TYPE ck_posnr,
v_typps TYPE typps,
v_herk2 TYPE herk2,
v_herk3 TYPE herk3,
v_menge(100) TYPE c,
v_meeht TYPE meins,
v_lwertb(100) TYPE c,
v_ltext TYPE kltxt,
v_lpreis(100) TYPE c,
v_lpeinh(100) TYPE c,
v_kstar TYPE kstar,
v_elemt TYPE ck_element,
v_lpreifx(100) TYPE c,
v_lwertfx(100) TYPE c,
v_fin1 TYPE matnr.

LOOP AT it_file INTO wa_file.
CLEAR : v_klvar,v_matnr,v_werks,v_losgr,v_tvers,v_kadat,v_bidat,v_posnr,v_typps,v_herk2,v_herk3,v_menge,v_meeht,
v_lwertb,v_ltext,v_lpreis,v_lpeinh,v_kstar, v_elemt, v_lpreifx, v_lwertfx,table_control_line,input_data,t_input_data.

SPLIT wa_file-line AT ';' INTO v_klvar v_matnr v_werks v_losgr v_tvers v_kadat v_bidat v_posnr v_typps v_herk2 v_herk3 v_menge v_meeht
v_lwertb v_ltext v_lpreis v_lpeinh v_kstar v_elemt v_lpreifx v_lwertfx.

input_data-klvar = v_klvar.
input_data-matnr = v_matnr.
input_data-werks = v_werks.
input_data-losgr = v_losgr.
input_data-tvers = v_tvers.
input_data-kadat = v_kadat.
input_data-bidat = v_bidat.
table_control_line-posnr = v_posnr.
table_control_line-typps = v_typps.
table_control_line-herk2 = v_herk2.
table_control_line-herk3 = v_herk3.
table_control_line-menge = v_menge.
table_control_line-meeht = v_meeht.
table_control_line-lwertb = v_lwertb.
table_control_line-ltext = v_ltext.
table_control_line-lpreis = v_lpreis.
table_control_line-lpeinh = v_lpeinh.
table_control_line-kstar = v_kstar.
table_control_line-elemt = v_elemt.
table_control_line-lpreifx = v_lpreifx.
table_control_line-lwertfx = v_lwertfx.
APPEND table_control_line TO input_data-position.
APPEND input_data TO t_input_data.
ENDIF.
ENDIF.
CALL FUNCTION 'KKPI_BDC_COSTING_CREATE'
EXPORTING
client = sy-mandt
user = sy-uname
mode = 'A'
update = 'A'
it_transfer_data = t_input_data
EXCEPTIONS
call_transaction_error = 1
no_transfer_data = 2
wrong_mode_parameter = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDLOOP.

when i am uploading for one header with one line item its working successfully but problems is when i uploading a one header have a multiple line item its generating a error like material is already exit .

my file data is

Z001;1600640014;3504;1;1;20190704;99990331;1;M;1300630004;1020;10;KG;570;Refined Palm Olein;57000.00;1;4100202;10;0;0.
Z001;1600640014;3504;1;1;20190704;99990331;2;M;5002120114;1020;1;NOS;71.5;15KGS TIN CONTAINERS 900G;71.5;1;4700103;40;0;0.

so, what i change in code for uploading a multiple line item .

plz suggest .