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: 

Target Qauntity not updating in VA01 from BAPI SD_SALESDOCUMENT_CREATE

Arif_ahmad
Explorer
0 Kudos
1,055

Hi Gurus,

I am trying to create debit notes in VA01 through BAPI

SD_SALESDOCUMENT_CREATE . ALL entries are updating correctly except target value in line item where quantity is showing 0 but required qty(order quantity) is updating correctly.I have tried manually creating one entry and it is saving along with target qty
but not the same through bapi.

Thanks

Heres my code

loop at it_record  into record.

header-DOC_TYPE = record-DOC_TYPE.

header-SALES_ORG = record-SALES_ORG.

header-DIVISION  = record-DIVISION.

header-DISTR_CHAN = record-DIST_CHANNEL.

header-BILL_BLOCK = ' '."record-BILLING.

header-ORD_REASON = record-ORDER_REASON.





REPLACE all OCCURRENCES OF '.' in record-ref_date with ''.

CONCATENATE record-ref_date+4(4) record-ref_date+2(2) record-ref_Date+0(2) into record-ref_Date.



header-PURCH_DATE = record-REF_DATE.



          .

CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'

  EXPORTING

    INPUT         = record-doc_Date

 IMPORTING

   OUTPUT        = record-DOC_DATE

          .





header-DOC_DATE = record-DOC_DATE.

header-PURCH_NO_C = record-REFERENCE.

CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'

  EXPORTING

    INPUT         = record-hdate

 IMPORTING

   OUTPUT        = record-hdate

          .

header-BILL_DATE = record-HDATE.

CALL FUNCTION 'CONVERSION_EXIT_SDATE_INPUT'

  EXPORTING

    INPUT         = record-price_Date

 IMPORTING

   OUTPUT        = record-price_DATE

          .

header-PRICE_DATE = record-PRICE_DATE.

headerx-PURCH_DATE = 'X'.

headerx-BILL_DATE = 'X'.

headerx-PRICE_DATE = 'X'.

headerx-PURCH_NO_C = 'X'.

headerx-DOC_DATE = 'X'.

headerx-DOC_TYPE = 'X'."record-DOC_TYPE.

headerx-SALES_ORG = 'X'."record-SALES_ORG.

headerx-DIVISION = 'X'."record-division.

headerx-DISTR_CHAN = 'X'."record-DIST_CHAN.

headerx-BILL_BLOCK = 'X'.

headerx-ORD_REASON = 'X'.

headerx-UPDATEFLAG = 'I'.



CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

  EXPORTING

    INPUT         = record-customer

 IMPORTING

   OUTPUT        = record-customer

          .



partner-PARTN_ROLE = 'WE'."ship to party

partner-PARTN_NUMB = record-CUSTOMER.

*partner-ITM_NUMBER = '10'.

append partner to tpartner.



CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

  EXPORTING

    INPUT         = record-customer1

 IMPORTING

   OUTPUT        = record-customer1

          .



partner-PARTN_ROLE = 'AG'. "sold to party

partner-PARTN_NUMB = record-CUSTOMER1.

*partner-ITM_NUMBER = '10'.

append partner to tpartner.



CALL FUNCTION 'CONVERSION_EXIT_MATNE_INPUT'

  EXPORTING

    INPUT              = record-matnr

 IMPORTING

   OUTPUT             = record-matnr

 EXCEPTIONS

   LENGTH_ERROR       = 1

   OTHERS             = 2

          .

IF SY-SUBRC <> 0.

* Implement suitable error handling here

ENDIF.



item-ITM_NUMBER =  '10'.

item-MATERIAL = record-MATNR.

item-TARGET_QTY = record-QUANTITY.

*item-TARGET_QU = 'EA'.

*item-BILL_BLOCK = ' '.

*item-u

*item-HG_LV_ITEM = item-itm_number.

*item-

*item-TARGET_QU  = record-QUANTITY.

*item-t

append item to titem.



itemx-itm_number = item-itm_number.



itemx-UPDATEFLAG = 'I'.

itemx-MATERIAL  = 'X'.

itemx-TARGET_QTY = 'X'.



append itemx to titemx.



*sched-

sched-ITM_NUMBER = item-ITM_NUMBER.

sched-REQ_QTY =  record-QUANTITY.



append sched to tsched.



schedx-ITM_NUMBER = item-ITM_NUMBER.

schedx-UPDATEFLAG = 'I'.

schedx-REQ_QTY = 'X'.

*schedx-SCHED_LINE = '0001'.

append schedx to tschedx.



               CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'

                EXPORTING

*                 SALESDOCUMENT                 =

                  SALES_HEADER_IN              = header

                  SALES_HEADER_INX              = headerx

*                 SENDER                        =

*                 BINARY_RELATIONSHIPTYPE       = ' '

*                 INT_NUMBER_ASSIGNMENT         = ' '

*                 BEHAVE_WHEN_ERROR             = ' '

*                 LOGIC_SWITCH                  = ' '

*                 BUSINESS_OBJECT               = ' '

*                 TESTRUN                       =

*                 CONVERT_PARVW_AUART           = ' '

*                 STATUS_BUFFER_REFRESH         = 'X'

*                 CALL_ACTIVE                   = ' '

*                 I_WITHOUT_INIT                = ' '

               IMPORTING

                 SALESDOCUMENT_EX              = sales

*                 SALES_HEADER_OUT              =

*                 SALES_HEADER_STATUS           =

               TABLES

                 RETURN                        = return

                 SALES_ITEMS_IN                = titem

                 SALES_ITEMS_INX               = titemx

                 SALES_PARTNERS                = tpartner

                 SALES_SCHEDULES_IN            = tsched

                 SALES_SCHEDULES_INX           = tschedx

*                 SALES_CONDITIONS_IN           =

*                 SALES_CONDITIONS_INX          =

*                 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                   = tpartnerx

*                 TEXTHEADERS_EX                =

*                 TEXTLINES_EX                  =

*                 BATCH_CHARC                   =

*                 CAMPAIGN_ASGN                 =

                        .



READ TABLE return[] into data(ls_return) with key type = 'S' number = '311'.

if sy-subrc = 0.

  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

   EXPORTING

     WAIT          = 'X'

*   IMPORTING

*     RETURN        =

            .



  append ls_return to return1.

  clear ls_return.

  else.

*    READ TABLE return[] into data(ls_return) with key type = 'E'. number = '311'.

    APPEND lines of return to return1.

  endif.

  refresh:return[],titem[],titemx[],tpartner[],tsched[],tschedx[].
endloop.


7 REPLIES 7

former_member184158
Active Contributor
0 Kudos
213

Hallo KIRAN KULKARNI

I think you have to do target qty in ORDER_SCHEDULE_IN and delete it from ITEM ( item-TARGET_QTY = record-QUANTITY--> Delete it)

sched-ITM_NUMBER = item-ITM_NUMBER. ( this is ok what you have done) only just delete it from ITEM (ORDER_ITEMS)

Best regards

Ebrahim

0 Kudos
213

Dear Ebrahim,

Thanks for your reply,

I have tried as per your suggestion and removed item-number and quantity assignment in line item table ,have kept

only material assignment ,yet target quantity is not updated but order quantity is.
Regards.

former_member225631
Active Contributor
0 Kudos
213

Try

header UPDATEFLAG ='U'.
item-ITM_NUMBER =  '00010'.  
and fill all the mandatory values.

0 Kudos
213

Hi Anand,

Thanks for your reply.

I am creating a debit note so when I use 'U' in update flag it is trying to validate non existing data.
I tried passing all necessary data , yet no desired result.

0 Kudos
213

Please ensure item number is passed as '00010', not as shown above '10'.

Pass Material Quantity Plant, Strage Location.

I am not sure, why shedule data is added. Please check, the amount needs to be added in Sales_condition_in table.

VeselinaPeykova
Active Contributor
0 Kudos
213

Probably a dumb question, but why do you have schedule lines for this sales document type in the first place?

Normally for debit memos you do not need schedule lines, because there is no delivery involved.

kathylau007
Discoverer
0 Kudos
213

item-TARGET_QU = 'EA'.
item-sales_unit = 'EA'.