‎2008 Feb 14 9:55 AM
I have this input field called IO_TABLE and a button. When the user key in the database name into IO_TABLE and press the button, the records/data in the database will be written out.
Here is my codes:
REPORT ZA_FIELD.
DATA IO_TABLE(30) TYPE C.
FIELD-SYMBOLS: <FS_INPUT> TYPE ANY,
<FS_ITAB> TYPE ANY TABLE.
START-OF-SELECTION.
CALL SCREEN 9000.
MODULE STATUS_9000 OUTPUT.
SET PF-STATUS 'SCREEN_9000'.
SET TITLEBAR 'TITLE_9000'.
ENDMODULE. "STATUS_9002 OUTPUT
MODULE USER_COMMAND_9000 INPUT.
IF SY-UCOMM = 'SAVE'.
ELSEIF SY-UCOMM = 'EXIT' OR SY-UCOMM = 'CANCEL'.
LEAVE PROGRAM.
ELSEIF SY-UCOMM = 'PUSH'.
ASSIGN IO_TABLE TO <FS_INPUT>.
SELECT * FROM <FS_INPUT> INTO TABLE <FS_ITAB>.
WRITE <FS_ITAB> .
" SUBMIT ZFINAL_2.
ENDIF.
ENDMODULE. "USER_COMMAND_9002 INPUT
As shown <FS_INPUT> is the field symbol that store the value of IO_TABLE. What am I suppose to replace my dynamic internal table for my codes?
dynamic internal table is needed to display out the values in it.
However, I got this error at my statement as shown at my link http://img337.imageshack.us/img337/3791/screenez4.png
What am I suppose to do to solve this problem?
‎2008 Feb 14 1:11 PM
Unfortunately -- it's not not quite that simple although still easy enough.
In order to use a dynamic table you need to create a field catalog first for the fields, build the dynamic table and then populate it.
Here's how to do it.
1) define some data we'll need for the process.
* Define any structure
TYPES: BEGIN OF s_elements,
vbeln TYPE vapma-vbeln,
posnr TYPE vapma-posnr,
matnr TYPE vapma-matnr,
kunnr TYPE vapma-kunnr,
werks TYPE vapma-werks,
vkorg TYPE vapma-vkorg,
vkbur TYPE vapma-vkbur,
status TYPE c,
END OF s_elements.
* end of your structure
DATA:wa_elements TYPE s_elements.
DATA: ord_nr TYPE vapma-vbeln,
mat_nr TYPE vapma-matnr,
cus_nr TYPE vapma-kunnr.
DATA lr_rtti_struc TYPE REF TO cl_abap_structdescr .
DATA:
zog LIKE LINE OF lr_rtti_struc->components .
DATA:
zogt LIKE TABLE OF zog,
wa_it_fldcat TYPE lvc_s_fcat,
it_fldcat TYPE lvc_t_fcat ,
dy_line TYPE REF TO data,
dy_table TYPE REF TO data.
DATA: dref TYPE REF TO data.
FIELD-SYMBOLS: <fs> TYPE ANY,
<dyn_table> TYPE STANDARD TABLE,
<dyn_wa>.
2) now build the fcat, create the dynamic table and populate it.
START-OF-SELECTION.
*now I want to build a field catalog
* First get your data structure into a field symbol
CREATE DATA dref TYPE s_elements.
ASSIGN dref->* TO <fs>.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
* Now get the structure details into a table.
* table zogt[] contains the structure details
* From which we can build the field catalog
zogt[] = lr_rtti_struc->components.
LOOP AT zogt INTO zog.
CLEAR wa_it_fldcat.
wa_it_fldcat-fieldname = zog-name .
wa_it_fldcat-datatype = zog-type_kind.
wa_it_fldcat-inttype = zog-type_kind.
wa_it_fldcat-intlen = zog-length.
wa_it_fldcat-decimals = zog-decimals.
wa_it_fldcat-coltext = zog-name.
wa_it_fldcat-lowercase = 'X'.
IF wa_it_fldcat-fieldname = 'VBELN'.
wa_it_fldcat-hotspot = 'X'.
ENDIF.
APPEND wa_it_fldcat TO it_fldcat.
ENDLOOP.
*
* You can perform any modifications / additions to your field catalog
* here such as your own column names etc.
* Now using the field catalog created above we can
* build a dynamic table
* and populate it
* First build the dynamic table
* the table will contain entries for
* our structure defined at the start of the program
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
* Now fill our table with data
SELECT vbeln posnr matnr kunnr werks vkorg vkbur
UP TO 200 ROWS
FROM vapma
INTO CORRESPONDING FIELDS OF TABLE <dyn_table>.
3) now if you want to say use a "classical" table all you need to do is
define a standard table of type s_elements and code something simple like
my_itab[] = <dyn_table>.
Then you could get the <dyn_table> after creation into yoour own table for further processing.
You can also display the <dyn_table> in a grid simply via some type of code such as
CALL METHOD grid1->set_table_for_first_display
EXPORTING is_layout = struct_grid_lset
CHANGING
it_outtab = <dyn_table>
it_fieldcatalog = it_fldcat.
You'll need to "instantiate" the class (have grid1 as a ref to cl_gui_alv_grid) and do some other work --that's a topic for another post - however since you now have the field catalog and the table in principle if you need a grid display you've done 90% of the work.
cheers
jimbo