cancel
Showing results for 
Search instead for 
Did you mean: 

User exit

Former Member
0 Kudos

Hi all,

I came across this user exit (below) which is used to enhance a datasource.

data: l_s_icctrcst like icctrcst,

l_s_icctract like icctract,

l_s_icctrsta like icctrsta,

l_tabix like sy-tabix.

case i_isource.

when '0CO_OM_CCA_1'.

loop at c_t_data into l_s_icctrcst.

l_tabix = sy- tabix.

select single * from z0001 where kokrs = l_s_icctrcst-kokrs

and kostl = l_s_icctrcst-kostl.

if sy-subrc = 0.

l_s_icctrcst-zfield1 = z0001-zfield1.

l_s_icctrcst-zfield2 = z0001-zfield2.

modify c_t_data from l_s_icctrcst index l_tabix.

endif.

endloop.

when '0CO_OM_CCA_2'.

...

when '0CO_OM_CCA_3'.

...

when others.

exit.

endcase.

Can anyone explain me this code?

Accepted Solutions (1)

Accepted Solutions (1)

edwin_harpino
Active Contributor
0 Kudos

hi Pooja,

*-----

data: l_s_icctrcst like icctrcst,

l_s_icctract like icctract,

l_s_icctrsta like icctrsta,

l_tabix like sy-tabix.

*------

<i>* this part is how we declare 'variable' to be used in the user exit, here declare some internal table/local structure to handle data manipulation (temporary storage)</i>

*-----

case i_idatasource.

*-----

<i>* multiple conditional with option datasources</i>

when '0CO_OM_CCA_1'.

  • if datasource = 0CO_OM_CCA_1 execute the following code

loop at c_t_data into l_s_icctrcst.

<i>- loop at c_t_data ... endloop -> populate the data into temporary table to further manipulation, in this case to fill up the new fields enhancement</i>

l_tabix = sy- tabix.

<i>* handling index, to make sure update to the right row</i>

*---

select single * from z0001 where kokrs = l_s_icctrcst-kokrs

and kostl = l_s_icctrcst-kostl.

<i>*--- retrieve data from table z0001 with condition field kokrs and kostl = kokrs and kostl value in data to go to bw</i> select single will retrieve just the first row if more than one record found

*--

if sy-subrc = 0.

l_s_icctrcst-zfield1 = z0001-zfield1.

l_s_icctrcst-zfield2 = z0001-zfield2.

modify c_t_data from l_s_icctrcst index l_tabix.

endif.

<i>*-- in the data is found the fill the new fields value with the data from table z0001</i>

endloop.

*-

when '0CO_OM_CCA_2'.

...

hope this helps.

Former Member
0 Kudos

Hi A.H.P..thanks for taking your time to reply.

I have a few questions.

1)Can we use any name for the temporary tables? Also, is 'icctrcst' a pre-defined type?

2) In the loop statement, is c_t_data something specific to this program or is this just a variable? I mean what's its significance?

3) What is handling index? Is l_tabix and sy_tabix used in all the user exits for enhancement?

4) I didn't understand the concept of selecting just the first row. Can ou please make it clear to me?

5)I assume that z-field1 and z-field2 are just dummy field names which will be replaced by my fields. Am I right?

Former Member
0 Kudos

Hi A.H.P,

Can you please tell me how to select Data via user exits.

Thanks & Regards

Rajesh

edwin_harpino
Active Contributor
0 Kudos

hi Pooja,

1. yes, you can use any name, for naming convention normally we use l_s_ and the structure name, if the structre is too long then we prefer a shorter name for ease in writing. in this case, icctrcst is the datasource extract structure name.

2. c_t_data is specific to this program, not just a variable, it's a parameter. actually zxrsau01 is an include program from function module EXIT_SAPLRSAP_001 (transaction se37), you can see parameter c_t_data in tab 'tables', and I_DATASOURCE also a parameter, see tab 'import'. so you have to use exactly 'c_t_data'.

3. this is to make sure the update go to the right row, we do this by 'marking'/point the index. l_tabix is local variable, you can use other name. sy-tabix (not underscore sy_tabix) is system parameter, there are lots of system parameter that filled in runtime, e.g username, client, etc. try to read 'abap 21 days'.

4. in abap, select statement will have looping, if we are sure we only need one record then we add 'single', but take care in using 'select single', it can be the #1 performance killer in data loading.

5. yes you are right, field1 and field2 just dummy, it will follow the name in append structure (normal with prefix zz...)

hope this answers your questions.

edwin_harpino
Active Contributor
0 Kudos

hi Rajesh,

can specify ? 'select data' in terms of get from other table to fill new fields (as in this thread) or you need to 'filter' data ? to filter data, you can populate first c_t_data to other temporary internal table with header and 'delete [table] where ....', or in looping c_t_data, do 'if [condition]. delete c_t_data. endif.'

*if this is not answer your question, please create a new posting to have better answers from our sdn bw-ers.

Former Member
0 Kudos

Thank you so much A.H.P.

You're starting to become my mentor.

Your lengthy explanations have made me understand a lot of stuff in the past two days.

edwin_harpino
Active Contributor
0 Kudos

dear Pooja,

you are welcome

former_member188325
Active Contributor
0 Kudos

Hi A.H.P,

i have been watching this topic.U r explanations are really helpful...than a lot.

regards

Former Member
0 Kudos

Edwin,

You do an excellent job at explaining things.

Former Member
0 Kudos

ITS REALLY HELPFUL....

Former Member
0 Kudos

A.H.P. That was an excellent explanation

Thanks

Sri

Former Member
0 Kudos

ya its very helpful

Former Member
0 Kudos

Hi AHC, i ve got a question, can I do an append to c_t_data??

I ve seen a lot of examples using modify c_t_data, is ok to use append?

I want to insert some records for this dataset.

Regards

joker

Answers (2)

Answers (2)

Former Member
0 Kudos

I wish I could assign pts to Edwin. His explainations were really helpful.

Thanks Edwin

RG

edwin_harpino
Active Contributor
0 Kudos

hi Pooja,

you should use

case i_datasource. instead of i_isource(the old one).

using i_isource you won't never get the code executed.

hope this helps.