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

Select query

Former Member
0 Likes
1,239

Hi All ,

I want all the data into one internal table ,Can anyone please give me the select query for this

Get VKONT from table FKKVKP for given BP into table T_FKKVKP.

Get VKTYP from table FKKVK for all VKONT in table T_FKKVKP into table T_FKKVK.

Get TEXT from table TFK002AT for all VKTYP in table T_FKKVK into table T_TFK002AT.

Collect distinct VKTYP and TEXT into a final table and display as output.

Thanks in advance for your time & effort !

1 ACCEPTED SOLUTION
Read only

dev_parbutteea
Active Contributor
0 Likes
1,143

Hi,

select vkont

into T_FKKVKP

from FKKVKP

where <b>conditions</b>

if sy-subrc = 0.

select VKTYP

into T_FKKVK.

from FKKVK

for all entries in T_FKKVKP

where vkont = T_FKKVKP-vkont

if sy-subrc = 0.

select TEXT

into T_TFK002AT

from TFK002AT

for all entries in T_FKKVK.

where vktyp = T_FKKVK.-vktyp

if sy-subrc = 0.

<b>sort tables</b>

loop at T_FKKVKP into wa_area1.

read table T_FKKVK into wa_area2 with key vkont = wa_area1-vkont

binary search.

if sy-subrc =0.

read table T_TFK002AT into wa_area3 with key vktyp = wa_area1-vktyp

binary search.

if sy-subrc = 0.

move wa_area2-vktyp to wa_final-vktyp.

move wa_area3-text to wa_final-text.

collect wa_final into final

endloop.

8 REPLIES 8
Read only

Former Member
0 Likes
1,143

Hi,

Check this code..

************************************************************************

  • INTERNAL TABLE AND WORK AREA FOR FIELDS IN ANLA TABLE

************************************************************************

DATA : BEGIN OF itab_anla OCCURS 0,

bukrs LIKE anla-bukrs, "Company Code

anln1 LIKE anla-anln1, "Main Asset Number

anln2 LIKE anla-anln2, "Asset Subnumber

anlkl LIKE anla-anlkl, "Asset class

END OF itab_anla.

DATA : wa_anla LIKE LINE OF itab_anla.

************************************************************************

  • INTERNAL TABLE AND WORK AREA FOR FIELDS IN ZCUST_TABLE_01 TABLE *

************************************************************************

DATA : BEGIN OF itab_zcust_table_01 OCCURS 0,

bukrs LIKE zcust_table_01-bukrs,

anln1 LIKE zcust_table_01-anln1,

anln2 LIKE zcust_table_01-anln2,

anlkl LIKE zcust_table_01-anlkl,

z001 LIKE zcust_table_01-z001,

z002 LIKE zcust_table_01-z002,

z003 LIKE zcust_table_01-z003,

z004 LIKE zcust_table_01-z004,

END OF itab_zcust_table_01.

DATA : wa_zcust_table_01 LIKE LINE OF itab_zcust_table_01.

************************************************************************

  • OUTPUT INTERNAL TABLE *

************************************************************************

DATA : BEGIN OF itab_output OCCURS 0,

bukrs LIKE anla-bukrs,

anln1 LIKE anla-anln1,

anln2 LIKE anla-anln2,

anlkl LIKE anla-anlkl,

z001 LIKE zcust_table_01-z001,

z002 LIKE zcust_table_01-z002,

z003 LIKE zcust_table_01-z003,

z004 LIKE zcust_table_01-z004,

END OF itab_output.

***********************************************************************

SELECTION-SCREEN BEGIN OF BLOCK input WITH FRAME TITLE text-t01.

SELECT-OPTIONS : bukrs FOR anla-bukrs,

anln1 FOR anla-anln1,

anln2 FOR anla-anln2,

anlkl FOR anla-anlkl.

SELECTION-SCREEN END OF BLOCK input.

***********************************************************************

  • SELECTING RECORDS FORM ANLA TABLE *

***********************************************************************

SELECT bukrs anln1 anln2 anlkl

FROM anla INTO CORRESPONDING FIELDS OF TABLE itab_anla

WHERE bukrs IN bukrs AND

anln1 IN anln1 AND

anln2 IN anln2 AND

anlkl IN anlkl.

***********************************************************************

SELECT bukrs anln1 anln2 anlkl z001 z002 z003 z004

FROM zcust_table_01 INTO CORRESPONDING FIELDS OF

TABLE itab_zcust_table_01.

**********************************************************************

  • <b>MOVING RECORDS FROM TWO ITAB TO ONE FINAL ITAB </b>

**********************************************************************

LOOP AT itab_anla.

READ TABLE itab_zcust_table_01 WITH KEY

bukrs = itab_anla-bukrs

anln1 = itab_anla-anln1

anln2 = itab_anla-anln2

anlkl = itab_anla-anlkl BINARY SEARCH.

IF sy-subrc EQ 0.

MOVE-CORRESPONDING itab_anla TO itab_output.

MOVE-CORRESPONDING itab_zcust_table_01 TO itab_output.

APPEND itab_output.

ENDIF.

ENDLOOP.

<b>Regards,

jackie..</b>

Read only

Former Member
0 Likes
1,143

Hi

Declare a ITAB as I_FINAL.

select VKONT from FKKVKP into table T_FKKVKP where BP in S_BP.

Loop at T_FKKVKP .

move corresponding T_FKKVKP to i_final.

select single VKTYP from FKKVK into T_FKKVK-vktyp

where VKONT = T_FKKVKP-vkont.

if sy-subrc = 0.

i_final-vktyp = T_FKKVK-vktyp.

endif.

select single TEXT from TFK002AT into T_TFK002AT-text

where VKTYP = T_FKKVKP-VKTYP and spras = sy-langu.

if sy-subrc = 0.

i_final-TEXT = T_TFK002AT-text.

endif.

append i_final.

clear i_final.

endloop.

Loop at i_final.

write 😕 i_final.

endloop.

Reward points if useful

Regards

Anji

Read only

dev_parbutteea
Active Contributor
0 Likes
1,144

Hi,

select vkont

into T_FKKVKP

from FKKVKP

where <b>conditions</b>

if sy-subrc = 0.

select VKTYP

into T_FKKVK.

from FKKVK

for all entries in T_FKKVKP

where vkont = T_FKKVKP-vkont

if sy-subrc = 0.

select TEXT

into T_TFK002AT

from TFK002AT

for all entries in T_FKKVK.

where vktyp = T_FKKVK.-vktyp

if sy-subrc = 0.

<b>sort tables</b>

loop at T_FKKVKP into wa_area1.

read table T_FKKVK into wa_area2 with key vkont = wa_area1-vkont

binary search.

if sy-subrc =0.

read table T_TFK002AT into wa_area3 with key vktyp = wa_area1-vktyp

binary search.

if sy-subrc = 0.

move wa_area2-vktyp to wa_final-vktyp.

move wa_area3-text to wa_final-text.

collect wa_final into final

endloop.

Read only

Former Member
0 Likes
1,143

HI Sharma,

Try this code after creating an itab that contain all the fields u want

select pvkont kvktyp t~text into corresponding fields of table itab

from ( (t_fkkvkp as p inner join T_FKKVK as k

on pvkont = kvkont)

inner join t_tfk002at as t

on kvbtyp = tvbtyp))

Reward points If Found useful

Regards

Sarath

Read only

Former Member
0 Likes
1,143

Hi,

use

select distinct FKKVKvktyp TFK002ATtext into table itab_final

from FKKVKP join FKKVKK on ( specify the fields) join TFK002AT on (specify field).

Thanks

Sandeep

Reward if helpful

Read only

0 Likes
1,143

Hi All ,

Thanks for your help , But I want my final data should come in Internal table

t_fp .

Program is like this :

******DECLARE RANGES

RANGES: r_buspartner FOR but000-partner .

***

*Types Declaration

TYPES : BEGIN OF d_fkkvkp ,

gpart TYPE fkkvkp-gpart,

vkont TYPE fkkvkp-vkont,

END OF d_fkkvkp .

TYPES : BEGIN OF d_fp ,

gpart TYPE fkkvkp-gpart,

vktyp TYPE fkkvk-vktyp ,

text TYPE tfk002at-text ,

END OF d_fp .

TYPES : BEGIN OF d_fkkvk ,

vkont TYPE fkkvkp-vkont,

vktyp TYPE fkkvk-vktyp,

END OF d_fkkvk .

TYPES : BEGIN OF d_tfk002at ,

text TYPE tfk002at-text,

vktyp TYPE fkkvk-vktyp,

END OF d_tfk002at .

*******************************************************************

***DECLARE INTERNAL TABLES

DATA : t_fkkvkp TYPE d_fkkvkp OCCURS 0 ,

t_fp TYPE d_fp OCCURS 0 ,

t_fkkvk TYPE d_fkkvk OCCURS 0 ,

t_tfk002at TYPE d_tfk002at OCCURS 0 ,

t_contract_account_types TYPE zbapi_contract_account_type OCCURS 0 .

**************************************************************************

****DECLARE WORK AREAS

DATA : wa_contract_account_types TYPE zbapi_contract_account_type,

wa_fkkvkp TYPE d_fkkvkp ,

wa_fp TYPE d_fp ,

wa_fkkvk TYPE d_fkkvk ,

wa_tfk002at TYPE d_tfk002at .

**********************************************************************************************

      • FILL RANGES

IF NOT buspartner IS INITIAL.

r_buspartner-sign = 'I'.

r_buspartner-low = buspartner.

r_buspartner-option = 'EQ'.

IF buspartner CA '*+'.

r_buspartner-option = 'CP'.

ELSE.

r_buspartner-option = 'EQ'.

ENDIF.

APPEND r_buspartner.

ENDIF.

*********************************************************************************

Selec query which I have writtten

SELECT vkont gpart

FROM

fkkvkp

INTO CORRESPONDING FIELDS OF

TABLE p_t_fkkvkp

WHERE

gpart IN p_r_buspartner.

SELECT

vktyp vkont

FROM

fkkvk

INTO CORRESPONDING FIELDS OF

TABLE t_fkkvk

FOR ALL ENTRIES IN t_fkkvkp

WHERE

vkont = t_fkkvkp-vkont.

SELECT

vktyp text

FROM tfk002at

INTO CORRESPONDING FIELDS OF

TABLE t_tfk002at

FOR ALL ENTRIES IN t_fkkvk

WHERE spras = sy-langu

AND vktyp = t_fkkvk-vktyp.

Read only

0 Likes
1,143

Hi ,

Can anyone please send me select query.

Read only

0 Likes
1,143

Hi All ,

Thanks for your time & effort ..points rewarded!