cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI for WCOCO tcode in S4HANA

former_member494960
Discoverer
0 Kudos
2,708

Hi everyone!

I've been looking for BAPI than I can use to upload multiple Rebate Contract which is created in Tcode WCOCO manually. I tried BAPI_CONDITION_CONTRACT_CREATE but I'm getting errors in Business Volume. Can you please send me your sample code on how to correctly populate the tables in BAPI? Thank you so much!

Regards,

Cams

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

if you need to pass the extensionin in your bapi, you can fill the data like below

DATA: lw_bapi_te_komg TYPE bapi_te_komg,
lw_bapi_te_komgx TYPE bapi_te_komgx.
CLEAR: lw_bapi_te_komg,
lw_bapi_te_komgx.

lw_bapi_te_komg-order_key = lv_cnt.
lw_bapi_te_komg-zzaufnr = lw_main-internal_order.

gw_extensionin-structure = 'BAPI_TE_KOMG'.
gw_extensionin-valuepart1 = lw_bapi_te_komg.
APPEND gw_extensionin TO gt_extensionin.

lw_bapi_te_komgx-order_key = lv_cnt.
lw_bapi_te_komgx-zzaufnr = abap_true.

gw_extensionin-structure = 'BAPI_TE_KOMGX'.
gw_extensionin-valuepart1 = lw_bapi_te_komgx.
APPEND gw_extensionin TO gt_extensionin.

before this step, you need to append new structure to BAPI_TE_KOMG, BAPI_TE_KOMGX and also KOMG structure

0 Kudos

Try This code, I work It well.

*&---------------------------------------------------------------------*
*& Report ZTESTCHEN009
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZTESTCHEN009.


DATA: HEADDATAIN TYPE BAPICCHEAD.
DATA: HEADDATAINX TYPE BAPICCHEADX.

DATA: WA_CONDITIONKEYDATAIN TYPE BAPICCCONDITIONKEY,
IT_CONDITIONKEYDATAIN LIKE STANDARD TABLE OF WA_CONDITIONKEYDATAIN.

DATA: WA_CONDITIONKEYDATAINX TYPE BAPICCCONDITIONKEYX,
IT_CONDITIONKEYDATAINX LIKE STANDARD TABLE OF WA_CONDITIONKEYDATAINX.


DATA: WA_CONDITIONITEMDATAIN TYPE BAPICCCONDITIONITEM,
IT_CONDITIONITEMDATAIN LIKE STANDARD TABLE OF WA_CONDITIONITEMDATAIN.

DATA: WA_CONDITIONITEMDATAINX TYPE BAPICCCONDITIONITEMX,
IT_CONDITIONITEMDATAINX LIKE STANDARD TABLE OF WA_CONDITIONITEMDATAINX.

DATA: WA_RETURN TYPE BAPIRET2,
IT_RETURN LIKE STANDARD TABLE OF WA_RETURN.

DATA: CONDITIONCONTRACTNUMBER TYPE BAPICCKEY-CONDITION_CONTRACT_NUMBER,
HEADDATAOUT TYPE BAPICCHEADOS.

DATA: L_ID TYPE I.

CLEAR: HEADDATAIN.
HEADDATAIN-CONTRACT_TYPE = 'ZBBI'.
HEADDATAIN-CUSTOMER_OWNER = '0001200001'.
HEADDATAIN-SALESORG = '1110'.
HEADDATAIN-DISTR_CHAN = '90'.
HEADDATAIN-DIVISION = '00'.
HEADDATAIN-VALIDITY_DATE_FROM = '20191101'.
HEADDATAIN-VALIDITY_DATE_TO = '20191231'.

CLEAR: HEADDATAINX.
HEADDATAINX-CONTRACT_TYPE = 'X'.
HEADDATAINX-CUSTOMER_OWNER = 'X'.
HEADDATAINX-SALESORG = 'X'.
HEADDATAINX-DISTR_CHAN = 'X'.
HEADDATAINX-DIVISION = 'X'.
HEADDATAINX-VALIDITY_DATE_FROM = 'X'.
HEADDATAINX-VALIDITY_DATE_TO = 'X'.


CLEAR: IT_CONDITIONKEYDATAIN.
CLEAR: IT_CONDITIONKEYDATAINX.
CLEAR: IT_CONDITIONITEMDATAIN.
CLEAR: IT_CONDITIONITEMDATAINX.
CLEAR: L_ID.

ADD 1 TO L_ID.
CLEAR: WA_CONDITIONKEYDATAIN.
WA_CONDITIONKEYDATAIN-ORDER_KEY = L_ID.
*WA_CONDITIONKEYDATAIN-TABLE_NO = '163'.
WA_CONDITIONKEYDATAIN-TABLE_NO = '4AB'.
WA_CONDITIONKEYDATAIN-COND_TYPE = 'ZO03'.
WA_CONDITIONKEYDATAIN-VALID_FROM = '20191101'.
WA_CONDITIONKEYDATAIN-VALID_TO = '20191231'.
*WA_CONDITIONKEYDATAIN-MATERIAL = 'EP4933-01-302'.
WA_CONDITIONKEYDATAIN-APPLICATIO = 'V'.
APPEND WA_CONDITIONKEYDATAIN TO IT_CONDITIONKEYDATAIN.

CLEAR: WA_CONDITIONKEYDATAINX.
WA_CONDITIONKEYDATAINX-ORDER_KEY = L_ID.
*WA_CONDITIONKEYDATAINX-MATERIAL = 'X'.
APPEND WA_CONDITIONKEYDATAINX TO IT_CONDITIONKEYDATAINX.

CLEAR: WA_CONDITIONITEMDATAIN.
WA_CONDITIONITEMDATAIN-ORDER_KEY = L_ID.
WA_CONDITIONITEMDATAIN-COND_COUNT = '01'.
WA_CONDITIONITEMDATAIN-CALC_TYPE = 'A'.
WA_CONDITIONITEMDATAIN-AMOUNT = 3.
WA_CONDITIONITEMDATAIN-CONDCURR = '%'.
APPEND WA_CONDITIONITEMDATAIN TO IT_CONDITIONITEMDATAIN.

CLEAR: WA_CONDITIONITEMDATAINX.
WA_CONDITIONITEMDATAINX-ORDER_KEY = L_ID.
WA_CONDITIONITEMDATAINX-COND_COUNT = '01'.
WA_CONDITIONITEMDATAINX-CALC_TYPE = 'X'.
WA_CONDITIONITEMDATAINX-AMOUNT = 'X'.
WA_CONDITIONITEMDATAINX-CONDCURR = 'X'.
APPEND WA_CONDITIONITEMDATAINX TO IT_CONDITIONITEMDATAINX.


CALL FUNCTION 'BAPI_CONDITION_CONTRACT_CREATE'
EXPORTING
HEADDATAIN = HEADDATAIN
HEADDATAINX = HEADDATAINX
* WITHDEFAULT =
* MIGRATIONTESTRUN =
IMPORTING
HEADDATAOUT = HEADDATAOUT
CONDITIONCONTRACTNUMBER = CONDITIONCONTRACTNUMBER
TABLES
* ITEMDATAIN =
* ITEMDATAINX =
CONDITIONKEYDATAIN = IT_CONDITIONKEYDATAIN
CONDITIONKEYDATAINX = IT_CONDITIONKEYDATAINX
CONDITIONITEMDATAIN = IT_CONDITIONITEMDATAIN
CONDITIONITEMDATAINX = IT_CONDITIONITEMDATAINX
* ITEMDATAOUT =
* CONDITIONKEYDATAOUT =
* CONDITIONITEMDATAOUT =
* EXTENSIONIN =
* EXTENSIONOUT =
* HEADTEXTIN =
* HEADTEXTOUT =
* ITEMTEXTIN =
* ITEMTEXTOUT =
RETURN = IT_RETURN
* SCALEDATAIN =
* SCALEDATAOUT =
* BVBDATAIN =
* BVBDATAINX =
* BVBDATAOUT =
* CALENDARDATAIN =
* CALENDARDATAINX =
* CALENDARDATAOUT =
.

LOOP AT IT_RETURN TRANSPORTING NO FIELDS
WHERE TYPE = 'E' OR TYPE = 'A'.
EXIT.
ENDLOOP.
IF SY-SUBRC = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
ENDIF.

CALL FUNCTION 'FINB_BAPIRET2_DISPLAY'
EXPORTING
IT_MESSAGE = IT_RETURN.