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

Dynamic SQL in abap

Former Member
0 Likes
1,958

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.

6 REPLIES 6
Read only

Former Member
0 Likes
1,130

Use for all entries query.

Read only

rosenberg_eitan
Active Contributor
0 Likes
1,130

Hi,

See if this article from IBM can help.

Using dynamic Open SQL to perform joins on SAP transparent tables

Regards.

Read only

himanshu_gupta13
Product and Topic Expert
Product and Topic Expert
0 Likes
1,130

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

Read only

VenkatRamesh_V
Active Contributor
0 Likes
1,130

Hi,

Use Field symbols.

Regards,

Venkat

Read only

former_member196651
Contributor
0 Likes
1,130

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

Read only

former_member202818
Active Contributor
0 Likes
1,130

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