Mr. R : I'm stuck in this ALV Grid. Help!!!

Question:
Hi,,
Thankx for showing me a way to achieve ITAB creation in runtime. But I'm stuck at the point where I'm to display the ITAB in an ALV grid struc.
Pl. note the code below. and if possible Guide me.
The field catalogue is already populated with the correct fields but the data comes in the line format.
The code :
APPEND 'DATA : BEGIN OF df_str OCCURS 0,' TO code.
LOOP AT ikey.
CONCATENATE ikey-fld 'like' tabnm INTO code_c
SEPARATED BY space.
CONCATENATE code_c '-' ikey-fld ',' INTO code_c.
APPEND code_c TO code.
ENDLOOP.
APPEND 'END OF df_str.' TO code.
APPEND 'DATA: BEGIN OF t_upld OCCURS 0,' TO code.
APPEND 'source(2048) TYPE c,' TO code.
APPEND 'END OF t_upld.' TO code.
APPEND 'GET REFERENCE OF df_str INTO dref.' TO code.
APPEND 'dref1 = dref.' TO code.
APPEND 'ASSIGN dref1->* TO <fs_wa>.' TO code.
* Upload Data to t_upld.
APPEND 'Call Function ''WS_UPLOAD'' Exporting ' TO code.
APPEND ' Filename = p_file' TO code.
APPEND ' FileType = ''DAT''' TO code.
APPEND 'Tables Data_Tab = t_upld. ' TO code.
*
APPEND 'LOOP AT t_upld INTO <FS_WA>.' TO code.
APPEND 'ASSIGN COMPONENT SY-INDEX OF STRUCTURE <FS_WA> TO <FS_FN>.'
TO code.
APPEND 'ENDLOOP.' TO code.
CONCATENATE 'DATA: IDKEY LIKE INDX-SRTFD VALUE '
'''' 'KEYVALUE' '''' '.' INTO code_c.
APPEND code_c TO code.
APPEND 'export t_upld to memory id idkey.' TO code.
APPEND 'ENDFORM.' TO code.
* Genetrate the runtime form.
GENERATE SUBROUTINE POOL code NAME prog MESSAGE msg
LINE lin WORD wrd
OFFSET off.
PERFORM runtmprg IN PROGRAM (prog).
IMPORT t_upld FROM MEMORY ID 'KEYVALUE'.
*-*-*-
CALL METHOD calv_grid->refresh_table_display .
*-*-*-
The prg gives a dump at *-*-*- . T-upld has'nt had the correct structure as dynamically sought.
Thankx in advance.
Regds.
SAPODA.
Answer:
Hi,
Creating an ABAP using this method should the be the last thing that you do once everything has been tested. I would suggest that you create a test program for ALV creation first and once that's working you should be to continue with your quest.
Have a look at /forums/viewtopic.php?t=1816
for example code.
Regards
Dr Sidewalk.
Answer:
Thankx Mr. Sidewalk !!
But the actual problem is I had to create the ITAB for the ALV grid during the run time. The user would select the fields and upload file in the selected field format which in turn should be shown in the Grid. Its part of this code. My only problem is to now get the data onto the Grid. Coz' the dynamic ITAB has to identified.
If any solution please revert back.
Regds.
SAPODA.
Answer:
There are a number of solutions here.
1). Allow the user to select the fields to be displayed. Create a program that loads all data into an itab but sets the ALV to display only those selected fields. This can be done dynamically and inlcuded into the method that you are using.
2). Create the itab by appending the required structure to code. You may have to use field symbols for this.
Sorry, I don't have time to give code examples at the moment.
Dr Sidewalk.
Answer:
Take a look at this,
u can do the alv grid by using another function
REPORT z_alv_demo .
*-----------------------------------------------------------------------
* TABLES
*-----------------------------------------------------------------------
TABLES: kna1.
*-----------------------------------------------------------------------
* TYPES DECLARATION
*-----------------------------------------------------------------------
TYPE-POOLS: slis.
*-----------------------------------------------------------------------
* DATA DECLARATION
*-----------------------------------------------------------------------
data: v_repid like sy-repid.
*-----------------------------------------------------------------------
* WORK AREAS
*-----------------------------------------------------------------------
DATA: BEGIN OF wa_kna1,
kunnr LIKE kna1-kunnr,
name1 LIKE kna1-name1,
name2 LIKE kna1-name2,
mark(1) type c,
END OF wa_kna1.
data: wa_variant type DISVARIANT.
data: wa_layout type slis_layout_alv.
*-----------------------------------------------------------------------
* INTERNAL TABLES
*-----------------------------------------------------------------------
DATA: itab_kna1 LIKE TABLE OF wa_kna1.
data: itab_fieldcat type SLIS_T_FIELDCAT_ALV.
*-----------------------------------------------------------------------
* INITIALIZATION
*-----------------------------------------------------------------------
initialization.
v_repid = sy-repid.
perform initialize_fieldcat.
perform initialize_variant.
perform initialize_layout.
*-----------------------------------------------------------------------
* START-OF-SELECTION
*-----------------------------------------------------------------------
START-OF-SELECTION.
SELECT kunnr name1 name2
INTO TABLE itab_kna1 FROM kna1.
*-----------------------------------------------------------------------
* END-OF-SELECTION
*-----------------------------------------------------------------------
END-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = v_repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* i_structure_name =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
IS_LAYOUT = wa_layout
IT_FIELDCAT = itab_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
I_SAVE = 'A'
IS_VARIANT = wa_variant
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IT_ALV_GRAPHICS =
* IT_ADD_FIELDCAT =
* IT_HYPERLINK =
* I_HTML_HEIGHT_TOP =
* I_HTML_HEIGHT_END =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = itab_kna1
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form initialize_fieldcat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form initialize_fieldcat.
data: wa_fieldcat type SLIS_FIELDCAT_ALV.
refresh: itab_fieldcat.
wa_fieldcat-col_pos = '1'.
wa_fieldcat-tabname = 'ITAB_KNA1'.
wa_fieldcat-fieldname = 'KUNNR'.
wa_fieldcat-seltext_m = 'Cust.no.'.
append wa_fieldcat to itab_fieldcat.
clear wa_fieldcat.
wa_fieldcat-col_pos = '2'.
wa_fieldcat-tabname = 'ITAB_KNA1'.
wa_fieldcat-fieldname = 'NAME1'.
wa_fieldcat-ref_fieldname = 'NAME1'.
wa_fieldcat-ref_tabname = 'KNA1'.
wa_fieldcat-ddictxt = 'M'.
append wa_fieldcat to itab_fieldcat.
clear wa_fieldcat.
endform. " initialize_fieldcat
*&---------------------------------------------------------------------*
*& Form initialize_variant
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form initialize_variant.
clear wa_variant.
wa_variant-report = v_repid.
endform. " initialize_variant
*&---------------------------------------------------------------------*
*& Form initialize_layout
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form initialize_layout.
clear wa_layout.
wa_layout-box_fieldname = 'MARK'.
wa_layout-box_tabname = 'ITAB_REC'.
endform. " initialize_layout
**************************************
Field cat is the field that u want to show in output screen.
Answer:
Why are you not using the dynamic itab method to create a dynamic itab at runtime?
Answer:
Why are you not using the dynamic itab method to create a dynamic itab at runtime?
Thanks a lot! JJWOLOS... It works like a charm. I used it and I am so happy with the results and all the possibilites it opens for dynamic programing.
Once again, thanks.
RR
Answer:
can someone here pls update me as to what is the method to create a dynamic itab...
_________________
codeboy

More Articles:

Writting a select when you don't know the structure?
Why are variants in client '000' created unintentionally?
Table Control?
LSMW?
Maximum number of entries in an internal table?
Can't use AT NEW in a loop?