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

Perform in SAPSCRIPT

Former Member
0 Likes
1,326

i want to pss 2 vriables through perfrom and then sum it up, by changing i will get back that summed variable to the Script.

Those 2 variables r Integers. now pls provide me the code for this, its urgent?

9 REPLIES 9
Read only

Former Member
0 Likes
1,232

http://www.sap-basis-abap.com//abap/how-to-call-a-subroutine-form-sapscripts.htm

more help on this.

here is the total logic for your requirement.

in the script layout,

/: PERFORM Get_Pack IN PROGRAM ZTEST
/: USING &V_FIELD1&
/: USING &V_FIELD2&
/: CHANGING &RESULT&
*----and so onn
/: ENDPERFORM

/* HERE WE are printing the result

<b>* result : &RESULT&</b>

Then in the program,

all the paramters you pass from SCRIPT with USING command will come into ITAB.

all parameters with CHANGING command will comes into OTAB

FORM  Get_Pack TABLES ITAB   STRUCTURE ITCSY
                      OTAB   STRUCTURE ITCSY.
data: v_field1 type i,
      v_field2 type i,
      v_result type i.
 
*--TO read the values from the ITAB you have to use this logic.
  READ TABLE ITAB WITH KEY NAME = <b>'V_FIELD1'</b>
         TRANSPORTING VALUE.
  IF SY-SUBRC = 0.
    CONDENSE ITAB-VALUE.
    V_FIELD1 = ITAB-VALUE.
  ENDIF.

  READ TABLE ITAB WITH KEY NAME = <b>'V_FIELD2'</b>
         TRANSPORTING VALUE.
  IF SY-SUBRC = 0.
    CONDENSE ITAB-VALUE.
    V_FIELD2 = ITAB-VALUE.
  ENDIF.

*--to modify PACK value
*--write your logic to get the value inTO RESULT. 
   V_RESULT = V_FIELD1 + V_FIELD2.

   OTAB-VALUE = V_RESULT.
   condense OTAB-VALUE.
   MODIFY OTAB  TRANSPORTING VALUE 
             WHERE <b>NAME = 'RESULT'</b>.
ENDFORM.

You can create the program either as Executable or subroutine pool in SE38. there will not be any difference,i guess.

Regards,

Srikanth

Message was edited by: Srikanth Kidambi

Read only

0 Likes
1,232

Thnks Srikant, i want to add 2 decimals and then my result shud also be in decimals? how shall i do it?

i done with the same logic but i am getting errors?

Read only

anversha_s
Active Contributor
0 Likes
1,232

hi,

try this.

PERFORM <function> IN PROGRAM <progr>

USING &val1&

USING &val2&

CHANGING &SUM&

ENDPERFORM.

rgds

anver

pls mrk hlpful answers

Read only

Former Member
0 Likes
1,232

Hi

Use the variables from the program in the sapscript editor using Global Varaiables & add the contents and store the same in any of the varaiables.

E.g., Say you have 2 varaiables Z1 & Z2. Use the option

Z1 = z1 + z2. and u wl get your solution.

Hope it helps.

Regards

AK

Read only

Former Member
0 Likes
1,232

Hello RAMADA,

Use this code.

PERFORM GET_SUM IN PROGRAM Z_SUM CHANGING INT1 INT2 SUM.

In report

FORM GET_SUM TABLES IN_PAR STRUCTURE ITCSY

OUT_PAR STRUCTURE ITCSY.

data: num1 type i,

num2 type i,

sum type i.

READ TABLE IN_PAR WITH KEY NAME = 'INT1'.

if sy-subrc = 0.

CONDENSE IN_PAR-VALUE NO-GAPS.

num1 = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY NAME = 'INT1'.

if sy-subrc = 0.

CONDENSE IN_PAR-VALUE NO-GAPS.

num2= IN_PAR-VALUE.

endif.

endif.

sum = num1 + num2.

READ TABLE IN_PAR WITH KEY NAME = 'SUM'.

OUT_PAR-VALUE = sum.

MODIFY OUT_PAR INDEX SY-TABIX.

ENDFORM.

If useful reward.

Vasanth

Read only

Former Member
0 Likes
1,232

hi,

A sample code of how to use performs in sap scripts.

In script program,

/:PERFORM GET_SBGRP_STEXT IN PROGRAM ZSDSCRIPT

/:USING &GV_MATNR&

/:CHANGING &GV_STEXT&

/:TABLES INPUT_TABLE

/: OUTPUT_TABLE

/:ENDPERFORM

In program ZSDSCRIPT,

form get_sbgrp_stext tables intab structure itcsy

outab structure itcsy.

DATA: LV_MATNR LIKE MARA-MATNR,

LV_TEXT(3) TYPE C VALUE 'ABC'.

clear intab.

read table intab with key name = 'GV_MATNR'.

if sy-subrc = 0.

lv_MATNR = intab-value.

ENDIF.

CLEAR OUTTAB.

READ TABLE OUTAB WITH KEY NAME = 'GV_STEXT'.

IF SY-SUBRC = 0.

OUTAB-VALUE = LV_TEXT.

modify outab index sy-tabix.

ENDIF.

endform.

Regards,

Sailaja.

Read only

Former Member
0 Likes
1,232

Hi,

Just Copy and paste theis code, this will work for you and the Field &RESULT& will avilable in the SCRIPT with result ....

in the script,

/: PERFORM SUM IN PROGRAM ZPROGRAM

/: USING &VAR1&

/: USING &VAR2&

/: CHANGING &RESULT&

/: ENDPERFORM

In the program(ZPROGRAM), we need to write the form ....

FORM SUM TABLES INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY.

data: field1 type i,

field2 type i,

result type i.

*--TO read the values from the ITAB you have to use this logic.

READ TABLE INTAB WITH KEY NAME = 'VAR1'.

IF SY-SUBRC = 0.

FIELD1 = INTAB-VALUE.

ENDIF.

READ TABLE INTAB WITH KEY NAME = 'VAR2'.

IF SY-SUBRC = 0.

FIELD2 = ITAB-VALUE.

ENDIF.

RESULT = V_FIELD1 + V_FIELD2.

READ TABLE OUTTAB INDEX 1.

IF SY-SUBRC = 0.

OTAB-VALUE = RESULT.

MODIFY OUTTAB INDEX 1 .

ENDIF.

ENDFORM.

Regards

Sudheer

Read only

Former Member
0 Likes
1,232

what if i want Decimals to be added and my result should also be in decimals? i done with the same code , but i am geting errors? pls help...

Read only

0 Likes
1,232

Hi ramada,

1. while calling subroutines from sapscripts,

there is a special technique,

which has got its own limitations.

2.

FORM abc

TABLES

in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

ENDFORM.

3. The perform in se38 program should be of the

above format only.

4. We cannot pass internal tables.

5. Rather we need to pass

VARIABLE NAME

VARIABLE VALUE

(see the structure of itcsy in se11)

6. In this form, we have to read

the internal table in_tab

to capture the variable name and its value.

7. Similary, to return the values,

we have to put one record (for each variable)

in out_tab.

regards,

amit m.