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

Correspondance between 3 tables

Former Member
0 Likes
876

Hi experts,

Internal table WT_CSGL

/BIC/Y_CSACCNT

GL_ACCOUNT

A2130

2130001

A2130

2140001

A2140

2140003

A2150

2150001

A2150

2150002

A2150

2150003

Internal table WT_CSRM

/BIC/Y_CSACCNT

/BIC/Y_RMACCNT

A2130

A2110M

A2140

A2110M

A2150

A2150

I would like to fill the internal table WT_RMGL . I have a correspondence between GL_ACCOUNT to /BIC/Y_CSACCNT in table WT_CSGL.

Another correspondence between /BIC/Y_RMACCNT to /BIC/Y_CSACCNT in table WT_CSRM.

The idea is to create a correspondence between GL_ACCOUNT to /BIC/Y_RMACCNT in table WT_RMGL.


Normally at the end, I should have the following table based on my example.


/BIC/Y_RMACCNT

GL_ACCOUNT

A2110M

2130001

A2110M

2140001

A2110M

2140003

A2150

2150001

A2150

2150002

A2150

2150003

I tried the following logic but I don’t get all the expected results

CLEAR: wa_csrm, wa_csgl,wa_rmgl .
LOOP AT wt_csrm  INTO wa_csrm.
READ TABLE wt_csgl INTO wa_csgl WITH KEY /bic/y_csaccnt  = wa_csrm-/bic/y_csaccnt.
IF sy-subrc = 0.
wa_rmgl-/bic/y_rmaccnt = wa_csrm-/bic/y_rmaccnt.
wa_rmgl-gl_account = wa_csgl-gl_account.
ENDIF.
APPEND wa_rmgl TO wt_rmgl.
CLEAR : wa_csgl, wa_csrm, wa_rmgl.
ENDLOOP.

SORT wt_rmgl BY /bic/y_rmaccnt gl_account.


Thanks.

Amine

1 ACCEPTED SOLUTION
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
845

CLEAR: wa_csrm, wa_csgl,wa_rmgl .
LOOP AT wt_csgl  INTO wa_csgl.
READ TABLE wt_csrm INTO wa_csrm WITH KEY /bic/y_csaccnt  = wa_csgl-/bic/y_csaccnt.
IF sy-subrc = 0.
wa_rmgl-/bic/y_rmaccnt = wa_csrm-/bic/y_rmaccnt.
wa_rmgl-gl_account = wa_csgl-gl_account.
ENDIF.
APPEND wa_rmgl TO wt_rmgl.
CLEAR : wa_csgl, wa_csrm, wa_rmgl.
ENDLOOP.

SORT wt_rmgl BY /bic/y_rmaccnt gl_account.


Hi experts,

Internal table WT_CSGL

/BIC/Y_CSACCNT

GL_ACCOUNT

A2130

2130001

A2130

2140001

A2140

2140003

A2150

2150001

A2150

2150002

A2150

2150003

Internal table WT_CSRM

/BIC/Y_CSACCNT

/BIC/Y_RMACCNT

A2130

A2110M

A2140

A2110M

A2150

A2150

I would like to fill the internal table WT_RMGL . I have a correspondence between GL_ACCOUNT to /BIC/Y_CSACCNT in table WT_CSGL.

Another correspondence between /BIC/Y_RMACCNT to /BIC/Y_CSACCNT in table WT_CSRM.

The idea is to create a correspondence between GL_ACCOUNT to /BIC/Y_RMACCNT in table WT_RMGL.


Normally at the end, I should have the following table based on my example.


/BIC/Y_RMACCNT

GL_ACCOUNT

A2110M

2130001

A2110M

2140001

A2110M

2140003

A2150

2150001

A2150

2150002

A2150

2150003

I tried the following logic but I don’t get all the expected results

CLEAR: wa_csrm, wa_csgl,wa_rmgl .
LOOP AT wt_csrm  INTO wa_csrm.
READ TABLE wt_csgl INTO wa_csgl WITH KEY /bic/y_csaccnt  = wa_csrm-/bic/y_csaccnt.
IF sy-subrc = 0.
wa_rmgl-/bic/y_rmaccnt = wa_csrm-/bic/y_rmaccnt.
wa_rmgl-gl_account = wa_csgl-gl_account.
ENDIF.
APPEND wa_rmgl TO wt_rmgl.
CLEAR : wa_csgl, wa_csrm, wa_rmgl.
ENDLOOP.

SORT wt_rmgl BY /bic/y_rmaccnt gl_account.


Thanks.

Amine

7 REPLIES 7
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
846

CLEAR: wa_csrm, wa_csgl,wa_rmgl .
LOOP AT wt_csgl  INTO wa_csgl.
READ TABLE wt_csrm INTO wa_csrm WITH KEY /bic/y_csaccnt  = wa_csgl-/bic/y_csaccnt.
IF sy-subrc = 0.
wa_rmgl-/bic/y_rmaccnt = wa_csrm-/bic/y_rmaccnt.
wa_rmgl-gl_account = wa_csgl-gl_account.
ENDIF.
APPEND wa_rmgl TO wt_rmgl.
CLEAR : wa_csgl, wa_csrm, wa_rmgl.
ENDLOOP.

SORT wt_rmgl BY /bic/y_rmaccnt gl_account.


Read only

Former Member
0 Likes
845

One of the most obvious problems is going to be that you can't do just a read.  That says that there will only ever be one match.  I'd do a loop where instead of a read.  there may be more elligant solutions, but it will solve your problem.

Neal

Read only

venkat_aileni
Contributor
0 Likes
845

Hi-

Try this:

LOOP AT wt_csrm INTO wa_csrm.

   wa_final-/bic/y_csaccnt = wa_csrm-/bic/y_csaccnt.

   LOOP AT wt_csgl INTO wa_csgl

                   WHERE /bic/y_csaccnt = wa_csrm-/bic/y_csaccnt.

     wa_final-gl_account = wa_csgl-gl_account.

     APPEND wa_final TO it_final.

     CLEAR wa_final-gl_account.

   ENDLOOP.

   CLEAR: wa_csrm.

ENDLOOP.

-Venkat

Read only

0 Likes
845

Hi Venkat,

The final table has to be

/BIC/Y_RMACCNT

GL_ACCOUNT

In your logic, i see that your final table looks as following:

/BIC/Y_CSACCNT

GL_ACCOUNT

which already exists

Amine

Read only

0 Likes
845

Hi-

I have selected other field, try below one....

LOOP AT wt_csrm INTO wa_csrm.

   wa_final-/BIC/Y_RMACCNT = wa_csrm-/BIC/Y_RMACCNT.

   LOOP AT wt_csgl INTO wa_csgl

                   WHERE /bic/y_csaccnt = wa_csrm-/bic/y_csaccnt.

     wa_final-gl_account = wa_csgl-gl_account.

     APPEND wa_final TO it_final.

     CLEAR wa_final-gl_account.

   ENDLOOP.

   CLEAR: wa_csrm.

ENDLOOP.

-Venkat

Read only

0 Likes
845

Thx guys.

Amine

Read only

anupam_anand
Participant
0 Likes
845

Hi Amine,

I have tried to replicate the scenario and could achieve your requirement:

TYPES: begin of ty_tab1,

        csaccnt TYPE c LENGTH 10,

        saknr   TYPE saknr,

       END OF ty_tab1,

       begin of ty_tab2,

        csaccnt TYPE c LENGTH 10,

        rmaccnt   TYPE c LENGTH 10,

       END OF ty_tab2,

       begin of ty_tab,

        saknr TYPE saknr,

        rmaccnt   TYPE c LENGTH 10,

       END OF ty_tab.

DATA: i_tab1  TYPE TABLE OF ty_tab1,

      i_tab2  TYPE TABLE OF ty_tab2,

      i_tab   TYPE TABLE OF ty_tab,

      wa_tab1 TYPE          ty_tab1,

      wa_tab2 TYPE          ty_tab2,

      wa_tab  TYPE          ty_tab.

REFRESH: i_tab1, i_tab2, i_tab.

CLEAR: wa_tab, wa_tab1, wa_tab2.

*   TAB 1

wa_tab1-csaccnt = 'A2130'.

wa_tab1-saknr = '2130001'.

APPEND wa_tab1 to i_tab1. CLEAR: wa_tab1.

wa_tab1-csaccnt = 'A2130'.

wa_tab1-saknr = '2140001'.

APPEND wa_tab1 to i_tab1. CLEAR: wa_tab1.

wa_tab1-csaccnt = 'A2140'.

wa_tab1-saknr = '2140003'.

APPEND wa_tab1 to i_tab1. CLEAR: wa_tab1.

wa_tab1-csaccnt = 'A2150'.

wa_tab1-saknr = '2150001'.

APPEND wa_tab1 to i_tab1. CLEAR: wa_tab1.

wa_tab1-csaccnt = 'A2150'.

wa_tab1-saknr = '2150002'.

APPEND wa_tab1 to i_tab1. CLEAR: wa_tab1.

wa_tab1-csaccnt = 'A2150'.

wa_tab1-saknr = '2150003'.

APPEND wa_tab1 to i_tab1. CLEAR: wa_tab1.

*   TAB 2

wa_tab2-csaccnt = 'A2130'.

wa_tab2-rmaccnt = 'A2110M'.

APPEND wa_tab2 to i_tab2. CLEAR: wa_tab2.

wa_tab2-csaccnt = 'A2140'.

wa_tab2-rmaccnt = 'A2110M'.

APPEND wa_tab2 to i_tab2. CLEAR: wa_tab2.

wa_tab2-csaccnt = 'A2150'.

wa_tab2-rmaccnt = 'A2150'.

APPEND wa_tab2 to i_tab2. CLEAR: wa_tab2.

LOOP AT i_tab2 INTO wa_tab2.

  LOOP AT i_tab1 INTO wa_tab1 WHERE csaccnt = wa_tab2-csaccnt.

    wa_tab-saknr = wa_tab1-saknr.

    wa_tab-rmaccnt = wa_tab2-rmaccnt.

    APPEND wa_tab to i_tab. CLEAR: wa_tab.

  ENDLOOP.

ENDLOOP.

You will have your required result in I_TAB now. The last nested loop should be your solution.

Do let me know if it helped.

Thanks,

Anupam