MODYFYING ITAB LINE

Hi Experts,
                I have a 2 internal tables. 1st is itab & 2nd is itabf. itabf is initial. In ITAB I have MATNR, WERKS, PQTY. And ITABF has MATNR, PQTY1, PQTY2.
I am moving rows from ITAB to ITABF. If werks in ITAB is PLANT1 then PQTY should go in PQTY1 of ITABF or if werks is PLANT2 then PQTY should go in PQTY2.
If MATNR is same then it will update the same row in ITABF else append a new row in ITABF.
According to my code its appending a row but in second loop when it gets same MATNR but diffrent WERKS, it delete exixting row and append new PQTY in respective column.
N = 1.
LOOP AT ITAB.
  ON CHANGE OF ITAB-MATNR.
     ITABF-MATNR = ITAB-MATNR.
     ITABF-WERKS = ITAB-WERKS.
     VMATNR = ITAB-MATNR.
     APPEND ITABF.
  ENDON.
  IF VMATNR = ITAB-MATNR.
       SY-TABIX = N.
       IF ITAB-WERKS = 'PC01'.
         ITABF-FPC01 = ITAB-PQTY.
      ELSEIF ITAB-WERKS = 'PC02'.
         ITABF-FPC02 = ITAB-PQTY.
      MODIFY ITABF INDEX SY-TABIX.
      CLEAR: ITAB, ITABF.
      AT END OF MATNR.
        N = N + 1.
      ENDAT.
   ENDIF.
ENDLOOP.
PLz help. URGENT..
KHAN

Hi,
try this
sort itab by matnr werks.
loop at itab.
move : itab-matnr to itabf-matnr.
if       itab-werks = 'PLANT1'.
move itab-pqty to itabf-pqty1.
elseif itab-werks = 'PLANT2'.
move itab-pqty to itabf-pqty2.
endif.
at end of matnr.
collect itabf.
endat.
endloop.
This ll work
Cheers,
Will.
Edited by: Will smith on Jan 29, 2008 8:39 AM
Edited by: Will smith on Jan 29, 2008 9:32 AM

Similar Messages

  • Wrong itab line

    Hi Everbody!
    DELETE lt_itab removes the wrong line
    from internal table because the
    number of lv_tabix is not equally with
    the really affected line of internal table which has
    to be deleted. Do you know a better
    way to do that.
    Thanks in advance
    sas
    data: lt_itab type standard table of IS_PDATFU,
          wa_itab type IS_PDATFU,
          lt_roles type standard table of BAPIBUS1006_BPROLES,
          wa_roles type BAPIBUS1006_BPROLES,
          lt_return  type standard table of BAPIRET2,
          lv_partner type BU_PARTNER,
          lv_tabix type i value 1.
    lt_itab = l_pdatfu_tab.
    LOOP AT lt_itab into wa_itab.
    CALL FUNCTION 'BUPA_ROLES_GET_2'
      EXPORTING
        IV_PARTNER            = wa_itab-IPPERS
      IV_PARTNER_GUID       =
      IV_DATE               = SY-DATLO
      TABLES
        ET_PARTNERROLES       = lt_roles
        ET_RETURN             = lt_return.
    read table lt_roles into wa_roles index 1.
    IF wa_itab-IPPERSGRP EQ 'C' AND wa_roles-PARTNERROLE EQ 'IKOS'  .
    DELETE lt_itab INDEX lv_tabix.
    ENDIF.
    clear wa_roles.
    lv_tabix = lv_tabix + 1.
    ENDLOOP.
    l_pdatfu_tab = lt_itab.

    Hello erdem sas ,
      Really good Question.  The Answer againest you question mark by other users are also good to adopt. But I have one another solution.
    tries it out.
    Don't delete the table by using the folowing statment
    DELETE lt_itab INDEX lv_tabix.
    out side the loop you try this. from the side of performance this one is really good.
    Sort it_itab by IPPERSGRP IPPERSGRP.
    Delete it_itab where IPPERSGRP EQ 'C'  and PARTNERROLE EQ 'IKOS' .
    Please Chcek the syntex error , because I am outside office and type the code.
    Regards
    Swati...

  • Smartform itab lines as row display

    hi gurus,
    in main window.
    1. itab-field2 itab-field3          2. itab-field2 itab-field3          3. itab-field2 itab-field3
    4. itab-field2 itab-field3          5. itab-field2 itab-field3          6. itab-field2 itab-field3
    7. itab-field2 itab-field3          8. itab-field2 itab-field3
    No: of records in ITAB may vary.. and itab-field3 should be right-aligned.
    how to achieve this?
    any suggestions guys?
    thanks
    Giri

    You have to duplicate the node "1" twice (and you may store "itab-field2 itab-field3" in a standard text so that to minimize the duplicate "code")

  • How to check itab1 with copy of itab by line wise?

    Hi Friends,
    I have two internal tables itab and jtab.
    jtab is a copy of itab with rows 10 and column wise 12.
    Both have same records since jtab is a copy of itab.
    My requirement is (at the end of the program if i update new reocrd to itab) I want to chek the itab line wise with jtab.
    I know we can do it with loop one by one with field. Is there any other way I can check the whole line of 12 fields with itab record.
    Ex:If lineitem = 2 of jtab with lineitem  = 2 of itab.
    itab have 12 fields in that 2nd line item of vendor name(ex) is XYZ and 2nd line item of jtab is ABC.I have to check the whole line item.
    Please advise.
    thanks & regards
    Sankar.

    if wa = wa1.
    endif.

  • How to get the multiple  lines on the header part in ALV

    HI all,
    In my program i am using the ALV- Grid functionality through methods. I have 2 different layouts in the same screen , for this i have 2 containers and i am displaying the title through the gird title now i need to add the few more lines under the title .
    Please suggest me, how can i proceede now.
    Thanks
    Giridhar

    Hi,
    check this sample code, i did it using splitter container. check it, it is weel documented to know what are required ....
    REPORT  ZTEST_ALV_TOP    MESSAGE-ID ZZ                           .
    DATA: G_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: L_VALID TYPE C,
          V_FLAG,
          V_DATA_CHANGE,
          V_ROW TYPE LVC_S_ROW,
          V_COLUMN TYPE LVC_S_COL,
          V_ROW_NUM TYPE LVC_S_ROID.
    DATA: IT_ROW_NO TYPE LVC_T_ROID,
          X_ROW_NO TYPE LVC_S_ROID.
    DATA:BEGIN OF  ITAB OCCURS 0,
         VBELN LIKE LIKP-VBELN,
         POSNR LIKE LIPS-POSNR,
         CELLCOLOR TYPE LVC_T_SCOL, "required for color
         DROP(10),
         END OF ITAB.
    "The Below Definitions Must.....
    DATA:
    * Reference to document
           DG_DYNDOC_ID       TYPE REF TO CL_DD_DOCUMENT,
    * Reference to split container
           DG_SPLITTER          TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
    * Reference to grid container
           DG_PARENT_GRID     TYPE REF TO CL_GUI_CONTAINER,
    * Reference to html container
           DG_HTML_CNTRL        TYPE REF TO CL_GUI_HTML_VIEWER,
    * Reference to html container
           DG_PARENT_HTML     TYPE REF TO CL_GUI_CONTAINER.
    "up to here
    *       CLASS lcl_event_handler DEFINITION
    CLASS LCL_EVENT_HANDLER DEFINITION .
      PUBLIC SECTION .
        METHODS:
    **Hot spot Handler
        HANDLE_HOTSPOT_CLICK FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
                          IMPORTING E_ROW_ID E_COLUMN_ID ES_ROW_NO,
    **Double Click Handler
        HANDLE_DOUBLE_CLICK FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
                                         IMPORTING E_ROW E_COLUMN ES_ROW_NO,
        TOP_OF_PAGE FOR EVENT TOP_OF_PAGE              "event handler
                             OF CL_GUI_ALV_GRID
                             IMPORTING E_DYNDOC_ID.
    *        END_OF_LIST FOR EVENT end_of_list              "event handler
    *                         OF CL_GUI_ALV_GRID
    *                         IMPORTING E_DYNDOC_ID.
    ENDCLASS.                    "lcl_event_handler DEFINITION
    *       CLASS lcl_event_handler IMPLEMENTATION
    CLASS LCL_EVENT_HANDLER IMPLEMENTATION.
    *Handle Hotspot Click
      METHOD HANDLE_HOTSPOT_CLICK .
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW_ID.
        V_COLUMN = E_COLUMN_ID.
        V_ROW_NUM = ES_ROW_NO.
    *    MESSAGE I000 WITH V_ROW 'clicked'.
        CLEAR IT_ROW_NO[].
        X_ROW_NO-ROW_ID = V_ROW.
        APPEND X_ROW_NO TO IT_ROW_NO .
        CALL METHOD G_GRID->SET_SELECTED_ROWS
          EXPORTING
            IT_ROW_NO = IT_ROW_NO.
      ENDMETHOD.                    "lcl_event_handler
    *Handle Double Click
      METHOD  HANDLE_DOUBLE_CLICK.
        CLEAR: V_ROW,V_COLUMN,V_ROW_NUM.
        V_ROW  = E_ROW.
        V_COLUMN = E_COLUMN.
        V_ROW_NUM = ES_ROW_NO.
        IF E_COLUMN = 'VBELN'.
          SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN.
        ENDIF.
        IF E_COLUMN = 'POSNR'.
          SET PARAMETER ID 'VL' FIELD ITAB-VBELN.
          CALL TRANSACTION 'VL03N' AND SKIP FIRST SCREEN."
        ENDIF.
      ENDMETHOD.                    "handle_double_click
    *  METHOD END_OF_LIST.                   "implementation
    ** Top-of-page event
    *    PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
    *  ENDMETHOD.                            "top_of_page
        METHOD TOP_OF_PAGE.                   "implementation
    * Top-of-page event
        PERFORM EVENT_TOP_OF_PAGE USING DG_DYNDOC_ID.
      ENDMETHOD.                            "top_of_page
    ENDCLASS.                    "LCL_EVENT_HANDLER IMPLEMENTATION
    *&             Global Definitions
    DATA:      G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,"Container1
                G_HANDLER TYPE REF TO LCL_EVENT_HANDLER. "handler
    DATA: OK_CODE LIKE SY-UCOMM,
          SAVE_OK LIKE SY-UCOMM,
          G_CONTAINER1 TYPE SCRFNAME VALUE 'TEST',
          GS_LAYOUT TYPE LVC_S_LAYO.
    data: v_lines type i.
    data: v_line(3) type c.
    *- Fieldcatalog for First and second Report
    DATA: IT_FIELDCAT  TYPE  LVC_T_FCAT,
          X_FIELDCAT TYPE LVC_S_FCAT,
          LS_VARI  TYPE DISVARIANT.
    *                START-OF_SELECTION
    START-OF-SELECTION.
      SELECT VBELN
             POSNR
             FROM LIPS
             UP TO 20 ROWS
             INTO CORRESPONDING FIELDS OF TABLE ITAB.
    describe table itab lines v_lines.
    END-OF-SELECTION.
      IF NOT ITAB[] IS INITIAL.
        CALL SCREEN 100.
      ELSE.
        MESSAGE I002 WITH 'NO DATA FOR THE SELECTION'(004).
      ENDIF.
    *&      Form  CREATE_AND_INIT_ALV
    *       text
    FORM CREATE_AND_INIT_ALV .
      DATA: LT_EXCLUDE TYPE UI_FUNCTIONS.
      "attention.....from here
      "split your container here...into two parts
      "create the container
      CREATE OBJECT G_CUSTOM_CONTAINER
               EXPORTING CONTAINER_NAME = G_CONTAINER1.
      "this is for top of page
    * Create TOP-Document
      CREATE OBJECT DG_DYNDOC_ID
                       EXPORTING STYLE = 'ALV_GRID'.
    * Create Splitter for custom_container
      CREATE OBJECT DG_SPLITTER
                 EXPORTING PARENT  = G_CUSTOM_CONTAINER
                           ROWS    = 2
                           COLUMNS = 1.
    * Split the custom_container to two containers and move the reference
    * to receiving containers g_parent_html and g_parent_grid
      "i am allocating the space for grid and top of page
      CALL METHOD DG_SPLITTER->GET_CONTAINER
        EXPORTING
          ROW       = 1
          COLUMN    = 1
        RECEIVING
          CONTAINER = DG_PARENT_HTML.
      CALL METHOD DG_SPLITTER->GET_CONTAINER
        EXPORTING
          ROW       = 2
          COLUMN    = 1
        RECEIVING
          CONTAINER = DG_PARENT_GRID.
    *  CALL METHOD DG_SPLITTER->GET_CONTAINER
    *    EXPORTING
    *      ROW       = 2
    *      COLUMN    = 1
    *    RECEIVING
    *      CONTAINER = DG_PARENT_HTML.
    *  CALL METHOD DG_SPLITTER->GET_CONTAINER
    *    EXPORTING
    *      ROW       = 1
    *      COLUMN    = 1
    *    RECEIVING
    *      CONTAINER = DG_PARENT_GRID.
      "you can set the height of it
    * Set height for g_parent_html
      CALL METHOD DG_SPLITTER->SET_ROW_HEIGHT
        EXPORTING
          ID     = 1
          HEIGHT = 5.
      "from here as usual..you need to specify parent as splitter part
      "which we alloted for grid
      CREATE OBJECT G_GRID
             EXPORTING I_PARENT = DG_PARENT_GRID.
    * Set a titlebar for the grid control
      CLEAR GS_LAYOUT.
      GS_LAYOUT-GRID_TITLE = TEXT-003.
      GS_LAYOUT-ZEBRA = SPACE.
      GS_LAYOUT-CWIDTH_OPT = 'X'.
      GS_LAYOUT-NO_ROWMARK = 'X'.
      GS_LAYOUT-CTAB_FNAME = 'CELLCOLOR'.
      CALL METHOD G_GRID->REGISTER_EDIT_EVENT
        EXPORTING
          I_EVENT_ID = CL_GUI_ALV_GRID=>MC_EVT_ENTER.
      CREATE OBJECT G_HANDLER.
      SET HANDLER G_HANDLER->HANDLE_DOUBLE_CLICK FOR G_GRID.
      SET HANDLER G_HANDLER->HANDLE_HOTSPOT_CLICK FOR G_GRID.
    *  SET HANDLER G_HANDLER->END_OF_LIST FOR G_GRID.
      SET HANDLER G_HANDLER->TOP_OF_PAGE FOR G_GRID.
      DATA: LS_CELLCOLOR TYPE LVC_S_SCOL. "required for color
      DATA: L_INDEX TYPE SY-TABIX.
      "Here i am changing the color of line 1,5,10...
      "so you can change the color of font conditionally
      LOOP AT ITAB.
        L_INDEX = SY-TABIX.
        IF L_INDEX = 1 OR L_INDEX = 5 OR L_INDEX = 10.
          LS_CELLCOLOR-FNAME = 'VBELN'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
          LS_CELLCOLOR-FNAME = 'POSNR'.
          LS_CELLCOLOR-COLOR-COL = '6'.
          LS_CELLCOLOR-COLOR-INT = '0'.
          LS_CELLCOLOR-COLOR-INV = '1'.
          APPEND LS_CELLCOLOR TO ITAB-CELLCOLOR.
          MODIFY ITAB INDEX L_INDEX TRANSPORTING CELLCOLOR.
        ENDIF.
      ENDLOOP.
    * setting focus for created grid control
      CALL METHOD CL_GUI_CONTROL=>SET_FOCUS
        EXPORTING
          CONTROL = G_GRID.
    * Build fieldcat and set editable for date and reason code
    * edit enabled. Assign a handle for the dropdown listbox.
      PERFORM BUILD_FIELDCAT.
      PERFORM  SET_DRDN_TABLE.
    * Optionally restrict generic functions to 'change only'.
    *   (The user shall not be able to add new lines).
      PERFORM EXCLUDE_TB_FUNCTIONS CHANGING LT_EXCLUDE.
    **Vaiant to save the layout
      LS_VARI-REPORT      = SY-REPID.
      LS_VARI-HANDLE      = SPACE.
      LS_VARI-LOG_GROUP   = SPACE.
      LS_VARI-USERNAME    = SPACE.
      LS_VARI-VARIANT     = SPACE.
      LS_VARI-TEXT        = SPACE.
      LS_VARI-DEPENDVARS  = SPACE.
    **Calling the Method for ALV output
      CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
        EXPORTING
          IT_TOOLBAR_EXCLUDING = LT_EXCLUDE
          IS_VARIANT           = LS_VARI
          IS_LAYOUT            = GS_LAYOUT
          I_SAVE               = 'A'
        CHANGING
          IT_FIELDCATALOG      = IT_FIELDCAT
          IT_OUTTAB            = ITAB[].
      "do these..{
    * Initializing document
      CALL METHOD DG_DYNDOC_ID->INITIALIZE_DOCUMENT.
    * Processing events
      CALL METHOD G_GRID->LIST_PROCESSING_EVENTS
        EXPORTING
          I_EVENT_NAME = 'TOP_OF_PAGE'
          I_DYNDOC_ID  = DG_DYNDOC_ID.
      "end }
    * Set editable cells to ready for input initially
      CALL METHOD G_GRID->SET_READY_FOR_INPUT
        EXPORTING
          I_READY_FOR_INPUT = 1.
    ENDFORM.                               "CREATE_AND_INIT_ALV
    *&      Form  EXCLUDE_TB_FUNCTIONS
    *       text
    *      -->PT_EXCLUDE text
    FORM EXCLUDE_TB_FUNCTIONS CHANGING PT_EXCLUDE TYPE UI_FUNCTIONS.
    * Only allow to change data not to create new entries (exclude
    * generic functions).
      DATA LS_EXCLUDE TYPE UI_FUNC.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_DELETE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_APPEND_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_INSERT_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_MOVE_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_COPY.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_CUT.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_PASTE_NEW_ROW.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
      LS_EXCLUDE = CL_GUI_ALV_GRID=>MC_FC_LOC_UNDO.
      APPEND LS_EXCLUDE TO PT_EXCLUDE.
    ENDFORM.                               " EXCLUDE_TB_FUNCTIONS
    *&      Form  build_fieldcat
    *       Fieldcatalog
    FORM BUILD_FIELDCAT .
      DATA: L_POS TYPE I.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Delivery'(024).
      X_FIELDCAT-FIELDNAME = 'VBELN'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-NO_ZERO    = 'X'.
      X_FIELDCAT-OUTPUTLEN = '10'.
      X_FIELDCAT-HOTSPOT = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Item'(025).
      X_FIELDCAT-FIELDNAME = 'POSNR'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
      L_POS = L_POS + 1.
      X_FIELDCAT-SCRTEXT_M = 'Drop'(025).
      X_FIELDCAT-FIELDNAME = 'DROP'.
      X_FIELDCAT-TABNAME = 'IT_FINAL'.
      X_FIELDCAT-COL_POS    = L_POS.
      X_FIELDCAT-OUTPUTLEN = '5'.
      X_FIELDCAT-EDIT = 'X'.
      X_FIELDCAT-DRDN_HNDL = '1'.
      X_FIELDCAT-DRDN_ALIAS = 'X'.
      APPEND X_FIELDCAT TO IT_FIELDCAT.
      CLEAR X_FIELDCAT.
    ENDFORM.                    " build_fieldcat
    *&      Module  STATUS_0100  OUTPUT
    *       text
    MODULE STATUS_0100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      SET TITLEBAR 'MAIN100'.
      IF G_CUSTOM_CONTAINER IS INITIAL.
    **Initializing the grid and calling the fm to Display the O/P
        PERFORM CREATE_AND_INIT_ALV.
      ENDIF.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
    *       text
    MODULE USER_COMMAND_0100 INPUT.
      CASE SY-UCOMM.
        WHEN 'BACK'.
          LEAVE TO SCREEN 0.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  SET_DRDN_TABLE
    *       text
    FORM SET_DRDN_TABLE.
      DATA:LT_DRAL TYPE LVC_T_DRAL,
            LS_DRAL TYPE LVC_S_DRAL.
      LOOP AT ITAB .
    * First listbox (handle '1').
        IF SY-INDEX = 1.
          LS_DRAL-HANDLE = '1'.
          LS_DRAL-VALUE =  ' '.
          LS_DRAL-INT_VALUE =  ' '.
        ELSE.
          LS_DRAL-HANDLE = '1'.
          LS_DRAL-VALUE =  ITAB-POSNR.
          LS_DRAL-INT_VALUE =  ITAB-POSNR.
        ENDIF.
        APPEND LS_DRAL TO LT_DRAL.
      ENDLOOP.
    **Setting the Drop down table for Reason Code
      CALL METHOD G_GRID->SET_DROP_DOWN_TABLE
        EXPORTING
          IT_DROP_DOWN_ALIAS = LT_DRAL.
    ENDFORM.                               " set_drdn_table
    *&      Form  EVENT_TOP_OF_PAGE
    *       text
    *      -->DG_DYNDOC_ID  text
    FORM EVENT_TOP_OF_PAGE USING   DG_DYNDOC_ID TYPE REF TO CL_DD_DOCUMENT.
      "this is more clear.....check it
      "first add text, then pass it to comentry write fm
      DATA : DL_TEXT(255) TYPE C.  "Text
    * Populating header to top-of-page
      CALL METHOD DG_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT      = 'Test Report'
          SAP_STYLE = CL_DD_AREA=>HEADING.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move program ID
      CONCATENATE 'Program Name :' SY-REPID
             INTO DL_TEXT SEPARATED BY SPACE.
    * Add Program Name to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move User ID
      CONCATENATE 'User ID :' SY-UNAME INTO DL_TEXT SEPARATED BY SPACE
    * Add User ID to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move count (no of records).
      move v_lines to v_line.
      CONCATENATE 'No of records :' v_line INTO DL_TEXT SEPARATED BY SPACE.
    * Add Client to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move date
      WRITE SY-DATUM TO DL_TEXT.
      CONCATENATE 'Date :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.
    * Add Date to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
      CLEAR : DL_TEXT.
    * Move time
      WRITE SY-UZEIT TO DL_TEXT.
      CONCATENATE 'Time :' DL_TEXT INTO DL_TEXT SEPARATED BY SPACE.
    * Add Time to Document
      PERFORM ADD_TEXT USING DL_TEXT.
    * Add new-line
      CALL METHOD DG_DYNDOC_ID->NEW_LINE.
    * Populating data to html control
      PERFORM HTML.
    ENDFORM.                    " EVENT_TOP_OF_PAGE
    *&      Form  ADD_TEXT
    *       To add Text
    FORM ADD_TEXT USING P_TEXT TYPE SDYDO_TEXT_ELEMENT.
    * Adding text
      CALL METHOD DG_DYNDOC_ID->ADD_TEXT
        EXPORTING
          TEXT         = P_TEXT
          SAP_EMPHASIS = CL_DD_AREA=>HEADING.
    ENDFORM.                    " ADD_TEXT
    *&      Form  HTML
    *       text
    FORM HTML.
      DATA : DL_LENGTH  TYPE I,                           " Length
             DL_BACKGROUND_ID TYPE SDYDO_KEY VALUE SPACE. " Background_id
    * Creating html control
      IF DG_HTML_CNTRL IS INITIAL.
        CREATE OBJECT DG_HTML_CNTRL
             EXPORTING
                  PARENT    = DG_PARENT_HTML.
      ENDIF.
    * Reuse_alv_grid_commentary_set
      CALL FUNCTION 'REUSE_ALV_GRID_COMMENTARY_SET'
        EXPORTING
          DOCUMENT = DG_DYNDOC_ID
          BOTTOM   = SPACE
        IMPORTING
          LENGTH   = DL_LENGTH.
    * Get TOP->HTML_TABLE ready
      CALL METHOD DG_DYNDOC_ID->MERGE_DOCUMENT.
    * Set wallpaper
      CALL METHOD DG_DYNDOC_ID->SET_DOCUMENT_BACKGROUND
        EXPORTING
          PICTURE_ID = DL_BACKGROUND_ID.
    * Connect TOP document to HTML-Control
      DG_DYNDOC_ID->HTML_CONTROL = DG_HTML_CNTRL.
    * Display TOP document
      CALL METHOD DG_DYNDOC_ID->DISPLAY_DOCUMENT
        EXPORTING
          REUSE_CONTROL      = 'X'
          PARENT             = DG_PARENT_HTML
        EXCEPTIONS
          HTML_DISPLAY_ERROR = 1.
      IF SY-SUBRC NE 0.
        MESSAGE I999 WITH 'Error in displaying top-of-page'(036).
      ENDIF.
    ENDFORM.                    " HTML
    Regards
    vijay

  • How To delete the Chosen line from the Table Control

    Hi Friends,
      i am new to Module Pool Programming , i developed a Table Control in input mode and i am getting data also into that table control. my requirement is that i want to delete the current chosen line from that table control. please help me out.

    HI
    GOOD
    GO THROUGH THIS REPORT
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF flights-cols,
    lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
          TABLES demo_conn.
    SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
      cols-screen-input = '0'.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
    DESCRIBE TABLE itab LINES lines.
    flights-lines = lines.
    ENDMODULE.
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
      MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'TOGGLE'.
          LOOP AT flights-cols INTO cols WHERE index GT 2.
            IF  cols-screen-input = '0'.
              cols-screen-input = '1'.
            ELSEIF  cols-screen-input = '1'.
              cols-screen-input = '0'.
          ENDIF.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
        WHEN 'SORT_UP'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
            cols-selected = ' '.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'SORT_DOWN'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
            cols-selected = ' '.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'DELETE'.
          READ TABLE flights-cols INTO cols
                                  WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              DELETE itab.
    ENDLOOP.
          ENDIF.
    ENDCASE.
    ENDMODULE.
    CHANGE THE CODE AS PER THIS LIGIC.
    THANKS
    MRUTYUN

  • Total number lines, in an alv (REUSE_ALV_GRID_DISPLAY)

    Hi,
    i want to know, if it´s possible to show the total number of lines displayed in an alv. I´not not sure if that, is an event of the table gt_events[] (maybe the end_of_list one???)
    I would like to show this total, like an status message...
    Thanks in advance
    Carles

    report  ztest_alv1                              .
    type-pools: slis.
    data:
      ls_fieldcat type slis_fieldcat_alv,
      lt_fieldcat type slis_t_fieldcat_alv,
      lt_sort     type slis_t_sortinfo_alv,
      ls_sort     type slis_sortinfo_alv.
    data: v_line type i,
          lines(3) type c.
    DATA: GT_LIST_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
    data: it_events type slis_t_event,
          x_events type slis_alv_event.
    data: begin of itab occurs 0,
           vbeln like vbak-vbeln,
           posnr like vbap-posnr,
          end of itab.
    itab-vbeln  = '12345'.
    itab-posnr = '10'.
    append itab.
    clear itab.
    itab-vbeln = '12345'.
    itab-posnr = '11'.
    append itab.
    clear itab.
    itab-vbeln = '12345'.
    itab-posnr = '12'.
    append itab.
    clear itab.
    itab-vbeln = '12356'.
    itab-posnr = '10'.
    append itab.
    clear itab.
    itab-vbeln = '12356'.
    itab-posnr = '11'.
    append itab.
    clear itab.
    itab-vbeln = '12356'.
    itab-posnr = '12'.
    append itab.
    clear itab.
    describe table itab lines v_line.
    lines = v_line.
    PERFORM E04_COMMENT_BUILD  USING GT_LIST_TOP_OF_PAGE[].
    x_events-name = 'TOP_OF_PAGE'.
    x_events-form = 'TOP_OF_PAGE'.
    append x_events to it_events.
    call function 'REUSE_ALV_FIELDCATALOG_MERGE'
      exporting
        i_program_name         = sy-repid
        i_internal_tabname     = 'ITAB'
        i_inclname             = sy-repid
      changing
        ct_fieldcat            = lt_fieldcat
      exceptions
        inconsistent_interface = 1
        program_error          = 2
        others                 = 3.
    if sy-subrc <> 0.
      message id sy-msgid type sy-msgty number sy-msgno
              with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    endif.
    ls_sort-fieldname = 'VBELN'.
    ls_sort-up        = 'X'.
    *ls_sort-group = 'UL'.
    append ls_sort to lt_sort.
    clear ls_sort.
    ls_sort-fieldname = 'POSNR'.
    ls_sort-up        = 'X'.
    *ls_sort-group = '*'.
    append ls_sort to lt_sort.
    call function 'REUSE_ALV_GRID_DISPLAY'
      exporting
        it_fieldcat = lt_fieldcat
        it_sort     = lt_sort
        it_events   = it_events
      tables
        t_outtab    = itab.
    FORM E04_COMMENT_BUILD USING E04_LT_TOP_OF_PAGE TYPE SLIS_T_LISTHEADER.
      DATA: LS_LINE TYPE SLIS_LISTHEADER.
      CLEAR LS_LINE.
      LS_LINE-TYP  = 'S'.
      LS_LINE-KEY  = 'NO of lines'.
      LS_LINE-INFO = lines.
      APPEND LS_LINE TO E04_LT_TOP_OF_PAGE.
    ENDFORM.
    * FORM TOP_OF_PAGE *
    form top_of_page.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
           EXPORTING
                I_LOGO             = 'ENJOYSAP_LOGO'
                IT_LIST_COMMENTARY = GT_LIST_TOP_OF_PAGE.
    endform.                    "top_of_page
    check this code..
    regards
    vijay

  • How to download data from itab to Excel sheet..

    Hi sap Experts,
    I develop one report to download data from itab to excel sheet.I done it perfectly.
    My doubt is in the excel sheet i need to put headings. and also at last i need to display total no.of Records.
    Please help me how to do this.
         Thanks in Advance....
    Thanks and Regards
    Siri.......................

    u can either use GUI_DOWNLOAD or the method below...just give a try
    DATA:WK_string TYPE STRING.
    DATA:Wk_EXT(4) TYPE C value '.xls'.
    DATA:WK_path TYPE STRING.
    DATA:wk_file_name type string.
    data:wk_records type sy-tfill.
    wk_file_name = 'Downloaded'.
    describe table itab lines wk_records.
    LOOP AT ITAB.
    at first.
    **Provide path
    concatenate 'C:\' wk_file_name Wk_EXT into wk_path.
    open dataset WK_path for output in text mode encoding default.
    if sy-subrc  0.
    write:'ERROR while opening dataset !!!!!!'.
    EXIT.
    endif.
    CONDENSE wk_path.
    **Heading Part
    concatenate 'Part No' 'Description'
         into wk_string separated by cl_abap_char_utilities=>horizontal_tab.
    endat.
    **Data ITAB
    CONCATENATE ITAB-MATNR itab-maktx into wk_string
         separated by cl_abap_char_utilities=>horizontal_tab.
    transfer wk_string to WK_path.
    at last.
    clear wk_string.
    Concatenate  'Records Passed:' wk_string into wk_string.
    transfer wk_string to WK_path.
    close dataset WK_path.
    endat.
    endloop.

  • Regarding nor of line items selected in per select query..

    hi,
    i want  to display nor of line items selected in per select query for two individual  queries which are linkesd by for all entries..
    regards..
    chetan

    Hi,
    I dont unserstand the problem you are facing. please paste your SELECT query and then explain the problem. then it will be easy for analysis.
    Basically DESCRIBE TABLE itab LINES n.  this statement will put the number of lines the internal table contains
    //Kothand

  • Print line items on next page if does not fir onto current page

    Hello Experts,
    I have a query related with Smartform.
    For every Line item, I have 4 lines. Means, if there are 4 line itmes in Internal table then it means, on form 16 lines should be printed.
    My Requirement - If any of the Line item does not fin onto a single page then shift the whole line item onto next page. Means, If Line item 1 and 2 are printing on 1st page completely, but line item 3 is not able to print completely on 1st page then shift all the 4 lines of line item 3 onto next page.
    I tried - Put the main table of main area in a Folder and checked the PAGE PROTECTION of that folder. And in the Foder itself, use a command with checked GO TO NEW PAGE. But it is not printing. Form goes into shortdump.
    Please help me to resolve this issue.
    Regards
    Kuldeep M.

    Hi,
    U try to fix the no of lines per page. If the no of lines in ur table are more than the lines per page then u call the COMMAND 'Go to New Page' and give the Page name.
    Eg:
    data : lv_lines TYPE i,
              lv_lines_per_page TYPE i value 12.    (Try to design the Window height to fit 12 lines or ur wish)
              lv_count TYPE i.
    describe table itab lines lv_lines.
    Now, u loop the itab table and put a condition in the LOOP:
    LOOP AT itab.
      lv_count = lv_count + 1.
    IF lv_count GT lv_lines_per_page.
       clear lv_count.
       create command 'Go to New Page'.             --->In COMMAND put condition lv_count GT 12
    endif.
    ENDLOOP.
    Hope it helps!!
    Rgds,
    Pavan

  • How to get no. of lines in a  function module

    Dear Experts,
       I want to get the no. of lines present in a function module. How can I do it.
       For reports/ include I did like
      read report 'rep name' into itab.
      describe table itab lines wa_line.
      But I am not able to do the same for function module. Is there any function module to find the no. of lines?
    or is there any other way?
    Thanks and regards,
    Venkat

    HI,
    In Se37, enter your FM name display,
    now Goto --> Mainprogram --> you can see include for function modules
    eg:   include lalfauxx.      " Function Modules
    double click the include
    you can see the function module names includes
    Eg:
      THIS FILE IS GENERATED BY THE FUNCTION LIBRARY.             *
      NEVER CHANGE IT MANUALLY, PLEASE!                           *
    include lalfau01.   "CONVERSION_EXIT_ALPHA_INPUT
    include lalfau02.   "CONVERSION_EXIT_ALPHA_OUTPUT  _
    double click your functipon module name 
    eg :lalfau02.
    you can follow the same as you did for the report
    read report 'rep name' into itab.
    describe table itab lines wa_line
    This is the Include program name for your function module.
    Basically FM is a include program.
    eg:
    data: begin of itab occurs 0,
            text type char2000,
           end of itab.
           data wa_line type syindex.
    read report 'lalfau02' into itab.
    describe table itab lines wa_line.
    write wa_line.
    output 13.
    regards,
    Nazeer

  • Number of lines in ABAP Dictionary table

    Hi to all!
    I've got a table in the ABAP Dictionary. Is there any function in any function module that lets know how many lines this table contains?
    I don't wanna use the way to read data to the internal table and describe it using
    DESCRIBE TABLE <itab> LINES <num_of_lines>.
    Thanks!!!

    REPORT ychatest.
    TABLES mara.
    SELECT COUNT(*) FROM mara.
    WRITE : sy-dbcnt.

  • Xml To itab

    Hi ,
    i'm trying extract data from PDF file. (Adobe Offline scenario).
    I'm getting this XML runtime error.
    could anybody can help me to solve this problem.
    This is my code ,
    CALL TRANSFORMATION id
    SOURCE XML lv_xml_data_string
    RESULT zscustomer12 = wa_zcustomer12.
    Here is the error
    The reason for the exception is:
    Either the source document contains invalid XML or it is handled
    incorrectly in the ABAP program that called the transformation.
    How to correct the error
    The most common cause of this error is a conflict between the encoding
    specified in the declaration <?xml version="1.0" encoding="..."?> in the
    document and the actual encoding of the data.
    If the document is held in an ABAP string, the actual encoding is the
    system code page. If this does not match the declaration, a parsing
    error may occur.
    These conflicts are a particular issue when XML documents are produced
    in one system and then imported into a system with a different code page
    (as strings).
    For this reason, XML documents should be held as binary data (X strings)
    , if they are extracted from the system or accessed from outside.
    If the error occures in a non-modified SAP program, you may be able to
    find an interim solution in an SAP Note.
    If you have access to SAP Notes, carry out a search with the following
    keywords:
    "XSLT_BAD_SOURCE_CONTEXT" "CX_XSLT_RUNTIME_ERROR"
    "ZFORM_12_RECEIVEPDF" or "ZFORM_12_RECEIVEPDF"
    "START-OF-SELECTION"
    please help me out.
    Regards,
    Keerthi

    code:
    TYPES: BEGIN OF T_ATTACHMENT,
    LINE_NO(5),
    FILENAME(200),
    DESCRIPTION TYPE STRING,
    END OF T_ATTACHMENT,
    D_ATTACHMENT TYPE T_ATTACHMENT OCCURS 0.
    TYPES: BEGIN OF T_ATTACHMENTLIST,
    ATTACHMENT TYPE D_ATTACHMENT,
    END OF T_ATTACHMENTLIST,
    D_ATTACHMENTLIST TYPE T_ATTACHMENTLIST OCCURS 0.
    TYPES: BEGIN OF T_HEADER,
    NAME(140),
    PHONE(23),
    EMAIL(100),
    ATTACHMENTLIST TYPE D_ATTACHMENTLIST,
    END OF T_HEADER,
    D_HEADER TYPE T_HEADER OCCURS 0.
    TYPES: BEGIN OF T_ITEM,
    HEADER TYPE D_HEADER,
    END OF T_ITEM.
    TYPES:D_ITEM TYPE T_ITEM OCCURS 0.
    TYPES: BEGIN OF T_LIST,
    ITEM TYPE D_ITEM,
    END OF T_LIST,
    D_LIST TYPE T_LIST OCCURS 0.
    TYPES: BEGIN OF TYPE_DATA,
    LIST TYPE D_LIST,
    END OF TYPE_DATA.
    DATA: ITEMLIST TYPE STANDARD TABLE OF T_LIST INITIAL SIZE 0.
    DATA: XMLOUT TYPE STRING.
    DATA: ITAB LIKE SOLI OCCURS 0 WITH HEADER LINE.
    PERFORM UPLOAD_XML.
    *& Form UPLOAD_XML
    text
    --> p1 text
    <-- p2 text
    FORM UPLOAD_XML .
    REFRESH ITAB.
    clear ITEMLIST.
    CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
    filename = 'C:\test11.XML'
    filetype = 'BIN'
    TABLES
    data_tab = ITAB.
    LOOP AT ITAB.
    CONCATENATE XMLOUT ITAB-LINE INTO XMLOUT.
    ENDLOOP.
    CALL TRANSFORMATION ('ZTEST11X2A')
    SOURCE XML XMLOUT
    RESULT ITEMLIST = ITEMLIST.
    BREAK-POINT.
    ENDFORM.[/code]
    Regards
    Venkat

  • How to MODIFY a dynamic ITAB...

    Hi!!!
    I wants to modify a dynamic itab in a Z-programme which takes inputs. But I can not use the normal itab modifying syntax for it. Therefore I needs to find out a way to modify this itab and it is really essential for my programme.
    Please help me on this...
    Thanking You,
    Yohan.

    Thanks for the prompt replies.
    Dear Amit,
    I have already done the things mention in the link you sent me. This is ok for when I loop the dynamic itab step by step. So it will modify the itab, line by line.  But, what I wants to do is modify an itab field which have the same key in multiple lines.
    For an example say in my structure I have material #. I wants to update all the rows of column 'material description' which have the same material #.
    This is where I have stucked...
    Please help me...
    Thanking you,
    Yohan.

  • To delete the last line of the internal table

    How to delete the last line of the internal table.???????
    The list which gets displayed from the internal table adds a dummy line at the last which shows zeros and zeros.all the otheer selections are perfect.i just want to delete the last line which comes as zero zero.is there any way to do it...

    Quite Easy......Use Describe command to Count the Total Number of Table Lines, and then Delete the Last Line using Index.
    Data L like sy-tabix.
    Describe Table Itab Lines L.
    Delete itab index L.

Maybe you are looking for