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

Reference to table in user-exit

MichiFr
Participant
0 Likes
2,327

Hi,

I'm trying to get a reference to a table which was passed to a user-exit function module (EXIT_SAPLMCI1_001, btw). The table is needed in a FORM routine and should be modified there.

Currently I'm using the following code:


  FIELD-SYMBOLS:
      <fs_tab> TYPE standard table
      .
  DATA:
     ref TYPE REF TO data
            .
  CREATE DATA ref LIKE i_mcipmb.
  GET REFERENCE OF i_mcipmb[] INTO ref.
  ASSIGN ref->* TO <fs_tab>.

which works fine so far. Field symbol <fs_tab> now has got the passed records from table i_mcipmb.

Now I'm trying this coding:


  LOOP AT <fs_tab> where supkz = '2'.
  ENDLOOP.

which fails because it doesn't recognize <fs_tab> as a structure. The same applies when using coding like this:


READ TABLE <fs_tab> INTO wa_mcipmb WITH KEY SUPKZ ='2'.

Is it possible at all to get this running? If so how can I solve this?

Thanks,

Michael

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,058

Here is something that may work, which is very similar to your original idea:


  FIELD-SYMBOLS:
    <fs_tab> like i_mcipmb[]. " Table structure must be defined

  DATA:
    ref TYPE REF TO data.

  CREATE DATA ref LIKE i_mcipmb.
  GET REFERENCE OF i_mcipmb[] INTO ref.
  ASSIGN ref->* TO <fs_tab>.

followed by


  FIELD-SYMBOLS: <fs_row>.
  LOOP AT <fs_tab> assigning <fs_row> where supkz = '2'.
  ENDLOOP.

best wishes

Ed

15 REPLIES 15
Read only

former_member376453
Contributor
0 Likes
2,058

I am not sure but have a try when you are trying to looping in the field-symbol, use a work area, as you have defined it as standard table, so I am assuming there is no header line is there for this field-symbols.

Kuntal

Read only

0 Likes
2,058

Kuntal,

yes, you are correct, there is no header line and I cannot add one to the field symbol at all.

Using this additional coding


  DATA:
     wa  TYPE mcipmb
            .
  LOOP AT <fs_tab> INTO wa.
    IF wa-supkz = '2'.
      EXIT.
    ENDIF.
  ENDLOOP.

works of course, but results in some extra coding like this one and much more at some other places in the user exit.

I would prefer something like this:

READ TABLE <fs_tab> WITH KEY supkz = '2'.

Btw, the purpose of this coding is that I can modify the table data of i_mcipmb without doing too much copying from the source tables to an internal tables and vice versa inside the numerous FORM routines I would like implement. I'm searching for a solution to work on the original table data which was passed in.

Read only

0 Likes
2,058

Then

READ TABLE <fs_tab> WITH KEY (supkz) = '2'.

a®

Read only

former_member156446
Active Contributor
0 Likes
2,058
FIELD-SYMBOLS <t_mci> LIKE i_mcipmb.

loop at <t_mci> where supkz = '2'.

endloop.
Read only

0 Likes
2,058

J@Y,

this will not work either since <t_mci> is not defined as an internal table and without any reference to the original table i_mcipmb it wouldn't contain any original records.

Read only

0 Likes
2,058

>

> J@Y,

>

> this will not work either since <t_mci> is not defined as an internal table and without any reference to the original table i_mcipmb it wouldn't contain any original records.

I tired a similar thing before in ZXBPFCU01 in EXIT_SAPLBPFC_001. ( well I am using a line of it though)

FIELD-SYMBOLS <t_mail_receivers> LIKE LINE OF t_mail_receivers.
LOOP AT t_mail_receivers ASSIGNING <t_mail_receivers>.
..
..
enloop.

Read only

0 Likes
2,058

J@Y,

I tired a similar thing before in ZXBPFCU01 in EXIT_SAPLBPFC_001. ( well I am using a line of it though)

Yes, this will work if your loop is inside include ZXBPFCU01, as I had before (in include ZXMCIU01), however we constantly added coding to this exit and it got a little bit complex after a while. So we decided to use FORMs in one of the available customer includes (ZXMCIZZZ).

Unfortunately you cannot use FORM routines between (the user exit) FUNCTION and ENDFUNCTION, so we had to move them into separate includes. Now we need access to the passed function parameters of course and that's why I'm posting here, searching for a solution.

Read only

0 Likes
2,058

I did not test it..

*&---------------------------------------------------------------------*
*&  Include           ZXMCIU01
*&---------------------------------------------------------------------*

PERFORM fr_change TABLES i_mcipmb. " can add using and changing parameters as well

FORM fr_change  TABLES   p_mcipmb STRUCTURE mcipmb.  " can pull using and changing parameters

  FIELD-SYMBOLS: <fs> TYPE mcipmb.
  LOOP AT p_mcipmb ASSIGNING <fs>.

  ENDLOOP.


ENDFORM.                    " FR_CHANGE

Hope this helps..

Read only

former_member194669
Active Contributor
0 Likes
2,058

   LOOP AT <fs_tab> assigning <wa_tab>.
     assign  component 'SUPKZ' of structure <wa_tab> to <fs1>.
     if <fs1> eq '2'.
         " do validation
     endif.
  ENDLOOP.

a®

Read only

0 Likes
2,058

a®s


   LOOP AT <fs_tab> assigning <wa_tab>.
     assign  component 'SUPKZ' of structure <wa_tab> to <fs1>.
     if <fs1> eq '2'.
         " do validation
     endif.
  ENDLOOP.

This would certainly do the job but I need to modify some more fields in table i_mcipmb, and believe me there are plenty of them. Accessing those fields, using your proposed coding, is a little bit overhead.

Thanks for your suggestion!

Read only

Former Member
0 Likes
2,059

Here is something that may work, which is very similar to your original idea:


  FIELD-SYMBOLS:
    <fs_tab> like i_mcipmb[]. " Table structure must be defined

  DATA:
    ref TYPE REF TO data.

  CREATE DATA ref LIKE i_mcipmb.
  GET REFERENCE OF i_mcipmb[] INTO ref.
  ASSIGN ref->* TO <fs_tab>.

followed by


  FIELD-SYMBOLS: <fs_row>.
  LOOP AT <fs_tab> assigning <fs_row> where supkz = '2'.
  ENDLOOP.

best wishes

Ed

Read only

0 Likes
2,058


   FIELD-SYMBOLS: <fs_row>.
   LOOP AT <fs_tab> assigning <fs_row> where supkz = '2'.
   ENDLOOP.

Ed,

I think while activating it may get an error that SUPKZ not found or not defined. due to will be defined only on runtime

Am I wrong please correct me.

a®

Read only

0 Likes
2,058

Hi! Thanks for your comment. The following example using the same pattern activates and runs OK...


report  zsdn_example.
data:  begin of gt_sflight occurs 0.
        include structure sflight.
data: end of gt_sflight,
      gs_sflight type sflight,
      ref       type ref to data.
field-symbols:
    <fs_row>   type sflight,
    <fs_tab> like gt_sflight[].

select * from  sflight client specified into table gt_sflight.

create data ref like gt_sflight[].
get reference of gt_sflight[] into ref.

assign ref->* to <fs_tab>.
loop at <fs_tab> assigning <fs_row> where carrid = 'AA'.
  write:
    / <fs_row>-carrid.
endloop.

best wishes

Ed

Read only

0 Likes
2,058

Ed, You are right


create data ref like gt_sflight[].
get reference of gt_sflight[] into ref.

Here ref pointing to standard table this will work

Thanks for example

a®

Read only

0 Likes
2,058

Ed,

thanks for your coding and assistance! Your example works exactly the way I wanted to.

@all, thanks for reading and commenting.