Sie sind auf Seite 1von 20

Looping Through Screen Directly

Program Name : ysubtabsimloop1 . Transaction Code : ytab02 . Mode of Action : The user will enter a material code in a field and press enter . Relevant records from the ABAP program will be populated into the table control .User can update The quantity in the table control .

Screen :

The table control is tabctrl , the table fields are prepared from internal table .Let us look the attributes of the table control :-

Let us look at the screen flow logic for the program :


PROCESS BEFORE OUTPUT. loop with control tabctrl module fetchrec . endloop . * MODULE STATUS_1000. * PROCESS AFTER INPUT. loop with control tabctrl module modrec . endloop . MODULE USER_COMMAND_1000. .

Now, let us look at the main program :PROGRAM YSUBTABSIMLOOP . tables : mara , mseg . data : menge like mseg-menge . data : ok_code like sy-ucomm , saveok like ok_code , rec type i , ind like rec , base type i value 0 . data : begin of material , matnr mblnr menge dmbtr like like like like mseg-matnr mseg-mblnr mseg-menge mseg-dmbtr , , , ,

end of material . controls tabctrl type tableview using screen 1000 . data : intmat like standard table of material with header line . module fetchrec output. READ TABLE intmat INDEX tabctrl-current_line. endmodule. " fetchrec OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_1000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module USER_COMMAND_1000 input. if not mara-matnr is initial . if rec le 0 . select distinct matnr mblnr menge dmbtr from mseg into corresponding fields of table intmat where matnr in ( select distinct matnr from mara where matkl like 'NF%' ) and bwart = '201' . rec = sy-dbcnt . describe table intmat lines rec . tabctrl-lines = rec . base = sy-loopc . endif . endif . endmodule. " USER_COMMAND_1000 module modrec input. modify intmat INDEX tabctrl-current_line. endmodule. " modrec INPUT

INPUT

Looping Through An Internal Table Looping Through Screen Directly


Program Name : ysubtabsimloop . Transaction Code : ytab01 . Mode of Action : The user will enter a material code in a field and press enter . Relevant records from the ABAP program will be populated into the table control .User can update The quantity in the table control .Value gets updated accordingly . The screen similar to above .The table fields are taken from dictionary table : mseg .

Screen Flow Logic For The Program :


PROCESS BEFORE OUTPUT. loop at intmat with control tabctrl. module fetchrec . endloop . * MODULE STATUS_1000. * PROCESS AFTER INPUT. loop at intmat . module modrec . endloop . MODULE USER_COMMAND_1000.

Let us look at the main program :PROGRAM YSUBTABSIMLOOP . tables : mara , mseg . data : menge like mseg-menge . data : ok_code like sy-ucomm , saveok like ok_code , rec type i , ind like rec , base type i value 0 . data : begin of material , matnr mblnr menge dmbtr like like like like mseg-matnr mseg-mblnr mseg-menge mseg-dmbtr , , , ,

end of material . controls tabctrl type tableview using screen 1000 . data : intmat like standard table of material with header line . *&---------------------------------------------------------------------*

*& Module fetchrec OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module fetchrec output. if rec gt 0 . mseg-matnr = intmat-matnr mseg-mblnr = intmat-mblnr mseg-menge = intmat-menge mseg-dmbtr = intmat-dmbtr base = sy-loopc . endif .

. . . .

endmodule. " fetchrec OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_1000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module USER_COMMAND_1000 input. if not mara-matnr is initial . if rec le 0 . select distinct matnr mblnr menge dmbtr from mseg into corresponding fields of table intmat where matnr in ( select distinct matnr from mara where matkl like 'NF%' ) and bwart = '201' . rec = sy-dbcnt . describe table intmat lines rec . tabctrl-lines = rec . endif . endif . endmodule. " USER_COMMAND_1000 INPUT *&---------------------------------------------------------------------* *& Module modrec INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module modrec input. *intmat-menge = mseg-menge . *MODIFY INTmat TRANSPORTING menge * * WHERE ( matnr = mseg-matnr * AND mblnr = mseg-mblnr * AND dmbtr = mseg-dmbtr ) . * read table intmat index tabctrl-current_line . mseg-dmbtr = ( mseg-dmbtr * mseg-menge ) div intmat-menge . clear intmat . move-corresponding mseg to intmat .

modify intmat endmodule.

index tabctrl-current_line . " modrec INPUT

TABLE CONTROL : COMPLETE EXAMPLES

Here , I will demonstrate two simple ABAP programs with table controls , one from internal table and other from database table . The mode of action for both the programs are more or less the same :User will enter plant and storage location code and the records of wastage sale will come into the table control . Options :By pressing the Change/Display button(toggle) , the user can shift from change mode to display mode and vice versa .

By selecting a record on clicking the row selection pushbutton at the left of the table , user can press Insert(ins) or Delete(del) pushbutton , when a blank line will be inserted / the record will be deleted from table control .

The user can change the quantity and press enter when the value will be updated . On pressing the Save pushbutton(Save) , the records will be saved into ysale_tbl . The user can enter a quantity in the simple field and can press the Select (SEL) pushbutton when the record in the table control containing that quantity will be set at the top of the table control . If the user double clicks at the rightmost column , some message will inform the user about the nature of the record on which the user clicked double .

Let us study the program where the table control is created from database table:PROCESS BEFORE OUTPUT. MODULE STATUS_1000.

LOOP at intsale . module disrec . ENDLOOP .

with control ysale

PROCESS AFTER INPUT. MODULE CANCEL AT EXIT-COMMAND . LOOP at intsale . module modint . field ysale_tbl-ind ENDLOOP .

module mod001 at cursor-selection .

MODULE USER_COMMAND_1000.

(Main program )
PROGRAM YSUBTAB3 .

DATA : FLD(20) TYPE C . tables : ysale_tbl , ywast_mst . data : begin of tsale , memo_no like ysale_tbl-memo_no , gpass_no like ysale_tbl-gpass_no, wast_cd like ysale_tbl-wast_cd , qty like ysale_tbl-qty , value like ysale_tbl-value , STATUS(1) , ind(1) , end of tsale . * CXTAB_CONTROL DATA : INTSALE LIKE STANDARD TABLE OF TSALE data : save_ok like sy-ucomm , okcode like sy-ucomm , QTY LIKE MSEG-MENGE , STATUS(1) , flag type i , rate like ywast_mst-rate . data : sen type i . data : r type i VALUE 0 , fill like r , cnt type i , BASE TYPE I VALUE 0 , IND LIKE FILL . BASE = SY-LOOPC . data : werks like ysale_tbl-werks , lgort like ysale_tbl-lgort . controls ysale type tableview using screen 1000 . data : cols like line of ysale-cols . *&---------------------------------------------------------------------* *& Module STATUS_1000 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_1000 OUTPUT. SET PF-STATUS 'SUB001'. * SET TITLEBAR 'xxx'. if not werks is initial . if not lgort is initial . if r eq 0 . select memo_no gpass_no wast_cd qty value sale_date into corresponding fields of table intsale FROM YSALE_TBL where werks = werks and lgort = lgort . WITH HEADER LINE .

describe table intsale lines fill . ysale-lines = fill . r = r + 1 . endif . endif . endif .

ENDMODULE.

" STATUS_1000

OUTPUT

*&---------------------------------------------------------------------* *& Module CANCEL INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE CANCEL INPUT. LEAVE PROGRAM . ENDMODULE. " CANCEL INPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_1000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_1000 INPUT. save_ok = okcode . clear okcode . CASE save_ok . WHEN 'LSEL' . IF YSALE-LINE_SELECTOR = SPACE . YSALE-LINE_SELECTOR = 'X' . ELSE . YSALE-LINE_SELECTOR = 'X' . ENDIF . WHEN 'COLOR' . LOOP AT YSALE-COLS INTO COLS WHERE INDEX EQ 4 . IF COLR EQ 6 . COLR = 1 . ELSE . COLR = COLR + 1 . ENDIF . COLS-SCREEN-COLOR = COLR . MODIFY YSALE-COLS FROM COLS INDEX SY-TABIX .

ENDLOOP . WHEN 'GRID' . IF YSALE-H_GRID = 'X' . YSALE-H_GRID = SPACE . ELSE . YSALE-H_GRID = 'X' . ENDIF . IF YSALE-V_GRID = 'X' . YSALE-V_GRID = SPACE . ELSE . YSALE-V_GRID = 'X' . ENDIF . WHEN 'MEMO' . LOOP AT YSALE-COLS INTO COLS WHERE INDEX EQ 1 . IF COLS-INVISIBLE = 1 . COLS-INVISIBLE = 0 . ELSE . COLS-INVISIBLE = 1 . ENDIF . MODIFY YSALE-COLS FROM COLS INDEX SY-TABIX . ENDLOOP .

when 'INS' . READ TABLE YSALE-COLS INTO COLS WITH KEY SCREEN-INPUT = '1' . IF SY-SUBRC = 0 . cnt = 0 . LOOP AT INTSALE into tsale cnt = cnt + 1 . if tsale-status = 'X' . exit . endif . ENDLOOP . endif .

clear tsale . *

insert tsale into intsale index cnt . WHEN 'SEL' . base = 0 . flag = 0 . loop at intsale into tsale . base = base + 1 . if tsale-qty = cnt . fld = 'YSALE_TBL-QTY' . flag = 1 . exit . endif . endloop . if flag = 1 . YSALE-TOP_LINE = BASE . else . message i398(00) with ' Sorry! No records found' . endif . when 'DEL' . READ TABLE YSALE-COLS INTO COLS WITH KEY SCREEN-INPUT = '1' . IF SY-SUBRC = 0 . LOOP AT INTSALE INTO YSALE_TBL WHERE STATUS = 'X' . DELETE INTSALE . ENDLOOP . ENDIF . WHEN 'TOGGLE' . LOOP AT YSALE-COLS INTO COLS WHERE INDEX GT 3 AND INDEX NE 5 . IF COLS-SCREEN-INPUT = 0 . COLS-SCREEN-INPUT = 1 . ELSEIF COLS-SCREEN-INPUT = 1 . COLS-SCREEN-INPUT = 0 . endif . MODIFY YSALE-COLS FROM COLS INDEX SY-TABIX . ENDLOOP . loop at ysale-cols into cols where index eq 4 . cols-screen-intensified = 1 . modify ysale-cols from cols index sy-tabix . endloop .

WHEN 'SAVE' . clear tsale . LOOP AT INTSALE INTO TSALE . UPDATE YSALE_TBL SET QTY = TSALE-QTY VALUE = TSALE-VALUE WHERE WAST_CD = TSALE-WAST_CD AND MEMO_NO = TSALE-MEMO_NO AND GPASS_NO = TSALE-GPASS_NO .

clear tsale . ENDLOOP . CLEAR INTSALE . REFRESH INTSALE . CLEAR WERKS . CLEAR LGORT . r = 0 . ENDCASE . ENDMODULE. " USER_COMMAND_1000 INPUT

*&---------------------------------------------------------------------* *& Module modint INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE modint INPUT.

select single rate into rate from ywast_mst where wast_cd = ysale_tbl-wast_cd . ysale_tbl-value = ysale_tbl-qty * rate .

MODIFY INTSALE FROM YSALE_TBL INDEX YSALE-CURRENT_LINE . *--------------------------------------------------*Quantity and value can be also be updated in the *following manner *--------------------------------------------*select single rate into rate from ywast_mst *where wast_cd = ysale_tbl-wast_cd . * *ysale_tbl-value = ysale_tbl-qty * rate . * *intsale-qty = ysale_tbl-qty .

*intsale-value = ysale_tbl-value . * * * *MODIFY INTSALE TRANSPORTING QTY *VALUE *WHERE ( MEMO_NO = YSALE_TBL-MEMO_NO * AND GPASS_NO = YSALE_TBL-GPASS_NO * AND WAST_CD = YSALE_TBL-WAST_CD ) . * *modify intsale from ysale_tbl index ysale-current_line . .

ENDMODULE. " modint INPUT *&---------------------------------------------------------------------* *& Module disrec OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE disrec OUTPUT.

ysale_tbl-memo_no = intsale-memo_no . ysale_tbl-gpass_no = intsale-gpass_no . ysale_tbl-wast_cd = intsale-wast_cd . ysale_tbl-qty = intsale-qty . ysale_tbl-value = intsale-value . ENDMODULE. " disrec OUTPUT *&---------------------------------------------------------------------* *& Module CURSOR OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* *&---------------------------------------------------------------------* *& Module cursor INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE cursor INPUT. ENDMODULE. " cursor INPUT *&---------------------------------------------------------------------* *& Module mod001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE mod001 INPUT. cnt = ysale-current_line . message i398(00) with ysale_tbl-wast_cd ysale_tbl-qty cnt . ENDMODULE. " mod001 INPUT

Now , let us study the program where the table control is created from internal table :PROCESS BEFORE OUTPUT. MODULE STATUS_1000. LOOP at intsale ENDLOOP . with control ysale .

PROCESS AFTER INPUT. MODULE CANCEL AT EXIT-COMMAND . LOOP . FIELD intsale-ind module mod001 at cursor-selection . module modint . ENDLOOP . MODULE USER_COMMAND_1000.

PROGRAM YSUBTAB3 .

tables : ysale_tbl , ywast_mst . DATA : NAME LIKE YWAST_MST-NAME . data : begin of tsale , memo_no like ysale_tbl-memo_no , gpass_no like ysale_tbl-gpass_no, wast_cd like ysale_tbl-wast_cd , qty like ysale_tbl-qty , value like ysale_tbl-value , status(1) , ind(1) , end of tsale . data : cnt type i . DATA : INTSALE LIKE STANDARD TABLE OF TSALE data : save_ok like sy-ucomm , okcode like sy-ucomm , QTY LIKE MSEG-MENGE , flag type i , base type i , rate like ywast_mst-rate . WITH HEADER LINE .

data : r type i VALUE 0 , fill like r , IND LIKE FILL . BASE = SY-LOOPC . data : werks like ysale_tbl-werks , lgort like ysale_tbl-lgort .

controls ysale type tableview using screen 1000 . data : cols like line of ysale-cols . *&---------------------------------------------------------------------* *& Module STATUS_1000 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_1000 OUTPUT. SET PF-STATUS 'SUB001' OF PROGRAM 'YSUBTAB3' . * SET TITLEBAR 'xxx'. if not werks is initial . if not lgort is initial . if r eq 0 . select memo_no gpass_no wast_cd qty value sale_date into corresponding fields of table intsale FROM YSALE_TBL where werks = werks and lgort = lgort . describe table intsale lines fill . ysale-lines = fill . r = r + 1 . endif . endif . endif .

ENDMODULE.

" STATUS_1000

OUTPUT

*&---------------------------------------------------------------------* *& Module CANCEL INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE CANCEL INPUT. LEAVE PROGRAM . ENDMODULE. " CANCEL INPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_1000 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_1000 INPUT. save_ok = okcode . clear okcode . CASE save_ok . WHEN 'TOGGLE' .

LOOP AT YSALE-COLS INTO COLS WHERE INDEX GT 3 AND INDEX NE 5 . IF COLS-SCREEN-INPUT = 0 . COLS-SCREEN-INPUT = 1 . ELSEIF COLS-SCREEN-INPUT = 1 . COLS-SCREEN-INPUT = 0 . endif . MODIFY YSALE-COLS FROM COLS INDEX SY-TABIX . ENDLOOP . loop at ysale-cols into cols where index eq 4 . cols-screen-intensified = 1 . modify ysale-cols from cols index sy-tabix . endloop .

WHEN 'SEL' . base = 0 . flag = 0 . loop at intsale into tsale . base = base + 1 . if tsale-qty = cnt . flag = 1 . exit . endif . endloop . if flag = 1 . YSALE-TOP_LINE = BASE . else . message i398(00) with ' Sorry! No records found' . endif .

when 'INS' . READ TABLE YSALE-COLS INTO COLS WITH KEY SCREEN-INPUT = '1' . IF SY-SUBRC = 0 . cnt = 0 . LOOP AT INTSALE into tsale cnt = cnt + 1 . if tsale-status = 'X' . exit . endif .

ENDLOOP . endif .

clear tsale . * insert tsale into intsale index cnt .

when 'DEL' .

READ TABLE YSALE-COLS INTO COLS WITH KEY SCREEN-INPUT = '1' . IF SY-SUBRC = 0 . LOOP AT INTSALE where status = 'X' . delete intsale . endloop .

ENDIF . WHEN 'LSEL' . IF YSALE-LINE_SELECTOR = SPACE . YSALE-LINE_SELECTOR = 'X' . ELSE . YSALE-LINE_SELECTOR = 'X' . ENDIF . WHEN 'COLOR' . LOOP AT YSALE-COLS INTO COLS WHERE INDEX EQ 4 . IF COLR EQ 6 . COLR = 1 . ELSE . COLR = COLR + 1 . ENDIF . COLS-SCREEN-COLOR = COLR . MODIFY YSALE-COLS FROM COLS INDEX SY-TABIX . ENDLOOP . WHEN 'GRID' . IF YSALE-H_GRID = 'X' . YSALE-H_GRID = SPACE .

ELSE . YSALE-H_GRID = 'X' . ENDIF . IF YSALE-V_GRID = 'X' . YSALE-V_GRID = SPACE . ELSE . YSALE-V_GRID = 'X' . ENDIF . WHEN 'MEMO' . LOOP AT YSALE-COLS INTO COLS WHERE INDEX EQ 1 . IF COLS-INVISIBLE = 1 . COLS-INVISIBLE = 0 . ELSE . COLS-INVISIBLE = 1 . ENDIF . MODIFY YSALE-COLS FROM COLS INDEX SY-TABIX . ENDLOOP .

WHEN 'SAVE' . LOOP AT INTSALE INTO TSALE . UPDATE YSALE_TBL SET QTY = TSALE-QTY VALUE = TSALE-VALUE WHERE gpass_no = TSALE-gpass_no AND MEMO_NO = TSALE-MEMO_NO AND WAST_CD = TSALE-WAST_CD .

ENDLOOP . CLEAR INTSALE . REFRESH INTSALE . CLEAR WERKS . CLEAR LGORT . r = 0 . ENDCASE . ENDMODULE. " USER_COMMAND_1000 INPUT

*&---------------------------------------------------------------------*

*& Module modint INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE modint INPUT. rate = 0 . select single rate into rate from ywast_mst where wast_cd = intsale-wast_cd .

intsale-value = intsale-qty * rate . modify intsale from intsale index ysale-current_line . * intsale-value = ysale_tbl-value . * *MODIFY INTSALE TRANSPORTING QTY *VALUE *WHERE ( MEMO_NO = intsale-MEMO_NO * AND GPASS_NO = intsale-GPASS_NO * AND WAST_CD = intsale-WAST_CD ) . * *modify intsale from ysale_tbl index ysale-current_line . .

ENDMODULE. " modint INPUT *&---------------------------------------------------------------------* *& Module disrec OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE disrec OUTPUT. ysale_tbl-memo_no = intsale-memo_no . ysale_tbl-gpass_no = intsale-gpass_no . ysale_tbl-wast_cd = intsale-wast_cd . ysale_tbl-qty = intsale-qty . ysale_tbl-value = intsale-value . ENDMODULE. " disrec OUTPUT *&---------------------------------------------------------------------* *& Module mod001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* module mod001 input. SELECT SINGLE NAME INTO NAME FROM YWAST_MST WHERE WAST_CD = INTSALE-WAST_CD .

MESSAGE I398(00) WITH ' Wastage item is ' intsale-wast_cd name .

endmodule.

" mod001

INPUT

Das könnte Ihnen auch gefallen