Making processing on an internal table generic

Hi,
I'm trying to make more generic a processing on an internal table.
Here's the idea :
"DELETE FROM TABLE T_VBAP every lines that do not exist IN table T_VBAK USING column VBELN for comparison"
You can see below the (not generic) version of this function.
I'd like to make it more generic.
It would be called this way :
     PERFORM reduire USING t_vbak t_vbap 'VBELN' 'vbak-vbeln'.
with the following code.
Here is my question :
How can I make the last statement generic too ?
  DELETE <table_travail> WHERE (column) NOT IN <fs_tab> won't work...
Thanks a lot !
Jessie
Non-generic version :
FORM reduire.
  DATA : liste_vbeln type range of vbak-vbeln,
               line_vbeln TYPE LINE OF liste_vbeln,
               lt_vbak TYPE TABLE OF ts_vbak,
               lt_vbap TYPE ts_vbak.
  lt_vbak = t_vbak.
  SORT lt_vbak BY vbeln.
  DELETE ADJACENT DUPLICATES FROM lt_vbak COMPARGIN vbeln.
  line_vbeln-sign = 'I'.
  line_vbeln-option = 'EQ'.
  LOOP AT lt_vbak INTO ls_vbak.
    line_vbeln-low = ls_vbak-vbeln.
    APPEND line_vbeln TO liste_vbeln.
  ENDLOOP.
  IF liste_vbeln IS INITIAL.
     CLEAR t_vbap.
  ELSE.
    DELETE t_vbap WHERE vbeln NOT IN liste_vbeln.
  ENDIF.
ENDFORM.
Generic version :
FORM reduire USING  p_reference STANDARD TABLE
                    p_travail TYPE STANDARD TABLE
                         column TYPE lvc_name
                         column_type TYPE string.
     FIELD-SYMBOLS <table_reference> TYPE STANDARD TABLE.
     FIELD-SYMBOLS <table_reference_copy> TYPE STANDARD TABLE.
     ASSIGN p_reference to <table_reference>.
     FIELD-SYMBOLS <table_travail> TYPE STANDARD TABLE.
     ASSIGN p_travail to <table_travail>.
     FIELD-SYMBOLS <table_reference_fields> TYPE ANY.
     DATA gs_fldname TYPE REF TO DATA.
     CREATE DATA gs_fldname LIKE LINE OF <table_reference>.
     ASSIGN gs_fldname->* TO <table_reference_fields>.
     DATA position TYPE i.
     DATA dyn_table TYPE REF TO DATA.
     DATA wa_fieldcat TYPE lvc_s_fcat.
     DATA it_fieldcat TYPE lvc_t_fcat.
     DATA table_reference_copy_pre TYPE REF TO DATA.
     DATA l_descr_ref TYPE REF TO cl_abap_structdescr.
     FIELD-SYMBOLS <ls_tab> TYPE ANY.
     FIELD-SYMBOLS <field> TYPE ANY.
     FIELD-SYMBOLS <lfs_comp_wa> TYPE abap_compdescr.
     l_descr_ref ?= cl_abap_typedescr=>describe_by_data( <table_reference_fields> ).
     LOOP AT l_descr_ref->components[] ASSIGNING <lfs_comp_wa>.
          IF <lfs_comp_wa>-name = column.
               position = sy-tabix.
          ENDIF.
          CLEAR wa_fieldcat.
          wa_fieldcat-fieldname = <lfs_comp_wa>-name.
          wa_fieldcat-datatype  = <lfs_comp_wa>-type_kind.
          wa_fieldcat-inttype   = <lfs_comp_wa>-type_kind.
          wa_fieldcat-intlen    = <lfs_comp_wa>-length / 2.
          wa_fieldcat-decimals  = <lfs_comp_wa>-decimals.
          APPEND wa_fieldcat TO it_fieldcat.
     ENDLOOP.
     CALL METHOD cl_alv_table_create=>create_dynamic_table
          EXPORTING
               it_fieldcatalog = it_fieldcat
          IMPORTING
               ep_table = table_reference_copy_pre.
     ASSIGN table_reference_copy_pre->* TO <table_reference_copy>.
     <table_reference_copy> = p_reference.
     SORT <table_reference_copy> BY (column).
     DELETE ADJACENT DUPLICATES FROM <table_reference> COMPARING (column).
     DATA :
          gr_structdescr TYPE REF TO cl_abap_structdescr,
          gr_tabledescr TYPE REF TO cl_abap_tabledescr,
          gr_datadescr TYPE REF TO cl_abap_datadescr,
          gr_typedescr TYPE REF TO cl_abap_typedescr,
          gt_components TYPE abap_component_tab,
          gw_component TYPE LINE OF abap_component_tab,
          gr_wa TYPE REF TO DATA,
          gr_tab TYPE REF TO DATA.
     FIELD-SYMBOLS :
          <fs_wa> TYPE ANY,
          <fs_tab> TYPE TABLE.
     MOVE 'SIGN' to gw_component-name.
     gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 1 ).
     INSERT gw_component INTO TABLE gt_components.
     MOVE 'OPTION' to gw_component-name.
     gw_component-type ?= cl_abap_elemdescr=>get_c( p_length = 2 ).
     INSERT gw_component INTO TABLE gt_components.
     MOVE 'LOW' to gw_component-name.
     gw_component-type ?= cl_abap_elemdescr=>describe_by_name( column_type ).
     INSERT gw_component INTO TABLE gt_components.
     MOVE 'HIGH' to gw_component-name.
     gw_component-type ?= cl_abap_elemdescr=>describe_by_name( column_type ).
     INSERT gw_component INTO TABLE gt_components.
     gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
     CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
     ASSIGN gr_wa->* to <fs_wa>.
     gr_datadescr ?= gr_structdescr.
     gr_tabledescr ?= cl_abap_tabledescr=>create( gr_datadescr ).
     CREATE DATA gr_tab TYPE HANDLE gr_datadescr.
     ASSIGN gr_tab->* TO <fs_tab>.
     LOOP AT <table_reference> ASSIGNING <ls_tab>.
          ASSIGN COMPONENT position OF STRUCTURE <ls_tab> to <field>.
          CONCATENATE 'IEQ' <field> INTO <fs_wa>.
          APPEND <fs_wa> TO <fs_tab>.
     ENDLOOP.
     DELETE t_vbap WHERE vbeln NOT IN <fs_tab>.
ENDFORM.

Hello Jessie,
Which ABAP Release are you working on? Dynamic WHERE conditions for LOOP AT itab, MODIFY itab, and DELETE itab statements are possible from Release 702.
Even if you're on 702, the statement DELETE <table_travail> WHERE (column) NOT IN <fs_tab> won't work! You need to change your coding to:
DATA lv_dyn_cond TYPE string.
CONCATENATE column `NOT IN` `<FS_TAB>` INTO lv_dyn_cond SEPARATED BY space.
DELETE <table_travail> WHERE (lv_dyn_cond).
BR,
Suhas

Similar Messages

  • How to do parallel processing with dynamic internal table

    Hi All,
    I need to implement parallel processing that involves dynamically created internal tables. I tried doing so using RFC function modules (using starting new task and other such methods) but didn't get success this requires RFC enabled function modules and at the same time RFC enabled function modules do not allow generic data type (STANDARD TABLE) which is needed for passing dynamic internal tables. My exact requirement is as follows:
    1. I've large chunk of data in two internal tables, one of them is formed dynamically and hence it's structure is not known at the time of coding.
    2. This data has to be processed together to generate another internal table, whose structure is pre-defined. But this data processing is taking very long time as the number of records are close to a million.
    3. I need to divide the dynamic internal table into (say) 1000 records each and pass to a function module and submit it to run in another task. Many such tasks will be executed in parallel.
    4. The function module running in parallel can insert the processed data into a database table and the main program can access it from there.
    Unfortunately, due to the limitation of not allowing generic data types in RFC, I'm unable to do this. Does anyone has any idea how to implement parallel processing using dynamic internal tables in these type of conditions.
    Any help will be highly appreciated.
    Thanks and regards,
    Ashin

    try the below code...
      DATA: w_subrc TYPE sy-subrc.
      DATA: w_infty(5) TYPE  c.
      data: w_string type string.
      FIELD-SYMBOLS: <f1> TYPE table.
      FIELD-SYMBOLS: <f1_wa> TYPE ANY.
      DATA: ref_tab TYPE REF TO data.
      CONCATENATE 'P' infty INTO w_infty.
      CREATE DATA ref_tab TYPE STANDARD TABLE OF (w_infty).
      ASSIGN ref_tab->* TO <f1>.
    * Create dynamic work area
      CREATE DATA ref_tab TYPE (w_infty).
      ASSIGN ref_tab->* TO <f1_wa>.
      IF begda IS INITIAL.
        begda = '18000101'.
      ENDIF.
      IF endda IS INITIAL.
        endda = '99991231'.
      ENDIF.
      CALL FUNCTION 'HR_READ_INFOTYPE'
        EXPORTING
          pernr           = pernr
          infty           = infty
          begda           = '18000101'
          endda           = '99991231'
        IMPORTING
          subrc           = w_subrc
        TABLES
          infty_tab       = <f1>
        EXCEPTIONS
          infty_not_found = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        subrc = w_subrc.
      ELSE.
      ENDIF.

  • How to process very large internal tables and stop time limit

    Hello Experts,
    I am currently having a problem on how to fix a certain report where we process more than 500 thousand
    records in the internal table. I can't think of any solution that can make the below code any faster.
    I just checked in our prod server and the error time limit exceeded stops in the loop statement. Anyway,
    Below is the code. Any input will be appreciated. Thanks guys and take care!
    Get sales document and corresponding line item
      SELECT avbeln bposnr a~auart
             avkorg avtweg a~kunnr
             bmatnr bpstyv b~spart
        FROM vbak AS a
       INNER JOIN vbap AS b
          ON avbeln = bvbeln
       APPENDING TABLE lt_vbap
       WHERE a~auart IN lr_auart
         AND a~vbeln IN s_vbeln
         AND a~vbeln IN s_vbill
         AND a~vbtyp EQ p_vbtyp.
      LOOP AT lt_vbap ASSIGNING <wa_vbap>.
        IF <wa_vbap>-auart EQ 'ZUCI' OR
           <wa_vbap>-auart EQ 'ZURV' OR
           <wa_vbap>-auart EQ 'ZUPR'.
        Check ifa delivery document has been created
          CLEAR wa_vbill.
          SELECT SINGLE vbeln
            FROM vbfa
            INTO wa_vbill
           WHERE vbelv = <wa_vbap>-vbeln
             AND ( ( vbtyp_n EQ 'J' AND vbtyp_v = 'C' )
              OR ( vbtyp_n EQ 'T' AND vbtyp_v = 'H' ) ).
          IF sy-subrc <> 0.
            <wa_vbap>-del_ind = 'X'.
            CONTINUE.
          ELSE.
          Check if within selection parameters
            CLEAR wa_likp.
            READ TABLE lt_likp INTO wa_likp WITH KEY vbeln = wa_vbill.
            IF sy-subrc <> 0.
              SELECT SINGLE *
                FROM likp
                INTO wa_likp
               WHERE vbeln = wa_vbill.
              APPEND wa_likp TO lt_likp.
            ENDIF.
            IF NOT wa_likp-wadat_ist IN s_erdat.
              <wa_vbap>-del_ind = 'X'.
              CONTINUE.
            ENDIF.
          ENDIF.
        ELSE.
      Check if this has already been billed
          CLEAR wa_vbill.
          SELECT SINGLE vbeln
            FROM vbfa
            INTO wa_vbill
           WHERE vbelv = <wa_vbap>-vbeln
             AND ( ( vbtyp_n EQ 'M' AND vbtyp_v = 'C' )
              OR ( vbtyp_n EQ 'O' AND vbtyp_v = 'H' ) ).
          IF sy-subrc <> 0.
            <wa_vbap>-del_ind = 'X'.
            CONTINUE.
          ELSE.
          Check if within selection parameters
            CLEAR wa_vbrk.
            READ TABLE lt_vbrk INTO wa_vbrk WITH KEY vbeln = wa_vbill.
            IF sy-subrc <> 0.
              SELECT SINGLE vbeln fkdat
                FROM vbrk
                INTO wa_vbrk
               WHERE vbeln = wa_vbill.
              APPEND wa_vbrk TO lt_vbrk.
            ENDIF.
            IF NOT wa_vbrk-fkdat IN s_erdat.
              <wa_vbap>-del_ind = 'X'.
              CONTINUE.
            ENDIF.
          ENDIF.
        ENDIF.
      Get Material Type and Division
        IF <wa_vbap>-spart IS NOT INITIAL.
          SELECT SINGLE mtart
            FROM mara
            INTO lv_mtart
           WHERE matnr = <wa_vbap>-matnr.
        ELSE.
          SELECT SINGLE mtart spart
            FROM mara
            INTO (lv_mtart,<wa_vbap>-spart)
           WHERE matnr = <wa_vbap>-matnr.
        ENDIF.
      If material division is same as parameter division
        IF <wa_vbap>-spart = p_spart.
      If material is subsidiary-owned
       IF <wa_vbap>-spart in lr_spart.
        If customer is the same as that of parameter division
          IF <wa_vbap>-kunnr NE lr_kunnr OR <wa_vbap>-auart EQ 'ZUDO' OR <wa_vbap>-auart EQ 'ZUS3'.
          If item is a free good, tag order type as 'ZUPR' to treat
          the item the same way as 'ZUPR'
            IF <wa_vbap>-pstyv = 'TANN' OR
               <wa_vbap>-pstyv = 'ZKNF' OR
               <wa_vbap>-pstyv = 'ZKNN' OR
               <wa_vbap>-pstyv = 'ZFLO' OR
               <wa_vbap>-pstyv = 'ZKBF' OR
               <wa_vbap>-pstyv = 'ZKLN' OR
               <wa_vbap>-pstyv = 'ZREN'.
              lv_auart = <wa_vbap>-auart.
              IF lv_auart EQ 'ZUPR'.
                CLEAR <wa_vbap>-pstyv.
              ENDIF.
              <wa_vbap>-auart = 'ZUPR'.
              CLEAR: lv_mtart.
            ENDIF.
          Set Cost of Goods Sold Account
            <wa_vbap>-cogshkont = '0050000010'.
            CASE <wa_vbap>-auart.
              WHEN 'ZUPR'.
                CASE lv_mtart.
                  WHEN 'ZUL4'.
                    <wa_vbap>-del_ind = 'X'.
                    CONTINUE.
                  WHEN OTHERS.
                  Check if division is defined in mapping table
                    READ TABLE lt_ulsub INTO wa_ulsub
                         WITH KEY spart = <wa_vbap>-spart.
                    IF sy-subrc = 0.
                      <wa_vbap>-kostl = wa_ulsub-kostlp.
                      <wa_vbap>-bukrs = wa_ulsub-bukrsp.
                      <wa_vbap>-type = 'TP'.
                    Set Cost of Goods Sold Account
                      IF lv_auart = 'ZUPR'.
                        <wa_vbap>-cogshkont = '0050000006'.
                      ENDIF.
                    ELSE.
                      <wa_vbap>-del_ind = 'X'.
                      CONTINUE.
                    ENDIF.
                ENDCASE.
              WHEN 'ZUCI' OR 'ZUDO' OR 'ZURD' OR 'ZUS3'.
            Get cost center from header text
                PERFORM get_cost_center USING <wa_vbap>-vbeln
                                     CHANGING <wa_vbap>-kostl.
    *  Change by LGTE 11-02-2006
            Check if Medvale sales
                IF <wa_vbap>-auart EQ 'ZUCI' AND <wa_vbap>-kostl IS INITIAL.
                  <wa_vbap>-del_ind = 'X'.
                  CONTINUE.
            Check if UL Cost Center
                ELSEIF <wa_vbap>-kostl NE gv_ul_kostl.
               IF <wa_vbap>-kostl NE gv_ul_kostl.
    *  End change.
              Get material division and check if subsidiary product
                 SELECT SINGLE spart FROM mara INTO <wa_vbap>-spart
                 WHERE matnr = <wa_vbap>-matnr.
                  READ TABLE lt_ulsub INTO wa_ulsub
                       WITH KEY spart = <wa_vbap>-spart.
                  IF sy-subrc = 0.
                  Get requestor's company code from cost center data
                    SELECT SINGLE bukrs
                      FROM csks
                      INTO <wa_vbap>-bukrs
                     WHERE kokrs =  lc_kokrs
                       AND kostl =  <wa_vbap>-kostl
                       AND datbi GE sy-datum
                       AND datab LE sy-datum.
                    IF sy-subrc = 0.
                    For donations, only include if a subsidiary company is donating
                      IF <wa_vbap>-auart EQ 'ZUDO' OR <wa_vbap>-auart EQ 'ZUS3'.
                        IF NOT <wa_vbap>-kunnr IN lr_kunnrnt.
                          <wa_vbap>-del_ind = 'X'.
                          CONTINUE.
                        ENDIF.
                       CHECK <wa_vbap>-kunnr IN lr_kunnrnt.
                      ENDIF.
                    For ZUCI, if the company code of the costcenter is UL, do not include
                      IF <wa_vbap>-bukrs EQ gc_ul_bukrs.
                        <wa_vbap>-del_ind = 'X'.
                        CONTINUE.
                      ENDIF.
                      IF <wa_vbap>-bukrs = wa_ulsub-bukrsp.
                        <wa_vbap>-type = 'RV'.
                      ELSE.
                        <wa_vbap>-type = 'RV'.
                      ENDIF.
                    ELSE.
                    Check if customer defined in table ZFI_DONATIONS
                      SELECT SINGLE kunnr FROM zfi_donations INTO <wa_vbap>-kostl
                        WHERE kunnr = <wa_vbap>-kostl.
                      IF sy-subrc <> 0.
                        lv_error = 'X'.
                        CONCATENATE 'Cost center/Customer' <wa_vbap>-kostl
                                    'does not exist. Please check Sales Order'
                                    <wa_vbap>-vbeln
                                    INTO lt_disp-message SEPARATED BY space.
                        lt_disp-type = 'E'.
                        <wa_vbap>-del_ind = 'X'.
                        APPEND lt_disp.
                        CONTINUE.
                      ELSE.
                        <wa_vbap>-type = 'RV'.
                      ENDIF.
                    ENDIF.
                  ELSE.
                    <wa_vbap>-del_ind = 'X'.
                    CONTINUE.
                  ENDIF.
                ELSE.
                  <wa_vbap>-del_ind = 'X'.
                  CONTINUE.
                ENDIF.
              WHEN OTHERS.
                <wa_vbap>-del_ind = 'X'.
                CONTINUE.
            ENDCASE.
          ELSE.
            <wa_vbap>-del_ind = 'X'.
            CONTINUE.
          ENDIF.
        ELSE.
          <wa_vbap>-del_ind = 'X'.
          CONTINUE.
        ENDIF.
      Get company code description
        SELECT SINGLE butxt FROM t001 INTO <wa_vbap>-butxt
         WHERE bukrs = <wa_vbap>-bukrs.
        IF sy-subrc <> 0.
          SELECT SINGLE name1 FROM kna1 INTO <wa_vbap>-butxt
           WHERE kunnr = <wa_vbap>-kostl.
        ENDIF.
    Change by LGTE on 11-02-2006
    Get Transaction Type
        CASE <wa_vbap>-auart.
          WHEN 'ZUPR'. "UL Promo/Samples
            IF <wa_vbap>-pstyv = 'TANN' OR
               <wa_vbap>-pstyv = 'ZKNF' OR
               <wa_vbap>-pstyv = 'ZKNN' OR
               <wa_vbap>-pstyv = 'ZFLO' OR
               <wa_vbap>-pstyv = 'ZKBF' OR
               <wa_vbap>-pstyv = 'ZKLN' OR
               <wa_vbap>-pstyv = 'ZREN'.
              <wa_vbap>-ltext = 'Free Goods'.
            ELSE.
              <wa_vbap>-ltext = 'Product Samples'.
            ENDIF.
          WHEN 'ZUDO'. "Donations - R/3
            <wa_vbap>-ltext = 'Donations - R/3'.
          WHEN 'ZUCI'. "Donations - ZUCI
            <wa_vbap>-ltext = 'Donations - ZUCI'.
          WHEN 'ZURD' OR 'ZUS3'. "UL Returns - Donation
            <wa_vbap>-ltext = 'UL Returns - Donation'.
        ENDCASE.
    Get material description
        SELECT SINGLE maktx
          FROM makt
          INTO <wa_vbap>-maktx
         WHERE matnr = <wa_vbap>-matnr
           AND spras = sy-langu.
    Get division from material master
       SELECT SINGLE spart FROM mara INTO <wa_vbap>-spart
        WHERE matnr = <wa_vbap>-matnr.
    Get division description
        SELECT SINGLE vtext
          FROM tspat
          INTO <wa_vbap>-vtext
         WHERE spras = sy-langu
           AND spart = <wa_vbap>-spart.
    Get Valuation Class
        SELECT SINGLE bklas
          FROM mbew
          INTO lv_bklas
         WHERE matnr = <wa_vbap>-matnr.
    Determine G/L of FG Based on Valuation Class
        READ TABLE lt_val_cls INTO wa_val_cls WITH TABLE KEY bklas = lv_bklas.
        <wa_vbap>-fghkont = wa_val_cls-hkont.
    Determine Cost Center of Cogs Account
        READ TABLE lt_ulsub INTO wa_ulsub WITH TABLE KEY spart = <wa_vbap>-spart.
        <wa_vbap>-cogskostl = wa_ulsub-kostlp.

    Hi!
    First of all, don't use SELECT SINGLE inside of LOOP,
    instead  SELECT all relevated rows before LOOP in intertal tables (using FOR ALL ENTRIES) and then use
    READ TABLE WITH KEY BINARY SEARCH.
    it will match faster.
    for example:
    IF NOT lt_vbap[] IS INITIAL.
    SELECT vbeln
    FROM vbfa
    INTO lt_vbill
    FOR ALL ENTRIES IN lt_vbap
    WHERE vbelv = lt_vbap-vbeln.
    ENDIF.
    SORT lt_vbap BY vbeln.
    READ TABLE lt_vbill WITH KEY vbeln = <wa_vbap>-vbeln
    BINARY SEARCH.

  • Usage of field-symbol to internal table generically.

    Hi gurus,
    please tell the usage of field symbol to an internall table.
    how do i use field symbol generically , so that i can use same field symbol for many different internal tables.
    regards,
    krishna
    TABLES: EKKO.
    DATA: ITAB TYPE STANDARD TABLE OF EKKO INITIAL SIZE 1.
    SELECT-OPTIONS: P_EBELN FOR EKKO-EBELN OBLIGATORY.
    FIELD-SYMBOLS <FS> TYPE any.
    SELECT *
    FROM EKKO
    INTO TABLE ITAB
    WHERE EBELN IN P_EBELN.
    LOOP AT ITAB ASSIGNING <FS> casting ekko.
      WRITE:/ <FS>-EBELN, <FS>-BUKRS, <FS>-LIFNR, <FS>-AEDAT, <FS>-EKGRP, <FS>-STATU, <FS>-SPRAS.
    ENDLOOP.

    How about something SIMPLE like this.
    This creates a dynamic table and displays it in an editable grid.
    The key to a real Generic internal table is to use the RTTI  functionality to generate a field catalog of the structure you want to use as an internal table and then create a dynamic table based on the FCAT created from your structure.
    For the code shown below code a simple screen ( SE51) with a custom container on it  called CCONTAINER1.
    Code also a standard status (SE41) with just the BACK, EXIT and CANCEL buttons on it.
    You can use this type of program as a model for ANY dynamic table. Note however that you still can't include DEEP structure in your dynamic table.
    With the program shown below you can edit the grid but you'll have to add your own functionality such as cell selection, double click etc etc.
    All the code is showning you really is how to take any user defined structure and simply without a whole load of fuss, buld an FCAT, a DYNAMIC TABLE, Populate it and display a grid.
    DO NOT EVER USE AGAIN THE OLD SLIS MODULES SUCH AS FM REUSE_ALV_etc.   Go for OO either cl_gui_alv_grid or if you don't need to edit anything the new SALV class.
    If you are still on 4.6 then the SALV class won't exist but the cl_gui_alv_grid class is fine.
    You can see also just by changing a few lines of codeyou can   display a grid of almost any structure you can think of (or populate another dynamic table).
    Note also if you have an actual table defined you can also always code something like your_itab[] = <dyn_table>  so you can retrieve your data easily enough via standard abap.
    All you need to do is define your structure, create the fcat and populate the dynamic table.
    Even if you don't want a a GRID you've got your data in a dynamic table which is what I believe you wanted in the first place. You don't have to display or use a GRID if you don't need to but I've added the code here as lots of applications need to display data in just these types of lists.
    Now surprise your Boss by coding in 10 mins a program he / she thought would take you 1 week. !!!!!.
    program zzz_simple_editable_grid.
    * Define any structure
    types:  begin of s_elements,
      vbeln   type vapma-vbeln,
      posnr   type vapma-posnr,
      matnr   type vapma-matnr,
      kunnr   type vapma-kunnr,
      werks   type vapma-werks,
      vkorg   type vapma-vkorg,
      vkbur   type vapma-vkbur,
      status  type c,
    end of  s_elements.
    * end of your structure
    data lr_rtti_struc type ref to cl_abap_structdescr .
    data:
        zog                     like line of lr_rtti_struc->components .
    data:
      zogt                    like table of zog,
    wa_it_fldcat type lvc_s_fcat,
    it_fldcat type lvc_t_fcat ,
    dy_line            type ref to data,
    dy_table           type ref to data.
    data:  dref               type ref to data.
    field-symbols: <fs> type any,
       <dyn_table>    type  standard table,
       <dyn_wa>.
    data grid_container1 type ref to cl_gui_custom_container .
    data grid1 type ref to cl_gui_alv_grid .
    data: ok_code type sy-ucomm.
    data: struct_grid_lset type lvc_s_layo.
    *now I want to build a field catalog
    * First get your data structure into a field symbol
    create data dref type s_elements.
    assign dref->* to <fs>.
    lr_rtti_struc ?= cl_abap_structdescr=>describe_by_data( <fs> ).
    * Now get the structure details into a table.
    * table zogt[] contains the structure details
    * From which we can build the field catalog
    zogt[]  = lr_rtti_struc->components.
    loop at zogt into zog.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = zog-name .
      wa_it_fldcat-datatype = zog-type_kind.
      wa_it_fldcat-inttype = zog-type_kind.
      wa_it_fldcat-intlen = zog-length.
      wa_it_fldcat-decimals = zog-decimals.
      wa_it_fldcat-coltext = zog-name.
      wa_it_fldcat-lowercase = 'X'.
      append wa_it_fldcat to it_fldcat .
    endloop.
    * You can perform any modifications / additions to your field catalog
    * here such as your own column names etc.
    * Now using the field catalog created above we can
    * build a dynamic table
    * and populate it
    * First build the dynamic table
    * the table will contain entries for
    * our structure defined at the start of the program
    call method cl_alv_table_create=>create_dynamic_table
           exporting
                it_fieldcatalog = it_fldcat
           importing
                ep_table = dy_table.
    assign dy_table->* to <dyn_table>.
    create data dy_line like line of <dyn_table>.
    assign dy_line->* to <dyn_wa>.
    * Now fill our table with data
    select vbeln posnr matnr kunnr werks vkorg vkbur
           up to 200 rows
           from vapma
           into  corresponding fields of table <dyn_table>.
    * Call the screen to display the grid
    call screen 100.
    * PBO module
    module status_0100 output.
    data: off type int4.
    break-point 1.
    if sy-batch = 'X'.
    call method cl_gui_alv_grid=>offline
    receiving
    e_offline = off.
    endif.
    if sy-batch = 'X'.
    if ( off is initial ).
        create object grid_container1
                exporting
                   container_name = 'CCONTAINER1'.
        create object  grid1
           exporting
              i_parent = grid_container1.
    endif.
    endif.
    if sy-batch ne 'X'.
       if grid_container1 is initial.
         create object grid_container1
                 exporting
                    container_name = 'CCONTAINER1'.
      endif.
        create object  grid1
           exporting
              i_parent = grid_container1.
       if sy-batch ne 'X'.
        struct_grid_lset-edit = 'X'.    "To enable editing in ALV
      endif.
      endif.
        call method grid1->set_table_for_first_display
          exporting is_layout =  struct_grid_lset
          changing
                     it_outtab       = <dyn_table>
                     it_fieldcatalog = it_fldcat.
      set pf-status '001'.
      set titlebar '000'.
    endmodule.
    * PAI module
    module user_command_0100 input.
      case sy-ucomm.
        when 'BACK'.
          leave program.
        when 'EXIT'.
          leave program.
        when 'RETURN'.
          leave program.
        when others.
      endcase.
    endmodule.
    Cheers
    jimbo

  • Processing in 2 internal tables -Performance wise better option

    Hi Experts,
    I have 2 internal tables.
    ITAB1 and ITAB2  both are sorted by PSPHI.
    ITAB1 has PSPHI  some more fields INVOICE DATE  and AMT
    ITAB2 has PSPHI  some more fields amount.
    Both itab1 and itab2 will always have same amount of data.
    I need to filter data from ITAB2 based invoice date given on selection screen.since ITAB2 doesnt have invoice date field.
    i am doing further processing to filter the records.
    I have thought of below processing logic and wanted to know if there is a better option performance wise?
    loop at ITAB1 into wa where invoice_date > selection screen date. (table which has invoice date)
    lv_index = sy-tabix.
    read table itab2 where psphi = wa-psphi and index = lv_index.
    if sy-subrc = 0.
    delete itab2 index lv_index.
    endif.
    endloop.

    Hi Madhu,
    My Requirement is as below could you please advice on this ?
    ITAB1
    Field   1 PSPHI ,    FIELD 2 INVOICE,  FIELD 3 INVOICE_DATE , FIELD4 AMT
                 15245,                       INV1,                           02/2011  ,  400
                  15245                       INV2                            02/2012  ,  430
    ITAB2
       Field   1 PSPHI ,    FIELD 2 PSNR,      FIELD 3 MATNR  , FIELD4 AMT
                 15245,                       PSNR1,                   X .          430
                  15245                       IPSNR2                    Y,          400
    When user enteres date on sel screen as 02/2011
    I want to delete the data from itab1 and itab2 for invoice date greater then 02/2011/
    If i delere ITAB1 for date > selection screen date.
    Loop itab1.
    delete itab2 where psphi in itab1 will delete both rows in above example because the field psphi which is common can be mutiple.
    endloop.
    Can you advice ?

  • Uploading data from excel file to a dynamically created internal table

    Hi,
    I have a requirement where i have to upload data from an excel file into a database table. I would be able to determine the structure of the table only at runtime based on the user input.. so i have created an internal table dynamically.
    Could you please tell me if its possible to upload data from an excel file to the dynamically created internal table using any function modules?
    I thought of doing this by declaring a generic internal table of one field and then uploading the *.csv file into it and then splitting it based on "," and then assigning it to the field symbol referencing the internal table.. but my file length exceeds 132 characters and i'm only able to get data of lenght 132 char's in my internal table ( generic one).
    Could anyone please show me a way around this.
    Thanks in advance,
    Harsha

    Sure, check this out.
    report zrich_0002.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: it_fldcat type lvc_t_fcat,
          wa_it_fldcat type lvc_s_fcat.
    type-pools : abap.
    data: new_table type ref to data,
          new_line  type ref to data.
    data: iflat type table of string.
    data: xflat type string.
      data: irec type table of string with header line.
      data: tabix type sy-tabix.
    data: file type string.
    selection-screen begin of block b1 with frame title text .
    parameters: p_file type  rlgrap-filename default 'c:Test.csv'.
    parameters: p_flds type i.
    selection-screen end of block b1.
    start-of-selection.
    * Add X number of fields to the dynamic itab cataelog
      do p_flds times.
        clear wa_it_fldcat.
        wa_it_fldcat-fieldname = sy-index.
        wa_it_fldcat-datatype = 'C'.
        wa_it_fldcat-inttype = 'C'.
        wa_it_fldcat-intlen = 10.
        append wa_it_fldcat to it_fldcat .
      enddo.
    * Create dynamic internal table and assign to FS
      call method cl_alv_table_create=>create_dynamic_table
                   exporting
                      it_fieldcatalog = it_fldcat
                   importing
                      ep_table        = new_table.
      assign new_table->* to <dyn_table>.
    * Create dynamic work area and assign to FS
      create data new_line like line of <dyn_table>.
      assign new_line->* to <dyn_wa>.
      file = p_file.
      call method cl_gui_frontend_services=>gui_upload
        exporting
          filename                = file
        changing
          data_tab                = iflat
        exceptions
          file_open_error         = 1
          file_read_error         = 2
          no_batch                = 3
          gui_refuse_filetransfer = 4
          invalid_type            = 5
          no_authority            = 6
          unknown_error           = 7
          bad_data_format         = 8
          header_not_allowed      = 9
          separator_not_allowed   = 10
          header_too_long         = 11
          unknown_dp_error        = 12
          access_denied           = 13
          dp_out_of_memory        = 14
          disk_full               = 15
          dp_timeout              = 16
          others                  = 17.
      loop at iflat into xflat.
        clear irec. refresh irec.
        split xflat at ',' into table irec.
        loop at irec.
          tabix = sy-tabix.
          assign component tabix of structure <dyn_wa> to <dyn_field>.
          <dyn_field> = irec.
        endloop.
        append <dyn_wa> to <dyn_table>.
      endloop.
    * 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.
    Regards,
    Rich Heilman

  • Control statement in internal tables

    hi experts,
    can any body will provide me the control statement of internal table.
                                                               thank you

    Hi,
    check this link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db9f1f35c111d1829f0000e829fbfe/content.htm
    Control Break Statements
    Control break statements are used to create statement blocks which process only specific table lines the LOOP – ENDLOOP block.
    You open such a statement block with the control level statement AT and close it with the control level statement ENDAT. The syntax is as follows:
    Table should be sorted when you use control-break statements
    You can break the sequential access of internal tables by using these statements.
    Syntax:
    At first.
    <Statement block>
    Endat.
    This is the first statement to get executed inside the loop (remember control break statements are applicable only inside the loop)
    So in this block you can write or process those statements which you want to get executed when the loop starts.
    At New carrid.
    Write:/ carrid.
    Endat.
    In this case whenever the new carrid is reached, carrid will be written.
    At End of carrid.
    Uline.
    Endat.
    In this case whenever the end of carrid is reached, a line will be drawn.
    At Last.
    Write:/ ‘Last Record is reached’.
    Endat.
    Processing of statements within this block is done when entire processing of entire internal table is over. Usually used to display grand totals.
    You can use either all or one of the above control break statements with in the loop for processing internal table.
    At end of carrid.
    Sum.
    Endat.
    In above case the statement SUM (applicable only within AT-ENDAT) will sum up all the numeric fields in internal table and result is stored in same internal table variable.
    Regards,
    Sruthi

  • Internal Table Logic Needed

    Hi all,
    I have a requirement regarding data processing in a internal table,
    internal table consists of filelds Vendor,Material and Scheduling Dates and Total Qty.
    Here i need to fill the field Total Quantity, individual addition of quanties of that material for a particular vendor .
    Let us consider intitially my internal table consists of data like this with these fields.
                      Vendor ,           Material  ,            qty(individual),   Total qty   ,  Schedule dates
                       v1        ,           m1       ,                 10          
                       v1        ,           m1        ,                10
                       v1       ,             m1       ,                  20
                       v1       ,              m2      ,                    5
                       v1       ,             m2        ,                 10
                       v2        ,            m2         ,                20
                      v2        ,             m2        ,                  15
                      v2        ,            m3         ,                  20
                      v2        ,            m3           ,                10
        Initiall the total qty field is empty i need to fill tht field for the last item for a particular material Like M1
      for vendor v1 and total qty of m2 for vendor v1, total qty of m1 for v2, total qty of m2 for v2 and so on.
    Requied output should be like this.
                     Vendor     ,          Material       ,    qty(individual)            Total qty   Schedule dates
                      v1         ,                m1         ,         10           ,               0        
                       v1          ,              m1          ,        10           ,                 0
                       v1         ,                m1         ,         20          ,                40(101020)
                       v1        ,                 m2          ,         5           ,               0
                       v1          ,               m2           ,      10            ,              15(5+10)
                       v2          ,               m2          ,        20            ,             0    
                       v2          ,               m2           ,       15             ,              35(20+15)
                      v2           ,              m3          ,        20              ,             0
                      v2            ,              m3           ,       10              ,           30(20+10)
    Here i made one thing , i calculated the total qty of material for particular vendor.
    Like              
             Vendor                           Material                     Total Qty      
                     v1        ,                        m1            ,             40
                     v1        ,                       m2              ,            15
                     v2         ,                     m2                ,           35
                     v2          ,                    m3                 ,           30
    Finally i need the logic by using Control Events(At New   , At End of )  to adjust that total qty of a material for a particular vendor by Modifying the internal table.
    i hope my problem is clear , pls let me know if any clarifications needed. and
    code for the same .
    Thannks in advance,
    Niranjan.

    Hi,
    Solution is here.
    sort itab by vendor material.
    field-symbols: <itab> like line of itab.
    loop at itab assigning <itab>.
    on change of vendor.
    clear flag.
    endon.
    add <itab>-quanity to lw_quantiy.
    *--here pdate internal table end of each similar kind of record
    at end of.
    flag = 'x'.
    <itab>-totalqty =  lw_quantiy.
    clear  lw_quantiy
    endat.
    *--rest of record update zero by checking flag
    if flag is initial.
    <itab>-totalqty = 0.
    endif.
    endloop.
    close this thread if you got solution.
    Regards,
    Peranandam

  • How to process a block for each row in an internal table....

    Hi experts....
    In po approval workflow the scenario is like this.... for each po there may be more than one approver. approvers list i am maintaining in the ztable. list of approvers(no of approvers) is decided by the po value. I have collected these approvers into internal table. now i have to process a block ( approving or rejecting the po... )in the workflow for each row in the internal table.
    how can i do this. based on the decision of the 1st approver  approves the po then it should go to next approver in the internal table...otherwise end the workflow.....
    Please help me......

    i have created an internal table in the workflow container in which i am getting the list of approvers....
    how can i loop the internal table in the workflow...?
    how can i know the index of the loop in the workflow.....(will sy-index work here....? so that i can use loop until step in the main workflow to call the subworkflow..so that if sy-index is greater than no of entires in the itab then i can come out of the loop)

  • Error "Error in ABAP statement when processing an internal table. table."

    Hello,
    I am facing the error when tried for GR from SRM portal for my shopping cart and for others created shopping cart. The error is
    "Error in ABAP statement when processing an internal table. table."
    I have the central receipient role. Couold any body assist me?
    Thanks,
    Pijush

    Hi Harish,
    Execute the query in RSRT and check whether you have any short dump is in ST22. This would give a clear idea at what might have gone wrong.
    Another thing is to check whether the code for the variable is fine in the user exit.
    Hope this helps.
    Bye
    Dinesh

  • Import from database an internal table with generic Type : Web Dynpro ABAP

    Hi everyone,
    i have a requirement in which i'm asked to transfer data flow between two frameworks, from WD Component to another. The problem is that i have to transfer internal tables with generic types. i used the import/ export from database approache but in that way i get an error message saying "Object references and data references not yet supported".
    Here is my code to extract a generic internal table from memory.
        DATA l_table_f4 TYPE TABLE OF REF TO data.
      FIELD-SYMBOLS: <l_table_f4> TYPE STANDARD TABLE.
      DATA lo_componentcontroller TYPE REF TO ig_componentcontroller .
      DATA: ls_indx TYPE indx.
      lo_componentcontroller =   wd_this->get_componentcontroller_ctr( ).
      lo_componentcontroller->fire_vh_search_action_evt( ).
      ASSIGN l_table_f4 TO <l_table_f4>.
    *-- Import table for Help F4
      IMPORT l_table_f4 TO <l_table_f4> FROM DATABASE indx(v1) TO ls_indx ID 'table_help_f4_ID'.
    The error message is desplayed when last instruction is executed " IMPORT l_table_f4...".
    I saw another post facing the same problem but never solved "Generic Type for import Database".
    Please can anyone help ?
    Thanks & Kind regards.

    hi KIan,
    go:
    general type
    TYPE : BEGIN OF ty_itab,
               field1 TYPE ztab-field1,
               field2 TYPE ztab-field2,
    *your own fields here:
               field TYPE i,
               field(30) TYPE c,
               END OF ty_itab.
    work area
    DATA : gw_itab TYPE ty_itab.
    internal table
    DATA : gt_itab TYPE TABLE OF ty_itab.
    hope this helps
    ec

  • Get the fieldnames of a generic internal table or work area

    Hi All,
           I have one generic work area which I have created in the below manner...
    * ET_DATA itself is a generic table of type ANY...can have any internal table data in it.
    * Create dynamic internal table
      CREATE DATA lv_new_table LIKE et_data.
      ASSIGN lv_new_table->* TO <fs_dyn_table>.
    * Create dynamic work area and assign to fieldsymbol.
      CREATE DATA lv_new_line LIKE LINE OF <fs_dyn_table>.
      ASSIGN lv_new_line->*   TO <fs_dyn_wa>.
    Now...I need to get the field names of this dynamic internal table or work area..
    I have already searched in forum...got many answers..but none them gives me the output.
    Please note that I require the field names and not field position..
    Awaiting your suggestions on how to get field names of this dynamic work area...

      create data wa_ref like line of it_data.
      assign wa_ref->* to <p_data>.
      desc_table ?= cl_abap_tabledescr=>describe_by_data( it_data ).
      desc_struc ?= desc_table->get_table_line_type( ).
      describe field <p_data> type rtty components ncom.
    This one is working in our environment without any error. it_data is an importing parameter in the signature of a method of type any table.

  • Generic Internal Table

    Hi,
       I need to develop a module that takes an infotype as input, does 'select * from <infotype table>' and writes data to a file. This module needs to be generic and should work for any infotype (even custom infotype).
    For example, if input is PA0001, it should do 'Select * from PA0001'.
    Any suggestions on how to do this?. Do i need to use field symbols?. Please let me know if you have any ideas.
    Thanks,
    Sandeep

    REPORT  Z_TEST.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: alv_fldcat type slis_t_fieldcat_alv,
          it_fldcat type lvc_t_fcat.
    type-pools : abap.
    data : it_details type abap_compdescr_tab,
           wa_details type abap_compdescr.
    data : ref_descr type ref to cl_abap_structdescr.
    data: new_table type ref to data,      new_line  type ref to data,      wa_it_fldcat type lvc_s_fcat.
    selection-screen begin of block b1 with frame title text .
    parameters: p_table(30) type c.
    selection-screen end of block b1.
    data: test type pa0008 occurs 0.
    select * from pa0008 into table test where endda = '99991231'.
    Get the structure of the table.
    ref_descr ?= cl_abap_typedescr=>describe_by_name( p_table ).
    it_details[] = ref_descr->components[].
    loop at it_details into wa_details.
      clear wa_it_fldcat.
      wa_it_fldcat-fieldname = wa_details-name .
      wa_it_fldcat-datatype = wa_details-type_kind.
      wa_it_fldcat-inttype = wa_details-type_kind.
      wa_it_fldcat-intlen = wa_details-length.
      wa_it_fldcat-decimals = wa_details-decimals.
      append wa_it_fldcat to it_fldcat .
    endloop.
    Create dynamic internal table and assign to FS
    call method cl_alv_table_create=>create_dynamic_table exporting
    it_fieldcatalog = it_fldcat
    importing
    ep_table        = new_table.
    assign new_table->* to <dyn_table>.
    Create dynamic work area and assign to FS
    create data new_line like line of <dyn_table>.
    assign new_line->* to <dyn_wa>.
    Select Data from table.
    select * into corresponding fields of table <dyn_table>           from
    (p_table).
    *select * from
    *(p_table) into corresponding fields of table <dyn_table>     up to 5 rows  where endda = '99991231'.
    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.

  • Making parmanent changes to a internal table inside a user exit

    Hi All,
    I am having a User exit to which I am passing a structure as importing parameter.
    The user exit is not exporting the same structure, but is exporting some other values.
    My problem is that I want to make parmanent changes in the structure I am passing to the user exit.
    Currently what is happening:
    I am passing the structure to the user exit. It has got 6 rows. Inside the user exit I am making some changes to a particular field of all the rows. Till the program control is inside the user exit the changes in the structure are visible. As soon as the control come out of the user exit, the values for the field are switched to teh old values(values before passing to teh user exit).
    My question is, is there any method to make changes to a internal table inside a user exit and these changes are visible outside it when the program control come out of the user exit. (This is when the internal table to which the change is made in not exported by the user exit)

    Hi Dear,
    Your changes done in import parameters will not reflect outside exit. You can only change the values of export parameters...
    If you have very urgent requirement then make changes in SAP''s Standard code.
    For your problem you can write to SAP. In many cases SAP provides the solution.
    Award Points If Useful.

  • Need help in processing internal table

    Hi all,
    Im facing a  problem in processing an internal table..especially with MODIFY.
    The internal table is having following records.(t_vttp)
    TKNUM       VBELN      KUNNR       NAME1                             LAND1
    0000975179|0071004839|0000022946|HUNTSMAN APC LIMITED               |SA   |
    0000975180|0071004845|0000022946|                                   |     |
    In the above, there are two delviry documents with same customers.
    The customer data is coming from different internal table.
      LOOP AT t_vttp.
        READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.
        IF sy-subrc = 0.
          t_vttp-name1 = wa_kna1_temp-name1.
          t_vttp-land1 = wa_kna1_temp-land1.
          MODIFY t_vttp INDEX sy-tabix TRANSPORTING name1 land1.
        ENDIF.
      ENDLOOP.
    Here for second record,,the customer name and country is nt getting populated to t_vttop.
    Pls correct where it is going wrong.
    Thanks,
    Priya

    Hi Try the follwoing code with a little modification in your code.
    LOOP AT t_vttp.
    READ TABLE t_kna1_temp INTO wa_kna1_temp WITH KEY kunnr = t_vttp-kunnr.
    IF sy-subrc = 0.
    t_vttp-name1 = wa_kna1_temp-name1.
    t_vttp-land1 = wa_kna1_temp-land1.
    MODIFY t_vttp INDEX sy-tabix  TRANSPORTING name1 land1.
    append t_vttp.
    ENDIF.
    clear: wa_kna1_temp, t_vttp.
    ENDLOOP
    Also Please debugg your code and check if you are getting values.
    also check the value of t_vttp-kunnr in debugging for the second run of your loop.
    thanks
    lalit

Maybe you are looking for

  • Mac mini Late 2012 - 8 gb of ram worth it?

    Hello :) Are 8 gigabytes of ram worth it for my my Mac mini? I use it for Xcode and sometimes my Mac takes a bit too long for easy tasks. Or should I take 16 gb ? Thanks for answers Thomas

  • Re run payment run

    Hi Friends , signatures did not pop up on prenumbered checks and I am in a situation where I have to reprint all the checks through payment run. can anyone tell me how do I do that. Thanks

  • Querying data from External Source from FORMS

    I have a form that is built based on Oracle tables. But I need to get data from external Data source from within Forms and use it fro validation. I need to execute a Select statement via ODBC from within Forms procedures. This is going to a SQL Serve

  • Download Standard Business Packages of MM,SD for IViews

    Hi Experts, I want to download the Standard Business Packages for MM, SD Etc Modules. So from where i can get this, such that i am able to use them in Portal. Pls help me out. Regards, DS

  • Problem starting Oracle Weblogic Admin Server in 11.1.1.3

    Hi, When I try to start the Weblogic Admin server on linux box,its throwing an error.Complete Error Stack trace is as follows. I have tried with solutions given in Facing problems will installing SOA 11.1.1.3 Error message: JPS-01538: The default pol