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

Specifying Dynamic database table

Former Member
0 Likes
525

Hi,

I have a requirement where

your are having a selection screen say tables .Based on the user input,i must display the structure of the table.

If the user gives ekko in the selection screen.my output should have all the fields of the sturcture ekko.It dynamically varies.Suppose all if he gives mseg,it must display the mseg sturcture.Can anyone help me plz.The coding i had done is

REPORT YCOMPLEXREQ .

type-pools : SLIS.

tables : DD02L.

parameter : p_table type DD02L-tabname.

data : ws_table like dd02l-tabname.

field-symbols : <f1> type any table.

data : itab like table of ws_table with header line.

select single tabname

from dd02l

into ws_table

where tabname = p_table.

assign ws_table to <f1>.

select single * from (ws_table)

into <f1>

.

but it goes to dump saying the output field can not hold the entire data ..

<b></b>good answers will be rewarded with points

4 REPLIES 4
Read only

Former Member
0 Likes
486

check this code....

u need to alter some part of the code....

&----


*& Report ZLOAD_DYNAMIC_UPLOAD *

*& *

&----


REPORT zload_dynamic_upload MESSAGE-ID zf_cd .

TYPES t_itab1 TYPE zfalsmex_tabline.

DATA: it_itab1 TYPE STANDARD TABLE OF t_itab1 WITH HEADER LINE,

it_itab_h TYPE STANDARD TABLE OF t_itab1 WITH HEADER LINE,

v_count TYPE i,

v_flag.

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

  • SELECTION-SCREEN *

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

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.

PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY,

p_tabnam LIKE dd02l-tabname OBLIGATORY.

SELECTION-SCREEN END OF BLOCK b.

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

  • AT SELECTION SCREEN ON VALUE-REQUEST

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

*----Gettting the local file with f4 button

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_local_file_name USING p_file.

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

  • AT SELECTION-SCREEN ON P_TABNAM

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

AT SELECTION-SCREEN ON p_tabnam.

PERFORM at_selectionscreen_on_p_tabnam.

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

  • START-OF-SELECTION *

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

START-OF-SELECTION.

PERFORM excel_to_it.

PERFORM dynamic_it_table.

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

  • END-OF-SELECTION *

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

END-OF-SELECTION.

IF v_flag IS INITIAL.

WRITE: / v_count,text-002,p_tabnam.

ELSEIF v_flag = 'N'.

WRITE: / text-003.

ENDIF. "if v_flag is initial.

&----


*& Form GET_LOCAL_FILE_NAME

&----


  • text

----


  • -->P_P_FILE text

----


FORM get_local_file_name USING p_p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

CHANGING

file_name = p_file.

ENDFORM. " GET_LOCAL_FILE_NAME

&----


*& Form AT_SELECTIONSCREEN_ON_P_TABNAM

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM at_selectionscreen_on_p_tabnam .

DATA: v_tabname LIKE dd02l-tabname.

SELECT SINGLE tabname INTO v_tabname FROM dd02l WHERE

tabname = p_tabnam.

IF sy-subrc <> 0.

MESSAGE e004 WITH text-004.

ENDIF.

ENDFORM. " AT_SELECTIONSCREEN_ON_P_TABNAM

&----


*& Form excel_to_it

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM excel_to_it .

DATA: BEGIN OF it_field OCCURS 0,

fieldname LIKE dd03l-fieldname,

END OF it_field.

DATA: BEGIN OF it_dd03l OCCURS 0,

tabname LIKE dd03l-tabname,

fieldname LIKE dd03l-fieldname,

END OF it_dd03l.

DATA: BEGIN OF it_field_count OCCURS 0,

fieldname LIKE dd03l-fieldname,

count TYPE i,

END OF it_field_count.

DATA: l_disp(256).

CALL FUNCTION 'ZF_ALSM_EXCEL_TO_INTERNAL_TAB'

EXPORTING

filename = p_file

i_begin_col = 1

i_begin_row = 1

i_end_col = 256

i_end_row = 1

TABLES

intern = it_itab_h

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

  • Checking of EXCEL Fieldnames with Tablename Field Names

LOOP AT it_itab_h.

TRANSLATE it_itab_h-value TO UPPER CASE.

MODIFY it_itab_h.

it_field-fieldname = it_itab_h-value.

APPEND it_field.

CLEAR it_field.

ENDLOOP.

SELECT tabname

fieldname

INTO TABLE it_dd03l

FROM dd03l

WHERE tabname = p_tabnam.

SORT it_dd03l BY fieldname.

LOOP AT it_field.

READ TABLE it_dd03l WITH KEY fieldname = it_field-fieldname

BINARY SEARCH.

IF sy-subrc <> 0 .

v_flag = 'N'.

WRITE: / text-005.

STOP.

ENDIF.

CLEAR: it_dd03l.

ENDLOOP.

  • Controlling the Repeating Field Names in EXCEL Header

LOOP AT it_field.

READ TABLE it_field_count WITH KEY fieldname = it_field-fieldname.

IF sy-subrc NE 0.

it_field_count-fieldname = it_field-fieldname.

it_field_count-count = it_field_count-count + 1.

APPEND it_field_count.

ELSE.

it_field_count-count = it_field_count-count + 1.

MODIFY it_field_count INDEX sy-tabix.

CONCATENATE it_field_count-fieldname

'is Repeating in EXCEL Header.'

INTO l_disp SEPARATED BY space. "#EC

WRITE: / l_disp.

WRITE: / 'So, Please Correct the EXCEL Header and Restart Again.'.

v_flag = 'N'.

STOP.

ENDIF.

CLEAR: it_field_count.

ENDLOOP.

CALL FUNCTION 'ZF_ALSM_EXCEL_TO_INTERNAL_TAB'

EXPORTING

filename = p_file

i_begin_col = 1

i_begin_row = 2

i_end_col = 256

i_end_row = 65536

TABLES

intern = it_itab1

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

ENDFORM. " excel_to_it

&----


*& Form dynamic_it_table

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM dynamic_it_table .

TYPE-POOLS: slis.

DATA: it_fcat TYPE lvc_t_fcat, "slis_t_fieldcat_alv,

is_fcat LIKE LINE OF it_fcat,

ls_layout TYPE slis_layout_alv,

it_fieldcat TYPE lvc_t_fcat,

is_fieldcat LIKE LINE OF it_fieldcat,

new_table TYPE REF TO data,

new_line TYPE REF TO data,

ob_cont_alv TYPE REF TO cl_gui_custom_container,

ob_alv TYPE REF TO cl_gui_alv_grid,

vg_campos(255) TYPE c,

i_campos LIKE TABLE OF vg_campos,

vg_campo(30) TYPE c,

vg_tables(60) TYPE c.

FIELD-SYMBOLS: <l_table> TYPE table,

<l_line> TYPE ANY,

<l_field> TYPE ANY.

LOOP AT it_itab_h.

is_fcat-fieldname = it_itab_h-value.

is_fcat-ref_field = it_itab_h-value.

is_fcat-ref_table = p_tabnam.

APPEND is_fcat TO it_fcat.

ENDLOOP.

*... Creating the dynamic internal table According to Excel Header

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fcat

IMPORTING

ep_table = new_table.

*... Create a new line

ASSIGN new_table->* TO <l_table>.

CREATE DATA new_line LIKE LINE OF <l_table>.

ASSIGN new_line->* TO <l_line>.

FIELD-SYMBOLS : <fs_dyn_table> TYPE ANY.

DATA : w_index TYPE i.

IF it_itab1[] IS INITIAL.

v_flag = 'N'.

WRITE: / text-006.

STOP.

ELSE.

SORT it_itab1 BY zrow zcol.

LOOP AT it_itab1.

MOVE : it_itab1-zcol TO w_index.

ASSIGN COMPONENT w_index OF STRUCTURE <l_line> TO <fs_dyn_table>.

MOVE it_itab1-value TO <fs_dyn_table>.

AT END OF zrow.

APPEND <l_line> TO <l_table>.

ENDAT.

ENDLOOP.

ENDIF.

      • Start of Creating Table work area

DATA: BEGIN OF it_fieldname OCCURS 0,

tabname LIKE dd03l-tabname,

fieldname LIKE dd03l-fieldname,

position LIKE dd03l-position,

END OF it_fieldname.

SELECT tabname

fieldname

position

INTO TABLE it_fieldname

FROM dd03l

WHERE tabname = p_tabnam.

  • delete it_fieldname[] where fieldname = '.INCLUDE'.

DELETE it_fieldname[] WHERE fieldname+0(1) = '.'.

SORT it_fieldname BY position.

DATA: it_fcat_tw TYPE lvc_t_fcat, "slis_t_fieldcat_alv,

is_fcat_tw LIKE LINE OF it_fcat,

ls_layout_tw TYPE slis_layout_alv,

it_fieldcat_tw TYPE lvc_t_fcat,

is_fieldcat_tw LIKE LINE OF it_fieldcat,

new_table_tw TYPE REF TO data,

new_line_tw TYPE REF TO data,

ob_cont_alv_tw TYPE REF TO cl_gui_custom_container,

ob_alv_tw TYPE REF TO cl_gui_alv_grid,

vg_campos_tw(255) TYPE c,

i_campos_tw LIKE TABLE OF vg_campos,

vg_campo_tw(30) TYPE c,

vg_tables_tw(60) TYPE c.

FIELD-SYMBOLS: <l_table_tw> TYPE table,

<l_line_tw> TYPE ANY,

<l_field_tw> TYPE ANY.

LOOP AT it_fieldname.

is_fcat_tw-fieldname = it_fieldname-fieldname.

is_fcat_tw-ref_field = it_fieldname-fieldname.

is_fcat_tw-ref_table = p_tabnam.

APPEND is_fcat_tw TO it_fcat_tw.

ENDLOOP.

*... Create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = it_fcat_tw

IMPORTING

ep_table = new_table_tw.

*... Create a new line

ASSIGN new_table_tw->* TO <l_table_tw>.

CREATE DATA new_line_tw LIKE LINE OF <l_table_tw>.

ASSIGN new_line_tw->* TO <l_line_tw>.

      • End of Creating Table work area

CLEAR: v_count.

LOOP AT <l_table> INTO <l_line>.

MOVE-CORRESPONDING <l_line> TO <l_line_tw>.

MODIFY (p_tabnam) FROM <l_line_tw>.

IF sy-subrc = 0.

v_count = v_count + 1.

ENDIF.

CLEAR: <l_line>,<l_line_tw>.

ENDLOOP.

COMMIT WORK.

ENDFORM. " it_dynamic_it_table

Read only

Former Member
0 Likes
486

Use the function module DDIF_TABL_GET. Pass the NAME as the table name.

REPORT ZTEST.

parameters p_name type ddobjname.

start-of-selection.

call function 'DDIF_TABL_GET'

exporting

name = p_name

tables

dd03p_tab = gt_table.

loop at gt_table.

write: / gt_table-fieldname.

endloop.

Manoj

Read only

0 Likes
486

i am ready to give away points.but my requirement is using dynamic programming .Can u look at my program and tell me what should be done at the last select statement.Because when i give as into<f1> .it doesnot hold the data of say ekko table..what should be done...

Read only

0 Likes
486

When you use ASSIGN ws_table TO <f1> only the contents of the field ws_table is getting assigned to the field symbol <f1> and not the structure of the table which is the content of ws_table. Hence what is actually getting assigned is the width of the definition of ws_table (dd02l-tabname) which is 30 characters. This width is not sufficient to hold the structure of EKKO table. So the program goes into a runtime error.