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: 

having same name aginst different document no , I want total amount

Former Member
0 Kudos
382

hi ababer's ,

I have a query , at output ,  having same name aginst different document no   , I want total amount .

for eg. having doc no 1000 and 1001 ( which is not to be print in o/p )

     

      name                  amount  

        xyz                     2000 

        xyz                     4000

(name and amount which is to be print in output ).

     final output should be,

    name                   amount

     xyz                      6000

please help me .

Regards

Navin .

13 REPLIES 13

Former Member
0 Kudos
202

Hi Navin,

If these Data sre stored in an Internal Table

You can use collect statement in internal table

Regards,

Pratheek

Former Member
0 Kudos
202

Hi Navin,

Suppose your internal table is of structure, It_tab1

Name Doc NumberField XField Y...Amount

Then you need to,

1) Sort the table by Name.

2) Loop at the Internal table into work area.

3)Move the contents of the work area to a temporay work area  and add the values for same name.

4) Use Control Break statement in loop like At new, At end, etc. i.e.

Code snippet,

sort lt_tab1 by name.

Loop at lt_tab1 into ls_tab1.

ls_tab_temp = ls_tab1.

ls_tab_output-amount = ls_tab_temp-amount + ls_tab_output-amount.

*-- <move other fields from ls_tab_temp to ls_tab_output>

at end of name,

append ls_tab_output to lt_tab_output.

clear : ls_tab_output.

endat.

clear : ls_tab_temp, ls_tab1.

endloop.

Final Output will be in IT_TAB_OUTPUT.

Reply if anything is not clear.

regards,

Ankit.

Former Member
0 Kudos
202

Hi Navin,

Use the collect statement as suggested by Pratheek K V.

Create 2 internal tables itab1 as source and itab2 as result table which has collected data.

itab1, itab2 and wa - all have the same structure.

loop at itab1 into wa.

     collect wa into itab2.

endloop.

Regards,

Sachin

0 Kudos
202

hi abaper's ,

I want output using doc no having payment  method = ' T ' . I am using BSEG table for Doc no and through Lifnr of Bseg I am using LFB1 table for payment method ( lifnr is the common field in both th table ) .

( e.g. doc = 1000 and payment method = 'T' .) then output should  display.

otherwise output should not be display.  what should I do. pls help me

Regards ,

Navin Mahendra

0 Kudos
202

Hi Navin,

I am not familiar with the module and table you are asking about.

But what I got from browsing more on tables is that these are Finance related tables.

Here Lifnr is a vendor. So assuming that it's linking to LFB1 table containing payment related information of a particular vendor.

>> Once you get the document number Use "select single" statement on BSEG table to get the "Lifnr" field value.

>> Then, use the retrieved Lifnr field value in "select single" statement on LFB1 again to check if particular vendor has payment method as ' T ' using where condition.

>> If the statement returns data into workarea. Then, payment method for the particular vendour in 'T' else it does not have a particular payment method. If workarea is initial, you can avoid displaying and respond with the relevant error message or do as per your requirement.

Note: Syntaxt of select single "SELECT single * into workarea from DBtable where <Condition>"

Regards,

Sachin

0 Kudos
202

Hi Navin,

Paymet Method is directly present in BSEG as ZLSCH. Please see if you can use the same.

regards,

Ankit.

0 Kudos
202

Hi Sachin ,

I am also using Wrbtr for Bseg-Lifnr having Bseg-Koart = 'S'. against the Bseg-2402153 having Payment mthd = 'T' . matching with  LFB1-LIFNR O/p is coming . But doc no = 2402157 having no payment mthd but still o/p is coming .

But as there is no lifnr aginst Koart = 'S' . I am unable to filter or fullfill the condition for ' T'.

Simply what I want , to filter paymnt mthd = 'T' against the document no .

If it ' T ' document no. will work  otherwise its fails.

Please tell me which table and field , I want to use .

Thanks ,

Regards,

Navin Mahendra

0 Kudos
202

Hi Ankit ,

But  Zlsch is empty aginst all document no.

Navin Mahendra

0 Kudos
202

Hi Navin

If payment method is empty in BSEG it means by config. it is not getting filled or the business does not want to maintain it here. Anyways then go by your logic of getting the values from LFB1.

Now you should be having a single internal table with document numbers and their amounts( i had explained the logic above) . In the same table have 2 more fields Vendor Number and Payment Method. Now use if condition and filter the data.

Please post code snippet if you need more clarity.

Thanks,

Ankit.

Former Member
0 Kudos
202

Hi Navin,

Use COLLECT statement as suggest by Sachin and Pratheek. Just you need to loop your internal table and collect the amount into another internal table.

Former Member
0 Kudos
202

Hi Navin,

Is this the structure of your table?or are there more fields? If this is the structure simply use collect.

Please specify complete structure

Regards,

Pratheek

Former Member
0 Kudos
202

Hi Navin,

If there are more fields then COLLECT statement wont work properly. So in this case you have to calculate sum manually as below:

itab is your internal table which has all the records and wa is work area for internal table itab.

TYPES:

BEGIN OF ty_amount,

name TYPE string,

amount TYPE i,

END OF ty_amount.

DATA:

lt_total_amount TYPE TABLE OF ty_amount,

ls_total_amount TYPE ty_amount,

total TYPE i.

SORT itab BY name.

LOOP AT itab INTO wa.

  ADD wa-amount TO total.

  AT END OF name.

    ls_total_amount-name = wa-name.

    ls_total_amount-amount = total.

    APPEND ls_total_amount TO lt_total_amount.

    CLEAR total.

  ENDAT.

ENDLOOP.

0 Kudos
202

Hi Navin,

If you fill an internal table as mentioned by Satish, you could also use keyword SUM in combination with the positional event AT END OF.

SUM adds all type P and I fields into the concerning field for that level-break (indicated at AT END OF).

TYPES:

BEGIN OF ty_amount,

name TYPE string,

amount TYPE i,

END OF ty_amount.

DATA:

lt_total_amount TYPE TABLE OF ty_amount,

ls_total_amount TYPE ty_amount,

total TYPE i.

SORT itab BY name.

LOOP AT itab INTO wa.

 

  AT END OF name.

    SUM.

    ls_total_amount-name = wa-name.

    ls_total_amount-amount =ls_total_amount-amount.

    APPEND ls_total_amount TO lt_total_amount.

  ENDAT.

ENDLOOP.

Wendy