<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Code to dynamically query  infotypes and fields -&amp;gt; gives dump in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440720#M546270</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please  see this code   it was working  for us  .... you can  use it for any  &amp;lt;b&amp;gt;Infotype or any table  ....&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT zmodtab NO STANDARD PAGE HEADING.

TYPE-POOLS: rsds.

DATA: is_x030l  TYPE x030l,
      it_dfies  TYPE TABLE OF dfies,
      is_dfies  TYPE dfies,
      it_fdiff  TYPE TABLE OF field_dif,
      is_fdiff  TYPE field_dif.

DATA: w_selid   TYPE rsdynsel-selid,
      it_tables TYPE TABLE OF rsdstabs,
      is_tables TYPE rsdstabs,
      it_fields TYPE TABLE OF rsdsfields,
      it_expr   TYPE rsds_texpr,
      it_ranges TYPE rsds_trange,
      it_where  TYPE rsds_twhere,
      is_where  TYPE rsds_where,
      w_active  TYPE i.

DATA: it_content TYPE REF TO data,
      it_modif   TYPE REF TO data,
      it_fcat    TYPE lvc_t_fcat.

DATA: w_okcode   TYPE sy-ucomm.


FIELD-SYMBOLS: &amp;lt;itab&amp;gt; TYPE STANDARD TABLE,
               &amp;lt;ntab&amp;gt; TYPE STANDARD TABLE.


* Macros
DEFINE table_error.
  message e398(00) with 'Table' p_table &amp;amp;1.
END-OF-DEFINITION.

DEFINE fixed_val.
  is_fdiff-fieldname = is_dfies-fieldname.
  is_fdiff-fixed_val = &amp;amp;1.
  is_fdiff-no_input  = 'X'.
  append is_fdiff to it_fdiff.
END-OF-DEFINITION.


* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME.
PARAMETERS: p_table TYPE tabname OBLIGATORY                    "table
                                 MEMORY ID dtb
                                 MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: BEGIN OF LINE,
                  PUSHBUTTON 33(20) selopt USER-COMMAND sel,
                  COMMENT    55(15) selcnt,
                  END OF LINE.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_rows  TYPE i.                                    "rows
SELECTION-SCREEN: END OF BLOCK b01,
                  SKIP,
                  BEGIN OF BLOCK b02 WITH FRAME.
PARAMETERS: p_displ TYPE c AS CHECKBOX.                        "display
SELECTION-SCREEN: END OF BLOCK b02.

* Initialization
INITIALIZATION.
  MOVE '@4G@ Filter records' TO selopt.

* PBO
AT SELECTION-SCREEN OUTPUT.
  IF w_active IS INITIAL.
    CLEAR: selcnt.
  ELSE.
    WRITE w_active TO selcnt LEFT-JUSTIFIED.
  ENDIF.

* PAI
AT SELECTION-SCREEN.
  IF p_table NE is_x030l-tabname.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
         EXPORTING
              tabname   = p_table
         IMPORTING
              x030l_wa  = is_x030l
         TABLES
              dfies_tab = it_dfies
         EXCEPTIONS
              OTHERS    = 1.
    IF is_x030l IS INITIAL.
      table_error 'does not exist or is not active'.
    ELSEIF is_x030l-tabtype NE 'T'.
      table_error 'is not selectable'.
    ELSEIF is_x030l-align NE 0.
      table_error 'has alignment - cannot continue'.
    ENDIF.

*   Default values for system fields
    REFRESH: it_fdiff.
    is_fdiff-tabname = p_table.
    LOOP AT it_dfies INTO is_dfies.
      IF is_dfies-datatype = 'CLNT'.
        fixed_val sy-mandt.
      ELSEIF is_dfies-rollname = 'ERDAT'
          OR is_dfies-rollname = 'ERSDA'
          OR is_dfies-rollname = 'AEDAT'
          OR is_dfies-rollname = 'LAEDA'.
        fixed_val sy-datum.
      ELSEIF is_dfies-rollname = 'ERTIM'
          OR is_dfies-rollname = 'AETIM'.
        fixed_val sy-uzeit.
      ELSEIF is_dfies-rollname = 'ERNAM'
          OR is_dfies-rollname = 'AENAM'.
        fixed_val sy-uname.
      ENDIF.
    ENDLOOP.

*   Prepare free selection on table
    REFRESH it_tables.
    is_tables-prim_tab = p_table.
    APPEND is_tables TO it_tables.

    CLEAR: w_selid.
  ENDIF.

  IF sy-ucomm = 'SEL'.
    IF w_selid IS INITIAL.
*     Init free selection dialog
      CALL FUNCTION 'FREE_SELECTIONS_INIT'
           EXPORTING
                expressions  = it_expr
           IMPORTING
                selection_id = w_selid
                expressions  = it_expr
           TABLES
                tables_tab   = it_tables
           EXCEPTIONS
                OTHERS       = 1.
    ENDIF.

*   Display free selection dialog
    CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
         EXPORTING
              selection_id            = w_selid
              title                   = 'Selection'
              status                  = 1
              as_window               = 'X'
         IMPORTING
              expressions             = it_expr
              field_ranges            = it_ranges
              number_of_active_fields = w_active
         TABLES
              fields_tab              = it_fields
         EXCEPTIONS
              OTHERS                  = 1.
  ENDIF.


* Start of processing
START-OF-SELECTION.

  PERFORM f_create_table USING p_table.

  PERFORM f_select_table.

  PERFORM f_display_table.


*---------------------------------------------------------------------*
*       FORM f_create_table                                           *
*---------------------------------------------------------------------*
FORM f_create_table USING in_tabname.

  FIELD-SYMBOLS: &amp;lt;fcat&amp;gt; TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name = in_tabname
       CHANGING
            ct_fieldcat      = it_fcat
       EXCEPTIONS
            OTHERS           = 1.
  IF sy-subrc = 0.
*   Complete field catalog
    LOOP AT it_fcat ASSIGNING &amp;lt;fcat&amp;gt;.
      &amp;lt;fcat&amp;gt;-tabname = in_tabname.
    ENDLOOP.
    CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'
         CHANGING
              ct_fieldcat = it_fcat
         EXCEPTIONS
              OTHERS      = 1.
  ELSE.
    WRITE: 'Error building field catalog'.
    STOP.
  ENDIF.

* Create dynamic table for data
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fcat
    IMPORTING
      ep_table        = it_content.
  IF sy-subrc = 0.
    ASSIGN it_content-&amp;gt;* TO &amp;lt;itab&amp;gt;.
  ELSE.
    WRITE: 'Error creating internal table'.
    STOP.
  ENDIF.

* Create dynamic table for modif
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fcat
    IMPORTING
      ep_table        = it_modif.
  IF sy-subrc = 0.
    ASSIGN it_modif-&amp;gt;* TO &amp;lt;ntab&amp;gt;.
  ELSE.
    WRITE: 'Error creating internal table'.
    STOP.
  ENDIF.

ENDFORM.


*---------------------------------------------------------------------*
*       FORM f_select_table                                           *
*---------------------------------------------------------------------*
FORM f_select_table.

  IF w_active = 0.
    SELECT * FROM (p_table)
             INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;
            UP TO p_rows ROWS.
  ELSE.
*   Selection with parameters
    CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
         EXPORTING
              field_ranges  = it_ranges
         IMPORTING
              where_clauses = it_where.
    READ TABLE it_where INTO is_where WITH KEY tablename = p_table.

    SELECT * FROM (p_table)
             INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;
            UP TO p_rows ROWS
            WHERE (is_where-where_tab).
  ENDIF.

  IF sy-dbcnt = 0.
    WRITE: 'No record selected'.
    STOP.
  ENDIF.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM f_display_table                                          *
*---------------------------------------------------------------------*
FORM f_display_table.
  DATA: l_answer TYPE c,
        l_eflag  TYPE c.

  CLEAR: w_okcode.
  REFRESH: &amp;lt;ntab&amp;gt;.
* Display table contents
  CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
       EXPORTING
            header       = p_table
            tabname      = p_table
            display_only = p_displ
            endless      = 'X'
            no_button    = space
       IMPORTING
            okcode       = w_okcode
       TABLES
            nametab      = it_dfies
            table        = &amp;lt;itab&amp;gt;
            fielddif     = it_fdiff
            modif_table  = &amp;lt;ntab&amp;gt;
       EXCEPTIONS
            OTHERS       = 1.
  IF sy-subrc = 0.
    IF p_displ IS INITIAL AND w_okcode = 'SAVE'.
*     Confirm update
      CALL FUNCTION 'POPUP_TO_CONFIRM'
           EXPORTING
                titlebar              = p_table
                text_question         = 'Do you want to update table ?'
                default_button        = '2'
                display_cancel_button = ' '
           IMPORTING
                answer                = l_answer
           EXCEPTIONS
                OTHERS                = 1.
      IF l_answer = '1'.
*       Apply modifications
        IF NOT &amp;lt;ntab&amp;gt;[] IS INITIAL.
          PERFORM f_add_system USING space.
          MODIFY (p_table) FROM TABLE &amp;lt;ntab&amp;gt;.
          IF sy-subrc NE 0.
            l_eflag = 'X'.
          ENDIF.
        ENDIF.
*       Apply deletions
        IF l_eflag IS INITIAL.
          REFRESH: &amp;lt;ntab&amp;gt;.
          CALL FUNCTION 'STC1_GET_DATA'
               TABLES
                    deleted_data = &amp;lt;ntab&amp;gt;
               EXCEPTIONS
                    OTHERS       = 1.
          IF NOT &amp;lt;ntab&amp;gt;[] IS INITIAL.
            DELETE (p_table) FROM TABLE &amp;lt;ntab&amp;gt;.
            IF sy-subrc NE 0.
              ROLLBACK WORK.
              l_eflag = 'X'.
            ENDIF.
          ENDIF.
        ENDIF.
*       Apply creations
        IF l_eflag IS INITIAL.
          REFRESH: &amp;lt;ntab&amp;gt;.
          CALL FUNCTION 'STC1_GET_DATA'
               TABLES
                    new_data = &amp;lt;ntab&amp;gt;
               EXCEPTIONS
                    OTHERS   = 1.
          IF NOT &amp;lt;ntab&amp;gt;[] IS INITIAL.
            PERFORM f_add_system USING 'X'.
            INSERT (p_table) FROM TABLE &amp;lt;ntab&amp;gt;.
            IF sy-subrc NE 0.
              ROLLBACK WORK.
              l_eflag = 'X'.
            ENDIF.
          ENDIF.
        ENDIF.
        IF l_eflag IS INITIAL.
          COMMIT WORK.
          MESSAGE s261(53).
        ELSE.
          MESSAGE s075(3i).
          PERFORM f_select_table.
        ENDIF.
      ENDIF.
*     Display table again
      PERFORM f_display_table.
    ENDIF.
  ENDIF.

ENDFORM.


*---------------------------------------------------------------------*
*       FORM f_add_system                                             *
*---------------------------------------------------------------------*
FORM f_add_system USING new TYPE c.

  FIELD-SYMBOLS: &amp;lt;irec&amp;gt; TYPE ANY,
                 &amp;lt;upd&amp;gt;  TYPE ANY.

  LOOP AT it_fdiff INTO is_fdiff.
    READ TABLE it_dfies INTO is_dfies
                    WITH KEY fieldname = is_fdiff-fieldname.
    LOOP AT &amp;lt;ntab&amp;gt; ASSIGNING &amp;lt;irec&amp;gt;.
      ASSIGN COMPONENT is_fdiff-fieldname OF STRUCTURE &amp;lt;irec&amp;gt; TO &amp;lt;upd&amp;gt;.
      IF is_dfies-datatype = 'CLNT'.
        &amp;lt;upd&amp;gt; = sy-mandt.
      ELSE.
        CASE is_dfies-rollname.
          WHEN 'AENAM'.
            &amp;lt;upd&amp;gt; = sy-uname.
          WHEN 'AEDAT' OR 'LAEDA'.
            &amp;lt;upd&amp;gt; = sy-datum.
          WHEN 'AETIM'.
            &amp;lt;upd&amp;gt; = sy-uzeit.
          WHEN OTHERS.
        ENDCASE.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward points if it is  heplfull ....&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 22 Jun 2007 05:41:14 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-06-22T05:41:14Z</dc:date>
    <item>
      <title>Code to dynamically query  infotypes and fields -&gt; gives dump</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440718#M546268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have written some code to dynamically query all infotypes and their fields.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, it gives a dump at a certain field:&lt;/P&gt;&lt;P&gt;DBIF_RSQL_INVALID_RSQL&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error in the module RSQL accessing the database interface.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the code I've written:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
      DATA: field(30) TYPE c,
            itype(6) TYPE c,
            cond(80) TYPE c.
      DATA: dataref TYPE REF TO data.


      FIELD-SYMBOLS: &amp;lt;field&amp;gt; TYPE ANY.


      CONCATENATE 'PA' it INTO itype.
      CREATE DATA dataref TYPE (itype).
      ASSIGN dataref-&amp;gt;* TO &amp;lt;field&amp;gt;.

      field = dd03l-fieldname.

      CONCATENATE field ' &amp;lt;&amp;gt; SPACE' INTO cond.

      SELECT SINGLE (field) FROM (itype)
      INTO &amp;lt;field&amp;gt;
      WHERE (cond).
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is only part of the code, the determination of the infotype and its fields happens earlier and there is no problem there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code manages to go through all fields of infotype 0000, but gives a dump at a custom field ZZFUNKT_DAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This field has as data element dat34, so that shouldn't be the error. And other custom fields can be read perfectly with my code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone got a clue? (I also don't know what the dump message means)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 Jun 2007 17:19:50 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440718#M546268</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-21T17:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Code to dynamically query  infotypes and fields -&gt; gives dump</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440719#M546269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;   Check in debugging mode what (field) contais. if this field doesnt exist in the infotype in will give a short dump. or try the code&lt;/P&gt;&lt;P&gt;select ******* into corresponding fields****. This shd work.&lt;/P&gt;&lt;P&gt;with egards,&lt;/P&gt;&lt;P&gt;Vamsi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 05:38:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440719#M546269</guid>
      <dc:creator>former_member219399</dc:creator>
      <dc:date>2007-06-22T05:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Code to dynamically query  infotypes and fields -&gt; gives dump</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440720#M546270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;please  see this code   it was working  for us  .... you can  use it for any  &amp;lt;b&amp;gt;Infotype or any table  ....&amp;lt;/b&amp;gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;REPORT zmodtab NO STANDARD PAGE HEADING.

TYPE-POOLS: rsds.

DATA: is_x030l  TYPE x030l,
      it_dfies  TYPE TABLE OF dfies,
      is_dfies  TYPE dfies,
      it_fdiff  TYPE TABLE OF field_dif,
      is_fdiff  TYPE field_dif.

DATA: w_selid   TYPE rsdynsel-selid,
      it_tables TYPE TABLE OF rsdstabs,
      is_tables TYPE rsdstabs,
      it_fields TYPE TABLE OF rsdsfields,
      it_expr   TYPE rsds_texpr,
      it_ranges TYPE rsds_trange,
      it_where  TYPE rsds_twhere,
      is_where  TYPE rsds_where,
      w_active  TYPE i.

DATA: it_content TYPE REF TO data,
      it_modif   TYPE REF TO data,
      it_fcat    TYPE lvc_t_fcat.

DATA: w_okcode   TYPE sy-ucomm.


FIELD-SYMBOLS: &amp;lt;itab&amp;gt; TYPE STANDARD TABLE,
               &amp;lt;ntab&amp;gt; TYPE STANDARD TABLE.


* Macros
DEFINE table_error.
  message e398(00) with 'Table' p_table &amp;amp;1.
END-OF-DEFINITION.

DEFINE fixed_val.
  is_fdiff-fieldname = is_dfies-fieldname.
  is_fdiff-fixed_val = &amp;amp;1.
  is_fdiff-no_input  = 'X'.
  append is_fdiff to it_fdiff.
END-OF-DEFINITION.


* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME.
PARAMETERS: p_table TYPE tabname OBLIGATORY                    "table
                                 MEMORY ID dtb
                                 MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: BEGIN OF LINE,
                  PUSHBUTTON 33(20) selopt USER-COMMAND sel,
                  COMMENT    55(15) selcnt,
                  END OF LINE.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_rows  TYPE i.                                    "rows
SELECTION-SCREEN: END OF BLOCK b01,
                  SKIP,
                  BEGIN OF BLOCK b02 WITH FRAME.
PARAMETERS: p_displ TYPE c AS CHECKBOX.                        "display
SELECTION-SCREEN: END OF BLOCK b02.

* Initialization
INITIALIZATION.
  MOVE '@4G@ Filter records' TO selopt.

* PBO
AT SELECTION-SCREEN OUTPUT.
  IF w_active IS INITIAL.
    CLEAR: selcnt.
  ELSE.
    WRITE w_active TO selcnt LEFT-JUSTIFIED.
  ENDIF.

* PAI
AT SELECTION-SCREEN.
  IF p_table NE is_x030l-tabname.
    CALL FUNCTION 'DDIF_NAMETAB_GET'
         EXPORTING
              tabname   = p_table
         IMPORTING
              x030l_wa  = is_x030l
         TABLES
              dfies_tab = it_dfies
         EXCEPTIONS
              OTHERS    = 1.
    IF is_x030l IS INITIAL.
      table_error 'does not exist or is not active'.
    ELSEIF is_x030l-tabtype NE 'T'.
      table_error 'is not selectable'.
    ELSEIF is_x030l-align NE 0.
      table_error 'has alignment - cannot continue'.
    ENDIF.

*   Default values for system fields
    REFRESH: it_fdiff.
    is_fdiff-tabname = p_table.
    LOOP AT it_dfies INTO is_dfies.
      IF is_dfies-datatype = 'CLNT'.
        fixed_val sy-mandt.
      ELSEIF is_dfies-rollname = 'ERDAT'
          OR is_dfies-rollname = 'ERSDA'
          OR is_dfies-rollname = 'AEDAT'
          OR is_dfies-rollname = 'LAEDA'.
        fixed_val sy-datum.
      ELSEIF is_dfies-rollname = 'ERTIM'
          OR is_dfies-rollname = 'AETIM'.
        fixed_val sy-uzeit.
      ELSEIF is_dfies-rollname = 'ERNAM'
          OR is_dfies-rollname = 'AENAM'.
        fixed_val sy-uname.
      ENDIF.
    ENDLOOP.

*   Prepare free selection on table
    REFRESH it_tables.
    is_tables-prim_tab = p_table.
    APPEND is_tables TO it_tables.

    CLEAR: w_selid.
  ENDIF.

  IF sy-ucomm = 'SEL'.
    IF w_selid IS INITIAL.
*     Init free selection dialog
      CALL FUNCTION 'FREE_SELECTIONS_INIT'
           EXPORTING
                expressions  = it_expr
           IMPORTING
                selection_id = w_selid
                expressions  = it_expr
           TABLES
                tables_tab   = it_tables
           EXCEPTIONS
                OTHERS       = 1.
    ENDIF.

*   Display free selection dialog
    CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
         EXPORTING
              selection_id            = w_selid
              title                   = 'Selection'
              status                  = 1
              as_window               = 'X'
         IMPORTING
              expressions             = it_expr
              field_ranges            = it_ranges
              number_of_active_fields = w_active
         TABLES
              fields_tab              = it_fields
         EXCEPTIONS
              OTHERS                  = 1.
  ENDIF.


* Start of processing
START-OF-SELECTION.

  PERFORM f_create_table USING p_table.

  PERFORM f_select_table.

  PERFORM f_display_table.


*---------------------------------------------------------------------*
*       FORM f_create_table                                           *
*---------------------------------------------------------------------*
FORM f_create_table USING in_tabname.

  FIELD-SYMBOLS: &amp;lt;fcat&amp;gt; TYPE lvc_s_fcat.

  CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
            i_structure_name = in_tabname
       CHANGING
            ct_fieldcat      = it_fcat
       EXCEPTIONS
            OTHERS           = 1.
  IF sy-subrc = 0.
*   Complete field catalog
    LOOP AT it_fcat ASSIGNING &amp;lt;fcat&amp;gt;.
      &amp;lt;fcat&amp;gt;-tabname = in_tabname.
    ENDLOOP.
    CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'
         CHANGING
              ct_fieldcat = it_fcat
         EXCEPTIONS
              OTHERS      = 1.
  ELSE.
    WRITE: 'Error building field catalog'.
    STOP.
  ENDIF.

* Create dynamic table for data
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fcat
    IMPORTING
      ep_table        = it_content.
  IF sy-subrc = 0.
    ASSIGN it_content-&amp;gt;* TO &amp;lt;itab&amp;gt;.
  ELSE.
    WRITE: 'Error creating internal table'.
    STOP.
  ENDIF.

* Create dynamic table for modif
  CALL METHOD cl_alv_table_create=&amp;gt;create_dynamic_table
    EXPORTING
      it_fieldcatalog = it_fcat
    IMPORTING
      ep_table        = it_modif.
  IF sy-subrc = 0.
    ASSIGN it_modif-&amp;gt;* TO &amp;lt;ntab&amp;gt;.
  ELSE.
    WRITE: 'Error creating internal table'.
    STOP.
  ENDIF.

ENDFORM.


*---------------------------------------------------------------------*
*       FORM f_select_table                                           *
*---------------------------------------------------------------------*
FORM f_select_table.

  IF w_active = 0.
    SELECT * FROM (p_table)
             INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;
            UP TO p_rows ROWS.
  ELSE.
*   Selection with parameters
    CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
         EXPORTING
              field_ranges  = it_ranges
         IMPORTING
              where_clauses = it_where.
    READ TABLE it_where INTO is_where WITH KEY tablename = p_table.

    SELECT * FROM (p_table)
             INTO CORRESPONDING FIELDS OF TABLE &amp;lt;itab&amp;gt;
            UP TO p_rows ROWS
            WHERE (is_where-where_tab).
  ENDIF.

  IF sy-dbcnt = 0.
    WRITE: 'No record selected'.
    STOP.
  ENDIF.
ENDFORM.


*---------------------------------------------------------------------*
*       FORM f_display_table                                          *
*---------------------------------------------------------------------*
FORM f_display_table.
  DATA: l_answer TYPE c,
        l_eflag  TYPE c.

  CLEAR: w_okcode.
  REFRESH: &amp;lt;ntab&amp;gt;.
* Display table contents
  CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
       EXPORTING
            header       = p_table
            tabname      = p_table
            display_only = p_displ
            endless      = 'X'
            no_button    = space
       IMPORTING
            okcode       = w_okcode
       TABLES
            nametab      = it_dfies
            table        = &amp;lt;itab&amp;gt;
            fielddif     = it_fdiff
            modif_table  = &amp;lt;ntab&amp;gt;
       EXCEPTIONS
            OTHERS       = 1.
  IF sy-subrc = 0.
    IF p_displ IS INITIAL AND w_okcode = 'SAVE'.
*     Confirm update
      CALL FUNCTION 'POPUP_TO_CONFIRM'
           EXPORTING
                titlebar              = p_table
                text_question         = 'Do you want to update table ?'
                default_button        = '2'
                display_cancel_button = ' '
           IMPORTING
                answer                = l_answer
           EXCEPTIONS
                OTHERS                = 1.
      IF l_answer = '1'.
*       Apply modifications
        IF NOT &amp;lt;ntab&amp;gt;[] IS INITIAL.
          PERFORM f_add_system USING space.
          MODIFY (p_table) FROM TABLE &amp;lt;ntab&amp;gt;.
          IF sy-subrc NE 0.
            l_eflag = 'X'.
          ENDIF.
        ENDIF.
*       Apply deletions
        IF l_eflag IS INITIAL.
          REFRESH: &amp;lt;ntab&amp;gt;.
          CALL FUNCTION 'STC1_GET_DATA'
               TABLES
                    deleted_data = &amp;lt;ntab&amp;gt;
               EXCEPTIONS
                    OTHERS       = 1.
          IF NOT &amp;lt;ntab&amp;gt;[] IS INITIAL.
            DELETE (p_table) FROM TABLE &amp;lt;ntab&amp;gt;.
            IF sy-subrc NE 0.
              ROLLBACK WORK.
              l_eflag = 'X'.
            ENDIF.
          ENDIF.
        ENDIF.
*       Apply creations
        IF l_eflag IS INITIAL.
          REFRESH: &amp;lt;ntab&amp;gt;.
          CALL FUNCTION 'STC1_GET_DATA'
               TABLES
                    new_data = &amp;lt;ntab&amp;gt;
               EXCEPTIONS
                    OTHERS   = 1.
          IF NOT &amp;lt;ntab&amp;gt;[] IS INITIAL.
            PERFORM f_add_system USING 'X'.
            INSERT (p_table) FROM TABLE &amp;lt;ntab&amp;gt;.
            IF sy-subrc NE 0.
              ROLLBACK WORK.
              l_eflag = 'X'.
            ENDIF.
          ENDIF.
        ENDIF.
        IF l_eflag IS INITIAL.
          COMMIT WORK.
          MESSAGE s261(53).
        ELSE.
          MESSAGE s075(3i).
          PERFORM f_select_table.
        ENDIF.
      ENDIF.
*     Display table again
      PERFORM f_display_table.
    ENDIF.
  ENDIF.

ENDFORM.


*---------------------------------------------------------------------*
*       FORM f_add_system                                             *
*---------------------------------------------------------------------*
FORM f_add_system USING new TYPE c.

  FIELD-SYMBOLS: &amp;lt;irec&amp;gt; TYPE ANY,
                 &amp;lt;upd&amp;gt;  TYPE ANY.

  LOOP AT it_fdiff INTO is_fdiff.
    READ TABLE it_dfies INTO is_dfies
                    WITH KEY fieldname = is_fdiff-fieldname.
    LOOP AT &amp;lt;ntab&amp;gt; ASSIGNING &amp;lt;irec&amp;gt;.
      ASSIGN COMPONENT is_fdiff-fieldname OF STRUCTURE &amp;lt;irec&amp;gt; TO &amp;lt;upd&amp;gt;.
      IF is_dfies-datatype = 'CLNT'.
        &amp;lt;upd&amp;gt; = sy-mandt.
      ELSE.
        CASE is_dfies-rollname.
          WHEN 'AENAM'.
            &amp;lt;upd&amp;gt; = sy-uname.
          WHEN 'AEDAT' OR 'LAEDA'.
            &amp;lt;upd&amp;gt; = sy-datum.
          WHEN 'AETIM'.
            &amp;lt;upd&amp;gt; = sy-uzeit.
          WHEN OTHERS.
        ENDCASE.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

ENDFORM.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;reward points if it is  heplfull ....&lt;/P&gt;&lt;P&gt;Girish&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 22 Jun 2007 05:41:14 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/code-to-dynamically-query-infotypes-and-fields-gt-gives-dump/m-p/2440720#M546270</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-06-22T05:41:14Z</dc:date>
    </item>
  </channel>
</rss>

