11-03-2007 9:20 AM
Hi,
Has anyone got experience with dynamical programming?
I have got the following problem:
i have got a loop over an internal talbe. In this loop I'm making another loop over an internal customizing table. There are names of some tables stored, and the data of theses tables should be displayed in an alv tree.
Therfore i created with create data a dynamical internal table and a dynamical workarea. Now i want to loop over the tables which are stored in the customizing table. This wokrs fine, but i have the problem, that i cannot use a where statement in the loop with the dynamical internal table and work area. When activating i get the message, that this is not possible with dynamical types.
Has anyone of you got an idea how i could use a where statement in my dynamical loop? I need too use the key of the first found entry of the superior loop.
Thanks for your help in advance.
null
null
11-04-2007 4:18 PM
Hello
Presumably dynamic WHERE conditions are not possible with LOOP - ENDLOOP.
However, you can use dynamic conditions with the <b>READ TABLE</b> statement. Have a look at the following sample report <b>ZUS_SDN_DYNAMIC_PROG</b>.
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_DYNAMIC_PROG
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_dynamic_prog.
DATA:
gd_msg TYPE bapi_msg,
gd_field TYPE string,
gd_where_1 TYPE string,
gd_where_2 TYPE string,
gd_where_clause TYPE string,
gd_data TYPE REF TO data.
FIELD-SYMBOLS:
<gt_knb1> TYPE table,
<gs_knb1> TYPE ANY,
<gs_vbak> TYPE ANY,
<gd_fld> TYPE ANY.
START-OF-SELECTION.
CREATE DATA gd_data TYPE TABLE OF ('KNB1').
ASSIGN gd_data->* TO <gt_knb1>.
CONCATENATE '''' '1000' '''' INTO gd_where_clause.
CONCATENATE 'BUKRS =' gd_where_clause
INTO gd_where_clause
SEPARATED BY space.
SELECT * FROM knb1 INTO TABLE <gt_knb1>
WHERE (gd_where_clause).
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING
i_structure_name = 'KNB1'
TABLES
t_outtab = <gt_knb1>
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.
gd_field = 'KUNNR'.
gd_where_1 = '0000001000'. " customer 1000
" Dynamic selection of itab records
READ TABLE <gt_knb1> ASSIGNING <gs_knb1>
WITH KEY (gd_field) = gd_where_1.
IF ( syst-subrc = 0 ).
CONCATENATE '''' gd_where_1 '''' INTO gd_where_clause.
CONCATENATE 'KUNNR =' gd_where_clause
INTO gd_where_clause
SEPARATED BY space.
CREATE DATA gd_data TYPE ('VBAK').
ASSIGN gd_data->* TO <gs_vbak>.
SELECT SINGLE * FROM vbak INTO <gs_vbak>
WHERE (gd_where_clause).
IF ( syst-subrc = 0 ).
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <gs_vbak> TO <gd_fld>.
IF ( <gd_fld> IS ASSIGNED ).
CONCATENATE 'SalesOrder =' <gd_fld>
INTO gd_msg
SEPARATED BY space.
MESSAGE gd_msg TYPE 'I'.
ENDIF.
ENDIF.
ENDIF.
** LOOP AT <gt_knb1> ASSIGNING <gs_knb1>
** WHERE (gd_field) = gd_where_1.
**
** ENDLOOP. " does not work -> syntax error
END-OF-SELECTION.
Regards
Uwe
11-05-2007 7:40 AM
hi,
thanks for your answer. i found the following coding in the sap help. do you know if this works in the dynamic loop:
PARAMETERS: column TYPE c LENGTH 8,
value TYPE c LENGTH 30.
DATA spfli_wa TYPE spfli.
DATA cond_syntax TYPE string.
CONCATENATE column '= value'
INTO cond_syntax SEPARATED BY space.
TRY.
SELECT SINGLE *
FROM spfli
INTO spfli_wa
WHERE (cond_syntax).
CATCH cx_sy_dynamic_osql_error.
MESSAGE `Wrong WHERE condition!` TYPE 'I'.
ENDTRY.
or is my only chance to realize this with a read table statement? then i will have to implement a read table statement in a do statement and read the internal table with an index and add 1 to the index after every pass.
11-05-2007 8:17 AM
Select statements do not work with internal tables, only with database tables.