Skip to Content

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

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 .


Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Posted on Oct 23, 2019 at 07:39 AM

    Hi Subham,

    And the mentioned FM is not BAPI. It's s FM contains the BDC codes.

    The reason for the you are getting as you are appending header data inside the loop(table: t_input_data). Let's say you have 5 line item for single material, then you should have append 1 header row and 5 item row. So, total 6 rows in this case. But, you are adding 5 header row and 5 item row, total 10 rows. Hence, getting issues.

    Hope this resolves your issues. Cheers!

    Gourab

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 23, 2019 at 01:40 PM

    If there is no documentation, i would do where used list to find out how the importing and tables are filled. ( This FM is used at one place).

    However this FM is "Not released", do not use it.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Nov 01, 2019 at 08:41 AM

    finally i got .

    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.

    TYPES:BEGIN OF ty_fin,
    klvar TYPE ck_klvar,
    matnr TYPE matnr,
    werks TYPE werks_d,
    losgr TYPE ck_losgr,
    tvers TYPE ck_tvers,
    kadat TYPE ck_abdat,
    bidat TYPE ck_bidat,
    raw_material TYPE ck_kzroh,
    pmark TYPE pmark,
    posnr TYPE ck_posnr,
    typps TYPE typps,
    arbplwerk TYPE kkek_arbplwerk,
    menge TYPE menge_pos,
    meeht TYPE meins,
    pmeht TYPE pmeht,
    ltext TYPE kltxt,
    price_manual TYPE ck_price_manual,
    lpeinh TYPE peinh,
    kstar TYPE kstar,
    elemt TYPE ck_element,
    lpreifx TYPE lpreifx,
    lwertfx TYPE lwertfx,
    opcod TYPE opcod,
    END OF ty_fin.

    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: lt_messages type standard table of bdcmsgcoll INITIAL SIZE 1,
    wa_message TYPE bdcmsgcoll.

    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 :V_ERROR(20) TYPE C,
    V_SUCCESS(1000) TYPE C.


    DATA : t_input_data TYPE kkpi_transfer_data.
    TYPES : BEGIN OF ty_cost,
    v_klvar TYPE ck_klvar,
    v_matnr TYPE matnr,
    v_werks TYPE werks_d,
    v_losgr 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 TYPE char16,
    v_meeht TYPE meins,
    v_lwertb(05) TYPE c,
    v_ltext TYPE kltxt,
    v_lpreis TYPE char17,
    v_lpeinh TYPE char17,
    v_kstar TYPE kstar,
    v_elemt TYPE ck_element,
    v_lpreifx(100) TYPE c,
    v_lwertfx(100) TYPE c,
    v_fin1 TYPE matnr,
    END OF ty_cost.
    DATA: wa_cost TYPE ty_cost,
    it_cost TYPE STANDARD TABLE OF ty_cost,
    wa_cost1 TYPE ty_cost,
    it_cost1 TYPE STANDARD TABLE OF ty_cost.
    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 wa_cost-v_klvar wa_cost-v_matnr wa_cost-v_werks wa_cost-v_losgr wa_cost-v_tvers wa_cost-v_kadat wa_cost-v_bidat
    wa_cost-v_posnr wa_cost-v_typps wa_cost-v_herk2 wa_cost-v_herk3 wa_cost-v_menge wa_cost-v_meeht wa_cost-v_lwertb
    wa_cost-v_ltext wa_cost-v_lpreis wa_cost-v_lpeinh wa_cost-v_kstar wa_cost-v_elemt wa_cost-v_lpreifx wa_cost-v_lwertfx.
    if sy-tabix = 1.
    CONTINUE.
    endif.

    APPEND wa_cost TO it_cost.
    CLEAR wa_cost.
    ENDLOOP.
    it_cost1[] = it_cost[].
    DELETE ADJACENT DUPLICATES FROM it_cost COMPARING v_matnr.
    LOOP AT it_cost INTO wa_cost.
    input_data-klvar = wa_cost-v_klvar.
    input_data-matnr = wa_cost-v_matnr.
    input_data-werks = wa_cost-v_werks.
    input_data-losgr = wa_cost-v_losgr.
    input_data-tvers = wa_cost-v_tvers.
    input_data-kadat = wa_cost-v_kadat.
    input_data-bidat = wa_cost-v_bidat.
    * APPEND input_data TO t_input_data.

    LOOP AT it_cost1 INTO wa_cost1 WHERE v_matnr = wa_cost-v_matnr.
    table_control_line-posnr = wa_cost1-v_posnr.
    table_control_line-typps = wa_cost1-v_typps.
    table_control_line-herk2 = wa_cost1-v_herk2.
    table_control_line-herk3 = wa_cost1-v_herk3.
    table_control_line-menge = wa_cost1-v_menge.
    table_control_line-meeht = wa_cost1-v_meeht.
    table_control_line-lwertb = wa_cost1-v_lwertb.
    table_control_line-ltext = wa_cost1-v_ltext.
    table_control_line-lpreis = wa_cost1-v_lpreis.
    table_control_line-lpeinh = wa_cost1-v_lpeinh.
    table_control_line-kstar = wa_cost1-v_kstar.
    table_control_line-elemt = wa_cost1-v_elemt.
    table_control_line-lpreifx = wa_cost1-v_lpreifx.
    table_control_line-lwertfx = wa_cost1-v_lwertfx.
    APPEND table_control_line TO input_data-position.

    ENDLOOP.
    APPEND input_data TO t_input_data.
    CALL FUNCTION 'KKPI_BDC_COSTING_CREATE'
    EXPORTING
    client = sy-mandt
    user = sy-uname
    mode = 'N'
    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.
    * CONCATENATE wa_cost-v_matnr INTO V_ERROR SEPARATED BY ' '.
    WRITE:/2 wa_cost-v_matnr, 15'Cost fail'.
    ELSE.
    * CONCATENATE wa_cost-v_matnr wa_cost-v_werks INTO V_SUCCESS SEPARATED BY ' '.
    WRITE:/2 wa_cost-v_matnr, 15'Cost Success'.
    ENDIF.
    ENDLOOP.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.