Application Development 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: 

Help for dynamic selection

Former Member
0 Kudos

Hello guy,

I want to dynamically search for the occurrence of certain words in each data record(each field) in each table. Below is my code

Parameters: p_tabname like dd02l-tabname.


SELECT * FROM dd02l
  INTO  TABLE itab
  WHERE as4local = 'A'
   AND tabname = p_tabname

 LOOP AT itab INTO w_tab.
CREATE DATA ref_itab TYPE STANDARD TABLE OF (w_tab-tabname).
    ASSIGN ref_itab->* TO <fs_itab>.
   
CREATE DATA ref_wa TYPE (w_tab-tabname).
    ASSIGN ref_wa->* TO <fs_wa>.

 SELECT * FROM (w_tab-tabname)
    INTO CORRESPONDING FIELDS OF TABLE <fs_itab>.
   DESCRIBE TABLE  itab. "check if the table contains entries.
   IF sy-tfill > 0.
LOOP AT <fs_itab> INTO <fs_wa>. " loop at each table that contains entries and search for the strings or characters
SEARCH <fs_wa> for 'bbbb_' and '3456*' and '8970*' and '2980*'  "this is not working
* If any of the entries exist in a table, I would like to give out the table name, the field which contains this entry and the dataelement
* of the field that contain the entry

      ENDLOOP.
ENDIF.
 ENDLOOP.

Can some one please show me how to move forward to achieve this?

Thank you

Nadin

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Nadin,

try this



REPORT  YCHATEST MESSAGE-ID ZZ                               .

DATA : IT_FIELDCAT TYPE LVC_T_FCAT.

DATA : TABLE TYPE REF TO DATA,
       V_TYPE(10).

FIELD-SYMBOLS : <FS> TYPE STANDARD TABLE,
<WA> TYPE ANY,
<VALUE> TYPE ANY.

PARAMETERS: P_TABNM LIKE DD02L-TABNAME.


CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    I_STRUCTURE_NAME = P_TABNM
  CHANGING
    CT_FIELDCAT      = IT_FIELDCAT.


CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
  EXPORTING
    IT_FIELDCATALOG           = IT_FIELDCAT
  IMPORTING
    EP_TABLE                  = TABLE
  EXCEPTIONS
    GENERATE_SUBPOOL_DIR_FULL = 1
    OTHERS                    = 2.

ASSIGN TABLE->* TO <FS>.

SELECT * FROM (P_TABNM) INTO CORRESPONDING FIELDS OF TABLE <FS>.

LOOP AT <FS> ASSIGNING <WA>.
  DO.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE <WA> TO <VALUE>.
    IF SY-SUBRC EQ 0.
      DESCRIBE FIELD <VALUE> TYPE V_TYPE.
      IF V_TYPE EQ 'C'.
        SEARCH <VALUE> FOR 'PRASADH'.
        IF SY-SUBRC EQ 0.
          WRITE : / <VALUE>.
        ENDIF.
      ENDIF.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
ENDLOOP.

14 REPLIES 14

Sm1tje
Active Contributor
0 Kudos

try and use the CP operator or CS operator.

Former Member
0 Kudos

Try to use

CHECK <fs_wa> ca 'bbbb_' and <fs_wa> ca '3456' and <fs_wa> ca '8970' and <fs_wa> ca '2980*'

Former Member
0 Kudos

Hi U have to write one more query to retrieve the fields...from DD03L please check the code which i had modified it. let me know if you have some questions..

Parameters: p_tabname like dd02l-tabname.

SELECT * FROM dd02l

INTO TABLE itab

WHERE as4local = 'A'

AND tabname = p_tabname

****write this query to retrieve all the fields for that table.

*select * from dd03l into table itab1

where tabname = p_tabname

and intlen > 0.

describe table itab1 lines v_no.*

***end of field retrival

LOOP AT itab INTO w_tab.

CREATE DATA ref_itab TYPE STANDARD TABLE OF (w_tab-tabname).

ASSIGN ref_itab->* TO <fs_itab>.

CREATE DATA ref_wa TYPE (w_tab-tabname).

ASSIGN ref_wa->* TO <fs_wa>.

SELECT * FROM (w_tab-tabname)

INTO CORRESPONDING FIELDS OF TABLE <fs_itab>.

DESCRIBE TABLE itab. "check if the table contains entries.

IF sy-tfill > 0.

LOOP AT <fs_itab> INTO <fs_wa>. " loop at each table that contains entries and search for the strings or characters

SEARCH <fs_wa> for 'bbbb_' and '3456' and '8970' and '2980*' "this is not working

  • If any of the entries exist in a table, I would like to give out the table name, the field which contains this entry and the dataelement

  • of the field that contain the entry

while v_fld_no < v_no.

assign component v_fld_no of structure <fs_wa> to <fs_fld_value>.

" here start comparing your values with <fs_fld_value> which contains the contents of the table line

"if your search is successful then do a read on above table

read table itab1 index v_fld_no. " from which u can get the field name and table name

v_fld_no = v_fld_no + 1.

endwhile.

ENDLOOP.

ENDIF.

ENDLOOP.

Regards,

Swaroop Patri

Former Member
0 Kudos

Hi Nadin,

try this



REPORT  YCHATEST MESSAGE-ID ZZ                               .

DATA : IT_FIELDCAT TYPE LVC_T_FCAT.

DATA : TABLE TYPE REF TO DATA,
       V_TYPE(10).

FIELD-SYMBOLS : <FS> TYPE STANDARD TABLE,
<WA> TYPE ANY,
<VALUE> TYPE ANY.

PARAMETERS: P_TABNM LIKE DD02L-TABNAME.


CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
  EXPORTING
    I_STRUCTURE_NAME = P_TABNM
  CHANGING
    CT_FIELDCAT      = IT_FIELDCAT.


CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
  EXPORTING
    IT_FIELDCATALOG           = IT_FIELDCAT
  IMPORTING
    EP_TABLE                  = TABLE
  EXCEPTIONS
    GENERATE_SUBPOOL_DIR_FULL = 1
    OTHERS                    = 2.

ASSIGN TABLE->* TO <FS>.

SELECT * FROM (P_TABNM) INTO CORRESPONDING FIELDS OF TABLE <FS>.

LOOP AT <FS> ASSIGNING <WA>.
  DO.
    ASSIGN COMPONENT SY-INDEX OF STRUCTURE <WA> TO <VALUE>.
    IF SY-SUBRC EQ 0.
      DESCRIBE FIELD <VALUE> TYPE V_TYPE.
      IF V_TYPE EQ 'C'.
        SEARCH <VALUE> FOR 'PRASADH'.
        IF SY-SUBRC EQ 0.
          WRITE : / <VALUE>.
        ENDIF.
      ENDIF.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
ENDLOOP.

0 Kudos

How can I search for many values in a raw of data?.

For example, I will be searching for the occurrence of many values like:

'bbc_'

'6781+'

'8790+'

'5438+'.

The '+' signs simply indicates that any letter from A to Z can be the next possible letter.

One other question is: Can I use the '+' like this in ABAP to indicate that any letter from

A to Z could be the next value?

I sincerely thank you all for your responds.

0 Kudos

Just make the following change to the previous post:

comment the following code lines:


"SEARCH <VALUE> FOR 'PRASADH'.
        "IF SY-SUBRC EQ 0.
          "WRITE : / <VALUE>.
        "ENDIF.

Replace the above lines with the following lines:


IF <VALUE> CS 'PRASADH'.
    WRITE : / <VALUE>.
ENDIF.

or instead can also do the following for each string you want to search:


FIND FIRST OCCURRENCE OF 'PRASADH' IN <VALUE>.
        IF SY-SUBRC EQ 0.
          WRITE : / <VALUE>.
        ENDIF.

Hope this helps.

Sanjeev

0 Kudos

Hello senior programmers,

I have tried to follow the examples shown here but I still have some problems. Below is the code. THE RED INDICATES THE ERRORS. I would really appreciate if some one helps me to solve this.

Thank you all-.

Parameters: p_tabname like dd02l-tabname default 'spfli'.

DATA: ref_itab  TYPE REF TO data.
DATA: ref_wa    TYPE REF TO data.

FIELD-SYMBOLS:
<fs_itab>           TYPE ANY TABLE,
<fs_wa>             TYPE ANY,

 
SELECT * FROM dd02l
  INTO  TABLE itab
  WHERE as4local = 'A'
   AND tabname = p_tabname
 
 LOOP AT itab INTO w_tab.
CREATE DATA ref_itab TYPE STANDARD TABLE OF (w_tab-tabname).
    ASSIGN ref_itab->* TO <fs_itab>.
   
CREATE DATA ref_wa TYPE (w_tab-tabname).
    ASSIGN ref_wa->* TO <fs_wa>.
 
 SELECT * FROM (w_tab-tabname)
    INTO CORRESPONDING FIELDS OF TABLE <fs_itab>.
   DESCRIBE TABLE  itab. 
   IF sy-tfill > 0.
LOOP AT <fs_itab> INTO <fs_wa>.
 IF <fs_wa> IS NOT INITIAL.

          MOVE <fs_wa>  TO w_string. "THIS DOMP. CAN SOME ONE SHOW ME HOW TO DO THIS? 
          
          	SEARCH w_string FOR 'TOKYO'.

          IF sy-subrc = 0.
            CLEAR w_output.

            w_output-tabname = <fs_wa>-tabname.  " COULD SOME ONE HELP ME HERE ALSO?
            w_output-inhalt  = w_string.
            APPEND w_output TO t_output.

          ENDIF.
        ENDIF.
 
      ENDLOOP.
ENDIF.
 ENDLOOP.

0 Kudos

Please supply ENTIRE code (missing data declarations for example), and I'll have a look.

0 Kudos

Hallo Micky, these are the data declaration and complete code of the program.

Parameters: p_tabname like dd02l-tabname default 'spfli'.

DATA: t_output  TYPE STANDARD TABLE OF ztest_output. "output strukture with 2 fields.
DATA: t_dd02l   TYPE STANDARD TABLE OF dd02l. 
DATA: ref_itab   TYPE REF TO data.
DATA: ref_wa    TYPE REF TO data.

DATA: w_dd02l  TYPE dd02l.
DATA: w_output TYPE  ztest_output.
DATA: w_string  TYPE string.
 
FIELD-SYMBOLS:
<fs_itab>           TYPE ANY TABLE,
<fs_wa>             TYPE ANY,
  
SELECT * FROM dd02l
  INTO  TABLE itab
  WHERE as4local = 'A'
   AND tabname = p_tabname
 
 LOOP AT itab INTO w_tab.
CREATE DATA ref_itab TYPE STANDARD TABLE OF (w_dd02l-tabname).
    ASSIGN ref_itab->* TO <fs_itab>.
   
CREATE DATA ref_wa TYPE (w_tab-tabname).
    ASSIGN ref_wa->* TO <fs_wa>.
 
 SELECT * FROM (w_tab-tabname)
    INTO CORRESPONDING FIELDS OF TABLE <fs_itab>.
   DESCRIBE TABLE  itab. 
   IF sy-tfill > 0.
LOOP AT <fs_itab> INTO <fs_wa>.
 IF <fs_wa> IS NOT INITIAL.
 
          MOVE <fs_wa>  TO w_string. "THIS DOMP. CAN SOME ONE SHOW ME HOW TO DO THIS? 
          
          	SEARCH w_string FOR 'TOKYO'.
 
          IF sy-subrc = 0.
            CLEAR w_output.
 
            w_output-tabname = <fs_wa>-tabname.  " COULD SOME ONE HELP ME HERE ALSO?
            w_output-inhalt  = w_string.
            APPEND w_output TO t_output.
 
          ENDIF.
        ENDIF.
 
      ENDLOOP.
ENDIF.
 ENDLOOP.

0 Kudos

I also need the field types of ZTEST_OUTPUT.

Btw: Your requirement is still the same: Dynamically determine if structure has certain values?

Or do you just want the CURRENT report to work?

0 Kudos

t_output has this following fields:

component: componenttype datatype length

TABNAME TABNAME CHAR 30

value Zvalue CHAR 240 "this is a dataelement with this length.

The assignment is still the same but if I could have this report working then I think I would use the technical to dynamically program the assignment.

In the assignment, I have to search for all tables in the ddo2l table, which fulfill the criteria you see above. one of those criteria is a certain string and some values.

I hope I was able to provide you with enough information. If you need more information please ask.

Thank you Micky.

0 Kudos

Coding below should fulfill your requirement just fine. If not, for some strange reason, let me know.

!! I made one assumption: RTTS (Run Time Type Services) available.

If not than in stead of using GR_TYPE_REF, you should retrieve the table fields from DD03L and do exactly the same. Might even be better if you want to determine the key fields. Because the output table you have defined may not be enough to determine the one UNIQUE entry in the database table. But this is a matter of requirement.So when outputting the the table with all table names, fieldnames and value, then knowing the key gives you more (all) information.

I'll keep watching thread for any updates. Good luck.

PARAMETERS: p_tab LIKE dd02l-tabname DEFAULT 'spfli'.

TYPE-POOLS: abap.

*DATA: t_output TYPE STANDARD TABLE OF ztest_output. "output strukture with 2 fields.

DATA: t_dd02l TYPE STANDARD TABLE OF dd02l.

DATA: ref_itab TYPE REF TO data.

DATA: ref_wa TYPE REF TO data.

DATA: w_dd02l TYPE dd02l.

DATA: w_component TYPE abap_compdescr.

DATA: w_string TYPE string.

DATA: gv_table_and_name TYPE string.

FIELD-SYMBOLS:

<fs_itab> TYPE ANY TABLE,

<fs_wa> TYPE ANY,

<component> TYPE ANY.

DATA: gr_type_ref TYPE REF TO cl_abap_structdescr.

SELECT * FROM dd02l

INTO TABLE t_dd02l

WHERE as4local = 'A'

AND tabname = p_tab.

LOOP AT t_dd02l INTO w_dd02l.

CREATE DATA ref_itab TYPE STANDARD TABLE OF (w_dd02l-tabname).

ASSIGN ref_itab->* TO <fs_itab>.

CREATE DATA ref_wa TYPE (w_dd02l-tabname).

ASSIGN ref_wa->* TO <fs_wa>.

SELECT * FROM (w_dd02l-tabname)

INTO CORRESPONDING FIELDS OF TABLE <fs_itab>.

DESCRIBE TABLE t_dd02l.

IF sy-tfill > 0.

  • Retrieve reference to current structure.

gr_type_ref ?= cl_abap_structdescr=>describe_by_name( w_dd02l-tabname ).

LOOP AT <fs_itab> INTO <fs_wa>.

IF <fs_wa> IS NOT INITIAL.

  • Loop over structure, to determine every single field of the structure,

  • and check its content.

DO.

ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa> TO <component>.

  • Move to character field.

IF sy-subrc IS INITIAL.

  • Move component to character field (in order to use CS / CP

  • or statement SEARCH for that matter.

w_string = <component>.

IF w_string CS 'NEW YORK' OR

w_string CP 'NEW*'. "OR WHATEVER, but case sensitive,

  • "so better TO UPPER CASE.

  • Get fieldname of structure.

READ TABLE gr_type_ref->components INTO w_component

INDEX sy-index.

  • Build table name and fieldname.

CONCATENATE w_dd02l-tabname

w_component-name

INTO gv_table_and_name

SEPARATED BY '-'.

WRITE:/1 gv_table_and_name, <component>.

ENDIF.

ELSE.

EXIT.

ENDIF.

ENDDO.

ENDIF.

ENDLOOP.

ENDIF.

ENDLOOP.

0 Kudos

Thank you so much Micky. It works perfectly. I really much appreciate your help. I will award points.

Now I want to do some thing more. I want to output the data element and description,fieldname tabledescription for example. I know that the dataelement of a field and the description can be found in the TABLE dd04t OR FM: DDIF_FIELDINFO_GET but you need to know the exact position of the field element dynamically. My problem now is I want to get the table description of SPFLI from dd02t, all the dataelements and the descriptions of the field 'TOKYO' and perhaps AIRPTO 'KIX'. Have adjusted my code as follows but still have trouble: Could you please Micky or any body show me how to achieve this?

It is kind of tricky because the sy-tabix can be 2 but the TOKYO is at the 5th field. Thank you.

Parameters: p_tabname like dd02l-tabname default 'spfli'.
DATA: t_dd02l   TYPE STANDARD TABLE OF dd02l. 
DATA: t_dd03l   TYPE STANDARD TABLE OF dd03l.
DATA: t_dfies   TYPE STANDARD TABLE OF dfies.
DATA: ref_itab   TYPE REF TO data.

DATA: ref_wa    TYPE REF TO data.
DATA: ref_itab_temp TYPE REF TO data.
DATA: ref_wa_temp   TYPE REF TO data.
 DATA: w_dd02l  TYPE dd02l.
DATA: w_dd03l  TYPE dd03l.
DATA: w_dfies   TYPE  dfies.
DATA: w_string  TYPE string.
DATA: w_fieldname   TYPE string.
DATA: w_fieldnamestring  TYPE string.
DATA: w_tabix TYPE sy-tabix.
DATA: w_dd02t  TYPE dd02t.
DATA: w_dd04t     TYPE dd04t.
DATA: w_datenelement TYPE rollname.
DATA: w_dfies_tmp TYPE dfies.
 
FIELD-SYMBOLS:
<fs_itab>          TYPE ANY TABLE,
<fs_itab_temp> TYPE ANY TABLE,
<fs_wa_temp>  TYPE ANY,
<fs_wa>           TYPE ANY,
<component>  TYPE ANY.
  

  CLEAR t_dd02l.

  SELECT * FROM dd02l
  INTO  TABLE t_dd02l
  WHERE as4local = 'A'
  AND tabclass   = 'TRANSP'
    AND tabname IN so_tab.


  LOOP AT t_dd02l INTO w_dd02l.
    CREATE DATA ref_itab TYPE STANDARD TABLE OF (w_dd02l-tabname).
    ASSIGN ref_itab->* TO <fs_itab>.
    ASSIGN ref_itab->* TO <fs_itab_temp>.

    CREATE DATA ref_wa TYPE (w_dd02l-tabname).
    ASSIGN ref_wa->* TO <fs_wa>.
    ASSIGN ref_wa->* TO <fs_wa_temp>.

    SELECT * FROM dd03l
    INTO  TABLE t_dd03l
   WHERE tabname = w_dd02l-tabname
   AND  as4local      = 'A'
   AND   datatype    = 'CHAR'.

    CLEAR: w_dd03l, w_fieldnamestring.
    LOOP AT t_dd03l INTO w_dd03l.
      CLEAR w_fieldname.

      w_fieldname = w_dd03l-fieldname.

      CONCATENATE w_fieldname w_fieldnamestring INTO
    w_fieldnamestring SEPARATED BY space IN CHARACTER MODE.
    ENDLOOP.

    CREATE DATA ref_itab_temp TYPE STANDARD TABLE OF (w_dd03l-tabname).
    ASSIGN ref_itab_temp->* TO <fs_itab_temp>.

    CREATE DATA ref_wa_temp TYPE (w_dd03l-tabname).
    ASSIGN ref_wa_temp->* TO <fs_wa_temp>.

    SELECT (w_fieldnamestring) FROM (w_dd03l-tabname)
    INTO CORRESPONDING FIELDS OF TABLE <fs_itab_temp>.

    DESCRIBE TABLE <fs_itab_temp>.
    IF sy-tfill > 0.

      CLEAR w_tabix.
      CLEAR w_nut.
      LOOP AT <fs_itab_temp> INTO <fs_wa_temp>.
        CLEAR w_longstring.
        w_tabix = w_tabix + 1.
        IF <fs_wa_temp> IS NOT INITIAL.

          DO.
            ASSIGN COMPONENT sy-index OF STRUCTURE <fs_wa_temp> TO <component>.

            CLEAR w_string.

            IF sy-subrc <> 0.
              EXIT.
            ENDIF.

            CLEAR: w_string.
            IF NOT <component> IS INITIAL.
              MOVE <component> TO w_string.

              CONCATENATE w_string w_longstring INTO w_longstring
              SEPARATED BY ';'.
              IF w_string CS 'TOKYO'.
                CLEAR w_dd02t.
                SELECT SINGLE * FROM dd02t INTO w_dd02t
                WHERE tabname    =  w_dd03l-tabname
                  AND ddlanguage = 'DE'.

                CLEAR t_dfies.
                CALL FUNCTION 'DDIF_FIELDINFO_GET'
                  EXPORTING
                    tabname        = w_dd03l-tabname
                  TABLES
                    dfies_tab      = t_dfies
                  EXCEPTIONS
                    not_found      = 1
                    internal_error = 2
                    OTHERS         = 3.
                IF sy-subrc = 0.

                  CLEAR w_dfies.
                  READ TABLE t_dfies INTO w_dfies
                  WITH KEY tabname = w_dd03l-tabname.

                  READ TABLE t_dfies INDEX  w_tabix INTO w_dfies_tmp.

                  SELECT SINGLE * FROM dd04t INTO w_dd04t
                  WHERE rollname    = w_dfies_tmp-rollname
                  AND   ddlanguage  = 'EN'
                  AND    as4local   = 'A'.
                  WRITE:/ w_dfies-tabname, w_dd02t-ddtext, w_string, w_dd04t-rollname, w_dd04t-ddtext, w_longstring.

                ENDIF.

              ENDIF.
            ENDIF.
          ENDDO.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDLOOP.
.

Edited by: nadin ram on Apr 11, 2008 7:06 PM

Former Member
0 Kudos

Extention of coding.Please help.