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

Char variable value check?

Former Member
0 Likes
574

Hi,

I have two variables of CHAR 2.

ie

var1 = 19

var2 = 3

I need to check

if var1 gt var2.

endif.

The above condition is failing ?

Thanks

Sa_r

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
545

If they must be character fields, then you must have leading zeros.

Regards,

RIch Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
546

If they must be character fields, then you must have leading zeros.

Regards,

RIch Heilman

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
545

Again, if these fields must be character, then you will need to have leading zeros in the fields in order to do the conditional statement, otherwise you can make them numeric fields or integar fields and do the condition. Here is an example of what you can do if these fields must remain as character.



report zrich_0001 .

data: var1(2) type c value '19'.
data: var2(2) type c value '3'.
data: n(2) type n.

* Convert the character fields to numeric and back
n = var1.
var1 = n.
n = var2.
var2 = n.

* Now do condition statement.
if var1 > var2.
  write:/ 'Var1 is > var2'.
else.
  write:/ 'Var1 is not > var2'.
endif.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
545

Rich,

You answer works well....

I need not to be changed the char to numeric , Instead of i used UNPACK to fill character 0 before the value.

Thanks

Sa_R