06-09-2014 9:13 AM
i have a requirement to retrieve only selected fields from db table. i have to use this code with jco, so i can't go with ALV. my requirement is as follows,
list of fields from mara and marc table will be shown as checkbox and user will be allowed to select the required fields. that selected fields only retrieved from the table. please gimme some idea.
Thanks in advance.
06-09-2014 9:17 AM
06-09-2014 9:29 AM
Hi,
See if this article from IBM can help.
Using dynamic Open SQL to perform joins on SAP transparent tables
Regards.
06-09-2014 9:42 AM
Hii
data : lv_tab(8) type c ,
lv_from(200) type c ,
lv_where(1024) type c ,
lv_fld(200) type c,
lv_temp_kbetr type konp-kbetr .
concatenate 'mara' into lv_tab .
concatenate lv_tab ' inner join marc on ' into lv_from separated by
space .
concatenate 'mara~matnr = marc~matnr' into lv_from .
loop at itab where chk = 'X'.
concatenate lv_fld itab-fld into lv_fld.
endloop.
select single (lv_fld)
into lv_temp_kbetr
from (lv_from)
where WERKS = <input>.
Kindly check the code above, it would be like that.
Many Thanks/ HImanshu Gupta
06-09-2014 10:02 AM
06-09-2014 10:10 AM
Hi Remya,
The fields that need to be selected can be given in an internal table and can be called in the Open SQL statements. Following is a sample code. You can modify this as you required.
TABLES ekko.
TYPES : BEGIN OF TY_FIELDS,
FNAME TYPE LVC_FNAME.
TYPES : END OF TY_FIELDS.
DATA : GT_FIELDS type table of TY_FIELDS,
WA_FIELDS like line of GT_FIELDS.
DATA : lt_ekko TYPE TABLE OF ekko.
SELECT-OPTIONS s_ebeln FOR ekko-ebeln.
CLEAR WA_FIELDS.
WA_FIELDS-FNAME = 'EBELN'.
APPEND WA_FIELDS TO IT_FIELDS.
CLEAR WA_FIELDS.
WA_FIELDS-FNAME = 'BUKRS'.
APPEND WA_FIELDS TO IT_FIELDS.
CLEAR WA_FIELDS.
WA_FIELDS-FNAME = 'BSTYP'.
APPEND WA_FIELDS TO IT_FIELDS.
SELECT (GT_FIELDS) FROM ekko INTO CORRESPONDING FIELDS OF TABLE lt_ekko
WHERE ebeln IN s_ebeln.
Based on your requirement, you need to modify your code.
Regards,
Abijith
06-09-2014 10:47 AM
HI Remya,
Try this..
TYPES: BEGIN OF STYPE_FIELDS,
FIELDNAME TYPE NAME_FELD,
END OF STYPE_FIELDS.
DATA: G_T_MSEG_FIELDS TYPE TABLE OF STYPE_FIELDS,
G_S_MSEG_FIELDS TYPE STYPE_FIELDS.
G_S_MSEG_FIELDS-FIELDNAME = 'BUSTM'.
APPEND G_S_MSEG_FIELDS TO G_T_MSEG_FIELDS.
G_S_MSEG_FIELDS-FIELDNAME = 'BWART'.
APPEND G_S_MSEG_FIELDS TO G_T_MSEG_FIELDS.
**Similarly u can modify the internal table with required fields to fetch according to ur requiremen
SELECT (g_t_mseg_fields)
INTO CORRESPONDING FIELDS OF TABLE g_t_mseg_lean
FROM mseg.
Regards
Sreekanth