2009 Jan 28 6:55 AM
Hi Experts,
I have a requirement where I have to programatically generate one idoc for 50 invoices.
The current program generates/creates one idoc for all the invoices.
The invoice range is entered on the selection-screen.
A situation may arise when I have, say, 103 invoices. So, first 2 idocs will have 50-50 invoices respectively. The 3rd idoc should have the remaining three invoices. I need to handle this situation in the code also.
What should be the code or logic to create 1idoc for 50 invoices.
Regards,
Sangeeta.
2009 Jan 28 9:04 AM
Hi,
i would store all invoicenumbers in one internal table (lt_invoices). Now loop over that lt_invoices and use a counter to count 50 invoices each paket.
if a paket is full (counter = 50) use your fm or logic to create ONE idoc for these 50 invoices. Clear the counter and go ahead.
I think this should work fine !
Regards,
Gordon
2009 Jan 28 9:56 AM
Hi Gordon,
Thanks for the reply.
The logic which you suggested will work fine if the invoice number is divisible by 50 and remainder is 0.
What happens when there is a remainder...i.e. say for example, I am having 104 invoices. 2idocs of 50 each will be created which will take care of the first 100 invoices.
What about the rest 4 invoices. How to handle those 4 remaining invoices.
Regards,
Sangeeta.
2009 Jan 28 10:03 AM
Hi Sangeeta,
Carrying along with the logic proposed by Gordon, it is very simple, if you consider 104 invoices, the first 50 - 50 invoices will create 2 idocs. And further to that any number of invoices will go and add up to the counter and you need to validate such as : if the counter is less than or equal to 50 -- Create an Idoc. And when the counter = 50, immediately clear after the idoc creation.
Please check the same and revert back in case of any issues on the same.
Regards,
-Syed.
2009 Jan 28 10:47 AM
Hi Syed,
Thanks for the reply.
If I take the logic:
if the counter is less than or equal to 50 -- Create an Idoc.
The above logic will generate an idoc for every line item in the internal table as sy-tabix will be less than 50 till it reaches 50. So, it will not handle the case of remaining idocs, say in the case of 104 idocs, it will not handle the 4 remaining invoices.
And when the counter = 50, immediately clear after the idoc creation: This statement only handles the case when the total invoice number is divisible by 50.
Please tell me how to handle the remaining invoices if the total number of invoices is not divisible by 50.
Regards,
Sangeeta.
2009 Jan 28 11:37 AM
Hi Sangeeta,
Yea you are absolutely right.
Do the following process:
data: lv_count1 type p decimals 2,
lv_counter type i,
lv_lines type i.
describe table itab lines lv_lines.
lv_count1 = lv_lines / 50.
lv_counter = lv_count1.
if lv_counter GT 0.
generate an idoc.
elseif lv_counter LT lv_count1.
lv_counter = lv_counter + 1.
do lv_counter times.
generate idoc.
enddo.
endif.
Pls check the same and revert back if any issues are there.
Regards,
-Syed.
Edited by: wahid hussain syed on Jan 28, 2009 12:37 PM
Edited by: wahid hussain syed on Jan 28, 2009 12:38 PM
2009 Jan 28 11:46 AM
Hi Syed,
I did not quite understand the logic as lv_count1 and lv_counter points to the same thing.
Kindly be more elaborative.
Regards,
Sangeeta.
2009 Jan 28 11:55 AM
Hi Sangeeta,
lv_count1 stores the values including the Decimals such as 2.08 or 3.10 after the calculation.
But when it comes to lv_counter when you map lv_count1 with lv_counter, lv_counter is going to take only the initial digit but not the complete value.
lv_counter stores all the rounded values such as 2.
So when you again compare the values against each other, definitely the lv_count1 should be higher, as it has the value after the decimals also.
If you have confusion or if you get error while mapping, you can declare the lv_counter as type P decimals 0.
Then it will take proper value and there will be no mapping issue.
Please check the same, if you still have confusion, pls revert back.
Regards,
-Syed.
2009 Jan 28 5:42 PM
Hi Sangeeta
Use below logic
suedo code logic :
Retrive Invoice Numbers in to internal table..use your own logic to get data into internal table.
Get invoice number count from internal table.
DO
if invoice count < 50
THEN generate the idoc using internal table invoice number.
Exit.
else.
Retrive the 50 invoice from internal table
generate the idoc.
Deleate the 50 invoice count from internal table.
Get count of invoice from internal table.
endif.
enddo
This will solve your issue
Ramesh
2009 Oct 01 7:12 AM