Application Development and Automation 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: 
Read only

ABAP pgm using append, sum, modify

Former Member
0 Likes
640

I am new to ABAP programming. Can somebody please help me out with the following program or give me some hints as to how to proceed?

1. ABAP inputs: The pgm will have following parameters:

P_ITEM - input string of 20 characters (select options)

P_QTY - input number (select options)

P_RATE - input number with 2 decimal points (select options)

2. Main processing logic:

1. Accept 5 items each with qty and rate.

2. store in internal table.

3. calculate their price.

4. sort on price in ascending order.

5. display o/p as per section 3.

3. Output format:

ITEM QTY RATE PRICE

TOTAL

Hints: For this ABAP make use of APPEND, SUM, MODIFY

Thank you.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
604

This can be coded, but it does make much sense. There is no "tie" between the selection-screen fields. If you are assuming that the first value in P_ITEM corresponds to the first value in P_QTY and P_RATE, then you can do it, but this is not really a good way of coding. Here is a sample anyway.

Add values to all three select-options and hit execute.




report zrich_0004
       no standard page heading.


data: begin of itab occurs 0,
      item(20) type c,
      qty type i,
      rate type p decimals 2,
      price type p decimals 2,
      end of itab.


select-options: s_item for itab-item,
                s_qty  for itab-qty,
                s_rate for itab-rate.

start-of-selection.


  clear itab. refresh itab.
  loop at s_item.
    clear itab.
    itab-item = s_item-low.
    read table s_qty index sy-tabix.
    if sy-subrc = 0.
      itab-qty = s_qty-low.
    endif.
    read table s_rate index sy-tabix.
    if sy-subrc = 0.
      itab-rate = s_rate-low.
    endif.
    itab-price = itab-qty * itab-rate.
    append itab.
  endloop.


  sort itab ascending by price.

  loop at itab.

    write:/ itab-item, itab-qty, itab-rate, itab-price.
  endloop.

Welcome to SDN! Please remember to award points for helpful answers and mark your posts as solved when solved completely.

Regards,

Rich Heilman

4 REPLIES 4
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
605

This can be coded, but it does make much sense. There is no "tie" between the selection-screen fields. If you are assuming that the first value in P_ITEM corresponds to the first value in P_QTY and P_RATE, then you can do it, but this is not really a good way of coding. Here is a sample anyway.

Add values to all three select-options and hit execute.




report zrich_0004
       no standard page heading.


data: begin of itab occurs 0,
      item(20) type c,
      qty type i,
      rate type p decimals 2,
      price type p decimals 2,
      end of itab.


select-options: s_item for itab-item,
                s_qty  for itab-qty,
                s_rate for itab-rate.

start-of-selection.


  clear itab. refresh itab.
  loop at s_item.
    clear itab.
    itab-item = s_item-low.
    read table s_qty index sy-tabix.
    if sy-subrc = 0.
      itab-qty = s_qty-low.
    endif.
    read table s_rate index sy-tabix.
    if sy-subrc = 0.
      itab-rate = s_rate-low.
    endif.
    itab-price = itab-qty * itab-rate.
    append itab.
  endloop.


  sort itab ascending by price.

  loop at itab.

    write:/ itab-item, itab-qty, itab-rate, itab-price.
  endloop.

Welcome to SDN! Please remember to award points for helpful answers and mark your posts as solved when solved completely.

Regards,

Rich Heilman

Read only

0 Likes
604

riding piggy back on Rich's code...


report zrich_0004       no standard page heading.
data: begin of itab occurs 0,
item(20) type c,
 qty type i,
 rate type p decimals 2,
 amount type p decimals 2,
 end of itab
 .
select-options: s_item for itab-item,
s_qty  for itab-qty,
s_rate for itab-rate.

start-of-selection.
  clear itab. refresh itab.
  loop at s_item.
    clear itab.
    itab-item = s_item-low.
    read table s_qty index sy-tabix.
    if sy-subrc = 0.
      itab-qty = s_qty-low.
    endif.
    read table s_rate index sy-tabix.
    if sy-subrc = 0.
      itab-rate = s_rate-low.
    endif.
    itab-amount = itab-qty * itab-rate.
    append itab.
  endloop.
  loop at itab.
    write:/ itab-item, itab-qty, itab-rate,itab-amount.
    at last.
      sum.
      write:/ 'Total:', itab-amount.
    endat.
  endloop.

Regards,

Suresh Datti

P.S. I din't see any need to use MODIFY

Read only

0 Likes
604

Oh yes, I missed the "Total". Oops. Thanks Suresh. I didn't see a use for MODIFY as well.

Regards,

Rich Heilman

Read only

0 Likes
604

Thanks a lot for the code. That is working fine. Good job!