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 Looping technique

former_member214084
Participant
0 Likes
3,507

Hi,

I want to calculate margin percentage based on line item wise & subtotal wise for a billing doc/sales doc.

I have already accomplish line item wise & working fine.  Problem occurs when I want it to be print subtotal wise.

I have applied logic to calculate subtotals but loop is not working properly though not getting any errors but not getting desired output ,instead I am getting same output in as getting in percentage line item wise but ideally figure should be different in % if we are calculating it line item wise & subtotal wise.

1 ACCEPTED SOLUTION
Read only

former_member214084
Participant
0 Likes
3,400

Hi suruchi,

Please click on code image it would be clear.

Instead of calculating lv_totamt & lv_maramt for all line items it calculates percentage & modifying table for all line items .. I want it to be be done per billing document. so that I can get percentage based on totalamt (netwr) & margin amt ..

Hi,

I want to calculate margin percentage based on line item wise & subtotal wise for a billing doc/sales doc.

I have already accomplish line item wise & working fine.  Problem occurs when I want it to be print subtotal wise.

I have applied logic to calculate subtotals but loop is not working properly though not getting any errors but not getting desired output ,instead I am getting same output in as getting in percentage line item wise but ideally figure should be different in % if we are calculating it line item wise & subtotal wise.

16 REPLIES 16
Read only

Former Member
0 Likes
3,400

can u share the code..

here it it unclear... let me understand the code where u r doing subtotals...

Read only

former_member214084
Participant
0 Likes
3,400

Read only

former_member214084
Participant
0 Likes
3,401

Hi suruchi,

Please click on code image it would be clear.

Instead of calculating lv_totamt & lv_maramt for all line items it calculates percentage & modifying table for all line items .. I want it to be be done per billing document. so that I can get percentage based on totalamt (netwr) & margin amt ..

Read only

0 Likes
3,400

Hi Drashti,

Both Header and Item table points same values here. But it should not be like that. Delete the duplicate values in header table and then please change the code as shown below.


"Sort the Header Table

SORT IT_DISPLAY BY VBELN.

"Delete the duplicate value

DELETE ADJACENT DUPLICATES IT_DISPLAY COMPARING VBELN.

LOOP AT IT_DISPLAY INTO WA_DISPLAY.

LOOP AT IT_TMP INTO WA_TMP.

"Use WA_TMP instead of WA_DISPLAY

LV_TOTAMT  = LV_TOTAMT + WA_TMP-NETWR.    

"Use WA_TMP instead of WA_DISPLAY

LV_MARAMT = LV_MARAMT+ WA_TMP-MRGAMT.  

---

---

ENDLOOP.

ENDLOOP.

Regards

Rajkumar Narasimman

Read only

0 Likes
3,400

Hi rajkumar,

I am getting my value in column  margin%subtotals  , Now end user doesn't want to see duplicate records ..... can I print that percentage value just once per billing document and keep rest cells blank ???

Read only

0 Likes
3,400

Hi Drashti,

You  can get the ouput using AT NEW  Statement

Make vbeln as the first field in it_display.

sort it_display by vbeln.

loop at it_display.

at new of vbeln.

flag = 'X'.

endat.

if flag is not initial.

modify it_display from wa_display transporting mrgpctt.

endif.

clear flag.

endloop.

margin%subtotals will be modified at the starting of vbeln.


Regards,

Venkat.

Read only

0 Likes
3,400

Hi Venkat,

Thank you for help. That way it is working but rest cells are showing 0,00  Is it possible to make that blank ?

Read only

0 Likes
3,400

Hello Drashti,

Set No_out = 'X in field catalogue definition for that field to show 0.0 as space.

Thanks

Read only

0 Likes
3,400

Hi drashti,

if you are using alv,

  wa_fcat-no_zero       = 'X'.

for classical write: / per no-zero .

Regards,

Venkat.

Read only

0 Likes
3,400

Hi all,

I am using reuse alv grid display & need to print % sign along with value in both percentage columns.

I am using edit_mask but it is just displaying sign & no values... do I need to call a function or something like that or change to  lvc_fcat_merge  ??

Read only

0 Likes
3,400

Hi,

     You May use Underscore for any Character and a period for decimal point like

     wa_fcat-EDIT_MASK = '__.__%.

     -----------------------

     clear wa_fcat.

Regards'

Read only

0 Likes
3,400

Hi,

I already tried that but values are not printing proper ..

EX : If actual percentage to be printed is 4.4%

with edit_mask option it is showing  44.0%  ( because of '__.__%' )

How to resolve that , I have kept my percentage field of type P decimal 2.

Read only

0 Likes
3,400

Hi Drashti,

if you never find any possibility, try this code.

Decalred one variable concatenate with Percentage symbol.

TYPE-POOLs: slis.

DATA: BEGIN of itab OCCURS 0,
       lv_type   TYPE  string,
       END OF itab.

data: lv_type   TYPE  string,
       it_fcat   TYPE slis_t_fieldcat_alv,
       wa_fcat   TYPE slis_fieldcat_alv.

START-OF-SELECTION.

CONCATENATE '12.0' '%' INTO itab-lv_type.
APPEND itab.

wa_fcat-fieldname = 'LV_TYPE'.
wa_fcat-seltext_m = '%'.
APPEND wa_fcat to it_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM                = sy-repid
    IT_FIELDCAT                       = it_fcat
   TABLES
     T_OUTTAB                          = itab[]
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2



Regards,

Venkat.
           .

Read only

0 Likes
3,400

hi Venkat,

This code throws me error

concatenate wa_display-mrgpctt '%' into wa_display-lv_per.

As  mrgpctt field is of type P decimal 2 and lv_per is of type string.

Read only

0 Likes
3,400

Hi Drashti,

Know Check,

if wa_display-mrgpctt is not initial.

move wa_display-mrgpctt to wa_display-lv_per.

concatenate wa_display-lv_per '%'  into wa_display-lv_per.

endif.

Regards,

Venkat.

Read only

0 Likes
3,400

Hi Drasthi,

Sample code,

REPORT  ZPRODUCT.

TYPE-POOLs: slis.

data: lv_p TYPE p DECIMALS 2,
       it_fcat TYPE slis_t_fieldcat_alv,
       wa_fcat TYPE slis_fieldcat_alv.

data: BEGIN OF itab OCCURS 0,
       lv_per TYPE string,
       END OF itab.


START-OF-SELECTION.
lv_p = '12.0'.

if lv_p is not initial.
MOVE lv_p to itab-lv_per.
CONCATENATE itab-lv_per '%' INTO itab-lv_per.
APPEND itab.

endif.

wa_fcat-fieldname = 'LV_PER'.
APPEND wa_fcat to it_fcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  EXPORTING
    I_CALLBACK_PROGRAM                = sy-repid
    IT_FIELDCAT                       = it_fcat
   TABLES
     T_OUTTAB                          = itab[]
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2




Regards,

Venkat.