Tuesday, May 6, 2008

Sample ABAP Program for Module Pool containing screen loop processing

PROGRAM YLSDM004.
TABLES: LTAP, "Transfer order item
LIPS, "SD doc delivery: item data
MAKT, "material description
VEPO, "SD Document: Shipping Unit Item
VEKP, "SD Document: Shipping Unit Header
USR01, "USER defaults
ZPACKMAT, "Packing material table
T646M, "hazard class descriptions
ZCASHAZLAB. "SCasehazardous label table
DATA: OK_CODE(4).

DATA: C LIKE SY-INDEX, " cursor for case labels
* C1 LIKE SY-INDEX, " cursor for storage class(haz)
C2 LIKE SY-INDEX. " cursor for text
* screen fields for selection screen 0100
DATA: S_ZZTRACKING LIKE LTAP-ZZTRACKING,
* S_VENUM LIKE VEKP-VENUM,
S_EXIDV LIKE VEKP-EXIDV.
*
DATA W_MAKTX LIKE MAKT-MAKTX.
* packaging materials
DATA: S_PACKMAT1 LIKE VEKP-ZZPACKMAT1,
S_BEZEI1 LIKE ZPACKMAT-BEZEI,
S_PACKMAT2 LIKE VEKP-ZZPACKMAT1,
S_BEZEI2 LIKE ZPACKMAT-BEZEI.
* Case label codes and descriptions
DATA: BEGIN OF LABELS OCCURS 5 ,
CODE LIKE VEKP-ZZCASELAB1,
TEXT LIKE ZCASHAZLAB-ZZCLB_TEXT,
END OF LABELS.
* hazard class and descriptions
DATA: BEGIN OF HAZ OCCURS 3,
CODE LIKE VEKP-ZZLAGKL,
TEXT LIKE T646M-LAGKT,
END OF HAZ.
DATA: W_HAZ_TEXT1 LIKE T646M-LAGKT,
W_HAZ_TEXT2 LIKE T646M-LAGKT,
W_HAZ_TEXT3 LIKE T646M-LAGKT.



DATA T_LINES LIKE TLINE OCCURS 1 WITH HEADER LINE.
DATA T_HEADER LIKE THEAD.
*DATA W_INDEX LIKE SY-INDEX.
* start line of the last screen of text lines
DATA W_MAX LIKE SY-INDEX.
DATA W_TIN_MAKTX LIKE MAKT-MAKTX.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* selection screen *
*----------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
CASE OK_CODE.
WHEN 'EXIT'. LEAVE TO SCREEN 0.
WHEN 'CANC'.

SELECT SINGLE * FROM USR01
WHERE BNAME = SY-UNAME .

LEAVE TO TRANSACTION USR01-STCOD.
ENDCASE.
SET PF-STATUS 'SELECT'.
CLEAR: VEKP,
LTAP.
SET TITLEBAR 'SEL'.

ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text *
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
C2 = 0.
* Mandatory Fields
CHECK OK_CODE = 'EXEC'.
*
CALL SCREEN '0110'.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Module VAL_ZZTRACKING INPUT
*&---------------------------------------------------------------------*
* text *
*----------------------------------------------------------------------*
MODULE VAL_ZZTRACKING INPUT.
* MUST enter at least one value
* IF S_ZZTRACKING = ' ' AND S_VENUM = ' ' AND S_EXIDV = ' '.
IF S_ZZTRACKING = ' ' AND S_EXIDV = ' '.
MESSAGE E001(YL).
ENDIF.

* if tracking label entered other fields must be initial
IF S_ZZTRACKING NE ' '
* AND ( S_VENUM NE ' ' OR S_EXIDV NE ' ' ).
AND S_EXIDV NE ' ' .
MESSAGE E083(YL).
ENDIF.
* if tracking label number entered get record from LTAP

IF S_ZZTRACKING NE ' '.

SELECT SINGLE * FROM LTAP
WHERE ZZTRACKING = S_ZZTRACKING.
IF SY-SUBRC NE 0.
MESSAGE E022(YL) WITH S_ZZTRACKING.
ELSE.
*--------------------------------------------------------------------
*
* IF LTAP-VENUM NE ' '.
*
* SELECT SINGLE * FROM VEKP
* WHERE VENUM = LTAP-VENUM .
*
IF LTAP-EXIDV NE ' '.

SELECT SINGLE * FROM VEKP
WHERE EXIDV = LTAP-EXIDV .
*---------------------------------------------------------------------
IF SY-SUBRC NE 0.
MESSAGE E022(YL) WITH LTAP-EXIDV.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDMODULE. " VAL_ZZTRACKING INPUT
*&---------------------------------------------------------------------*
*& Module VAL_VENUM INPUT
*&---------------------------------------------------------------------*
* text *
*----------------------------------------------------------------------*
*MODULE VAL_VENUM INPUT.
* SET CURSOR FIELD S_VENUM.
* IF S_VENUM NE ' '
* AND S_EXIDV NE ' '.
* MESSAGE E083(YL).
* ENDIF.
* IF S_VENUM NE ' '.
*
* SELECT SINGLE * FROM VEKP
* WHERE VENUM = S_VENUM.
* IF SY-SUBRC NE 0.
* MESSAGE E022(YL) WITH S_VENUM.
* ENDIF.
* ENDIF.
*ENDMODULE. " VAL_VENUM INPUT
*&---------------------------------------------------------------------*
*& Module EXIT_COMMAND INPUT
*&---------------------------------------------------------------------*
* text *
*----------------------------------------------------------------------*
MODULE EXIT_COMMAND INPUT.
CASE OK_CODE.
WHEN 'EXIT'. LEAVE TO SCREEN 0.
WHEN 'CANC'.
SELECT SINGLE * FROM USR01
WHERE BNAME = SY-UNAME .

LEAVE TO TRANSACTION USR01-STCOD.
WHEN 'BACK'. LEAVE TO SCREEN 0.
ENDCASE.

ENDMODULE. " EXIT_COMMAND INPUT
*&---------------------------------------------------------------------*
*& Module VAL_EXIDV INPUT
*&---------------------------------------------------------------------*
* validate external shipping unit number exits on VEKP *
*----------------------------------------------------------------------*
MODULE VAL_EXIDV INPUT.
IF S_EXIDV NE ' '.
CONCATENATE '00' S_EXIDV INTO VEKP-EXIDV.
SELECT SINGLE * FROM VEKP
WHERE EXIDV = VEKP-EXIDV.
IF SY-SUBRC NE 0.
MESSAGE E022(YL) WITH S_EXIDV.
ENDIF.
ENDIF.
ENDMODULE. " VAL_EXIDV INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0110 OUTPUT
*&---------------------------------------------------------------------*
* Display screen *
*----------------------------------------------------------------------*
MODULE STATUS_0110 OUTPUT.
IF OK_CODE = 'P+ ' OR OK_CODE = 'P- ' OR OK_CODE = 'P++ '
OR OK_CODE = 'P-- '.
EXIT.
ENDIF.
IF VEKP-VENUM = ' '.
* processing mode b
PERFORM DISP_DELIVERY.
ELSE.
* processing mode a
PERFORM DISP_SHIP_UNIT.
ENDIF.
* common processing
* get mara details
CLEAR MAKT.
*SELECT SINGLE * FROM MARA
* WHERE MATNR = LIPS-MATNR .
*IF SY-SUBRC = 0.
* material description
SELECT SINGLE * FROM MAKT
WHERE MATNR = LIPS-MATNR
AND SPRAS = SY-LANGU .
DATA W_TDNAME LIKE THEAD-TDNAME.
W_TDNAME = LIPS-VBELN.
W_TDNAME+10 = LIPS-POSNR.
CLEAR T_LINES.
REFRESH T_LINES.
CALL FUNCTION 'READ_TEXT'
EXPORTING
ID = 'Z034'
LANGUAGE = SY-LANGU
NAME = W_TDNAME
OBJECT = 'VBBP'
IMPORTING
HEADER = T_HEADER
TABLES
LINES = T_LINES
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8.
LOOP AT T_LINES.
EXIT.
ENDLOOP.
IF SY-TFILL > 1.
* W_MAX = SY-TFILL - 5.
W_MAX = SY-TFILL - 1.
ELSE.
W_MAX = 1.
ENDIF.
*
IF W_MAX > 3 .
SET PF-STATUS 'DELIVERY'.
ELSE.
SET PF-STATUS 'ONE'.
ENDIF.
ENDMODULE. " STATUS_0110 OUTPUT

*&---------------------------------------------------------------------*
*& Form DISP_DELIVERY
*&---------------------------------------------------------------------*
* Diplay delivery title - Read delivery item from LIPS
* processing mode B
*----------------------------------------------------------------------*
FORM DISP_DELIVERY.
* SET PF-STATUS 'DELIVERY'.
SET TITLEBAR 'DEL'.
CLEAR LIPS.
SELECT SINGLE * FROM LIPS
WHERE VBELN = LTAP-VBELN_VL
AND POSNR = LTAP-POSNR_VL .

ENDFORM. " DISP_DELIVERY

*&---------------------------------------------------------------------*
*& Form DISP_SHIP_UNIT
*&---------------------------------------------------------------------*
* Display Shipping unit title and read shipping details
*----------------------------------------------------------------------*
* Processing MODE a
*----------------------------------------------------------------------*
FORM DISP_SHIP_UNIT.

* SET PF-STATUS 'DELIVERY'.
SET TITLEBAR 'SHP'.
* vekp already read
* read vepo
* only one line per case
CLEAR VEPO.
CLEAR LIPS.
CLEAR W_MAKTX.
CLEAR W_TIN_MAKTX.
CLEAR ZPACKMAT.
CLEAR S_PACKMAT1.
CLEAR S_PACKMAT2.
CLEAR S_BEZEI1.
CLEAR S_BEZEI2.
CLEAR LABELS.
REFRESH LABELS.
SELECT SINGLE * FROM VEPO
WHERE VENUM = VEKP-VENUM.
IF SY-SUBRC = 0.
SELECT SINGLE * FROM LIPS
WHERE VBELN = VEPO-VBELN
AND POSNR = VEPO-POSNR .
ENDIF.
* packaging material
IF VEKP-ZZPACKMAT1 NE ' '.
SELECT SINGLE * FROM ZPACKMAT
WHERE ZZPACKMAT = VEKP-ZZPACKMAT1.
IF SY-SUBRC = 0.
S_PACKMAT1 = VEKP-ZZPACKMAT1.
S_BEZEI1 = ZPACKMAT-BEZEI.
ENDIF.
ENDIF.

IF VEKP-ZZPACKMAT2 NE ' '.
SELECT SINGLE * FROM ZPACKMAT
WHERE ZZPACKMAT = VEKP-ZZPACKMAT2.
IF SY-SUBRC = 0.
S_PACKMAT2 = VEKP-ZZPACKMAT2.
S_BEZEI2 = ZPACKMAT-BEZEI.
ENDIF.
ENDIF.
* hazard class x 3
CLEAR: W_HAZ_TEXT1, W_HAZ_TEXT2, W_HAZ_TEXT3.
* REFRESH HAZ.
IF VEKP-ZZLAGKL NE ' '.
* HAZ-CODE = VEKP-ZZLAGKL.

SELECT SINGLE * FROM T646M
WHERE SPRAS = SY-LANGU
AND LAGKL = VEKP-ZZLAGKL .
IF SY-SUBRC = 0.
W_HAZ_TEXT1 = T646M-LAGKT.
ENDIF.
* APPEND HAZ.
ENDIF.
IF VEKP-ZZLAGKL2 NE ' '.
* HAZ-CODE = VEKP-ZZLAGKL2.

SELECT SINGLE * FROM T646M
WHERE SPRAS = SY-LANGU
AND LAGKL = VEKP-ZZLAGKL2 .
IF SY-SUBRC = 0.
W_HAZ_TEXT2 = T646M-LAGKT.
ENDIF.
* APPEND HAZ.
ENDIF.
IF VEKP-ZZLAGKL3 NE ' '.
* CLEAR HAZ.
* HAZ-CODE = VEKP-ZZLAGKL3.

SELECT SINGLE * FROM T646M
WHERE SPRAS = SY-LANGU
AND LAGKL = VEKP-ZZLAGKL3 .
IF SY-SUBRC = 0.
W_HAZ_TEXT3 = T646M-LAGKT.
ENDIF.
* APPEND HAZ.
ENDIF.
* LOOP AT HAZ.
* EXIT.
* ENDLOOP.

* case label details
IF VEKP-ZZCASELAB1 NE ' '.
LABELS-CODE = VEKP-ZZCASELAB1.
APPEND LABELS.
ENDIF.
IF VEKP-ZZCASELAB2 NE ' '.
LABELS-CODE = VEKP-ZZCASELAB2.
APPEND LABELS.
ENDIF.
IF VEKP-ZZCASELAB3 NE ' '.
LABELS-CODE = VEKP-ZZCASELAB3.
APPEND LABELS.
ENDIF.
IF VEKP-ZZCASELAB4 NE ' '.
LABELS-CODE = VEKP-ZZCASELAB4.
APPEND LABELS.
ENDIF.
IF VEKP-ZZCASELAB5 NE ' '.
LABELS-CODE = VEKP-ZZCASELAB5.
APPEND LABELS.
ENDIF.

LOOP AT LABELS.

SELECT SINGLE * FROM ZCASHAZLAB
WHERE ZZCASELAB = LABELS-CODE .
LABELS-TEXT = ZCASHAZLAB-ZZCLB_TEXT.
MODIFY LABELS.
ENDLOOP.
* tin material description
IF VEPO-ZZTINNR NE ' '.
SELECT SINGLE * FROM MAKT
WHERE MATNR = VEPO-ZZTINNR
AND SPRAS = SY-LANGU .


IF SY-SUBRC = 0.
W_TIN_MAKTX = MAKT-MAKTX.
ENDIF.
ENDIF.


* case material description
IF VEKP-VHILM NE ' '.
SELECT SINGLE * FROM MAKT
WHERE MATNR = VEKP-VHILM
AND SPRAS = SY-LANGU .


IF SY-SUBRC = 0.
W_MAKTX = MAKT-MAKTX.
ENDIF.
ENDIF.

ENDFORM. " DISP_SHIP_UNIT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0110 INPUT
*&---------------------------------------------------------------------*
* text *
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0110 INPUT.
* position text line cursor
CASE OK_CODE.
WHEN 'P+ '.
C2 = C2 + 3.
IF C2 > W_MAX.
C2 = W_MAX.
ENDIF.
WHEN 'P- '.
C2 = C2 - 3.
IF C2 < 1.
C2 = 1.
ENDIF.
WHEN 'P++ '.
C2 = W_MAX.
WHEN 'P-- '.
C2 = 1.
WHEN 'VL02'.
SET PARAMETER ID 'VL ' FIELD LIPS-VBELN.
CALL TRANSACTION 'VL02'.

ENDCASE.
ENDMODULE. " USER_COMMAND_0110 INPUT

No comments:

Blog Archive