Application Development 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: 

sap script if else statement

Former Member
0 Kudos
914

I am trying to use.

/: IF &S_DATE& > &RF140-SALDO&.

/: &S_VALUE1& = &RF140-WRSHB&+&S_VALUE1.

/:endif.

I want to add up all into &S_VALUE1& and want to display at the end.?

I get the error as

AND, OR or end of condition expected

Control commands were not closed within the text element

IF

Is there some thing which I am missing..?let me know.

Thanks,

4 REPLIES 4

former_member181995
Active Contributor
0 Kudos
202

Use subroutine pools in Script.

for more infor you can search in SCN with term subroutine pools

Former Member
0 Kudos
202

HI

use following code

if you smartforms/sapscript

use program line

IF S_DATE > RF140-SALDO

S_VALUE1 = RF140-WRSHB+S_VALUE1.

endif.

and after retrive taht value in smartforms

Regards

Sam

Former Member
0 Kudos
202

Hi,

I think there must be some condition for which you are adding these values like for the same values of a field add these .Make use of the command PERFORM in Script:

IN Script:

DEFINE &S_VALUE1& = ' '

IF &S_DATE& > &RF140-SALDO&.

PERFORM get_total IN PROGRAM <xyz>

USING &RF140-WRSHB&

CHANGING &S_VALUE1&

endif.

in Program:

"Declare a global variable of type RF140-WRSHB.

g_WRSHB_t type RF140-WRSHB.

FORM get_total TABLES input_table STRUCTURE itcsy

output_table STRUCTURE itcsy.


LOOP AT input_table.
CASE input_table-name.
WHEN 'RF140-WRSHB'.
g_wrshb = input_table-value. 
WHEN OTHERS.
ENDCASE.

if g_int = 0.                "for the 1st record 
  g_WRSHB_t = g_wrshb.
  READ TABLE output_table WITH KEY name = 'S_VALUE1'.
    if sy-subrc = 0.
      MOVE g_wrshb TO output_table-value.
      MODIFY output_table INDEX sy-tabix.
      CLEAR output_table.
    endif.
else                        "For 2nd rec onwards

          g_WRSHB_t = g_wrshb +   g_WRSHB_t .
           READ TABLE output_table WITH KEY name = 'S_VALUE1'.
           if sy-subrc = 0.
               MOVE g_wrshb_t TO output_table-value.
               MODIFY output_table INDEX sy-tabix.
              CLEAR output_table.
          endif.
   endif.
    g_int = g_int + 1.
ENDFORM.

Former Member
0 Kudos
202

done