2013 May 02 5:26 AM
Following is my code to arrive customer code wise consolidated sales. Issue is - same customer is repeated in the following lines with individual sale value rather than in one line customer code and its sales. Please guide to proceed further.
LOOP at it_display.
READ TABLE it_display.
it_display-TOTAL = it_display-kwert1 + it_display-kwert2 + it_display-kwert3.
if It_display-fkart = 'F2'.
it_display-TOTAL1 = it_display-TOTAL.
MODIFY it_display.
endif.
ENDLOOP.
PERFORM add_fieldcat TABLES it_fieldcat.
PERFORM output.
*&---------------------------------------------------------------------*
*& Form add_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_FIELDCAT text
*----------------------------------------------------------------------*
FORM add_fieldcat TABLES p_it_fieldcat LIKE it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'KUNAG'.
wa_fieldcat-tabname = 'IT_DISPLAY'.
wa_fieldcat-outputlen = 10.
wa_fieldcat-seltext_l = 'CUSTOMER'.
APPEND wa_fieldcat TO p_it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'TOTAL1'.
wa_fieldcat-tabname = 'IT_DISPLAY'.
wa_fieldcat-outputlen = 10.
wa_fieldcat-seltext_l = 'Sale Value'.
APPEND wa_fieldcat TO p_it_fieldcat.
Following is my code to arrive customer code wise consolidated sales. Issue is - same customer is repeated in the following lines with individual sale value rather than in one line customer code and its sales. Please guide to proceed further.
LOOP at it_display.
READ TABLE it_display.
it_display-TOTAL = it_display-kwert1 + it_display-kwert2 + it_display-kwert3.
if It_display-fkart = 'F2'.
it_display-TOTAL1 = it_display-TOTAL.
MODIFY it_display.
endif.
ENDLOOP.
PERFORM add_fieldcat TABLES it_fieldcat.
PERFORM output.
*&---------------------------------------------------------------------*
*& Form add_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_FIELDCAT text
*----------------------------------------------------------------------*
FORM add_fieldcat TABLES p_it_fieldcat LIKE it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'KUNAG'.
wa_fieldcat-tabname = 'IT_DISPLAY'.
wa_fieldcat-outputlen = 10.
wa_fieldcat-seltext_l = 'CUSTOMER'.
APPEND wa_fieldcat TO p_it_fieldcat.
CLEAR wa_fieldcat.
wa_fieldcat-col_pos = 1.
wa_fieldcat-fieldname = 'TOTAL1'.
wa_fieldcat-tabname = 'IT_DISPLAY'.
wa_fieldcat-outputlen = 10.
wa_fieldcat-seltext_l = 'Sale Value'.
APPEND wa_fieldcat TO p_it_fieldcat.
2013 May 02 5:46 AM
Hi Pooja,
Still not clear about your requirement, but from the description you have given I think you need to get consolidated sales for that use control break statement to arrive.
Ex:
loop at it_display into ls_display.
at end of sales.
sum.
append ls_display to lt_final.
endat.
endloop.
2013 May 02 6:30 AM
Hi Pooja,
The issue u are facing is because of "Wrong" ALV filed catalogue. Please check the filed names are same as there are in the internal table.
From the above code I have doubt in below line.
"wa_fieldcat-fieldname = 'TOTAL1'."
Guess it should be "TOTAL" instead "TOTAL1' .
Let me know if it not solve your issue.
Thanks
CB
2013 May 02 7:27 AM
Hi Pooja,
Your requirement is not clear enough. Let me try putting my idea across and then you can comment.
I assume that your requirement is to get a consolidated sales output per customer. Your table IT_DISPLAY currently has all the customers and corresponding sales and you need customer wise total sales report.
I would suggest you to move the IT_DISPLAY into IT_TEMP table.
SORT IT_TEMP by KUNAG. DELETE adjacent duplicates from IT_TEMP comparing KUNAG.
This way you will have all the unique customers in IT_TEMP table.
Now loop at IT_TEMP table and inside that loop at IT_DISPLAY table comparing the KUNAGs. This way your inner loop will iterate on all the sales for that customer(KUNAG ). Add all these amounts in the second loop and append this record into third table IT_FINAL after the inner ENDloop but inside the outer ENDLOOP(ie, between both endloops). hence when your outer loop completes interating for all the customers, your inner loop will have populated the corresponding total sales data and then you append only one entry into IT_FINAL for each customer.
Revert if not clear or my understanding of your issue is wrong.
Regards,
Deepak
2013 May 02 10:14 AM
2013 May 02 10:26 AM
Hi Pooja,
what i want to say is:
IT_TEMP[] = IT_DISPLAY[].
SORT IT_TEMP by KUNAG.
DELETE adjacent duplicates from IT_TEMP comparing KUNAG.
*please clear the work areas properly' treat this code as psuedo code only'
Loop at IT_TEMP into WA_TEMP.
LOOP at IT_DISPLAY into WA_DISPLAY where KUNAG = WA_TEMP-KUNAG.
*write your logic for adding the amounts below as per your req.
if It_display-fkart = 'F2'.
wa_final-TOTAL = wa_final-TOTAL + ( it_display-kwert1 + it_display-kwert2 + it_display-kwert3 ).
wa_final-kunag = wa_dispaly-kunag.
ENDIF.
ENDLOOP. "IT_DISPLAY
append wa_final into it_final.
ENDLOOP. "IT_TEMP.
Reagrds,
Deepak.
2013 May 02 4:14 PM
One info to all. My it_display has vbeln,custcode, grndat, bill date,sales value.
should i need to move to another internal table and delete the entries except cust code and sales value.
2013 May 03 2:07 AM
Hi Pooja,
Not required. Please test with my code above, that should get you your expected result.
Please test and let me know if you find any issue.
Regards,
Deepak.
2013 May 03 3:55 AM
Hi Pooja,
Say for example you have
VBELN CUSTOMER GRNDAT BILLDATE SALESVALUE
1 XYZ 1/5/2013 1/5/2013 1000
2 XYZ 2/5/2013 2/5/2013 2000
3 XYZ 3/5/2013 3/5/2013 3000
4 ABC 4/5/2013 4/5/2013 8000
In order to get the final consolidated report in correspondance to the customer as
CUSTOMER SALESVALUE
XYZ 6000
ABC 8000
follow the post that i have given earlier.
Regards
AyyamPerumal
2013 May 02 9:24 AM
Hi Pooja,
Through my understanding on your requirement,
I think there is a problem in sorting the Internal table that you have before finding the consolidated report for finding the total sales for a customer.
Transfer the fields Customer and Sales Value to an internal table IT_EXAMPLE. (can also be done on the same Internal table that you have)
SORT IT_EXAMPLE BY CUSTOMER.
LOOP AT IT_EXAMPLE INTO WA_EXAMPLE.
AT END OF CUSTOMER.
SUM.
APPEND WA_EXAMPLE TO IT_CONSOLIDATEDOUTPUT.
ENDAT.
ENDLOOP.
In the IT_CONSOLIDATEDOUTPUT internal table, you will have the final result of One customer having the total sales for the customer.
Please revert back if i have misjudged your requirement.
Regards,
AyyamPerumal
2013 May 02 10:14 AM
LOOP at it_display.
READ TABLE it_display.
it_display-TOTAL = it_display-kwert1 + it_display-kwert2 + it_display-kwert3.
if It_display-fkart = 'F2'.
it_display-TOTAL1 = it_display-TOTAL.
MODIFY it_display.
endif.
ENDLOOP.
From your code I do not understand why you have used the internal table "IT_DISPLAY" in both loop and Read statement.
Here your read statement will read the first line of internal table always. Hence your output is coming for one customer. !
-Satya
2013 May 02 10:36 AM
You are right , 2nd line should be read as read table it_display3.
By my query is individual lines are repeated for sales eg
10044 - 30000
10044 - 40000
10044 - 20000
10044-10000
rather than 10044 - 100000 (sum of all the values above)
2013 May 02 10:44 AM
Hi Pooja,
Please try the codes mentioned by me above and let me know if u find further issues.
Regards
AyyamPerumal
2013 May 02 10:24 AM
The code should be:
FIELD-SYMBOLS: <ls_display> TYPE <your_structure_type>.
LOOP AT it_display ASSIGNING <ls_dipslay>.
<ls_dipslay>-total = <ls_dipslay>-kwert1 + <ls_dipslay>-kwert2 + <ls_dipslay>-kwert3.
IF <ls_dipslay>-fkart = 'F2'.
<ls_dipslay>-total1 = <ls_dipslay>-total.
ENDIF.
ENDLOOP.
Hope it helps. Cheers!
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |