cancel
Showing results for 
Search instead for 
Did you mean: 

How to use IF ELSE statement in Script

Former Member
0 Kudos

Hi,

I am trying to write a If condition in script as below

/: IF &QALS-ANZGEB& = 1

S1 Sample Size,,1

/: ELSEIF &QALS-ANZGEB& > 1 AND &QALS-ANZGEB& <= 15

S1 Sample Size,,2

/:ELSE

S1 Sample size,,3

ENDIF

But only the statement after ELSE is executed ..Can you please tell me whats the error in the above.

I tired using '1' but still sample size 3 is printed.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Please try and check in debug mode.

Go to SE71, give your script name. In the menu options 'Utilities', press 'Activate debugger'. Execute.

It will start executing in debugging mode. Execute step by step by F5 and reach your statement. Check the value in the field &QALS-ANZGEB& .

Former Member
0 Kudos

Hi,

I tired debugging . it shows the correct value only for QALS-ANZGEB.

Can any one tell me the how to write the program step by step and call it in script..

Former Member
0 Kudos

Hi,

use proper syntax while comparing the values.The constants should be in single quotes!!

/: IF &QALS-ANZGEB& = '1'

S1 Sample Size,,1

/: ELSEIF &QALS-ANZGEB& > '1' AND &QALS-ANZGEB& <= '15'

S1 Sample Size,,2

/:ELSE

S1 Sample size,,3

ENDIF

Former Member
0 Kudos

Hi,

I tired using single quotes and it didnt work.

Former Member
0 Kudos

Hi,

ANZGEB is a quantityy field with 3 decimal spaces.

In debugging check , you should get 1.000 instead of 1 in its value.I amnot sure if this would work or not, but you can try comparing it to 1.000 and 15.000 and then see if work.or assign this fields value to a temp variable and compare that.

It should work.

And ye syour comparison constants are in quotes always. so its '1.000'.

Edited by: sap_wiz on May 26, 2011 2:13 PM

Former Member
0 Kudos

Hi,

Here below is very useful link related to writing a perform routine.

[http://wiki.sdn.sap.com/wiki/display/Snippets/Callingasub-routineinSAP+scripts]

Pls learn, understand and implement...

Close this thread if your purpose is resolved...

Rgs,

Lokesh.

Former Member
0 Kudos

yes i know its a qty field with 3 decimals...

I have already tired it with 1.000 and also have tired using &QALS-ANZGB(CE.3) but it didnt work....

can you tell me how to write the program for this and then call it in the script..this will help me..

Former Member
0 Kudos

Hi,

thats strange, Lokes has shared a link with you,You can use that,

In brief , you nee dto create a subroutine pool through se38. In it create a subroutine.

And call it from teh script. You will pass ANZGEB as input parameter to it. And you can get the text as output.

Please refer the lokesh's link for details.

Former Member
0 Kudos

Thanks Lokesh and all.

Problem solved ,.

FORM GET_PACKSIZE TABLES in_tab STRUCTURE itcsy out_tab STRUCTURE itcsy.

LOOP AT in_tab INTO wa_tin.

IF sy-tabix = 1.

WS_ANZGEB = wa_tin-value.

ENDIF.

ENDLOOP.

IF WS_ANZGEB = 0.

ws_sample = 0.

ELSEIF WS_ANZGEB = 1.

ws_sample = 1.

ELSEIF WS_ANZGEB > 1 AND WS_ANZGEB <= 15.

ws_sample = 2.

ELSEIF WS_ANZGEB > 15 AND WS_ANZGEB <= 25.

ws_sample = 3.

ELSEIF WS_ANZGEB > 25 AND WS_ANZGEB <= 90.

ws_sample = 5.

ELSEIF WS_ANZGEB > 90 AND WS_ANZGEB <= 150.

ws_sample = 8.

ELSE.

ws_sample = 15.

ENDIF.

out_tab-name = 'SAMPLE'.

out_tab-value = WS_SAMPLE.

MODIFY out_tab INDEX 1 TRANSPORTING value.

ENDFORM.

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

I need to create a dop down option status in that need to fill the value

Status = Status should have dropdown 3 drop down values like, Trip Completed/Open (3 and 0), Trip Completed and To be settled (3 and1), Trip Approved/To be settled (4and1) and Trip Approved/Settled (4and 2).



If we select any value and execute the report Trip details need to be identified & fetched from the table PTRV_CHANGE from Fields (ANTRG and ABREC).


i have created the drop down option but not getting how to fetch the values.Please help it out.




  CASE so_stat.

    WHEN 'A'.

      READ TABLE lt_ptrv_change INTO ls_ptrv_change WITH KEY pernr = ls_ptrv_head-pernr

                                                             reinr = ls_ptrv_srec-pernr.

      IF sy-subrc = 0.

     

      ENDIF.

  ENDCASE.



DATA : v_id TYPE  vrm_id,

            values TYPE  vrm_values.

  DATA : BEGIN OF vrm_value,

           key(40) TYPE c,

           text(80) TYPE c,

         END OF vrm_value.

  vrm_value-key = 'A'.

  vrm_value-text = 'Trip Completed/Open '.

  APPEND vrm_value TO values.

  vrm_value-key = 'B'.

  vrm_value-text = 'Trip Completed/To be settled'.

  APPEND vrm_value TO values.

  v_id = 'SO_STAT'.

  vrm_value-key = 'C'.

  vrm_value-text = 'Trip Approved/To be settled '.

  APPEND vrm_value TO values.

  vrm_value-key = 'D'.

  vrm_value-text = 'Trip Approved/Settled '.

  APPEND vrm_value TO values.

  v_id = 'SO_STAT'.

  CALL FUNCTION 'VRM_SET_VALUES'

    EXPORTING

      id              = v_id

      values          = values[]

    EXCEPTIONS

      id_illegal_name = 1

      OTHERS          = 2.

  IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

  ENDIF.

brad_bohn
Active Contributor
0 Kudos

I tired using '1' but still sample size 3 is printed.

That's because the comparison is still not correct. You must use the character representation of the quantity value. Adjust your quantity comparisons to literals (in the correct format) and it will work...

As Lokesh suggested, if you have a custom driver program, it is always easier to use the internal representation in the code for comparison and set your value accordingly...

Former Member
0 Kudos

Hi,

You can do this calculation in your driver program itself.

In the program code like this:

IF QALS-ANZGEB = 1 
      w_text = 1 
ELSEIF ( QALS-ANZGEB& > 1 AND QALS-ANZGEB <= 15 ) 
      w_text = 2. 
ELSE 
       w_text = 3 
ENDIF. 

Now call and print your text in script: Like below: 

HT  &w_text&

It would be much easier way.

Regards,

Lokesh.

Edited by: Lokesh Tarey on May 24, 2011 1:16 PM

Former Member
0 Kudos

Hi,

Did you debug and check?