‎2007 Sep 26 8:17 PM
Hi Guys,
Can you please suggest me the best code to do the following.
Internal Table one :
a | b | c
1 |1 | 1
1 | 1 | 2
1 | 1 | 3
Internal Table two :
a | b | c
1 | 1 | 2
1 | 1| 3
Now the output should look like
a | b | c
1 | .. | 1
1 | 1 | 2
1 | 1 | 3.
Basically, if second internal table doesnt have a value of c which the first internal table has, the output should not have b.
Thanks
Kumar.
‎2007 Sep 26 9:01 PM
Hi Kumar,
try it:
data: BEGIN OF <b>TABLE1</b> OCCURS 0,
A(1),
B(1),
C(1),
END OF TABLE1,
<b>TABLE2</b> LIKE STANDARD TABLE OF TABLE1 WITH HEADER LINE.
TABLE1-A = 1.
TABLE1-B = 1.
<b>TABLE1-C = 1</b>.
APPEND TABLE1.
TABLE1-A = 1.
TABLE1-B = 1.
<b>TABLE1-C = 2</b>.
APPEND TABLE1.
TABLE1-A = 1.
TABLE1-B = 1.
<b>TABLE1-C = 3</b>.
APPEND TABLE1.
TABLE2-A = 1.
TABLE2-B = 1.
<b>TABLE2-C = 2</b>.
APPEND TABLE2.
TABLE2-A = 1.
TABLE2-B = 1.
<b>TABLE2-C = 3</b>.
APPEND TABLE2.
NEW-LINE.
ULINE (13).
WRITE: / SY-VLINE, <b>'A'</b>, SY-VLINE, <b>'B'</b>, SY-VLINE, <b>'C'</b>, SY-VLINE.
NEW-LINE.
ULINE (13).
<b>LOOP AT TABLE1.</b>
<b>READ TABLE TABLE2 WITH KEY C = TABLE1-C.</b>
<b>IF SY-TABIX <> 0.</b>
WRITE: / SY-VLINE, <b>TABLE1-A</b>, SY-VLINE, <b>TABLE1-B</b>, SY-VLINE, <b>TABLE1-C</b>, SY-VLINE.
ELSE.
WRITE: / SY-VLINE, <b>TABLE1-A</b>, SY-VLINE, <b>' '</b>, SY-VLINE, <b>TABLE1-C</b>, SY-VLINE.
ENDIF.
ENDLOOP.
NEW-LINE.
ULINE (13).
Regards,
Allan Cristian
‎2007 Sep 26 8:28 PM
Something like this...
LOOP AT TAB1 ASSIGNING <FS_TAB1>.
READ TABLE TAB2 WITH KEY FIELD_C = <FS_TAB1>-FIELD_C
ASSIGNING <FS_TAB2>.
IF SY-SUBRC EQ 0.
APPEND <FS_TAB2> TO TAB3.
ELSE.
CLEAR <FS_TAB1>-FIELD_B.
APPEND <FS_TAB1> TO TAB3.
ENDIF.
ENDLOOP.
Greetings,
Blag.
Message was edited by:
Alvaro Tejada Galindo
‎2007 Sep 26 8:38 PM
Thanks for your reply,
SELECT * FROM equi into TABLE lt_equi
WHERE matnr EQ t_output-matnr
AND CHARGe EQ t_output-CHARG.
SELECT * FROM v_equi_eqbs_sml INTO TABLE lt_equi_eqbs_sml
WHERE matnr EQ t_output-matnr
AND CHARGe EQ t_output-charg.and i also have another table <b>t_ouput</b> which has all the values of output.
To explain my scenario properly, let me explain with an example.
lets say there will be 2 values of sernr in <b>lt_equi_eqbs_sml</b> and 3 values(2 of them from lt_equi_eqbs_sml and an additional vaue) of sernr in <b>lt_equi</b>. Now I should not be displaying a certain field in t_output when that particular value of sernr occurs.
Thanks
Kumar.
‎2007 Sep 26 9:01 PM
Hi Kumar,
try it:
data: BEGIN OF <b>TABLE1</b> OCCURS 0,
A(1),
B(1),
C(1),
END OF TABLE1,
<b>TABLE2</b> LIKE STANDARD TABLE OF TABLE1 WITH HEADER LINE.
TABLE1-A = 1.
TABLE1-B = 1.
<b>TABLE1-C = 1</b>.
APPEND TABLE1.
TABLE1-A = 1.
TABLE1-B = 1.
<b>TABLE1-C = 2</b>.
APPEND TABLE1.
TABLE1-A = 1.
TABLE1-B = 1.
<b>TABLE1-C = 3</b>.
APPEND TABLE1.
TABLE2-A = 1.
TABLE2-B = 1.
<b>TABLE2-C = 2</b>.
APPEND TABLE2.
TABLE2-A = 1.
TABLE2-B = 1.
<b>TABLE2-C = 3</b>.
APPEND TABLE2.
NEW-LINE.
ULINE (13).
WRITE: / SY-VLINE, <b>'A'</b>, SY-VLINE, <b>'B'</b>, SY-VLINE, <b>'C'</b>, SY-VLINE.
NEW-LINE.
ULINE (13).
<b>LOOP AT TABLE1.</b>
<b>READ TABLE TABLE2 WITH KEY C = TABLE1-C.</b>
<b>IF SY-TABIX <> 0.</b>
WRITE: / SY-VLINE, <b>TABLE1-A</b>, SY-VLINE, <b>TABLE1-B</b>, SY-VLINE, <b>TABLE1-C</b>, SY-VLINE.
ELSE.
WRITE: / SY-VLINE, <b>TABLE1-A</b>, SY-VLINE, <b>' '</b>, SY-VLINE, <b>TABLE1-C</b>, SY-VLINE.
ENDIF.
ENDLOOP.
NEW-LINE.
ULINE (13).
Regards,
Allan Cristian
‎2007 Sep 26 9:15 PM
Thanks Allan,
Just for the laughs, from you code
LOOP AT TABLE1.
READ TABLE TABLE2 WITH KEY C = TABLE1-C.
IF SY-TABIX <> 0. "shouldnt it be sy-subrc <>0.I didnt realise it was sy-tabix and spent a lot of time thinking why is it going into the if statement even when sy-subrc was equal to zero.
Anyways it works and thank you very much.
‎2007 Sep 26 9:44 PM
Hi Kumar,
U can use SY-SUBRC or SY-TABIX;
<b>If An entry was read. </b>
<b>SY-SUBRC = 0: </b> and
<b>SY-TABIX is set to the index of the entry;</b>
<b>If No entry was read. </b>
<b>SY-SUBRC = 4;</b> and
<b>SY-TABIX is undefined; so SY-TABIX = 0.</b>
obs: Srry, not good in English...
Good Luck!
Regards,
Allan Cristian
‎2007 Sep 27 12:34 PM
Allan,
I have changed that to sy-subrc and a small other change and the code is working perfectly for me.
Thanks for you help.
Kumar.