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

Subroutines in SAP Sapcript

Former Member
0 Likes
744

Hi Experts,

I want to pick up some 7 fields from different tables with one input criteria in a sap script. I tried using the subroutines for this. But the problem i am facing is that it is just returning one value. I want 7 fields.

The code is used

Perform xyz in program aaa using one

chaning two

chaning three

chaning four

chaning five.

endperform.

Same goes for the report.

form xyz tables in_par structure itcsy

out_par structure itcsy.

Read table in_par with key 'one'.

(select statements....

these values are stored in internal table.. or variables.)

move ITAB-one to out_par-value.

move ITAB-two to out_par-value.

move ITAB-three to out_par-value.

move ITAB-four to out_par-value.

move ITAB-five to out_par-value.

modify out_par index sy-tabix.

endform.

but here it is overwritting the value everytime and just the last thats itab-five is returned.

Any inputs to resolve this issue. If for such a requirment subroutine willnot work, then pls suggest some other solution for this.

Thanks.

NC

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
718

Hi NC,

if you call like this:


perform xyz in program aaa
  using &one&
  changing &two&
  changing &three&
  changing &four&
  changing &five&

then you should develop the following code in subroutine pool "aaa":


form xyz tables in_par structure itcsy
         tables out_par structure itcsy.
  read table in_par with key 'ONE'.
  check sy-subrc = 0.
* (select whatever you want)...
  read table out_par with key 'TWO'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.

  read table out_par with key 'THREE'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.

  read table out_par with key 'FOUR'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.

  read table out_par with key 'FIVE'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.
endform.

That is, you should read every output parameter from itab out_par, and then modify column "value" by this "modify...index sy-tabix".

Please let us know if it helped. Best regards,

Alvaro

Hi Experts,

I want to pick up some 7 fields from different tables with one input criteria in a sap script. I tried using the subroutines for this. But the problem i am facing is that it is just returning one value. I want 7 fields.

The code is used

Perform xyz in program aaa using one

chaning two

chaning three

chaning four

chaning five.

endperform.

Same goes for the report.

form xyz tables in_par structure itcsy

out_par structure itcsy.

Read table in_par with key 'one'.

(select statements....

these values are stored in internal table.. or variables.)

move ITAB-one to out_par-value.

move ITAB-two to out_par-value.

move ITAB-three to out_par-value.

move ITAB-four to out_par-value.

move ITAB-five to out_par-value.

modify out_par index sy-tabix.

endform.

but here it is overwritting the value everytime and just the last thats itab-five is returned.

Any inputs to resolve this issue. If for such a requirment subroutine willnot work, then pls suggest some other solution for this.

Thanks.

NC

4 REPLIES 4
Read only

Former Member
0 Likes
719

Hi NC,

if you call like this:


perform xyz in program aaa
  using &one&
  changing &two&
  changing &three&
  changing &four&
  changing &five&

then you should develop the following code in subroutine pool "aaa":


form xyz tables in_par structure itcsy
         tables out_par structure itcsy.
  read table in_par with key 'ONE'.
  check sy-subrc = 0.
* (select whatever you want)...
  read table out_par with key 'TWO'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.

  read table out_par with key 'THREE'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.

  read table out_par with key 'FOUR'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.

  read table out_par with key 'FIVE'.
  check sy-subrc = 0.
  out_par-value = '...'.
  modify out_par index sy-tabix.
endform.

That is, you should read every output parameter from itab out_par, and then modify column "value" by this "modify...index sy-tabix".

Please let us know if it helped. Best regards,

Alvaro

Read only

0 Likes
718

Hi Alvaro,

This is exactly what i required. Thanks for your prompt reply. It solved my problem.

Thanks,

NC

Read only

0 Likes
718

Hi alvaro,

Can u please explain how do i exactly declare this in my custom form , like where exactly i have to declare and how to i declare the subroutine pool.

my customform is ZMEDRUCK and my program is medruck.

i want to insert and extra field like ekko-unsez.

could explain me if possible in a step by step procedure.

Thanks in advance.

Regards,

Roberts.K

Read only

0 Likes
718

Hi alvaro,

in the program you have given select statments , so like if my select statment is like this

select ebeln ekorg from ekko where bukrs = p_bukrs.

where do i have to declare parametetrs : p_bukrs like ekko-bukrs.

and in the statement out-par = 'itab-ebeln', is this return the numeric value on the form.

let me know please.

thanks in advance,

regards,

Roberts.K