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

Logic in code while using if condition.

SujeetMishra
Active Contributor
0 Likes
622

Dear All,

I have below field :

v_lar01 = t_plpo-lar01. "Activity Type MSTD or FSTD

v_vge01 = t_plpo-vge01. " Unit of measure for the standard value MIN (minutes) or S (second)

v_vgw01 = t_plpo-vgw01. " Standard value (Numeric value for minutes or second)

v_lar02 = t_plpo-lar02.

v_vge02 = t_plpo-vge02.

v_vgw02 = t_plpo-vgw02.

v_lar03 = t_plpo-lar03.

v_vge03 = t_plpo-vge03.

v_vgw03 = t_plpo-vgw03.

v_lar04 = t_plpo-lar04.

v_vge04 = t_plpo-vge04.

v_vgw04 = t_plpo-vgw04.

v_lar05 = t_plpo-lar05.

v_vge05 = t_plpo-vge05.

v_vgw05 = t_plpo-vgw05.

v_lar06 = t_plpo-lar06.

v_vge06 = t_plpo-vge06.

v_vgw06 = t_plpo-vgw06.

Now i want to check :

If any of v_lar01,02,03,03,04,05,06 is MSTD and v_vge01,02,03,04,05,06 is MIN then

final v_vgw should be combination of all hours.

same like for other..

so how can i write code to validate this.

eg:

IF v_lar01 = 'MSTD' and v_vge01 = 'MIN'.

then v_vgw01 = 35 " in minute

endif.

IF v_lar01 = 'MSTD' and v_vge01 = 'S'.

v_vgw01 = 1000 "second

endif.

so finally i have to add both above duration in single variable in have to calculate finally in hours.

and so on for all fileds,

its so confusing. can be use CASE??? please guide me appropriate coding for this.

Thanks and regards,

Sujeet

5 REPLIES 5
Read only

Former Member
0 Likes
589

Hi,

use if statement inside loop....endloop.

like...

loop at t_plpo.

if t_plpo-lar01 = 'MSTD' and t_plpo-vge01 = 'MIN'.

add t_plpo-vgw to v_vgw.

endif.

regsrds,

sankar

Read only

Former Member
0 Likes
589

Declare an internal table with two fields lar and another field for seconds.

IF v_lar01 = 'MSTD' and v_vge01 = 'MIN'.

it_time-lar = lar1

it_time-seconds = t_plpo-vgw01 * 60 " minutes to seconds

else.

it_time-lar = lar1

it_time-seconds = t_plpo-vgw01 " second

endif.

append it_time.

IF v_lar02 = 'MSTD' and v_vge02= 'MIN'.

it_time-lar = lar2

it_time-seconds = t_plpo-vgw02 * 60 " minutes to seconds

else.

it_time-lar = lar2

it_time-seconds = t_plpo-vgw02 " seconds

endif.

append it_time.

and so on...at the end sum it_time-seconds and do the calculate to get hrs n minutes from seconds

Mathews

Read only

Former Member
0 Likes
589

Hi,,

It can be done very easily in case and end case compared to If statement....

Case 'v_lar'

when '01' ....

case 'vge'

when '01'....

Read only

Former Member
0 Likes
589

Hi,

You can do like this:

Loop at itab into wa.
   if wa-lar01 = 'MSTD'.
       if wa-vge01 = 'MIN'.
           g_vgw02 = g_vgw02 + ( wa-vgw02 * 60 ).  " convert it into seconds
       elseif wa-vge01 = 'S'.
            g_vgw02 = g_vgw02 + wa-vgw02. 
       endif.
  endif.
endloop.

* g_vgw02 will be in seconds which u can covert in Hours
g_vgw02_hrs = g_vgw02 / 3600.

Regards,

Neha

Read only

SujeetMishra
Active Contributor
0 Likes
589

Thanks all