Saturday, March 21, 2015



Delete Table Entries from Database

1. select entries which u want to delete from the list of entries of database table in se16.
2. type /h in the command field.
3. press enter and then F8.
4. it will take u to debugging mode. Press F5 and F6.
5. give ok-code value as 'DEL5' and then F8.
6.Pop-up will to delete selected values.

Friday, March 20, 2015



CHECK STATEMENT IN ABAP



CHECK statement in ABAP is used for leaving a loop or processing block with some conditional check. If the conditional check with the CHECK statement is true, the process will continue the execution with the next statement. If the conditional check is false, the process will quit the current loop pass and will process the next loop. If CHECK statement is not within a loop, the false condition will terminate the current event.
Syntax Usages
Inside loops /bloks
CHECK <expr>

With Reports with logical databse
CHECK sel.
CHECK SELECT-OPTIONS

You will get clearer picture by seeing the following sample scenarios.

Check statement in a loop
We can use check statement within a loops like
  • DO … ENDDO
  • WHILE … ENDWHILE
  • LOOP … ENDLOOP
  • SELECT … ENDSELECT

In these loops, if the check statement returns the false, it will stop the current loop pass and start the next loop. Here is an example.
DATA: I =0,
J=0.
WHILE  J < 5.
J = J + 1.
CHECK J NE 2.
WRITE J.
ENDWHILE.

Its output will be
1345

Tip: You can see that check statement terminates the loop with value 2.In that loop check conditional statement return false and the loop pass terminated.

CHECK statement with logical databases

CHECK sel: Checks the selection criterion requested by the statement SELECT-OPTIONS sel. If the result of this check is negative, the processing in this event is terminated and the GET events for any subordinate database tables are not processed either.
CHECK SELECT-OPTIONS: checks all the selections for SELECT-OPTIONS where the reference field after FOR belongs to the current table dbtab. And it is calling only after GET event.




IF, CHECK & WHEN ABAP commends example source code and information.


The IF and the CHECK statements perform similar functionality but whereas The IF statement gives you the option to run different code based on if the condition is true or not, the CHECK just stops the current unit of processing code (i.e. LOOP, PERFORM, FM etc) if the condition is false. See example ABAP code below:


data: it_ekko type STANDARD TABLE OF ekko,
      wa_ekko like line of it_ekko.

SELECT *
from ekko
into table it_ekko
where ebeln eq '1111'.
if sy-subrc = 0.
* code for if sy-subrc = 0


if sy-subrc = 0.
* code for if sy-subrc = 0
elseif sy-subrc = 4.
* code for if sy-subrc = 4
else.
* code for if sy-subrc not = 0 or 4
endif.

SELECT *
  from ekko
  into table it_ekko
 where ebeln eq '1111'.
check sy-subrc = 0.
*only progresses further of sy-subrc = 0
The check statement kind of acts like a combination of the IF & EXIT commands. So when you want to stop processing within something like a loop, perform or function module etc. Instead of using the IF/EXIT commands you can just use the CHECK.
SELECT *
  from ekko
  into table it_ekko.
loop at it_ekko into wa_ekko.
  if sy-tabix eq 14.
    EXIT.
  endif.
*At line 14 the loop processing would stop
endloop.

SELECT *
  from ekko
  into table it_ekko.
loop at it_ekko into wa_ekko.
  check sy-tabix lt 14.
*At line 14 the loop processing would stop
endloop.
In conclusion there isn't really anything the check can do that you can't do with the IF and EXIT commands, just provides a slightly neater way of doing a true/fasle check using a few less lines of ABAP code. The IF on the other hand allows for further conditions other than true or false via the ELSEIF and ELSE statements.


WHEN statement
It's probably at this point I should mention the CASE, WHEN statements, which can be used in the same way as the IF. i.e.
CASE sy-subrc.
  When 0.
*            code for if sy-subrc = 0
  When 4.
*           code for if sy-subrc = 4
  When others.
*           code for if sy-subrc not = 0 or 4
endifcase.
Like the CHECK there is nothing really a when can do that can't be achieved by an IF ELSE but does look a bit neater and is potential more efficient. You can also do something like this if you want to find out which flag has been checked (i.e. contains the value X). For some reason it looks cleverer than it actually is, just seems to switch around what you would expect in the When and case sections.
CASE 'X'.
  When ld_flag1.
  When ld_flag2.
  When ld_flag3.
ENDCASE.
Again the IF does have a further trick up its sleeve that makes it the most comprehensive of the options discussed here and that is the ability to use operators such as AND, OR, NOT etc. for example you could have something like
SELECT *
  from ekko
  into table it_ekko
 where ebeln eq '1111'.
if sy-subrc = 0 or sy-subrc = 4.
* code for if sy-subrc = 0 or 4
elseif sy-subrc = 8 and
       sy-datum gt '20120101' .
* code for if sy-subrc = 8 and date is greater than 01.01.2012
else.
* code for if sy-subrc not = 0 or 4
endif.

Thursday, March 19, 2015



Adding F4 help in table maintainace







*----------------------------------------------------------------------*
***INCLUDE LZHR_DHARMOFFF01.
*----------------------------------------------------------------------*

FORM get_org.

  TYPES:
    BEGIN OF ty_t527x,
     orgeh               TYPE orgeh,
     orgtx               TYPE orgtx,
   END OF ty_t527x.


  DATA:
      lwa_t527x             TYPE ty_t527x,
      lt_t527x              TYPE TABLE OF ty_t527x,
      lt_retval             TYPE TABLE OF ddshretval,
      lwa_retval            TYPE ddshretval,
      lt_fields             TYPE TABLE OF dynpread,
      lwa_fields            LIKE LINE OF lt_fields.

  DATA:
     lv_line                TYPE string.


**Get Org Unit

  SELECT SINGLE orgeh
                orgtx FROM t527x INTO lwa_t527x WHERE sprsl = sy-langu AND
                                               orgeh = zhr_dharmoff-orggh.

  zhr_dharmoff-orgex = lwa_t527x-orgtx.


ENDFORM.                    "get_org







*---------------------------------------------------------------------*
*    view related PAI modules
*   generation date: 12.02.2015 at 15:21:28 by user ABAP05
*   view maintenance generator version: #001407#
*---------------------------------------------------------------------*

INCLUDE lsvimitx . "base table related PAI modules

*----------------------------------------------------------------------*
*  MODULE get_org
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE get_org.

  TYPES:
    BEGIN OF ty_t527x,
     orgeh               TYPE orgeh,
     orgtx               TYPE orgtx,
   END OF ty_t527x.


  DATA:
      lwa_t527x             TYPE ty_t527x,
      lt_t527x              TYPE TABLE OF ty_t527x,
      lt_retval             TYPE TABLE OF ddshretval,
      lwa_retval            TYPE ddshretval,
      lt_fields             TYPE TABLE OF dynpread,
      lwa_fields            LIKE LINE OF lt_fields.

  data:
     lv_line                TYPE string.


**Get Org Unit

  SELECT orgeh orgtx FROM t527x INTO TABLE lt_t527x WHERE sprsl = sy-langu.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'ORGEH'
      value_org       = 'S'
      dynprofield     = 'ORGEH'
    TABLES
      value_tab       = lt_t527x
      return_tab      = lt_retval
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  READ TABLE lt_retval INTO lwa_retval INDEX 1.

  get CURSOR LINE lv_line.

  lwa_fields-fieldname  = 'ZHR_DHARMOFF-ORGGH'.
  lwa_fields-fieldvalue = lwa_retval-fieldval.
  lwa_fields-STEPL      = lv_line.
  APPEND lwa_fields TO lt_fields.
  CLEAR: lwa_fields.

  READ TABLE lt_t527x INTO lwa_t527x WITH KEY orgeh = lwa_retval-fieldval.
  lwa_fields-fieldname  = 'ZHR_DHARMOFF-ORGEX'.
  lwa_fields-fieldvalue = lwa_t527x-orgtx.
  lwa_fields-STEPL      = lv_line.
  APPEND lwa_fields TO lt_fields.
  CLEAR: lwa_fields.

  IF lt_fields IS NOT INITIAL.

    CALL FUNCTION 'DYNP_VALUES_UPDATE'
      EXPORTING
        dyname               = sy-cprog
        dynumb               = sy-dynnr
      TABLES
        dynpfields           = lt_fields
      EXCEPTIONS
        invalid_abapworkarea = 1
        invalid_dynprofield  = 2
        invalid_dynproname   = 3
        invalid_dynpronummer = 4
        invalid_request      = 5
        no_fielddescription  = 6
        undefind_error       = 7
        OTHERS               = 8.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.


ENDMODULE.                    "get_org












*----------------------------------------------------------------------*
***INCLUDE LZHR_MAS_TIDI01.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  GET_PERSA  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE get_persa INPUT.
TYPES:
    BEGIN OF ty_T500P,
     PERSA               TYPE persa,
     name1               TYPE PBTXT,
   END OF ty_T500P.


  DATA:
      lwa_T500P             TYPE ty_T500P,
      lt_T500P              TYPE TABLE OF ty_T500P,
      lt_retval             TYPE TABLE OF ddshretval,
      lwa_retval            TYPE ddshretval,
      lt_fields             TYPE TABLE OF dynpread,
      lwa_fields            LIKE LINE OF lt_fields.

  data:
     lv_line                TYPE string.


**Get employee subgroup
*break abap07.
  SELECT PERSA NAME1 FROM T500P INTO TABLE lt_T500P. " WHERE sprsl = sy-langu.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'PERSA'
      value_org       = 'S'
      dynprofield     = 'PERSA'
    TABLES
      value_tab       = lt_T500P
      return_tab      = lt_retval
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  READ TABLE lt_retval INTO lwa_retval INDEX 1.

  get CURSOR LINE lv_line.

  lwa_fields-fieldname  = 'ZHR_MAS_TID-PERSA'.
  lwa_fields-fieldvalue = lwa_retval-fieldval.
  lwa_fields-STEPL      = lv_line.
  APPEND lwa_fields TO lt_fields.
  CLEAR: lwa_fields.

  READ TABLE lt_T500P INTO lwa_T500P WITH KEY PERSA = lwa_retval-fieldval.
  lwa_fields-fieldname  = 'ZHR_MAS_TID-NAME1'.
  lwa_fields-fieldvalue = lwa_T500P-NAME1.
  lwa_fields-STEPL      = lv_line.
  APPEND lwa_fields TO lt_fields.
  CLEAR: lwa_fields.

  IF lt_fields IS NOT INITIAL.

    CALL FUNCTION 'DYNP_VALUES_UPDATE'
      EXPORTING
        dyname               = sy-cprog
        dynumb               = sy-dynnr
      TABLES
        dynpfields           = lt_fields
      EXCEPTIONS
        invalid_abapworkarea = 1
        invalid_dynprofield  = 2
        invalid_dynproname   = 3
        invalid_dynpronummer = 4
        invalid_request      = 5
        no_fielddescription  = 6
        undefind_error       = 7
        OTHERS               = 8.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.




ENDMODULE.                 " GET_PERSA  INPUT



*********************************************************************
*********************************************************************


*----------------------------------------------------------------------*
***INCLUDE LZHR_MAS_TIDI02.
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  GET_BTRTL  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE get_btrtl INPUT.

TYPES:
    BEGIN OF ty_T001P,
     BTRTL               TYPE BTRTL,
     BTEXT               TYPE PBTXT,
   END OF ty_T001P.


  DATA:
      lwa_T001P             TYPE ty_T001P,
      lt_T001P              TYPE TABLE OF ty_T001P,
      lt_retval1             TYPE TABLE OF ddshretval,
      lwa_retval1            TYPE ddshretval,
      lt_fields1             TYPE TABLE OF dynpread,
      lwa_fields1            LIKE LINE OF lt_fields1.

  data:
     lv_line1                TYPE string.


**Get employee subgroup
*break abap07.
  SELECT BTRTL BTEXT FROM T001P INTO TABLE lt_T001P. " WHERE sprsl = sy-langu.

  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'BTRTL'
      value_org       = 'S'
      dynprofield     = 'BTRTL'
    TABLES
      value_tab       = lt_T001P
      return_tab      = lt_retval1
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  READ TABLE lt_retval1 INTO lwa_retval1 INDEX 1.

  get CURSOR LINE lv_line1.

  lwa_fields1-fieldname  = 'ZHR_MAS_TID-BTRTL'.
  lwa_fields1-fieldvalue = lwa_retval1-fieldval.
  lwa_fields1-STEPL      = lv_line1.
  APPEND lwa_fields1 TO lt_fields1.
  CLEAR: lwa_fields1.

  READ TABLE lt_T001P INTO lwa_T001P WITH KEY BTRTL = lwa_retval1-fieldval.
  lwa_fields1-fieldname  = 'ZHR_MAS_TID-BTEXT'.
  lwa_fields1-fieldvalue = lwa_T001P-BTEXT.
  lwa_fields1-STEPL      = lv_line1.
  APPEND lwa_fields1 TO lt_fields1.
  CLEAR: lwa_fields1.

  IF lt_fields1 IS NOT INITIAL.

    CALL FUNCTION 'DYNP_VALUES_UPDATE'
      EXPORTING
        dyname               = sy-cprog
        dynumb               = sy-dynnr
      TABLES
        dynpfields           = lt_fields1
      EXCEPTIONS
        invalid_abapworkarea = 1
        invalid_dynprofield  = 2
        invalid_dynproname   = 3
        invalid_dynpronummer = 4
        invalid_request      = 5
        no_fielddescription  = 6
        undefind_error       = 7
        OTHERS               = 8.
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDIF.


ENDMODULE.                 " GET_BTRTL  INPUT







Wednesday, March 18, 2015



Table control examples

*&---------------------------------------------------------------------*
*& Report  Z_DB_TABLECONTROL                                           *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*
REPORT  Z_DB_TABLECONTROL.
TABLES: MARA.
CONTROLS MATERIAL TYPE TABLEVIEW USING SCREEN 130.
TYPES: BEGIN OF ST_MARA,
       MATNR TYPE MARA-MATNR,
       ERSDA TYPE MARA-ERSDA,
       ERNAM TYPE MARA-ERNAM,
       LAEDA TYPE MARA-LAEDA,
       END OF ST_MARA.
DATA: IT_ST TYPE TABLE OF ST_MARA,
      WA_ST TYPE ST_MARA,
      IT_MARA TYPE MARA,
      WA_MARA TYPE MARA,
      OK_CODE LIKE SY-UCOMM.
CALL SCREEN 130.
*&---------------------------------------------------------------------*
*&      Module  V1  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE V1 INPUT.
CASE OK_CODE.
WHEN 'SAVE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING WA_ST TO WA_MARA.
INSERT INTO MARA VALUES WA_MARA.
WHEN 'DELETE'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING  WA_ST TO WA_MARA.
DELETE MARA FROM WA_MARA.
WHEN 'MODIFY'.
WA_ST-MATNR = MARA-MATNR.
WA_ST-ERSDA = MARA-ERSDA.
WA_ST-ERNAM = MARA-ERNAM.
WA_ST-LAEDA = MARA-LAEDA.
MOVE-CORRESPONDING  WA_ST TO WA_MARA.
MODIFY MARA FROM WA_MARA.
ENDCASE.
ENDMODULE.                 " V1  INPUT
*&---------------------------------------------------------------------*
*&      Module  EXIT  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
IF OK_CODE = 'EXIT'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.                 " EXIT  INPUT
Create a screen by number 130 and provide the following attributes: 
 
LAYOUT:
 
ELEMENT LIST:
 
FLOW LOGIC.
 
EXECUTE: 




http://scn.sap.com/thread/1067760




Simple Table Control

Table control is one of a ABAP displaying mechanisms. With the help of Table control we can see the output table in different visibility approach. Here we have developed a Module Pool program where a simple table control has been incorporated.

The output of the table control is like following:

1. Initial screen where we have to give the Transaction Code to run the Module Pool Program.


2. This is the first screen where we have to give the Purchase Order number in the input field. DISPLAY button will display the entered PO details at the second screen. CLEAR button will clear the entered data in the input field. Also we can see the title is coming for the first screen.


3. If nothing is give here then an Information message will come by clicking DISPLAY button.


4. Now we are giving a valid PO which has 22 items like follows.


5. By clicking on DISPLAY button we are going to the second screen where the Table Control is there to display the Item wise details as per Output table structure.


6. Now if we Scroll down by putting the mouse pointer on the Table Control then we shall go to the next slot of records as following.


7. By clicking on the BACK or EXIT or CANCEL button we shall come back to the first screen with a blank input field.

8. Now we are giving another PO and click on DISPLAY button.


9. New list will be coming with the same format but data are different. Here previous data will not be there. The entered PO contains 311 Items as follows.


10. By scroll down we can go to the last slot of data as follows.


11. By clicking BACK we shall come back to first screen like follows.


Following is the Coding for various Modules:

*&---------------------------------------------------------------------*
*& Module Pool       ZSR_MOD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*


INCLUDE zsr_top                                 .  " global Data
INCLUDE zsr_o01                                 .  " PBO-Modules
INCLUDE zsr_i01                                 .  " PAI-Modules
INCLUDE zsr_f01                                 .  " FORM-Routines


Top Include:

*&---------------------------------------------------------------------*
*& Include ZSR_TOP                                           Module Pool      ZSR_MOD
*&
*&---------------------------------------------------------------------*

PROGRAM  zsr_mod.

TABLES: ekko, ekpo.

TYPES: BEGIN OF ty_ekko,
        ebeln TYPE ekko-ebeln,
        bukrs TYPE ekko-bukrs,
        ernam TYPE ekko-ernam,
        lifnr TYPE ekko-lifnr,
       END OF ty_ekko,

       BEGIN OF ty_ekpo,
         ebeln TYPE ekpo-ebeln,
         ebelp TYPE ekpo-ebelp,
         matnr TYPE ekpo-matnr,
         werks TYPE ekpo-werks,
         lgort TYPE ekpo-lgort,
       END OF ty_ekpo,

       BEGIN OF ty_out,
        ebeln TYPE ekko-ebeln,
        ebelp TYPE ekpo-ebelp,
        ernam TYPE ekko-ernam,
        matnr TYPE ekpo-matnr,
        werks TYPE ekpo-werks,
        lgort TYPE ekpo-lgort,
        bukrs TYPE ekko-bukrs,
        lifnr TYPE ekko-lifnr,
       END OF ty_out.

DATA: ok_code1 TYPE sy-ucomm,
      ok_code2 TYPE sy-ucomm,
      editable TYPE i.

DATA: wa_ekko TYPE ty_ekko,
      wa_ekpo TYPE ty_ekpo,
      wa_out  TYPE ty_out,
      it_ekko TYPE STANDARD TABLE OF ty_ekko,
      it_ekpo TYPE STANDARD TABLE OF ty_ekpo,
      it_out  TYPE STANDARD TABLE OF ty_out WITH HEADER LINE.

CONTROLS: tab_ctrl TYPE TABLEVIEW USING SCREEN 9001.


Include for PBO:

*&---------------------------------------------------------------------*
*&  Include           ZSR_O01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.

  SET PF-STATUS 'GUI_9000'.
  SET TITLEBAR 'TITLE_9000'.

ENDMODULE.                 " STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  TABLE_CTRL  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE table_ctrl OUTPUT.

  CLEAR: ekko, ekpo.
  ekko-ebeln = wa_out-ebeln.
  ekpo-ebelp = wa_out-ebelp.
  ekko-ernam = wa_out-ernam.
  ekpo-matnr = wa_out-matnr.
  ekpo-werks = wa_out-werks.
  ekpo-lgort = wa_out-lgort.
  ekko-bukrs = wa_out-bukrs.
  ekko-lifnr = wa_out-lifnr.
  CLEAR wa_out.

ENDMODULE.                 " TABLE_CTRL  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_9001  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE status_9001 OUTPUT.

  SET PF-STATUS 'GUI_9001'.
  SET TITLEBAR 'TITLE_9001'.

ENDMODULE.                 " STATUS_9001  OUTPUT


Include for PAI:

*&---------------------------------------------------------------------*
*&  Include           ZSR_I01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.

  IF ok_code1 IS NOT INITIAL.
    CASE ok_code1.
      WHEN 'BACK'.
        PERFORM leave_program.
      WHEN 'EXIT'.
        PERFORM leave_program.
      WHEN 'CANCEL'.
        PERFORM leave_program.
      WHEN 'DISP'.
        PERFORM display_po_details.
      WHEN 'CLR'.
        PERFORM clear_screen.
    ENDCASE.
  ENDIF.

ENDMODULE.                 " USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE user_command_9001 INPUT.

  IF ok_code1 IS NOT INITIAL.
    CASE ok_code2.
      WHEN 'BACK'.
        PERFORM leave_program.
      WHEN 'EXIT'.
        PERFORM leave_program.
      WHEN 'CANCEL'.
        PERFORM leave_program.
    ENDCASE.
  ENDIF.

ENDMODULE.                 " USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*&      Module  MODIFY_TABLE_CTRL  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE modify_table_ctrl INPUT.

  READ TABLE it_out INTO wa_out
  INDEX tab_ctrl-current_line.

  IF sy-subrc = 0.
    MODIFY it_out INDEX tab_ctrl-current_line FROM wa_out.
  ENDIF.

ENDMODULE.                 " MODIFY_TABLE_CTRL  INPUT


Include for Subroutine:

*&---------------------------------------------------------------------*
*&  Include           ZSR_F01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  LEAVE_PROGRAM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM leave_program .

  "Refreshing all Internal Tables
  REFRESH: it_out[], it_ekko, it_ekpo.

  "Clearing work area with Screen fields
  CLEAR: it_out, ekko, ekpo.

  "Clearing OK_CODE for new user command
  CLEAR: ok_code1, ok_code2.

  "Going back to initial screen
  LEAVE TO SCREEN 0.

ENDFORM.                    " LEAVE_PROGRAM
*&---------------------------------------------------------------------*
*&      Form  CLEAR_SCREEN
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM clear_screen .

  CLEAR ekko-ebeln.
  SET SCREEN 9000.

ENDFORM.                    " CLEAR_SCREEN
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_PO_DETAILS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM display_po_details .

  IF ekko-ebeln IS NOT INITIAL.
    "Selection of PO Header based Screen 1 PO
    SELECT ebeln bukrs ernam lifnr
      FROM ekko INTO TABLE it_ekko
      WHERE ebeln = ekko-ebeln.

    IF sy-subrc = 0.
      SORT it_ekko BY ebeln.

      "Selection of PO Item for all entries in header table
      SELECT ebeln ebelp matnr werks lgort
        FROM ekpo INTO TABLE it_ekpo
        FOR ALL ENTRIES IN it_ekko
        WHERE ebeln = it_ekko-ebeln.

      IF sy-subrc = 0.
        SORT it_ekpo BY ebeln.
      ELSE.
        MESSAGE 'Item not found' TYPE 'I'.
      ENDIF.

    ELSE.
      MESSAGE 'PO doesn''t exist' TYPE 'I'.
    ENDIF.

    IF it_ekpo IS NOT INITIAL.
      LOOP AT it_ekpo INTO wa_ekpo.
        READ TABLE it_ekko INTO wa_ekko
        WITH KEY ebeln = wa_ekpo-ebeln
        BINARY SEARCH.

        IF sy-subrc = 0.
          "Preparing Output table of Table Control
          wa_out-ebeln = wa_ekko-ebeln.
          wa_out-ebelp = wa_ekpo-ebelp.
          wa_out-ernam = wa_ekko-ernam.
          wa_out-matnr = wa_ekpo-matnr.
          wa_out-werks = wa_ekpo-werks.
          wa_out-lgort = wa_ekpo-lgort.
          wa_out-bukrs = wa_ekko-bukrs.
          wa_out-lifnr = wa_ekko-lifnr.
          APPEND wa_out TO it_out.
          CLEAR: wa_out, wa_ekko, wa_ekpo.
        ENDIF.
      ENDLOOP.
    ENDIF.

  ELSE.
    MESSAGE 'Please Select Valid PO' TYPE 'I'.
  ENDIF.

  IF it_out[] IS NOT INITIAL.

    "Output table is Sorted out by Item
    SORT it_out[] BY ebelp.

    "Table Control is refreshed before get into of this
    REFRESH CONTROL 'TAB_CTRL' FROM SCREEN 9001.

    "Calling Table control screen
    CALL SCREEN 9001.
  ENDIF.

ENDFORM.                    " DISPLAY_PO_DETAILS


Coding for Screen - 1:

PROCESS BEFORE OUTPUT.
  MODULE status_9000.

PROCESS AFTER INPUT.
  MODULE user_command_9000.


Coding for Screen - 2:

PROCESS BEFORE OUTPUT.

  "Module for PF Status & Title Bar of 2nd Screen
  MODULE status_9001.

  "Looping at Output table to pass value to Table Control
  LOOP AT it_out INTO wa_out WITH CONTROL tab_ctrl.

    "Module to pass the value to Screen Fields
    MODULE table_ctrl.
  ENDLOOP.


PROCESS AFTER INPUT.

  "Looping at Output table to fetch next set of values
  LOOP AT it_out.

    "Module to modify Output table with Current Line Index
    MODULE modify_table_ctrl.
  ENDLOOP.

  "Module for using Button on the screen - 2
  MODULE user_command_9001.

http://sapabap-4.blogspot.in/2013/06/simple-table-control.html