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

Internal table logic

Former Member
0 Likes
1,083

Hello Experts,

I need to write the each content (each row) of my internal table to output parameters (out1, out2,out3...outn) of my Func Module.

The internal table has only one column. The contents of my internal table is as follows:

cont1

cont2

cont3

..............

-


contn

output should be :

out1 = cont1

out2 = cont2

-


outn = contn

Pls tell me if this a way of doing this. Points will be awarded.

thanks

Dany

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,058

Hi,

I believe the exporting parameters is static..You cannot create exporting parameters on the fly..

Thanks,

Naren

11 REPLIES 11
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,058

You can use field symbols for this. Questions, are CONT1, CONT2, CONT3 are these varaibles names within the function module? Are the field names always like this CONT and (1) numeric or alpha? What about OUT1, OUT2, etc, same thing here? Always OUT and numeric or alpha? If so you can build the field names on the fly and assign to field symbols in order to move them.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,058

Hi,

You can do it using field-symbols..

But if there are more number of rows in the internal table than the number of exporting parameters...what should happen..

Or it the number of rows in the internal table is always fixed as the number of exporting parameters..

Thanks,

Naren

Read only

Former Member
0 Likes
1,058

Hi Dan,

Its like if you have particular number of output parameters (suppose 5 output parameters) then you can loop on internal table and assign the values like:

Read table itab into x_itab index 1.

out1 = x_itab-field.

Read table itab into x_itab index 2.

out2 = x_itab-field.

Read table itab into x_itab index 3.

out3 = x_itab-field.

Read table itab into x_itab index 4.

out4 = x_itab-field.

Read table itab into x_itab index 5.

out5 = x_itab-field.

Otherwise,

You can use the output parameter as Table and pass your table to it directly and take you internal table in the program and work with it.

Regards,

Amandeep Kumar

Read only

0 Likes
1,058

Something like this maybe.



report zrich_0001.

data: cont1 type c value 'A',
      cont2 type c value 'B',
      cont3 type c value 'C',
      cont4 type c value 'D'.

data: out1 type c,
      out2 type c,
      out3 type c,
      out4 type c.


data: begin of itab occurs 0,
      fld(30) type c,
      end of itab.

data: out_field(30).

field-symbols: <fs_i>,
               <fs_o>.

itab-fld = 'CONT1'.  append itab.
itab-fld = 'CONT2'.  append itab.
itab-fld = 'CONT3'.  append itab.
itab-fld = 'CONT4'.  append itab.


loop at itab.

  assign (itab-fld) to <fs_i>.

  out_field = 'OUT'.
  out_field+3(1) = itab-fld+4(1).

  assign (out_field) to <fs_o>.

  <fs_o> = <fs_i>.


endloop.


write:/ out1, out2, out3, out4.

Regards,

RIch Heilman

Read only

Former Member
0 Likes
1,058

Hi Rich,

CONT1..etc are contents of my itab. It can be num or alphanum..& its char type.

The field names can be num or alphanu.

OUT 1, OUT2 are export params of FM ..just display the content of my itab.

Q) How can we build the field names on the fly and assign to field symbols in order to move them? Pls tell me using Work Areas?

Narendra:

Thanks for your response.

The no of rows of internal table is not fixed...can u help me doing this with work areas ?

Thanks

Read only

Former Member
0 Likes
1,058

Hi,

Check this example..

DATA: BEGIN OF itab OCCURS 0,

value(10),

END OF itab.

itab-value = 'CONT1'.APPEND itab.

itab-value = 'CONT2'.APPEND itab.

itab-value = 'CONT3'.APPEND itab.

***Assuming if you have three exporting parameters..

***Named OUT1 OUT2 & OUT3

DATA: v_field(30).

DATA: v_char(5).

FIELD-SYMBOLS: <fs>.

DO.

READ TABLE itab INDEX sy-index.

IF sy-subrc <> 0.

EXIT.

ENDIF.

CLEAR: v_field.

v_char = sy-index.

SHIFT v_char LEFT DELETING LEADING space.

CONCATENATE 'OUT' v_char INTO v_field.

ASSIGN (v_field) TO <fs>.

<fs> = itab-value.

ENDDO.

Thanks,

Naren

Read only

Former Member
0 Likes
1,058

Hi All,

The no of rows of internal table is not fixed.

Cant we build the export parameters of the FM dynamically based on no of records in itab.

thanks

Read only

Former Member
0 Likes
1,059

Hi,

I believe the exporting parameters is static..You cannot create exporting parameters on the fly..

Thanks,

Naren

Read only

Former Member
0 Likes
1,058

Hi Naren,

I am getting the output provided its for fixed no of output params.

Please tell me if i can do it like this

LOOP AT itab INTO wa_itab.

IF sy-tabix = 1.

strout1 = wa_itab-f1.

ELSEIF sy-tabix = 2.

strout2 = wa_itab-f1.

ELSEIF sy-tabix = 3.

strout3 = wa_itab-f1.

ELSEIF sy-tabix = 4.

strout4 = wa_itab-f1.

ELSEIF sy-tabix = 5.

strout5 = wa_itab-f1.

ELSEIF sy-tabix = 6.

strout6 = wa_itab-f1.

ELSEIF sy-tabix = 7.

strout7 = wa_itab-f1.

ELSEIF sy-tabix = 8.

strout8 = wa_itab-f1.

ELSEIF sy-tabix = 9.

strout9 = wa_itab-f1.

ENDIF.

ENDLOOP.

Read only

0 Likes
1,058

Yes, you can do it like that if you want, as long as the iTAB is sorted correctly.

Regards,

Rich Heilman

Read only

0 Likes
1,058

You can do this. It will work.

Regards,

Amandeep Kumar