Application Development 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: 

Dynamic selction tables and fields

Former Member
0 Kudos

Hi Folks,

I have an issue while creating program using field symbols My requirement is I need to develop a program to get table counts with respect to username and date .For that I wrote below program

REPORT ZDYNAMICFIELDS.

PARAMETERS: TABNAM TYPE DD03L-TABNAME.

PARAMETERS: FLD1 TYPE DD03L-FIELDNAME.

PARAMETERS: FLD2 TYPE DD03L-FIELDNAME.

DATA: FIELD1 TYPE REF TO DATA,

FIELD2 TYPE REF TO DATA.

CREATE DATA: FIELD1 TYPE (FLD1),

FIELD2 TYPE (FLD2).

*FIELD-SYMBOLS: <FLD1> TYPE ANY,

  • <FLD2> TYPE ANY.

*

ASSIGN: FIELD1-> TO <FLD1>,

  • FIELD2->* TO <FLD2>.

DATA: BEGIN OF ITAB,

FIELD1 LIKE FIELD1,

FIELD2 LIKE FIELD2,

END OF ITAB.

DATA: ITAB1 TYPE REF TO DATA.

CREATE DATA: ITAB1 TYPE TABLE OF ITAB.

FIELD-SYMBOLS: <FS_IT> type standard table.

ASSIGN: ITAB1->* TO <FS_IT> .

DATA: STR TYPE STRING.

CONCATENATE FLD1 FLD2 INTO STR SEPARATED BY ''.

CONDENSE STR.

SELECT (STR) FROM (TABNAM) INTO TABLE <FS_IT> UP TO 1000 ROWS.

write:/ 'total number of records' ,sy-dbcnt.

But this is not working for DATE and TIME fileld,

Can anyone please help me to resolve this issue....

Thanks & Regards,

Sreedhar Tammineni.

1 ACCEPTED SOLUTION

Jelena
Active Contributor
0 Kudos

Uhm... I'm not sure what to say... It seems that you are confusing the concept of dynamic field assignment and with the dynamic specification in SQL statement. IMHO you don't even need to ASSIGN anything but just create a string for FROM/WHERE (read Help) based on the parameters.

Also your SELECT statement will not get the number of records if there are more than 1000 records in the table. And, on top of that, there is COUNT operator; you don't need to actually select the data to get the record count.

There is an excellent session on dynamic programming in eLearning here, I suggest you look it up. Also reading ABAP Help might, err, help.

P.S. Also please use tags for the code.

Edited by: Jelena Perfiljeva on Mar 26, 2010 5:25 PM

4 REPLIES 4

Jelena
Active Contributor
0 Kudos

Uhm... I'm not sure what to say... It seems that you are confusing the concept of dynamic field assignment and with the dynamic specification in SQL statement. IMHO you don't even need to ASSIGN anything but just create a string for FROM/WHERE (read Help) based on the parameters.

Also your SELECT statement will not get the number of records if there are more than 1000 records in the table. And, on top of that, there is COUNT operator; you don't need to actually select the data to get the record count.

There is an excellent session on dynamic programming in eLearning here, I suggest you look it up. Also reading ABAP Help might, err, help.

P.S. Also please use tags for the code.

Edited by: Jelena Perfiljeva on Mar 26, 2010 5:25 PM

Former Member
0 Kudos

Hi Jaleena,

Thanks for your quick repply

Actually that is sample code I wrote that code to get the count numbers loaded into tables.For example today I have loaded 2000 sales records into SAP for checking this I need to go vbak and need to give today's date and username instead of that i need one program input para meters as table name ,username, date output as table counts .

Thanks & Regards,

Sreedhar.

Former Member
0 Kudos

Hi Sreedhar,

Are you trying to achieve something like this?

SELECT * FROM (p_table) INTO TABLE <gt_itab>.
  READ TABLE <gt_itab> ASSIGNING <gs_result>
          WITH KEY (lw_key_field1) = p_cond1
                   (lw_key_field2) = p_cond2
                   (lw_key_field3) = p_cond3
                   BINARY SEARCH.
  IF sy-subrc = 0.
    WRITE / 'Record found.'.
  ELSE.
    WRITE / 'No record found.'.
  ENDIF.

where p_table, p_cond1 etc., are selection screen parameters? I found such example in the link below

http://www.divulgesap.com/blog.php?p=ODM=

Hope it helps.

Regards,

Ravi

Former Member
0 Kudos

Hi Sridhar,

Refer to the below link which has coding for developing a generalized sub-routines to import and export data to any DB table.

http://www.divulgesap.com/blog.php?p=OTQ=

It will give you an idea of how to use dynamic internal tables.

Regards,

Ravi