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

subroutine

Former Member
0 Likes
552

Hi experts,

Can somebody explain me how to write a subroutine pool for follwoing code?

I am using same code in different places with different parameters.

ie. I have code like this.

select field1 field2 from /bic/AZODS1 into

table Itab where field1 = datapackage-field1.

if sy-subrc = 0

sort itab by field1.

endif.

Here I have total 6 ODS for 6 different regions.

I have to get same fields (field1 field2) from 6 ODS (ZODS1,ZODS2,ZODS3,ZODS4,ZODS5 and ZODS6) into target ods ( look up).

Could somebody explain me how to write a common subroutine for above code instead of hardcoding each ODS name in the code( for example

Form Get_field tables ypacket type datapackage

ymonitor type rsmonitor.

select field1 field2 from ( /bic/AZODS1 or /bic/AZODS2 so on ) into itab

where field1 = datapackage-field1.

if sy-subrc = 0

sort itab by field1.

endif.

Endform.

Thanks in advance and points will be assigned.

Regards,

Mark

1 ACCEPTED SOLUTION
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
524

Hi,

Here is the coding which will help you.

According to the follg. code,you pass table name to the subroutine.Inside the form,you use dynamic select.

select * from (itab)...

Sample code:

data itab1 type standard table of mara .

data itab2 type standard table of makt .

data ln type i.

select * from mara into table itab1.

perform display tables itab1 .

write 'MAKT'.

uline.

select * from makt into table itab2.

perform display tables itab2.

&----


*& Form display

&----


  • text

----


  • -->P_ITAB text

----


form display tables itab type table.

field-symbols: <fs> type any,

<fs1> type any.

loop at itab assigning <fs>.

do.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <fs1>.

write <fs1>.

if sy-subrc ne 0.

exit.

endif.

enddo.

new-line.

endloop.

endform.

Message was edited by:

Jayanthi Jayaraman

4 REPLIES 4
Read only

jayanthi_jayaraman
Active Contributor
0 Likes
525

Hi,

Here is the coding which will help you.

According to the follg. code,you pass table name to the subroutine.Inside the form,you use dynamic select.

select * from (itab)...

Sample code:

data itab1 type standard table of mara .

data itab2 type standard table of makt .

data ln type i.

select * from mara into table itab1.

perform display tables itab1 .

write 'MAKT'.

uline.

select * from makt into table itab2.

perform display tables itab2.

&----


*& Form display

&----


  • text

----


  • -->P_ITAB text

----


form display tables itab type table.

field-symbols: <fs> type any,

<fs1> type any.

loop at itab assigning <fs>.

do.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs> TO <fs1>.

write <fs1>.

if sy-subrc ne 0.

exit.

endif.

enddo.

new-line.

endloop.

endform.

Message was edited by:

Jayanthi Jayaraman

Read only

Former Member
0 Likes
524

Hi Raymond

You can modify this Form. and make it like this

Form Get_field tables ypacket type datapackage <b>using P_ODS</b>

ymonitor type rsmonitor.

select field1 field2 from <b>(P_ODS)</b> into itab

where field1 = datapackage-field1.

if sy-subrc = 0

sort itab by field1.

endif.

Endform.

this will work.

now pass ODS1, ODS2 through your P_ODS variable.

hope this helps you

Read only

0 Likes
524

Hi Sandeep,

Thanks for your very very helpful answer and it allmost solved my problem but still I have a small doubt.

how do I defined P_ODS variable and how do I pass ODS through that variable?

Thanks in advance.

Regards,

Mark.

Read only

0 Likes
524

Hi Raymond,

I think by now u must have got how to create that variable ..

but still if you have not got it .....

just type in your code.

perform xyz using dos.

now double click on xyz. here abap editor will ask you to create a new form .. click yes and ABAP editor will automatically create the form as

FORM xyz USING p_dos.

ENDform.

now you can write the above mentioned code here .

hope this helps.