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

IF and Elseif statement in validation

sridhar_muthekepalli3
Active Contributor
0 Likes
2,731

Dear Friends,

Does IF and Elseif statement work in validation?

The requirement is if first line item contains business area "ABC", the second line item should also contain "ABC".

If the document type is ZA or ZB, first line item should be 'ABC, second line item can be DEF.

Please suggest.

All the help will be greatly appreciated.

Regards

Sridhar

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,898

hi Sridahr,

According to me If elseif endif block will definetly work in validation block...

you can try like this


if wa_firstlineitem EQ 'ABC'.
wa_secondlineitem = 'ABC'.
elseif wa_document_type EQ 'ZA' or wa_document_type EQ 'ZB'.
wa_firstlineitem = 'ABC'.
endif."as second line item can be anything so no need to write its value in wa.
append wa to itab.

hope this will help you,can u please be move clear whats your exact requirement is so that i can help you out in a better way.

Thanks

Tanmaya

Dear Friends,

Does IF and Elseif statement work in validation?

The requirement is if first line item contains business area "ABC", the second line item should also contain "ABC".

If the document type is ZA or ZB, first line item should be 'ABC, second line item can be DEF.

Please suggest.

All the help will be greatly appreciated.

Regards

Sridhar

10 REPLIES 10
Read only

kesavadas_thekkillath
Active Contributor
0 Likes
1,898

are you having the dta in internal table ?

If endif will do

Read only

0 Likes
1,898

Hi Keshav ,

Data is present in internal table.

You have given very little information .

Please explain how to use if and end if in valiation.

I got very little information while searching in google.

All the help will be greatly appreciated.

Regards

Sridhar

Read only

0 Likes
1,898

Hi,

Instead of google, Clicking F1 on the word IF in your ABAP code editor would give you more information. Below is the basic syntax.

IF (source variable) <Logical expression> (Target variable/constant/space).

ELSEIF.....

ENDIF.

Thanks,

Vinod.

Read only

Former Member
0 Likes
1,898

Hi,

>

> The requirement is if first line item contains business area "ABC", the second line item should also contain "ABC".

loop it.

if sy-tabix ne 1.

if local variable = 'ABC' and it-busnessarea = 'ABC'.

*If condition passed then it means second item also contians ABC.

endif.

endif.

>If the document type is ZA or ZB, first line item should be 'ABC, second line item can be DEF.

**Consediring IT has item no as well

if it-itmno = 1 and ( it-docno = 'ZA' or it-docno = 'ZB' ) and it-busnessarea = 'ABC'.

*If condition passed then it means first item also contians ABC.

endif.

*Moving First item to local variable inorder to chec for next time.

move it-busnessarea to local variable.

endloop.

Can you provide me the strucure of Internal table. It will be easy to explian.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,898

Hello Sridhar,

Are you talking about FI Validations ?

BR,

Suhas

Read only

0 Likes
1,898

Hi Suhas,

I am talking about FI Validations .

Regards

Sridhar

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,898

Hello Sridhar,

You should mention this in your subject line, else you will get crappy responses

Anyways back to your question, what makes you think you cannot use IF ... ELESIF condition in your validation.

For this you have to create an exit in your validation & put your ABAP code there.

BR,

Suhas

Read only

Former Member
0 Likes
1,898

You can do like this i give simple logic in simple english u convert into abap syntex


loop at itab where business are = 'abc'

FIND FIRST OCCURRENCES  document type = za or document type = zb

if sy-subtc = 0.
continue.
else.
replace business are = 'ABC'  into itab-business are  with 'DEF'
  MODIFY itab INDEX sy-tabix .
endif.

Edited by: kk.adhvaryu on Mar 11, 2010 6:54 AM

Read only

Former Member
0 Likes
1,899

hi Sridahr,

According to me If elseif endif block will definetly work in validation block...

you can try like this


if wa_firstlineitem EQ 'ABC'.
wa_secondlineitem = 'ABC'.
elseif wa_document_type EQ 'ZA' or wa_document_type EQ 'ZB'.
wa_firstlineitem = 'ABC'.
endif."as second line item can be anything so no need to write its value in wa.
append wa to itab.

hope this will help you,can u please be move clear whats your exact requirement is so that i can help you out in a better way.

Thanks

Tanmaya

Read only

sridhar_muthekepalli3
Active Contributor
0 Likes
1,898

thanks for the answers