Read contents of changing fields from internal table

Hi Folks,
Please help me in my query below:
Consider there is a Z-table with two fields TABNAM and FIELD having values KNA1 and NAME1 respectively.
In my report I have fetched entries for customers from KNA1. Now based on the field from Z-table I want to populate a variable suppose V_FREE_VAR with the value from KNA1 table.
Here V_FREE_VAR is of CHAR200 so that it accomodate all types of values from KNA1.
The value of Z-table FIELD can change daily i.e next day the value may be PSTLZ.
So how can I read the particular field from internal table as the field to be read is dynamic.
Note: using case is not feasible.
Thanks in advance.
Regards,
Shardul

@Hartmut P
As Rob said i want to get the value of the field from internal table. the code is something like this.
I_KNA1 contains records for customers.
Suppose values of Z-table are in internal table I_TEMP_TABLE.
Entries in I_TEMP_TABLE are as follows
TABNAME      FIELDNAME
KNA1                 NAME1
The value of FIELNAME in Z-table can be changed
Loop at I_TEMP_TABLE into WA_TEMP_TABLE.
Read I_KNA1 into WA_KNA1 with key KUNNR = '0001002234'.
IF SY-SUBRC EQ 0.
   CASE WA_TEMP_TABLE-FIELDNAME.
        WHEN 'NAME1'.
             V_VAR = WA_KNA1-NAME1.
         WHEN 'PSTLZ'
              V_VAR = WA_KNA1-PSTLZ.
ENDIF.
But using case is not appropriate as KNA1 contains 176 fields.

Similar Messages

  • How to add the contents of a field of internal table.

    Hello Everybody,
    How to sum up the individual field from a internal table. Like i have a internal table that has menge field , I need to sum up the menge field for each matnr..
    exm : for each matnr there are 5 menge entries, I need to add all the menge fields and shud be put against the matnr .
    Thanks,

    Hi Khaleel,
    One more option is using the "collect" statement.....
    imagine in the internal table itab..we have 2 fields only..
    MATNR,MENGE,
    we have 2 internal tables itab1 and itab2...
    loop at itab1.
    collect itab1 to itab2.
    endloop.
    Action performed is ...for the same MATNR...menge gets added and saved as a single record...When matnr changes...new record is Appended
    another case is we have 3 fields in internal table
    MATNR,UNIT,MENGE
    imagine we hane the records
    Material1 KG  100
    Material1 LT   20
    Material1 LT   200
    MAterial2 KG 100
    in this case...the output will be
    Material1 KG 100
    Material1 LT  220
    MAterial2 KG 100
    Reason is that the fields before the addable value is checked for similarity..
    here field UNIT is also checked and also MATNR before adding up....
    Hope it gave you some alternative idea to proceed with....
    Reward if helpful
    Regards
    Byju

  • Populate dynamic table fields from internal table

    Hi,
    Im trying to populate an dynamic table , but it's giving me a few errors witch i can't solve ...
    Basically i have an internal table with te following types :
    DATA: BEGIN OF tab_docs41 OCCURS 0,
          conta TYPE bsis-hkont,
          banco TYPE t012t-text1,
          ano_3 TYPE i,
          ano_2 TYPE i,
          ano_1 TYPE i,
          jan TYPE  i,
          fev TYPE  i,
          mar TYPE  i,
          abr TYPE  i,
          mai TYPE  i,
          jun TYPE  i,
          jul TYPE  i,
          ago TYPE  i,
          set TYPE  i,
          out TYPE  i,
          nov TYPE  i,
          dez TYPE  i,
          total TYPE i,
          montante TYPE betrag11,
    END OF tab_docs41.
    and the following fieldcatalog , for the dynamic table :
    DATA : ls_fieldcat TYPE lvc_s_fcat.
      DATA: lv_period TYPE i.
      DATA str_period TYPE string.
      SUBTRACT 3 FROM ano.
      MOVE ano TO str_period.
      CLEAR ls_fieldcat.
      ls_fieldcat-fieldname = 'CONTA'.
      ls_fieldcat-seltext = 'Conta do Razão'.
      ls_fieldcat-datatype = 'HKONT'.
    *  ls_fieldcat-intlen = '10'.
      APPEND ls_fieldcat TO p_fieldcat.
    Since the internal table, tab_docs41 it's allready filled how can i pass the tab_docs41 values to the corresponding fields of the dynamic table (the move-corresponding it's not working..)
      ASSIGN fs_data->* TO <fs_1>.
      CREATE DATA new_line LIKE LINE OF <fs_1>.
    *  ASSIGN new_line->*  TO <fs_2>.
    *** Next step is to create a work area for our dynamic internal table.
      LOOP AT tab_docs41.
       ASSIGN COMPONENT 'CONTA' OF STRUCTURE  tab_docs41 TO <fs2>.
    But this last step it's not working ...
    Can anyone help me please ?
    Point's will be rewarded
    Best Regards
    Thanks in advance
    João Martins

    Looks like you have used the method CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE to create the dynamic internal table.
    You have to change the last part of the code:
    FIELD-SYMBOLS:
    <itab> TYPE STANDARD TABLE,
    <wa> TYPE ANY,
    <val> TYPE ANY .
    ASSIGN fs_data->* TO <itab>.
    CREATE DATA new_line LIKE LINE OF <itab>.
    ASSIGN new_line->*  TO <wa>.
    LOOP AT tab_docs41.
      ASSIGN COMPONENT 'CONTA' OF STRUCTURE <wa> TO <val>.
      <val> = tab_docs41-conta.
      ASSIGN COMPONENT 'BANCO' OF STRUCTURE <wa> TO <val>.
      <val> = tab_docs41-banco.
      APPEND <wa> to <itab>.
    ENDLOOP.
    BR,
    Suhas

  • Reading contents of a field from a screen

    Hi all,
         Is there a way to read the contents of a field in a particular screen. I want to read the data entered into  a particular field on a screen into the BADI and implement the logic based on the contents of the field.
    Thanks.
    Neha.

    Hi,
    You can use following code
    data: it_dynpfields type STANDARD TABLE OF DYNPREAD,
          wa_dynpfields type dynpread.
    wa_dynpfields-fieldname = 'CURR_PHASE'.
    append wa_dynpfields to it_dynpfields.
    CALL FUNCTION 'DYNP_VALUES_READ'
      EXPORTING
        dyname                               = SAPLCRM_1O_MANAG_UI
        dynumb                               = "<screen number where field is defined>
    *   TRANSLATE_TO_UPPER                   = ' '
    *   REQUEST                              = ' '
    *   PERFORM_CONVERSION_EXITS             = ' '
    *   PERFORM_INPUT_CONVERSION             = ' '
    *   DETERMINE_LOOP_INDEX                 = ' '
    *   START_SEARCH_IN_CURRENT_SCREEN       = ' '
    *   START_SEARCH_IN_MAIN_SCREEN          = ' '
    *   START_SEARCH_IN_STACKED_SCREEN       = ' '
    *   START_SEARCH_ON_SCR_STACKPOS         = ' '
    *   SEARCH_OWN_SUBSCREENS_FIRST          = ' '
    *   SEARCHPATH_OF_SUBSCREEN_AREAS        = ' '
      tables
        dynpfields                           = it_dynpfields
    EXCEPTIONS
       INVALID_ABAPWORKAREA                 = 1
       INVALID_DYNPROFIELD                  = 2
       INVALID_DYNPRONAME                   = 3
       INVALID_DYNPRONUMMER                 = 4
       INVALID_REQUEST                      = 5
       NO_FIELDDESCRIPTION                  = 6
       INVALID_PARAMETER                    = 7
       UNDEFIND_ERROR                       = 8
       DOUBLE_CONVERSION                    = 9
       STEPL_NOT_FOUND                      = 10
       OTHERS                               = 11
    IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    hope it helps

  • Looping over fields from internal table

    In a FM I have to check records of two ITABs against each other. Most fields can be checked 1:1 but some must be checked according to some business logic.
    I first want to check field-by-field and then I want to deal with exceptions.
    Question: How can I loop over fields in an ITAB in such a manner that I can compare fields?

    Hi, you can loop thru the columns(fields) of an internal table like so.
    field-symbols: <fs>.
    loop at itab.
    do.
    * Here you can use the field name instead of SY-INDEX
       assign component sy-index of structure itab to <fs>.
       if sy-subrc <>.
       exit.
       endif.
    * Now that you have access to the field via field symbol, you can compare
    * this value.
    Write:/ <fs>.
    enddo. 
    endloop.
    Regards,
    Rich Heilman

  • End Routine ABAP to read from Internal table and do calculation.

    Hi All...
    I have completed some coding in a start routine to extract some fields from a DSO containing Master Data (Stock Age) into an internal table (the internal table has been defined in the global declarations area) which will then be read in the end routine.
    (the internal table will be read) at loadtime in the end routine and used in a calculation as described below.
    I.E
    GLOBAL DATA DECLARATION
    Data: ITAB1 TYPE TABLE OF /BIC/DSOTAB
    (DSOTAB has 3 fields PLANT, STYLE, 1STDATE (1STDATE IS A DATE FIELD)
    The start routine has the following code:
    IF ITAB1 IS INITIAL.
    SELECT /BIC/PLANT /BIC/STYLE /BIC/1STDATE
                    FROM /BIC/DSOTAB
                    INTO CORRESPONDING FIELDS OF TABLE ITAB1.
    This is working fine when run under simulation i.e ITAB1 is filled no problem.
    I then need to do a calculation in the end routine.
    1. First I have to find the record in the internal table using the key of PLANT AND STYLE from the RESULT_PACKAGE.
    The code i am using now is as follows....
        READ TABLE ITAB1 TRANSPORTING NO FIELDS WITH KEY
        /BIC/PLANT = <result_fields>-/BIC/PLANT /BIC/STYLE =
        <result_fields>-/BIC/STYLE.
    Once this record has been read I then have to perform the following calculation using the following additional fields
    <result_fields>-/BIC/DYS1ST is a NUMC field in the <result_fields> that will be be filled by the result of the calculation described below.
    <result_fields>-CALDAY is a date field which is already populated in the <result-fields> which is used in the calculation below.
    The Calculation required is a difference in days between two dates
    DYS1ST = CALDAY - 1STRED.
    The code i am using is
    If sy-subrc = 0.
         <result_fields>-/BIC/DYS1ST = <result_fields>-CALDAY -
         i_t_1stred_dso-/BIC/1STRED.
    So the whole section of code inside the LOOP at RESULT PACKAGE looks like this in the end routine
           READ TABLE ITAB1 TRANSPORTING NO FIELDS WITH KEY
        /BIC/PLANT = <result_fields>-/BIC/PLANT /BIC/STYLE =
        <result_fields>-/BIC/STYLE.
    IF sy-subrc = 0.
         <result_fields>-/BIC/DYS1ST = <result_fields>-CALDAY -
         i_t_1stred_dso-/BIC/1STRED.
    Im getting the error
    "ITAB1 " is a table without a header line and therefore has no component called "/BIC/1STRED
    Please can someone advise as to what I need to do to get this fixed please.
    Thanks in advance
    Stevo:)

    Hi,
    You will have to do few changes in your code as below,
    GLOBAL DATA DECLARATION
    Data: ITAB1 TYPE standard TABLE OF /BIC/DSOTAB.
    After that declare a workarea to read the values.
    DATA: i_wa_itab1 type /bic/dsotab.
    (DSOTAB has 3 fields PLANT, STYLE, 1STDATE (1STDATE IS A DATE FIELD)
    The start routine has the following code:
    IF ITAB1 IS INITIAL.
    SELECT /BIC/PLANT /BIC/STYLE /BIC/1STDATE
    FROM /BIC/DSOTAB
    INTO CORRESPONDING FIELDS OF TABLE ITAB1.
    This is working fine when run under simulation i.e ITAB1 is filled no problem.
    I then need to do a calculation in the end routine.
    1. First I have to find the record in the internal table using the key of PLANT AND STYLE from the RESULT_PACKAGE.
    The code i am using now is as follows....
    READ TABLE ITAB1 TRANSPORTING NO FIELDS WITH KEY
    /BIC/PLANT = <result_fields>-/BIC/PLANT /BIC/STYLE =
    <result_fields>-/BIC/STYLE.
    Once this record has been read I then have to perform the following calculation using the following additional fields
    <result_fields>-/BIC/DYS1ST is a NUMC field in the <result_fields> that will be be filled by the result of the calculation described below.
    <result_fields>-CALDAY is a date field which is already populated in the <result-fields> which is used in the calculation below.
    The Calculation required is a difference in days between two dates
    DYS1ST = CALDAY - 1STRED.
    The code i am using is
    If sy-subrc = 0.
    <result_fields>-/BIC/DYS1ST = <result_fields>-CALDAY -
    i_t_1stred_dso-/BIC/1STRED.
    So the whole section of code inside the LOOP at RESULT PACKAGE looks like this in the end routine
    READ TABLE ITAB1 into i_wa_itab1 WITH KEY
    /BIC/PLANT = <result_fields>-/BIC/PLANT /BIC/STYLE =
    <result_fields>-/BIC/STYLE.
    IF sy-subrc = 0.
    <result_fields>-/BIC/DYS1ST = <result_fields>-CALDAY -
    i_wa_itab1-/BIC/1STRED.
    Once you do this changes, your code will work fine.
    Regards,
    Durgesh.

  • Reading Data from Internal Table

    Hi,
    Can anyone please tell me how to read data from Internal Tables in the Event Handler without using the Select statement OnInitialization?
    Thanks,
    Gaurav

    Hi Siddhartha,
    Can you tell me the problem in my code. I tried to work on the way you suggested. Though I have not finished with the coding, I just wanted to know whether I am going in the direction or not.
    I have declared the the structure in Type Defination as
    TYPES: BEGIN OF TEST_STRUC,
             BEGDA TYPE BEGDA,
             ENDDA TYPE ENDDA,
           END OF TEST_STRUC.
    TYPES: TEST_TAB_TYPE TYPE TABLE OF TEST_STRUC.
    In the Event Handler, I have added the following code on OnInputProcessing:
    event handler for checking and processing user input and
    for defining navigation
    DATA TEST_INFO LIKE LINE OF TEST_TAB.
    DATA: MYTAB6 TYPE TABLE OF PA0006,
          MYTAB6_WA LIKE LINE OF MYTAB6.
    REFRESH TEST_TAB.
    CLEAR TEST_INFO.
    MYTAB6_WA-BEGDA = REQUEST->GET_FORM_FIELD( STARTDATE ).
    MYTAB6_WA-ENDDA = REQUEST->GET_FORM_FIELD( ENDDATE ).
    IF EVENT->NAME EQ 'button'
       AND EVENT->SERVER_EVENT EQ 'click'.
      LOOP AT MYTAB6 INTO MYTAB6_WA.
        TEST_INFO-BEGDA = MYTAB6_WA-BEGDA.
        TEST_INFO-ENDDA = MYTAB6_WA-ENDDA.
      ENDLOOP.
      APPEND TEST_INFO TO TEST_TAB.
      CLEAR TEST_INFO.
      NAVIGATION->SET_PARAMETER( NAME = 'test_tab'
      VALUE = 'begda' ).
      NAVIGATION->SET_PARAMETER( NAME = 'test_tab'
      VALUE = 'endda' ).
      NAVIGATION->GOTO_PAGE( 'MyBSP2.htm').
    ENDIF.
    P.S. MyBSP2.htm is my next page.
    Thanks,
    Gaurav

  • Downloading data from internal table to xls file leading zeros are not disp

    Hai abap gurus,
    when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
    Ex:
    <b>ECC Code.</b>
    045234
      88567
    098456 
    but output is giving like this:
    45234
    88567
    98456
    how to get the actual values.....
    plz help me in this matter.

    Dear Kiran,
    Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
    Then use the function module to download the content of the internal table to the excel file.
    Regards,
    Abir
    Don't forget to Reward Points  *

  • How to handle field symbols internal table values?

    HI all,
              I declared field string as below.The below code is working fine.
    Data : ITAB TYPE STANDARD TABLE OF YAPOPLN, (Custom table).
              wa_itab like line of ITAB.
    field-symbol : <fs> type ITAB.
    ASSIGN PARAM TO <FS>
    LOOP AT <FS> INTO WA_ITAB.
    WRITE:/ 'ABC'.
    ENDLOOP.
    But my requirement is that I dont want all the fields of the table YAPOPLN.My output contains only 2 fields of the table YAPOPLN,which contains total 4 fields.According to my requirement only 2 fields will be getting into one parameter PARAM(this is function module parameter,which is from ALV classes) from the user entered output,which contains only 2 fields.So the above code is not working properly because wa_itab contains 4 fields and giving short dump.
    If I am declaring the internal table with the required fields(only 2 fields) and referring that internal table to field symbol <FS>
    Data : BEGIN OF ITAB1 OCCURS 0,
             FIELD1 LIKE YAPOPLN-FIELD1,
             FIELD2 LIKE YAPOPLN-FIELD2,
             END OF ITAB1.
    field-symbol : <fs> LIKE ITAB1 OR  <FS> TYPE ANY.
    DATA :WA_ITAB1 LIKE LINE OF ITAB1.
    ASSIGN PARAM TO <FS>
    LOOP AT <FS> INTO WA_ITAB.
    WRITE:/ 'ABC'.
    ENDLOOP.
    But when I am compiling this code i am getting the below error.I am gettting the same below error when even <FS> is also declared as <FS> TYPE ANY.
    .'FS' is not an internal table or defined in TABLES.
    Can anyone help me in this regard?
    Thanks,
    Balaji

    Hello,
    Try this way:
    If both the type of internal tables are same then you can directly assign dynamic internal table to static internal table.
    itab = <itab>.
    Suppose you have field symbol internal table <itab> which is different in structure from ITAB.
    Now, you can create <wa> as follow:
    FIELD-SYMBOLS <wa>.
    DATA wa TYPE REF TO DATA.
    CREATE DATA wa TYPE LINE OF <itab>.
    ASSIGN wa->* to <wa>.
    This way your work area is read.
    Using [ASSIGN COMPONENT|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm] syntax you can read required component of <wa>.
    Finally you can use that value to load static internal table.
    You can also refer to my thread on [Dynamic table|Re: Creating Dynamic table].
    Hope this helps!
    Thanks,
    Augustin.
    Edited by: Augustarian on Aug 20, 2009 10:06 AM

  • How to transfer from internal table to table control ?

    How to transfer data from internal table to table control wihtout using select statement?

    HI
    GOOD
    The commands in the flow logic are:
    LOOP AT itab [INTO wa] WITH CONTROL ctrl.
    ENDLOOP.
    This statement assigns an internal table itab of the ABAP program to the table control and triggers a parallel loop run over the table control rows displayed on the screen and over the internal table itab. The additions INTO and WITH CONTROL are possible at the time of PBO, but not at PAI. The assignment of the loop to the table control takes place at PAI through the internal table.
    Using the INTO addition, the fields of the internal table itab are written to the work area wa at the time of PBO and the content of wa is transported, line by line, to the identically-named fields of the table control on the screen. Without the INTO addition, you must use an internal table with a header line. Then the content of the header line is transported line by line to the identically-named fields of the table control on the screen at the time of PBO. No module is required for filling the table control rows.
    Conversely, at the time of PAI, the internal table rows are not automatically filled with the contents of the table control rows. Instead, you must call a dialog module within the loop that modifies the table.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dbac5135c111d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw2004s/helpdata/en/fa/0970a4543b11d1898e0000e8322d00/content.htm
    THANKS
    MRUTYUN^

  • How to move field symbol internal table to internal table with header line?

    Dear all,
    hi...hereby i would like to ask how i can move field symbol internal table to a internal table?
    as i know field symbol internal table is without header line..
    so, may i know how to do this....to move field symbol internal table to internal table which consist of header line and field and record will same as field symbol internal table...in additional, my field symbol internal table is dynamic table mean everytime will have flexible columns..?
    Please advise...
    Thanks
    Regard,
    ToToRo.
    Edited by: @ToToRo@ on Aug 20, 2009 6:16 AM

    Hello,
    Try this way:
    If both the type of internal tables are same then you can directly assign dynamic internal table to static internal table.
    itab = <itab>.
    Suppose you have field symbol internal table <itab> which is different in structure from ITAB.
    Now, you can create <wa> as follow:
    FIELD-SYMBOLS <wa>.
    DATA wa TYPE REF TO DATA.
    CREATE DATA wa TYPE LINE OF <itab>.
    ASSIGN wa->* to <wa>.
    This way your work area is read.
    Using [ASSIGN COMPONENT|http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3923358411d1829f0000e829fbfe/content.htm] syntax you can read required component of <wa>.
    Finally you can use that value to load static internal table.
    You can also refer to my thread on [Dynamic table|Re: Creating Dynamic table].
    Hope this helps!
    Thanks,
    Augustin.
    Edited by: Augustarian on Aug 20, 2009 10:06 AM

  • I NEED FIELDS FROM VBFA TABLE

    HI ALL,
    I NEED FIELDS FROM VBFA TABLE
    THE FIELDS I WANT IS :
    CUSTOMER-ID
    CUSTOMER NAME
    CONTACT NAME
    PROJECTID
    ORDER NO
    SALES MAN ID
    ORDER PROCESS DATE
    INVOICE DATE
    GROSS AMOUNT
    NET AMOUNT POSTAL CODE.
    THANKS & REGARDS,
    R.VINOD.

    Hi Vinod..
    Try this Code. I made all the modifications in your code .. It will solve ur issues..
    REPORT zsdr_omvsa40.
    TYPE-POOLS
    TYPE-POOLS: slis.
    TABLE DECLARATIONS
    TABLES : vbak, vbkd,
    zzvbak,
    kna1, vbrk, vbrp, knvp .
    INTERNALTABLE DECLARATION *
    DATA: BEGIN OF i_vbak OCCURS 0,
    vbelv LIKE vbfa-vbelv, " Sales Order no
    vbeln like vbfa-vbeln, "Invoice No
    erdat LIKE vbak-erdat, " Date on Which Record Was Created
    kunnr LIKE vbak-kunnr,
    ps_psp_pnr LIKE vbak-ps_psp_pnr, " Work Breakdown Structure Element
    END OF i_vbak.
    *DATA : BEGIN OF i_zzvbak OCCURS 0,
    *vbeln LIKE zzvbak-vbeln,
    *zssidc LIKE zzvbak-zssidc, "Salesman ID
    *END OF i_zzvbak.
    DATA : BEGIN OF i_vbrk OCCURS 0,
    vbeln LIKE vbrk-vbeln,
    fkdat LIKE vbrk-fkdat, "Invoice Date
    END OF i_vbrk.
    DATA : BEGIN OF i_kna1 OCCURS 0,
    kunnr LIKE kna1-kunnr , " Customer Number 1
    name1 LIKE kna1-name1, " Customer Name
    pstlz LIKE kna1-pstlz , " Postal Code
    END OF i_kna1.
    DATA : BEGIN OF i_vbrp OCCURS 0,
    vbeln LIKE vbrp-vbeln,
    aubel LIKE vbrp-aubel,
    netwr LIKE vbrp-netwr , " Net Value in Document Currency
    kzwi1 LIKE vbrp-kzwi1, " Subtotal 1 from pricing procedure for condition
    erdat LIKE vbrp-erdat, "Billing document.
    END OF i_vbrp.
    DATA : BEGIN OF i_knvp OCCURS 0,
    parvw LIKE knvp-parvw , " Partner Function
    kunnr LIKE knvp-kunnr ,
    parnr LIKE knvp-parnr , " Number of contact person
    END OF i_knvp .
    DATA : BEGIN OF i_data OCCURS 0,
    erdat LIKE vbak-erdat, " Date on Which Record Was Created
    vbeln LIKE vbak-vbeln, " Sales Order no
    fkdat LIKE vbrk-fkdat, " Invoice date.
    kunnr LIKE kna1-kunnr , " Customer Number
    ps_psp_pnr LIKE vbak-ps_psp_pnr, " Work Breakdown Structure Element
    name1 LIKE kna1-name1, " Customer Name
    netwr LIKE vbrp-netwr , " Net Value in Document Currency
    kzwi1 LIKE vbrp-kzwi1, " Subtotal 1 from pricing procedure for condition
    parvw LIKE knvp-parvw , " Partner Function
    parnr LIKE knvp-parnr , " Number of contact person
    *zssidc LIKE zzvbak-zssidc, "Salesman ID
    pstlz LIKE kna1-pstlz , " Postal Code
    END OF i_data.
    ALV Declaraton
    DATA: fieldcatalog TYPE slis_t_fieldcat_alv WITH HEADER LINE,
    gd_tab_group TYPE slis_t_sp_group_alv,
    gd_layout TYPE slis_layout_alv,
    it_listheader TYPE slis_t_listheader,
    gd_repid LIKE sy-repid.
    Selection - Screen
    SELECTION-SCREEN : BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS creation FOR vbak-erdat . " Sales Order Date
    SELECT-OPTIONS period FOR vbrk-fkdat . " Invoice Date
    SELECT-OPTIONS order FOR vbak-vbeln . " Sales order no
    SELECT-OPTIONS name FOR kna1-name1 . " Customer Name
    SELECT-OPTIONS contact FOR knvp-parnr . " Contact Name.
    *SELECT-OPTIONS ssid FOR zzvbak-zssidc . " Salesman ID
    SELECT-OPTIONS project FOR vbak-ps_psp_pnr . " Work Breakdown Structure Element
    SELECTION-SCREEN : END OF BLOCK b1.
    START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM build_fieldcatalog.
    PERFORM BUILD_LAYOUT.
    PERFORM top_of_page.
      PERFORM fill_listheader USING it_listheader.
      PERFORM display_alv_report.
    END-OF-SELECTION.
    *TOP-OF-PAGE.
    TOP-OF-PAGE.
    END-OF-PAGE.
    *& Form BUILD_FIELDCATALOG
    text
    FORM build_fieldcatalog.
      fieldcatalog-fieldname = 'KUNNR'.
      fieldcatalog-seltext_m = 'Sold to Party'.
      fieldcatalog-col_pos = 0.
      fieldcatalog-outputlen = 10.
      fieldcatalog-emphasize = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'NAME1'.
      fieldcatalog-seltext_m = 'Hlev Customer'.
      fieldcatalog-col_pos = 1.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'PARNR'.
      fieldcatalog-seltext_m = 'Contact name'.
      fieldcatalog-col_pos = 2.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'PS_PSP_PNR'.
      fieldcatalog-seltext_m = 'Project ID'.
      fieldcatalog-col_pos = 3.
      fieldcatalog-do_sum = 'X'.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'VBELN'.
      fieldcatalog-seltext_m = 'Sales Document Type'.
      fieldcatalog-col_pos = 4.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'ZSSIDC'.
      fieldcatalog-seltext_m = 'SSID'.
      fieldcatalog-col_pos = 5.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'ERDAT'.
      fieldcatalog-seltext_m = 'so date'.
      fieldcatalog-col_pos = 6.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'FKDAT'.
      fieldcatalog-seltext_m = 'inv date'.
      fieldcatalog-col_pos = 7.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'KWZI1'.
      fieldcatalog-seltext_m = 'gross amt'.
      fieldcatalog-col_pos = 8.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'NETWR'.
      fieldcatalog-seltext_m = 'net amt'.
      fieldcatalog-col_pos = 9.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
      fieldcatalog-fieldname = 'PSTLZ'.
      fieldcatalog-seltext_m = 'Postal code'.
      fieldcatalog-col_pos = 10.
      APPEND fieldcatalog TO fieldcatalog.
      CLEAR fieldcatalog.
    ENDFORM. "BUILD_FIELDCATALOG
    *& Form DATA_RETRIEVAL
    text
    FORM data_retrieval.
      SELECT VBFAvbelv VBFAvbeln
             VBAKerdat VBAKkunnr VBAK~ps_psp_pnr
             INTO TABLE i_vbak
      FROM VBFA
      INNER JOIN vbak
      ON VBFAVBELV = VBAKVBELN
      WHERE VBAK~erdat IN creation
      AND VBFA~vbelV IN ORDER
      AND VBAK~ps_psp_pnr IN project
      AND VBFA~VBTYP_N = 'M'  "Subsequent doc is Invoice
      AND VBFA~VBTYP_V = 'C'  "Prec doc is Sales order
      IF NOT i_vbak[] IS INITIAL.
    **Change of ORDER in SELECTS HERE
        SELECT vbeln fkdat FROM vbrk INTO TABLE i_vbrk
        FOR ALL ENTRIES IN i_vbak
        WHERE vbeln = i_vbak-vbeln
        AND fkdat IN period.
        IF NOT i_vbrk[] IS INITIAL.
          SELECT vbeln aubel netwr kzwi1 FROM vbrp INTO TABLE i_vbrp
          FOR ALL ENTRIES IN i_vbrk
          WHERE VBELN = i_vbrk-vbeln.
        endif.
        SELECT kunnr name1  pstlz  FROM kna1 INTO TABLE i_kna1 FOR ALL ENTRIES IN i_vbak
        WHERE kunnr = i_vbak-kunnr
        AND name1 IN name.
    *SELECT vbeln zssidc FROM zzvbak INTO TABLE i_zzvbak FOR ALL ENTRIES IN i_vbak
    *WHERE vbeln = i_vbak-vbeln
    *AND zssidc IN ssid .
    select netwr kzwi1 erdat from vbrp into table i_vbrp for all entries in i_vbak
    where erdat = i_vbak-erdat.
        SELECT kunnr parnr parvw FROM knvp INTO CORRESPONDING FIELDS OF TABLE i_knvp FOR ALL ENTRIES IN i_vbak
        WHERE kunnr = i_vbak-kunnr
        AND parvw = 'AP'
        AND parnr IN contact.
      ENDIF .
      SORT I_VBAK BY VBELN .
      SORT I_VBRK BY VBELN .
      LOOP AT i_vbrp.  "Invoice Item data
        MOVE i_vbrp-netwr TO i_data-netwr .
        MOVE i_vbrp-kzwi1 TO i_data-kzwi1.
        READ table I_VBAK WITH KEY VBELN = I_VBRP-VBELN BINARY SEARCH.  "Sales Order info
        IF SY-SUBRC = 0.
          MOVE I_VBAK-VBELV TO I_DATA-VBELN.   "Sales Order no
          MOVE I_VBAK-erdat TO I_DATA-erdat.   " Date on Which Record Was Created
          MOVE I_VBAK-kunnr TO I_DATA-KUNNR.    "Customer No
          MOVE I_VBAK-ps_psp_pnr TO I_DATA-ps_psp_pnr. " Work Breakdown Structure Element
        endif.
        READ TABLE I_VBRK WITH KEY VBELN = I_VBRP-VBELN BINARY SEARCH.   "Invoice header info
        IF SY-SUBRC = 0.
          MOVE i_vbrk-fkdat TO i_data-fkdat.
        endif.
        READ TABLE I_KNA1 WITH KEY KUNNR = I_VBAK-KUNNR BINARY SEARCH.   "Customer info
        IF SY-SUBRC = 0.
          MOVE i_kna1-kunnr TO i_data-kunnr.
          MOVE i_kna1-name1 TO i_data-name1.
          MOVE i_kna1-pstlz TO i_data-pstlz .
        endif.
        READ TABLE I_KNvp WITH KEY KUNNR = I_VBAK-KUNNR BINARY SEARCH.   "Partner info
        IF SY-SUBRC = 0.
          MOVE i_knvp-parnr TO i_data-parnr.
        endif.
        APPEND i_data.
      ENDLOOP.
    ENDFORM. "DATA_RETRIEVAL
    *& Form DISPLAY_ALV_REPORT
    text
    FORM display_alv_report.
    GD_REPID = SY-REPID.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
    I_INTERFACE_CHECK = ' '
    I_BYPASSING_BUFFER = ' '
    I_BUFFER_ACTIVE = ' '
      i_callback_program = sy-repid
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
      i_callback_top_of_page = 'TOP_OF_PAGE'
    I_CALLBACK_HTML_TOP_OF_PAGE = ' '
    I_CALLBACK_HTML_END_OF_LIST = ' '
    I_STRUCTURE_NAME =
    I_BACKGROUND_ID = ' '
    I_GRID_TITLE =
    I_GRID_SETTINGS =
    IS_LAYOUT =
      it_fieldcat = fieldcatalog[]
    IT_EXCLUDING =
    IT_SPECIAL_GROUPS =
    IT_SORT =
    IT_FILTER =
    IS_SEL_HIDE =
    I_DEFAULT = 'X'
    I_SAVE = ' '
    IS_VARIANT =
    IT_EVENTS =
    IT_EVENT_EXIT =
    IS_PRINT =
    IS_REPREP_ID =
    I_SCREEN_START_COLUMN = 0
    I_SCREEN_START_LINE = 0
    I_SCREEN_END_COLUMN = 0
    I_SCREEN_END_LINE = 0
    I_HTML_HEIGHT_TOP = 0
    I_HTML_HEIGHT_END = 0
    IT_ALV_GRAPHICS =
    IT_HYPERLINK =
    IT_ADD_FIELDCAT =
    IT_EXCEPT_QINFO =
    IR_SALV_FULLSCREEN_ADAPTER =
    IMPORTING
    E_EXIT_CAUSED_BY_CALLER =
    ES_EXIT_CAUSED_BY_USER =
      TABLES
      t_outtab = i_data.
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2 .
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    ENDFORM. "DISPLAY_ALV_REPORT
    FORM FOR FILLING LISTHEADER *
    FORM fill_listheader USING it_listheader TYPE slis_t_listheader.
      DATA : wa_listheader TYPE slis_listheader.
      wa_listheader-typ = 'H'.
      wa_listheader-info = 'Noel Gifts International Limited '.
      APPEND wa_listheader TO it_listheader.
      wa_listheader-typ = 'S'.
      wa_listheader-info = 'CUSTOMER CREDIT EXCEPTION REPORT' .
      APPEND wa_listheader TO it_listheader.
      CLEAR wa_listheader.
    ENDFORM. "fill_listheader
    *& Form top_of_page
    text
    FORM top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary = it_listheader.
    ENDFORM. "top_of_page
    REWARD IF HELPFUL.

  • Can not insert or update [TABLE] from internal table in method

    I've faced a problem with OO abap. I've tried to insert into [ TABLE ] from internal table, but i've got error msg after i compiled.
    "An explicit work area is necessary in the OO context. Use "INSERT wa INTO [TABLE] itab""
    After  i changed to loop in work area and INSERT INTO  [TABLE] VALUES gw_data., everything is fine, can compile and run.
    This is error code.
      METHOD set_data_to_table.
        REFRESH gi_data.
        CLEAR gi_data.
        IF gi_file[] IS NOT INITIAL.
    * Set data for modify table
          LOOP AT gi_file INTO gw_file.
            MOVE-CORRESPONDING gw_file TO gw_data.
            me->conversion_input( EXPORTING im_vendor = gw_data-vendor
                                  CHANGING  ch_vendor = gw_data-vendor ).
            APPEND gw_data TO gi_data.
          ENDLOOP.
          INSERT [TABLE] FROM TABLE gi_data.
    *      LOOP AT gi_data INTO gw_data.
    *        INSERT INTO  [TABLE] VALUES gw_data.
    *        IF sy-subrc = 0.
    *          COMMIT WORK.
    *        ELSE.
    *          ROLLBACK WORK.
    *        ENDIF.
    *      ENDLOOP.
        ELSE.
          MESSAGE 'No data found' TYPE 'I'.
        ENDIF.
      ENDMETHOD.                    "set_data_to_table

    Hi Matthew,
    I think there is no difference in database insert between OO and non-OO.
    The correct syntax according to ECC600 online documentation is
    [Inserting Several Lines|http://help.sap.com/saphelp_erp2005vp/helpdata/en/fc/eb3a6d358411d1829f0000e829fbfe/content.htm]
    To insert several lines into a database table, use the following:
    INSERT target FROM TABLE itab \[ACCEPTING DUPLICATE KEYS].
    This writes all lines of the internal table itabto the database table in one single operation. If one or more lines cannot be inserted because the database already contains a line with the same primary key, a runtime error occurs. You can prevent the runtime error occurring by using the addition ACCEPTING DUPLICATE KEYS.
    Whenever you want to insert more than one line into a database table, it is more efficient to work with an internal table than to insert the lines one by one.
    I think the syntax
    INSERT my_dbtable FROM TABLE gi_data.
    should work, your suggestion may lead to syntax error.
    Regards,
    Clemens

  • To get recent timestamp records from internal table

    hi all,
      i have one requirment
      i'm storing error messages in one table  while creating a sales order basing on timestamp
      which is of this format yyyy-mm-dd hh:mm:ss (random Number) 
      if i want to see the error messages left i'm getting all the error messages displayed
      for example i have created a sales order
    i got 10 errors displayed
    i have rectified 5 errors ... if i again display error messages the 10 errors + the 5 errors is getting displayed
    i want to display the 5 error messages only not the previous messages from internal table
    basing on timestamp current one has to displayed remaining has to deleted from internal table.

    I thought we used Sales Order Incompletion process for this....  but, if you're recreating the errors list every time you save with a create or change transaction then, at save, delete all rows in your error table for this document.   Then get your errors and update your db table from your current errors table.   From this viewpoint, the timestamp is not relevant.

  • Downloding from internal table to excel

    Hi All,
    I am using ole concept to download data from internal table to excel because i want to fill few records with colors and few with bold etc.
    But this ole concept is downloading to excel line by line and taking much time.
    How can i improve the performance in this concept or is there any other concept please let me know.
    i am using fallowng logic to download to excel.
    *Generating the Excel report in the foreground
    data: h_excel type ole2_object, " Excel object
    h_mapl type ole2_object, " list of workbooks
    h_map type ole2_object, " workbook
    start Excel
    create object h_excel 'EXCEL.APPLICATION'.
    set property of h_excel 'Visible' = 1.
    get list of workbooks, initially empty
    call method of h_excel 'Workbooks' = h_mapl.
    perform err_hdl.
    add a new workbook
    call method of h_mapl 'Add' = h_map.
    perform err_hdl.
    output column headings to active Excel sheet
    perform fill_cell using 1 1 1 000 'Job Name'(001).
    perform fill_cell using 1 2 1 000 'Variant'(002).
    perform fill_cell using 1 3 1 000 'Description'(003).
    perform fill_cell using 1 4 1 000 'Run Date'(004).
    perform fill_cell using 1 5 1 000 'Run Time'(005).
    perform fill_cell using 1 6 1 000 'Duration'(006).
    perform fill_cell using 1 7 1 000 'Spool'(007).
    perform fill_cell using 1 8 1 000 'Records Upl'(008).
    perform fill_cell using 1 9 1 000 'Error'(009).
    perform fill_cell using 1 10 1 000 'Total'(010).
    perform fill_cell using 1 11 1 000 'Action'(011).
    perform fill_cell using 1 12 1 000 'ReRun'(012).
    loop at t_final.
    copy datato active EXCEL sheet
    h = sy-tabix + 1.
    perform fill_cell using h 1 0 000 t_final-jobname.
    perform fill_cell using h 2 0 000 t_final-variant.
    perform fill_cell using h 3 0 000 t_final-description.
    perform fill_cell using h 4 0 000 t_final-strtdate.
    perform fill_cell using h 5 0 000 t_final-strttime.
    perform fill_cell using h 6 0 000 t_final-duration.
    perform fill_cell using h 7 0 000 t_final-listident.
    perform fill_cell using h 8 0 000 t_final-rec_upl.
    perform fill_cell using h 9 0 000 t_final-rec_err.
    perform fill_cell using h 10 0 000 t_final-rec_tot.
    if t_final-comment eq 'job did not run'.
    perform fill_cell using h 11 0 200 t_final-comment.
    elseif t_final-rec_err eq 0.
    perform fill_cell using h 11 0 000 t_final-comment.
    else.
    perform fill_cell using h 11 0 200 t_final-comment.
    endif.
    perform fill_cell using h 12 0 000 t_final-rerun.
    endloop.
    CALL METHOD OF H_EXCEL 'Workbooks' = H_MAPL.
    call method of h_excel 'Worksheets' = h_mapl." EXPORTIN G #1 = 2.
    perform err_hdl.
    add a new workbook
    call method of h_mapl 'Add' = h_map exporting #1 = 2.
    perform err_hdl.
    tell user what is going on
    set property of h_map 'NAME' = 'COPY'.
    loop at t_final.
    copy flights to active EXCEL sheet
    h = sy-tabix + 1.
    perform fill_cell using h 1 0 000 t_final-jobname.
    perform fill_cell using h 2 0 000 t_final-variant.
    perform fill_cell using h 3 0 000 t_final-description.
    perform fill_cell using h 4 0 000 t_final-strtdate.
    perform fill_cell using h 5 0 000 t_final-strttime.
    perform fill_cell using h 6 0 000 t_final-duration.
    perform fill_cell using h 7 0 000 t_final-listident.
    perform fill_cell using h 8 0 000 t_final-rec_upl.
    perform fill_cell using h 9 0 000 t_final-rec_err.
    perform fill_cell using h 10 0 000 t_final-rec_tot.
    if t_final-comment eq 'job did not run'.
    perform fill_cell using h 11 0 200 t_final-comment.
    elseif t_final-rec_err eq 0.
    perform fill_cell using h 11 0 000 t_final-comment.
    else.
    perform fill_cell using h 11 0 200 t_final-comment.
    endif.
    perform fill_cell using h 12 0 000 t_final-rerun.
    endloop.
    free object h_excel.
    perform err_hdl.
    *& Form ERR_HDL
    outputs OLE error if any *
    form err_hdl.
    if sy-subrc <> 0.
    write: / 'Batch Job Automation Carried Out Succesfully'.
    stop.
    endif.
    endform. " ERR_HDL .
    FORM FILL_CELL *
    sets cell at coordinates i,j to value val boldtype bold *
    form fill_cell using i j bold col val.
    call method of h_excel 'Cells' = h_zl exporting #1 = i #2 = j.
    perform err_hdl.
    set property of h_zl 'Value' = val .
    perform err_hdl.
    get property of h_zl 'Font' = h_f.
    perform err_hdl.
    set property of h_f 'Bold' = bold .
    perform err_hdl.
    set property of h_f 'Color' = col.
    perform err_hdl.
    endform. "FILL_CELL

    Hi,
    You are populating the Cells one by one from the internal table, and all of them are coloured and font is bold. the method is OK, but when the amount of data is huge - it is going to take a longer time. May be the performance will improve a little if you turn the visibility off.
    I ll suggest you to use ALV_XXL_CALL, it can color the key columns, at the same time you can have colored headings - and the performance is good. It is the same function module called when you do a "Export to Excel" from an ALV grid. But you can compain about the Font characteristics - as this does not change the Font size etc.
    Your code has got a lot of freedom as long as the formatting is concerned - for bigger data - i ll suggest you to use a WS_DOWNLOAD kind of a function module to get the data at once in the presentation server and then call Excel methods and do the formatting.

Maybe you are looking for

  • How to calculate the sales in the last month of last year

    Hi all, I have a requirement need to implement , the report has three columns, MONTH----SALES----SALES2 201201----10------------100 201202----20------------100 201203----30------------100 201204----40------------100 201205----50------------100 The Sa

  • IWeb projects from two computers. How do I combine onto one machine.

    Hi, I have been working on five sites in total. Three of them were satrted on my iMac G5 and recently I have just started two more but on my new MacBookPro. They are all published, but I now want to combine all of the projects onto my MacBookPro. Aft

  • My ipod touch 4g would not turn on.. Help

    My 4g ipod touch would not turn on since last night.. And I've tried to put it on charge for 4-5 hours and still would not work.. I've also tried to hold the sleep and home button as instructed in other articles.. help !! what should i do?

  • ITunes on Windows 7 64-bit

    Upon reboot iTunes will stop working. It will return with an error that "Quicktime was not found." I will uninstall and remove Quicktime and iTunes from my computer, clean out the registry, and then reinstall iTunes 9. It will work but the next time

  • Aspect Ratio settings were wrong... Help

    Okay so I am doing a project for a class using FCP. I set my project settings to the requirements we were given. However somehow down the line the settings got changed and I have my edit all done. However when I go to change it back to the proper set