‎2011 Mar 30 8:50 AM
Hello,
I'm using the function 'NUMBER_GET_NEXT' for obtaining the next contract document number from the sap system, and I'd like to use this document number with the function 'BAPI_CONTRACT_CREATEFROMDATA'. In other words I want to generate a contract with this function with the document number speficied by me. Is there any way to do that ?
Any help would be greatly appreciated. Thanks in advance.
‎2011 Mar 30 8:58 AM
If you are using INTERNAL number range for Contract document type, why you want to determine next number and pass it to BAPI ? The value passed to BAPI parameter SALESDOCUMENTIN will have effect only if the document type number range is EXTERNAL other wise number will be determined by BAPI.
‎2011 Mar 30 8:58 AM
If you are using INTERNAL number range for Contract document type, why you want to determine next number and pass it to BAPI ? The value passed to BAPI parameter SALESDOCUMENTIN will have effect only if the document type number range is EXTERNAL other wise number will be determined by BAPI.
‎2011 Mar 30 9:17 AM
Thank you for the quick answer, Vinod
I am trying to generate an ADRNR number with the function 'ADDR_NUMBER_GET', to populate the ADRC table with some data for the partner adresses.
This function uses the address_reference line where I need to update the APPL_KEY with sy-mandt + VBELN (concatenated). Well, the function successfully generates a document number, let's say 0040000333, but then the BAPI generates the next one, 0040000334.
If I uncomment SALESDOCUMENTIN and set it with the number given by the NUMBER_GET_NEXT FUNCTION, I get an error in the return table, wich tells me to use the external number range (in my case between 0045000000 and 0049999999).
Here's what I do:
call function 'NUMBER_GET_NEXT'
exporting
nr_range_nr = '09'
object = 'RV_BELEG'
quantity = '1'
" SUBOBJECT = 'AMBI'
TOYEAR = '0000'
IGNORE_BUFFER = ' '
importing
number = l_vbeln
QUANTITY =
RETURNCODE =
exceptions
interval_not_found = 1
number_range_not_intern = 2
object_not_found = 3
quantity_is_0 = 4
quantity_is_not_1 = 5
interval_overflow = 6
buffer_overflow = 7
others = 8
.
if sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
concatenate sy-mandt l_vbeln into wa_ref-appl_key.
move: 'VBUK' to wa_ref-appl_table,
'VBELN' to wa_ref-appl_field,
'SD01' to wa_ref-addr_group.
call function 'ADDR_NUMBER_GET'
exporting
address_handle = 'AG $00000'
address_reference = wa_ref
personal_address = ' '
NUMBERRANGE_NUMBER = '01'
E071K_WA =
GENERATE_TRANSPORT_ENTRIES =
OWNER = 'X'
TABLE_NAME =
FIELD_NAME =
OBJKEY =
importing
address_number = l_adrnr
RETURNCODE_NUMBERRANGE =
TABLES
E071K_TAB =
EXCEPTIONS
ADDRESS_HANDLE_NOT_EXIST = 1
INTERNAL_ERROR = 2
PARAMETER_ERROR = 3
OTHERS = 4
.
call function 'BAPI_CONTRACT_CREATEFROMDATA'
exporting
salesdocumentin = l_vbeln
contract_header_in = wa_bapihead
contract_header_inx = wa_bapiheadx
SENDER =
BINARY_RELATIONSHIPTYPE = ' '
INT_NUMBER_ASSIGNMENT = ' '
behave_when_error = 'P'
LOGIC_SWITCH =
testrun = 'X'
convert = 'X'
importing
salesdocument = l_sapdoc
tables
return = it_return
contract_items_in = it_bapiitem
contract_items_inx = it_bapiitemx
contract_partners = it_bapipartn
contract_conditions_in = it_bapicond
contract_conditions_inx = it_bapicondx
CONTRACT_CFGS_REF =
CONTRACT_CFGS_INST =
CONTRACT_CFGS_PART_OF =
CONTRACT_CFGS_VALUE =
CONTRACT_CFGS_BLOB =
CONTRACT_CFGS_VK =
CONTRACT_CFGS_REFINST =
contract_data_in = it_ctr_in
contract_data_inx = it_ctr_inx
CONTRACT_TEXT =
CONTRACT_KEYS =
" extensionin = it_extension
partneraddresses = it_bapiaddr
.
Edited by: adrian_marchis on Mar 30, 2011 10:27 AM
‎2011 Mar 30 2:20 PM
Check the Number range type (EXTERNAL/INERNAL) for the document type (Transaction VOV8). If the number range is defined as external (most probable in your case), you need to not generate the number using NUMBER_GET_NEXT. Instead of that you should pass the document number manually (within the range mentioned in number range) to the BAPI and the same can be used for function module ADDR_NUMBER_GET.
‎2011 Mar 30 2:57 PM
It seems that the function ADDR_NUMBER_GET works even without providing the document number in the appl_key concatenation (sy-mandt is sufficient), do the NUMBER_GET_NEXT function is not necesarry anymore. So the contract numbers are consecutive now.
Thank you for the ideeas.
concatenate sy-mandt l_vbeln into wa_refwa_ref-appl_key.
move: 'VBUK' to wa_ref-appl_table,
'VBELN' to wa_ref-appl_field,
'SD01' to wa_ref-addr_group.
call function 'ADDR_NUMBER_GET'
exporting
address_handle = 'AG $00000'
address_reference = wa_ref
personal_address = ' '
NUMBERRANGE_NUMBER = '01'
E071K_WA =
GENERATE_TRANSPORT_ENTRIES =
OWNER = 'X'
TABLE_NAME =
FIELD_NAME =
OBJKEY =
importing
address_number = l_adrnr
RETURNCODE_NUMBERRANGE =
TABLES
E071K_TAB =
EXCEPTIONS
ADDRESS_HANDLE_NOT_EXIST = 1
INTERNAL_ERROR = 2
PARAMETER_ERROR = 3
OTHERS = 4
.