Application Development and Automation 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: 
Read only

free goods by a program

Former Member
0 Likes
720

How to create a sales order with free goods with an abap function?

Now, I'm creating a sales order with function 'SD_SALESDOCUMENT_CREATE' but don't know how to include free goods.

I would like to use a manual condition type to introduce free goods with a program.

Thanks in advance.

How to create a sales order with free goods with an abap function?

Now, I'm creating a sales order with function 'SD_SALESDOCUMENT_CREATE' but don't know how to include free goods.

I would like to use a manual condition type to introduce free goods with a program.

Thanks in advance.

4 REPLIES 4
Read only

Former Member
0 Likes
648

Hi,

I think You dont necessarily need to give the Condition records in the Interface of the 'SD_SALESDOCUMENT_CREATE' FM. IF you just give the Required Header Details and the Material and their Quantity at Item level ( Ofcourse with Codition Types, Condition Records and Pricing Proceedure maintained for the Combination ) the System will pick up the Prices automatically.

Also BAPI_SALESORDER_CREATEFROMDAT2 is a better and revised FM to create Sales Orders.

regards,

Mahesh

Read only

0 Likes
648

Thank you Mahesh.

But I don't want the system to pick up the prices automatically. These sales orders are sent by salesmen and each document has its prices.

I'm going to try BAPI_SALESORDER_CREATEFROMDAT2

Read only

Former Member
0 Likes
648

check the following code, it may be useful

SORT I_CR BY BUKRS KNUMA VKORG VTWEG SPART.

*Generate Cr. Memo request Sales area wise.

LOOP AT I_CR.

*Do not conider the record which net scheme amount is lessthan or equal

*to zero

IF I_CR-NSAMT > 0.

L_ITEM = L_ITEM + 1.

CLEAR IT_ORIT.

IT_ORIT-ITM_NUMBER = L_ITEM.

IT_ORIT-MATERIAL = I_CR-MATNR.

  • IT_ORIT-BILL_BLOCK = ''.

IT_ORIT-TARGET_QTY = '0'.

IT_ORIT-MATL_GROUP = I_CR-MATKL.

APPEND IT_ORIT.

CLEAR IT_ITINX.

IT_ITINX-ITM_NUMBER = 'X'.

IT_ITINX-MATERIAL = 'X'.

  • IT_ITINX-BILL_BLOCK = 'X'.

IT_ITINX-TARGET_QTY = 'X'.

IT_ITINX-MATL_GROUP = 'X'.

APPEND IT_ITINX.

CLEAR IT_ORPT.

IT_ORPT-PARTN_ROLE = 'AG'.

IT_ORPT-PARTN_NUMB = I_CR-KUNAG.

APPEND IT_ORPT.

    • CLEAR L_VAL.

  • L_VAL = I_CR-MG_NSAMT.

    • L_FK = I_CR-FKIMG.

  • DIVIDE I_CR-FKIMG BY I_CR-MG_FKIMG.

  • L_VAL = L_VAL * I_CR-FKIMG.

    • DIVIDE L_VAL BY L_FK.

    • CLEAR L_FK.

IT_COND-ITM_NUMBER = L_ITEM.

IT_COND-COND_TYPE = 'ZBLD'.

IT_COND-COND_VALUE = I_CR-NSAMT.

IT_COND-CURRENCY = 'INR'.

APPEND IT_COND.

IT_CONDX-ITM_NUMBER = L_ITEM.

IT_CONDX-COND_TYPE = 'ZBLD'.

IT_CONDX-UPDATEFLAG = 'U'.

IT_CONDX-COND_VALUE = 'X'.

IT_CONDX-CURRENCY = 'X'.

APPEND IT_CONDX.

AT END OF SPART.

L_FLAG = 'X'.

ENDAT.

IF L_FLAG = 'X'.

IT_HEADER-REFOBJTYPE = 'BUS2094'.

IT_HEADER-DOC_TYPE = 'ZCMR'.

IT_HEADER-SALES_ORG = I_CR-VKORG.

IT_HEADER-DISTR_CHAN = I_CR-VTWEG.

IT_HEADER-DIVISION = I_CR-SPART.

IT_HEADER-ORD_REASON = 'Z15'.

IT_HEADER-BILL_BLOCK = ' '.

  • IT_HEADER-TELEPHONE = 'AUTO'.

IT_HEADX-DOC_TYPE = 'X'.

IT_HEADX-SALES_ORG = 'X'.

IT_HEADX-DISTR_CHAN = 'X'.

IT_HEADX-DIVISION = 'X'.

IT_HEADX-ORD_REASON = 'X'.

IT_HEADX-UPDATEFLAG = 'I'.

IT_HEADX-BILL_BLOCK = 'X'.

  • IT_HEADX-TELEPHONE = 'X'.

PERFORM SUB_CALL_BAPI.

REFRESH : IT_HEADER, IT_ORIT, IT_ORPT, IT_ITINX,

IT_COND, IT_CONDX.

CLEAR : IT_HEADER, IT_ORIT, IT_ORPT, IT_ITINX,

L_VKORG, L_VTWEG, L_SPART, L_FLAG, L_ITEM,

IT_COND, IT_CONDX,L_FLAG.

ENDIF.

ENDIF.

ENDLOOP.

&----


*& Form SUB_CALL_BAPI

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM SUB_CALL_BAPI .

DATA: L_ERR(1),

L_VBELN LIKE ZSD_RBT_ELG_INV-VBELN,

L_FLAG1(1),

L_ERR1(1),

L_FLAG2(1),

L_ERR2(1),

L_VAL1 LIKE ZSD_RBT_ELG_INV-NETWR.

DATA: ARKTX(15) TYPE C VALUE 'VBRP-ARKTX(&1)'.

DATA: C(2) VALUE '&1'.

DATA: COUNTER(2) TYPE N.

  • SET UPDATE TASK LOCAL.

REFRESH: IT_RET.

CLEAR: L_ERR, L_VBELN, L_VAL1, L_FLAG1.

CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'

EXPORTING

  • SALESDOCUMENT =

SALES_HEADER_IN = IT_HEADER

SALES_HEADER_INX = IT_HEADX

  • SENDER =

  • BINARY_RELATIONSHIPTYPE = ' '

  • INT_NUMBER_ASSIGNMENT = ' '

  • BEHAVE_WHEN_ERROR = ' '

  • LOGIC_SWITCH = ' '

  • BUSINESS_OBJECT = ' '

  • TESTRUN =

  • CONVERT_PARVW_AUART = ' '

  • STATUS_BUFFER_REFRESH = 'X'

IMPORTING

SALESDOCUMENT_EX = L_VBELN

  • SALES_HEADER_OUT =

  • SALES_HEADER_STATUS =

TABLES

RETURN = IT_RET

SALES_ITEMS_IN = IT_ORIT

SALES_ITEMS_INX = IT_ITINX

SALES_PARTNERS = IT_ORPT

  • SALES_SCHEDULES_IN =

  • SALES_SCHEDULES_INX =

SALES_CONDITIONS_IN = IT_COND

SALES_CONDITIONS_INX = IT_CONDX

  • SALES_CFGS_REF =

  • SALES_CFGS_INST =

  • SALES_CFGS_PART_OF =

  • SALES_CFGS_VALUE =

  • SALES_CFGS_BLOB =

  • SALES_CFGS_VK =

  • SALES_CFGS_REFINST =

  • SALES_CCARD =

  • SALES_TEXT =

  • SALES_KEYS =

  • SALES_CONTRACT_IN =

  • SALES_CONTRACT_INX =

  • EXTENSIONIN =

  • PARTNERADDRESSES =

  • SALES_SCHED_CONF_IN =

  • ITEMS_EX =

  • SCHEDULE_EX =

  • BUSINESS_EX =

  • INCOMPLETE_LOG =

  • EXTENSIONEX =

  • CONDITIONS_EX =

  • PARTNERS_EX =

  • TEXTHEADERS_EX =

  • TEXTLINES_EX =

  • BATCH_CHARC =

.

CLEAR L_ERR.

LOOP AT IT_RET.

IF IT_RET-TYPE EQ 'E'.

LEAVE TO LIST-PROCESSING.

WRITE:/ 'BAPI ERROR', IT_RET-MESSAGE.

L_ERR = 'X'.

ELSEIF IT_RET-TYPE = 'S'

AND IT_RET-ID = 'V1'.

LEAVE TO LIST-PROCESSING.

WRITE:/ IT_RET-MESSAGE.

ENDIF.

ENDLOOP.

IF L_ERR IS INITIAL.

CLEAR L_ERR.

COMMIT WORK.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

Read only

Former Member
0 Likes
648

This message was moderated.