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,623

Moderator message: please use a more informative subject in future

i have a scenario like this:

Depending on the condition record number KNUMH of table KONH,i want to fect the data kvewe and kotabnr from KONH.

then concatenate kvewe and kotabnr into one variable.

now,need to fecth language,ddtext fields from dd02t table using the variable which has a value after concatenation.

this ddtext will then be populated in the field of final internal table for fieldcatalog display

kidly help in thie kind of code.

thanks in adv!!

Edited by: Matt on Dec 23, 2008 12:11 PM

12 REPLIES 12
Read only

Former Member
0 Likes
1,479

Hi Tanisha,

First of all apply

select single kvewe kotabnr

from <dbtab>

into (var1 , var2) ***< Please check the syntax here I dont have system right now

where <col> = <val> .

concatenate var1 var2 into vaR3 .

select <text>

from <dbtab1>

into <var4>

where (ur condition goes here......)

modify itab transporting <var4>

where (ur condition goes here)

thanks

sahil

Read only

Former Member
0 Likes
1,479

Hi,

Fetch ur data from KONH table as per ur requirement.

Add one field like what u have said variable with kvewe , kotabnr and variable.

Now concatenate those two fields and put it in the variable and do the next selection on dd02t .

Read only

Former Member
0 Likes
1,479

I think you need to write self join for this , can you write back what is the condition to fetch the record,

say for example you need to fetch data from table1.

like this

select A.field1 , A.field2 from table1 into ( v1 ,v2 )

from A as Table1 , B as table1

where A.field3 = B.field3

now you have the value concate it into one and fetch the desired value from other table.

Read only

Former Member
0 Likes
1,479

Am i doing correctly or some modifications,kindly suggest:-)

Types:begin of ty_konh,

knumh like konh-knumh,

kvewe like konh-kvewe,

kotabnr like konh-kotabnr,

end of ty_konh,

Begin of ty_dd02t,

TABNAME like DD02T-TABNAME,

DDLANGUAGE like DD02T-DDLANGUAGE,

DDTEXT like DD02T-DDTEXT,

end of ty_DD02T.

data:it_konh TYPE STANDARD TABLE OF ty_konh WITH HEADER LINE,

wa_konh TYPE ty_konh,

it_DD02T TYPE STANDARD TABLE OF ty_DD02T WITH HEADER LINE,

wa_DD02T TYPE ty_DD02T.

data:v_text type c.

clear wa_konh,wa_DD02T.

select single knumh

kvewe

kotabnr

from konh

into it_konh

where kvewe = wa_konh-kvewe

and kotabnr = wa_konh-kotabnr.

if sy-subrc = 0.

concatenate wa_konh-kvewe wa_konh-kotabnr into v_text.

select single TABNAME

DDLANGUAGE

DDTEXT

from DD02T

into it_DD02T

where DDLANGUAGE = SY-LANGU

and ddtext = wa_dd02t-ddtext.

wa_dd02t-ddtext = v_text.

if sy-subrc = 0.

ITAB-L_ddtext = wa_dd02t-ddtext.

append itab.

endif.

endif.

Read only

0 Likes
1,479

Hi Tanisha ,

I think the code is fine...

Thnks

Sahil

Read only

Former Member
0 Likes
1,479

Hi,

Here I have used two internal table it_tab,it_tab1.

it_tab1-final table,

structure of it_tab and wa_tab: kvewe kotabnr var text
structure of it_tab1 and wa_tab1: tabname ddlanguage ddtext

Logic:

SELECT kvewe
         kotabnr
         FROM konh
         INTO TABLE it_tab
         WHERE knumh = so_knmuh. "<=your selection value

  LOOP AT it_tab INTO wa_tab.
    CONCATENATE wa_tab-kvewe wa_tab-kotabnr INTO w_var.
    wa_tab-var = w_var.
    MODIFY it_tab FROM wa_tab INDEX sy-tabix. "Assign the concatd value
  ENDLOOP.

  SELECT tabname
         ddlanguage
         ddtext
         FROM dd02t
         INTO TABLE it_tab1
         FOR ALL ENTRIES IN it_tab
         WHERE tabname = it_tab-var.

  LOOP AT it_tab INTO wa_tab.
    READ TABLE it_tab1 INTO wa_tab1 WITH
    KEY tabname.
    wa_tab-text = wa_tab1-ddtext.
    MODIFY it_tab FROM wa_tab INDEX sy-tabix."Assign ddtext
  ENDLOOP.

Hope this helps you.

Regards,

Manoj Kumar P

Read only

0 Likes
1,479

thanks for the reply but how can i add var to the strcuture ann what could be its type.

Also,how can i equate the tabname field of dd02t with the one that you said like.

kindly reply with clarity.

Read only

Former Member
0 Likes
1,479

Hi Tanisha,

itab-var should be of type tabname(becoz we gonna store tabname of dd02t).

I have made some changes, now it will give better understanding i guess.

Revert in case of any issues.

SELECT kvewe
         kotabnr
         FROM konh
         INTO TABLE it_tab
         WHERE knumh = so_knmuh. "<=your selection value
 
  LOOP AT it_tab INTO wa_tab.
    CONCATENATE 'T' wa_tab-kotabnr INTO w_var."Getting table name
"For example if kotabnr = 003 the conditon table is 'T003' 
    wa_tab-var = w_var.
    MODIFY it_tab FROM wa_tab INDEX sy-tabix. "Assign the concatd value
  ENDLOOP.
 
"Now you have two keys to fetch value from DD02T
" tabname = conctenated value as4vers = kvewe
  SELECT tabname
         ddlanguage
         ddtext
         FROM dd02t
         INTO TABLE it_tab1
         FOR ALL ENTRIES IN it_tab
         WHERE tabname = it_tab-var and
               as4vers = it_tab-kvewe. "This gvs wht type of tabl it is
"Example A-pricing  E-rebate
    

  LOOP AT it_tab INTO wa_tab.
    READ TABLE it_tab1 INTO wa_tab1 WITH
    KEY tabname.
    wa_tab-text = wa_tab1-ddtext.
    MODIFY it_tab FROM wa_tab INDEX sy-tabix."Assign ddtext
  ENDLOOP.

Regards,

Manoj Kumar P

Read only

0 Likes
1,479

my code is not getting executed.am i doing it right.

Also,i am modifying my final table after these code.

kindly suggest.

Types:begin of ty_konh,

knumh like konh-knumh,

kvewe like konh-kvewe,

kotabnr like konh-kotabnr,

var like DD02t-tabname,

end of ty_konh,

Begin of ty_dd02t,

TABNAME like DD02T-TABNAME,

DDLANGUAGE like DD02T-DDLANGUAGE,

DDTEXT like DD02T-DDTEXT,

end of ty_DD02T.

data:it_konh TYPE STANDARD TABLE OF ty_konh WITH HEADER LINE,

wa_konh TYPE ty_konh,

it_DD02T TYPE STANDARD TABLE OF ty_DD02T WITH HEADER LINE,

wa_DD02T TYPE ty_DD02T.

data:w_var type c.

clear: wa_konh,wa_DD02T.

select single knumh

kvewe

kotabnr

from konh

into it_konh

where knumh = i_konv-knumh

and kvewe = wa_konh-kvewe

and kotabnr = wa_konh-kotabnr.

loop at it_konh into wa_konh.

concatenate wa_konh-kvewe wa_konh-kotabnr into wa_konh-var.

*wa_konh-var = w_var.

MODIFY it_konh from wa_konh INDEX sy-tabix.

endloop.

select TABNAME

DDLANGUAGE

DDTEXT

from DD02T

into table it_DD02T

for all entries in it_konh

where tabname = it_konh-var.

loop at itab.

read table it_konh with key wa_konh-var.

read table it_DD02t into wa_DD02T with KEY tabname = wa_konh-var .

wa_konh-var = wa_dd02t-ddtext.

*modify itab index sy-tabix.

endloop.

itab-l_ddtext = wa_DD02T-ddtext.

*append itab.

Read only

0 Likes
1,479

Hi Tanisha,

Have you tried the code which i have posted in the you previous question for the same query .

Cheers

Joginder

Read only

matt
Active Contributor
0 Likes
1,479

Please use a more informative subject in future

Read only

Former Member
0 Likes
1,479

Hi,

Refer the below code,

TABLES: dd02t.
TYPES:BEGIN OF ty_konh,
knumh LIKE konh-knumh,
kvewe LIKE konh-kvewe,
kotabnr LIKE konh-kotabnr,
var LIKE dd02t-tabname,
text LIKE dd02t-ddtext, "Add this field
END OF ty_konh,

BEGIN OF ty_dd02t,
tabname LIKE dd02t-tabname,
ddlanguage LIKE dd02t-ddlanguage,
ddtext LIKE dd02t-ddtext,
END OF ty_dd02t.

DATA:it_konh TYPE STANDARD TABLE OF ty_konh,
wa_konh TYPE ty_konh,
it_dd02t TYPE STANDARD TABLE OF ty_dd02t WITH HEADER LINE,
wa_dd02t TYPE ty_dd02t.

DATA:w_ind TYPE i.
CLEAR: wa_konh,wa_dd02t.

SELECT knumh
kvewe
kotabnr
FROM konh

INTO TABLE it_konh
WHERE knumh = '0000000002' "Give some meaningful variables such as
                           "select options
AND kvewe = 'A' "wa_konh is initial here
AND kotabnr = '003'.

LOOP AT it_konh INTO wa_konh.
  CONCATENATE wa_konh-kvewe wa_konh-kotabnr INTO wa_konh-var.
  MODIFY it_konh FROM wa_konh INDEX sy-tabix.
ENDLOOP.

SELECT tabname
ddlanguage
ddtext
FROM dd02t
INTO TABLE it_dd02t
FOR ALL ENTRIES IN it_konh
WHERE tabname = it_konh-var.

LOOP AT it_konh INTO wa_konh. "Changed here
  w_ind = sy-tabix.
  READ TABLE it_dd02t INTO wa_dd02t
  WITH KEY tabname = wa_konh-var "Note for unique value you have
           ddlanguage = 'E'.         "use language also here.E-english
  wa_konh-text = wa_dd02t-ddtext.
  MODIFY it_konh FROM wa_konh INDEX w_ind.
ENDLOOP.

LOOP AT it_konh INTO wa_konh.
  WRITE: / wa_konh-knumh,
         / wa_konh-kvewe,
         / wa_konh-kotabnr,
         / wa_konh-var,
         / wa_konh-text.
ENDLOOP.