Posted: Sat Sep 22, 2007 6:14 pm Post subject: ALV with Dynamic Table
Code:
REPORT zcreate_dynamic_alv.
DATA: t_ftab TYPE lvc_t_fcat,
wa_ftab TYPE lvc_s_fcat,
t_file TYPE REF TO data,
wa_file TYPE REF TO data.
FIELD-SYMBOLS: <table> TYPE STANDARD TABLE,
<data> TYPE ANY.
* Below, the fields for the dynamic table are appended to the fieldcatelog.
* Just in the way we build field catelog for ALV output
wa_ftab-tabname = 'MARC'.
wa_ftab-fieldname = 'MATNR'.
APPEND wa_ftab TO t_ftab.
wa_ftab-fieldname = 'WERKS'.
APPEND wa_ftab TO t_ftab.
wa_ftab-fieldname = 'PSTAT'.
APPEND wa_ftab TO t_ftab.
wa_ftab-fieldname = 'LVORM'.
APPEND wa_ftab TO t_ftab.
wa_ftab-fieldname = 'BWTTY'.
APPEND wa_ftab TO t_ftab.
*Call OOPs method to create the structure
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = t_ftab
IMPORTING
ep_table = t_file.
ASSIGN t_file->* TO <table>. "This is the table
CREATE DATA wa_file LIKE LINE OF <table>. "Create a structure for the table
ASSIGN wa_file->* TO <data>. "Assigning into Field Symbols
*Selection into table
SELECT matnr werks pstat lvorm bwtty UP TO 10 ROWS FROM marc INTO TABLE <table>.
*In general case, you will be creating the dynamic table when you are not knowing
* how many fields you will need to select or consider in the program.
*Which means you will be using a dynamic select. Since this is an example program,
* I've hard coded the FIELDS in the select statement
*Just in case you need to loop at the table, do the following
LOOP AT <table> ASSIGNING <data>.
ENDLOOP.
*Call function module for ALV output
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
it_fieldcat_lvc = t_ftab
TABLES
t_outtab = <table>
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.
**********
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>,
<dyn_field>,
<dyn_table1> TYPE STANDARD TABLE,
<dyn_wa1>,
<dyn_field1>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
ifc TYPE lvc_t_fcat,
xfc TYPE lvc_s_fcat,
dy_table1 TYPE REF TO data,
dy_line1 TYPE REF TO data.
DATA: BEGIN OF list_protype OCCURS 0,
extwg LIKE mara-extwg,
END OF list_protype.
DATA: show_protype LIKE list_protype OCCURS 0 WITH HEADER LINE.
DATA: l_title TYPE string.
CONSTANTS: tab_key TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
**********************
DATA: it_fieldcat TYPE slis_t_fieldcat_alv,
wa_fieldcat LIKE LINE OF it_fieldcat,
wa_layout TYPE slis_layout_alv,
it_extab TYPE slis_t_extab.
DATA: name(20).
DATA: BEGIN OF it_item OCCURS 0,
vkorg LIKE vbak-vkorg, "Sales organization
vtweg LIKE vbak-vtweg, "distribution channel
kunnr LIKE vbak-kunnr, "sold-to party
name1 LIKE kna1-name1, "Customer name
bstnk LIKE vbak-bstnk, "PO number
vbeln LIKE vbak-vbeln, "sales document
erdat LIKE vbak-erdat, "document date
extwg LIKE mara-extwg, "product type
posnr LIKE vbap-posnr, "order item
matnr LIKE vbap-matnr, "Material
kwmeng LIKE vbap-kwmeng, "Order Qty
vrkme LIKE vbap-vrkme, "Sales Unit
netwr LIKE vbap-netwr, "Order Net Value
waerk LIKE vbap-waerk, "Currency
za_kbetr LIKE konv-kbetr, "ZA01 %Discount
ra_kbetr LIKE konv-kbetr, "RA00 %Discount
za_kwert LIKE konv-kwert, "ZA01 discount amount
ra_kwert LIKE konv-kwert, "ZA01 discount amount
knumv LIKE vbak-knumv, "condition number
vbtyp LIKE vbak-vbtyp, "SO type
END OF it_item.
DATA: BEGIN OF it_output OCCURS 0,
vkorg(4) TYPE c, "Sales organization
vtweg(2), "distribution channel
kunnr(10), "sold-to party
name1(35), "Customer name
bstnk(20), "PO number
vbeln(10), "sales document
erdat(8), "document date
extwg(18), "product type
posnr(6), "order item
matnr(18), "Material
kwmeng(15), "Order Qty
vrkme(3), "Sales Unit
netwr(15), "Order Net Value
waerk(13), "Currency
za_kbetr(11), "ZA01 %Discount
ra_kbetr(11), "RA00 %Discount
za_kwert(13), "ZA01 discount amount
ra_kwert(13), "ZA01 discount amount
END OF it_output.
DATA: BEGIN OF it_op_sum OCCURS 0,
vkorg(4) TYPE c, "Sales organization
vtweg(2), "distribution channel
kunnr(10), "sold-to party
name1(35), "Customer name
bstnk(20), "PO number
vbeln(10), "sales document
erdat(8), "document date
extwg(18), "product type
kwmeng(15), "Order Qty
vrkme(3), "Sales Unit
netwr(15), "Order Net Value
waerk(13), "Currency
za_kwert(13), "ZA01 discount amount
ra_kwert(13), "ZA01 discount amount
END OF it_op_sum.
TYPES: BEGIN OF ty_sum,
vkorg LIKE vbak-vkorg, "Sales organization
vtweg LIKE vbak-vtweg, "distribution channel
kunnr LIKE vbak-kunnr, "sold-to party
name1 LIKE kna1-name1, "Customer name
bstnk LIKE vbak-bstnk, "PO number
* vbeln like vbak-vbeln, "sales document
erdat LIKE vbak-erdat, "document date
extwg LIKE mara-extwg, "product type
kwmeng LIKE vbap-kwmeng, "Order Qty
vrkme LIKE vbap-vrkme, "Sales Unit
netwr LIKE vbap-netwr, "Order Net Value
waerk LIKE vbap-waerk, "Currency
za_kwert LIKE konv-kwert, "ZA01 discount amount
ra_kwert LIKE konv-kwert, "ZA01 discount amount
END OF ty_sum.
DATA: BEGIN OF sel OCCURS 0,
knumv LIKE vbrk-knumv,
posnn LIKE vbfa-posnn,
vbtyp_n LIKE vbfa-vbtyp_n,
END OF sel.
DATA: wa_sum TYPE ty_sum.
DATA: BEGIN OF it_protype OCCURS 0,
extwg LIKE mara-extwg,
netwr LIKE vbap-netwr,
END OF it_protype.
DATA: it_sum TYPE STANDARD TABLE
OF ty_sum INITIAL SIZE 10 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK fname1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_vkorg FOR vbak-vkorg DEFAULT '4800' TO '4801',
s_vtweg FOR vbak-vtweg DEFAULT '31',
s_kunnr FOR vbak-kunnr,
s_erdat FOR vbak-erdat DEFAULT sy-datum,
s_extwg FOR mara-extwg.
SELECTION-SCREEN END OF BLOCK fname1.
SELECTION-SCREEN BEGIN OF BLOCK fname3 WITH FRAME TITLE text-003.
PARAMETER: rbank RADIOBUTTON GROUP rd1,
rintake RADIOBUTTON GROUP rd1 DEFAULT 'X',
rinvoice RADIOBUTTON GROUP rd1.
SELECTION-SCREEN END OF BLOCK fname3.
SELECTION-SCREEN BEGIN OF BLOCK fname4 WITH FRAME TITLE text-004.
PARAMETER: rabap RADIOBUTTON GROUP rd2 DEFAULT 'X',
rfile RADIOBUTTON GROUP rd2,
v_file LIKE rlgrap-filename
DEFAULT 'c:tempacdelco-statis.txt',
rserver RADIOBUTTON GROUP rd2,
v_server TYPE filepath-pathintern
DEFAULT '/icsdata/acdelco/acdelco-statis.txt'.
SELECTION-SCREEN END OF BLOCK fname4.
START-OF-SELECTION.
PERFORM selectdata.
PERFORM output.
*&---------------------------------------------------------------------*
*& Form selectdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selectdata .
IF rbank = 'X'.
PERFORM selectrbank.
ELSEIF rintake = 'X'.
PERFORM selectintake.
ELSEIF rinvoice = 'X'.
PERFORM selectrinvoice.
ENDIF.
ENDFORM. " selectdata
*&---------------------------------------------------------------------*
*& Form output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM output .
IF rabap = 'X'.
PERFORM outputabap.
ELSEIF rfile = 'X'.
PERFORM outputfile.
ELSEIF rserver = 'X'.
PERFORM outputfile.
ENDIF.
ENDFORM. " output
*&---------------------------------------------------------------------*
*& Form selectintake
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selectintake .
* select basic order data
PERFORM selectbasic.
LOOP AT it_item.
* get customer name
SELECT SINGLE kna1~name1 FROM kna1
INTO it_item-name1
WHERE kna1~kunnr = it_item-kunnr.
* If SO is 'H'(return)
IF it_item-vbtyp = 'H'.
it_item-netwr = - it_item-netwr.
ENDIF.
MODIFY it_item.
MOVE-CORRESPONDING it_item TO wa_sum.
COLLECT wa_sum INTO it_sum.
ENDLOOP.
PERFORM dynamictable.
ENDFORM. " selectintake
*&---------------------------------------------------------------------*
*& Form selectrbank
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selectrbank .
PERFORM selectbasic.
LOOP AT it_item.
* get customer name
SELECT SINGLE kna1~name1 FROM kna1
INTO it_item-name1
WHERE kna1~kunnr = it_item-kunnr.
* clear: it_item-kwmeng, it_item-netwr.
DATA: t_kwmeng LIKE it_item-kwmeng,
t_netwr LIKE it_item-netwr.
* When SD document category (VBAK~VBTYP) is ??(Order)
IF it_item-vbtyp = 'C'.
* If VBFA-VBTYP_N = M (invoice) ++
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (t_kwmeng, t_netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'M'.
* If VBFA-VBTYP_N = N (invoice cancellation) --
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (t_kwmeng, t_netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'N'.
IF it_item-kwmeng = 0.
DELETE it_item.
CONTINUE.
ENDIF.
* When SD document category (VBAK~VBTYP) is H (Returns)
ELSEIF it_item-vbtyp = 'H'.
* If VBFA-VBTYP_N = O (Credit memo) ++
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (t_kwmeng, t_netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'O'.
* If VBFA-VBTYP_N = S (Credit memo cancellation)
CLEAR: t_kwmeng, t_netwr.
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (t_kwmeng, t_netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'S'.
IF it_item-kwmeng = 0.
DELETE it_item.
CONTINUE.
ENDIF.
ENDIF.
* If SO is 'H'(return)
IF it_item-vbtyp = 'H'.
it_item-netwr = - it_item-netwr.
ENDIF.
MODIFY it_item.
MOVE-CORRESPONDING it_item TO wa_sum.
COLLECT wa_sum INTO it_sum.
ENDLOOP.
PERFORM dynamictable.
ENDFORM. " selectrbank
*&---------------------------------------------------------------------*
*& Form selectrinvoice
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selectrinvoice .
PERFORM selectbasic.
LOOP AT it_item.
* get customer name
SELECT SINGLE kna1~name1 FROM kna1
INTO it_item-name1
WHERE kna1~kunnr = it_item-kunnr.
CLEAR: it_item-kwmeng, it_item-netwr.
DATA: t_kwmeng LIKE it_item-kwmeng,
t_netwr LIKE it_item-netwr.
* When SD document category (VBAK~VBTYP) is ??(Order)
IF it_item-vbtyp = 'C'.
* If VBFA-VBTYP_N = M (invoice) ++
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (it_item-kwmeng, it_item-netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'M'.
* If VBFA-VBTYP_N = N (invoice cancellation) --
CLEAR: t_kwmeng, t_netwr.
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (t_kwmeng, t_netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'N'.
* M (invoice) - N (invoice cancellation)
it_item-kwmeng = it_item-kwmeng - t_kwmeng.
it_item-netwr = it_item-netwr - t_netwr.
IF it_item-kwmeng = 0.
DELETE it_item.
CONTINUE.
ENDIF.
* When SD document category (VBAK~VBTYP) is H (Returns)
ELSEIF it_item-vbtyp = 'H'.
* If VBFA-VBTYP_N = O (Credit memo) ++
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (it_item-kwmeng, it_item-netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'O'.
* If VBFA-VBTYP_N = S (Credit memo cancellation)
CLEAR: t_kwmeng, t_netwr.
SELECT SUM( vbfa~rfmng ) SUM( vbrp~netwr )
FROM vbfa JOIN vbrp ON vbfa~vbeln = vbrp~vbeln AND vbfa~posnn =
vbrp~posnr
INTO (t_kwmeng, t_netwr)
WHERE vbfa~vbelv = it_item-vbeln
AND vbfa~posnv = it_item-posnr
AND vbfa~vbtyp_n = 'S'.
* O (Credit memo) - S (Credit memo cancellation)
it_item-kwmeng = it_item-kwmeng - t_kwmeng.
it_item-netwr = it_item-netwr - t_netwr.
IF it_item-kwmeng = 0.
DELETE it_item.
CONTINUE.
ENDIF.
ENDIF.
* If SO is 'H'(return)
IF it_item-vbtyp = 'H'.
it_item-netwr = - it_item-netwr.
ENDIF.
MODIFY it_item.
MOVE-CORRESPONDING it_item TO wa_sum.
COLLECT wa_sum INTO it_sum.
ENDLOOP.
PERFORM dynamictable.
ENDFORM. " selectrinvoice
*&---------------------------------------------------------------------*
*& Form selectbasic
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selectbasic .
* select basic order data
SELECT vbak~kunnr vbap~kwmeng vbak~vbeln
vbap~posnr vbap~matnr mara~extwg vbap~netwr vbap~waerk vbak~vbtyp
FROM vbak JOIN vbap ON vbap~vbeln = vbak~vbeln JOIN mara ON vbap~matnr =
mara~matnr
INTO CORRESPONDING FIELDS OF TABLE it_item
WHERE vbak~vkorg NE '4802'
AND vbak~vkorg NE '4803'
AND ( vbak~vbtyp EQ 'C' OR vbak~vbtyp EQ 'H')
AND vbap~abgru = ''
AND vbak~vkorg IN s_vkorg
AND vbak~vtweg IN s_vtweg
AND vbak~kunnr IN s_kunnr
AND vbak~erdat IN s_erdat
AND mara~extwg IN s_extwg
AND vbap~abgru EQ ''
AND mara~extwg NE ''.
ENDFORM. " selectbasic
*&---------------------------------------------------------------------*
*& Form outputabap
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM outputabap .
DEFINE a_fieldcat.
clear wa_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-seltext_l = &2.
* wa_fieldcat-just = 'C'.
* wa_fieldcat-outputlen = &3.
wa_fieldcat-key = &3.
append wa_fieldcat to it_fieldcat.
END-OF-DEFINITION.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
is_layout = wa_layout
it_fieldcat = it_fieldcat
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = <dyn_table>.
* 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.
ENDFORM. " outputabap
*&---------------------------------------------------------------------*
*& Form outputfile
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM outputfile .
*loop at show_protype.
* concaterate
*endloop.
******* print head **********
CLEAR xfc.
REFRESH ifc.
IF sy-subrc = 0.
MESSAGE s999(fr) WITH 'Downloaded succesfully'.
ENDIF.
ENDIF.
ENDFORM. " outputfile
*&--------------------------------------------------------------------*
*& Form dynamictable
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM dynamictable.
LOOP AT it_sum.
MOVE-CORRESPONDING it_sum TO it_protype.
APPEND it_protype.
MOVE-CORRESPONDING it_sum TO list_protype.
APPEND list_protype.
ENDLOOP.
DATA period(25) TYPE c.
READ TABLE s_erdat INDEX 1.
CONCATENATE s_erdat-low '~' s_erdat-high INTO period.
SORT list_protype BY extwg.
DELETE ADJACENT DUPLICATES FROM list_protype.
*************** sold to party, name **********
xfc-fieldname = 'kunnr'.
xfc-datatype = 'CHAR'.
xfc-intlen = '10'.
APPEND xfc TO ifc.
xfc-fieldname = 'name1'.
xfc-datatype = 'CHAR'.
xfc-intlen = '35'.
APPEND xfc TO ifc.
xfc-fieldname = 'period'.
xfc-datatype = 'CHAR'.
xfc-intlen = '25'.
APPEND xfc TO ifc.
LOOP AT list_protype.
MOVE list_protype TO show_protype.
APPEND show_protype.
REPLACE '/' WITH '' INTO list_protype-extwg.
REPLACE '-' WITH '' INTO list_protype-extwg.
CONDENSE list_protype-extwg NO-GAPS.
TYPE-POOLS : abap.
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>,
<dyn_field>.
DATA: dy_table TYPE REF TO data,
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM get_structure.
PERFORM create_dynamic_itab.
**********Creates a dyanamic internal table**********
PERFORM get_data.
PERFORM write_out.
*&--------------------------------------------------------------------*
*& Form get_structure
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM get_structure.
DATA : idetails TYPE abap_compdescr_tab,
xdetails TYPE abap_compdescr.
DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
* DATA : ref_table_des TYPE REF TO "cl_abap_structdescr
* CL_ABAP_TABLEDESCR.
* Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails[] = ref_table_des->components[].
LOOP AT idetails INTO xdetails.
CLEAR xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
APPEND xfc TO ifc.
ENDLOOP.
* TYPES: BEGIN OF typ_01,
* clo1,
* clo2,
* END OF typ_01.
*
* DATA: it_01 TYPE TABLE OF typ_01.
* DATA: wa_01 TYPE typ_01.
* wa_01 = '11'.
* APPEND wa_01 TO it_01.
* ref_table_des ?=
* cl_abap_typedescr=>describe_by_data( it_01 ).
ENDFORM. "get_structure
*&--------------------------------------------------------------------*
*& Form create_dynamic_itab
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM create_dynamic_itab.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
* Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
ENDFORM. "create_dynamic_itab
*&--------------------------------------------------------------------*
*& Form get_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM get_data.
* Select Data from table.
SELECT * INTO TABLE <dyn_table>
FROM (p_table).
ENDFORM. "get_data
"get_data
*&--------------------------------------------------------------------*
*& Form write_out
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM write_out.
* Write out data from table.
LOOP AT <dyn_table> INTO <dyn_wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <dyn_field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ <dyn_field>.
ELSE.
WRITE: <dyn_field>.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.