Wednesday, 30 May 2012

MODULE POOL

SIMPLE PROGRAM ON MODULE POOL

Scenario : Here we would design a single screen(9000) with two i/p fields & one o/p field. Upon entering the values in the i/p field, if the user clicks on the add button then the sum will be displayed in the o/p field.

Step-1. Go to SE80. Choose Program And Give a Name ( zmp_test1 ) and press Enter.
















Step -3. Un check the check box and Click Yes button.


















Step-4. Select Module Pool From the Type and Click on Save button.



 













Step-6. Double Click on Program Name & Click on Change Button.

 












Step-7. Create A screen - right click on Program Name ->Create->Screen

                        








 Step-8.  Give Screen number - 9000 & click on Yes Button.








 





Step-9. Give a short Description &  It's a normal Screen.

 

 














Step-10. Click on layout Button & the Screen Painter Window will appear .

 
















Step-11. Create two input fields , one push button & an output field & at last click on flow logic button on the toolbar.

 



Step-12.  Now uncomment the two modules in PBO & PAI . Double click on the module name and create it in main program.










Step-13. Write the code in the program.

PROGRAM  zmp_test1.

DATA : num1 TYPE i,
       num2 
TYPE i,
       res 
TYPE i.

MODULE status_9000 OUTPUT.
  
SET PF-STATUS 'STATUS'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 
" STATUS_9000  OUTPUT

MODULE user_command_9000 INPUT.
  
CASE sy-ucomm.
    
WHEN 'SHOW'.
      res = num1 + num2.
    
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
      
LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.                 
" USER_COMMAND_9000  INPUT

 


Step-14. Uncomment the SET PF-STATUS 'XXXX'  line  and give any name(STATUS) & double click  on it to create it. From the popup click on yes .

 










Step-15. Give A short text and Click on yes button.

 









Step-16. Click on the (+) Button on the right of Function keys to expand it. Give SAVE, BACK,   EXIT & CANCEL in the standard toolbar & activate it and press back button to come back to the program.

 












Step-17. Now create a transaction code for the program. Right click on program name->create->transaction.





 

 








Step-18. Give a T-code, short description and click yes button.

 










Step-19. Give program name , screen number and click on the three check boxes and then click on save button on the standard toolbar. Click on back button to come the program.

 











Step-20. Now  open a new session and put the T-code of the program in the Command field and press Enter.

 










Step-21. Fill the two input field with some values and then press ADD button. Find the Result.









PROGRAM DEMONSTRATING (ON INPUT)

data : N1 type i.
data : N2 type i.
data ok_code type sy-ucomm.

module STATUS_9000 output.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

endmodule.                 " STATUS_9000  OUTPUT

module USER_COMMAND_9000 input.
CASE OK_CODE.
  
WHEN 'SHOW'.
  
CALL  SCREEN 9001.
  
ENDCASE.
endmodule.                 " USER_COMMAND_9000  INPUT

module STATUS_9001 output.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
N2 
N1.
endmodule.                 " STATUS_9001  OUTPUT

module USER_COMMAND_9001 input.
CASE OK_CODE.
  
WHEN 'BACK'.
    
CALL SCREEN 9000.
  
ENDCASE.
endmodule.                 " USER_COMMAND_9001  INPUT


module CHECK_N1 input.
N1 
N1 + 10.
endmodule.                 " CHECK_M1  INPUT


FLOW LOGIC OF SCREEN 9000
PROCESS BEFORE OUTPUT.
 
MODULE STATUS_9000.

PROCESS AFTER 
INPUT.
FIELD N1 MODULE CHECK_N1 ON INPUT.
MODULE USER_COMMAND_9000.











FLOW LOGIC OF SCREEN 9001

PROCESS BEFORE OUTPUT.
 
MODULE STATUS_9001.

PROCESS AFTER 
INPUT.
 
MODULE USER_COMMAND_9001.






 Run the program and if you give any value to the input field (n1) then only    CHECK_N1  module will execute . press SHOW & BACK button many times to see the change. If it finds any value in the input field (n1) then every time  CHECK_N1 module will execute and it will add up 10 to its value.

PROGRAM DEMONSTRATING (ON REQUEST)

data : N1 type i.
data : N2 type i.
data ok_code type sy-ucomm.

module STATUS_9000 output.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

endmodule.                 " STATUS_9000  OUTPUT

module USER_COMMAND_9000 input.
CASE OK_CODE.
  
WHEN 'SHOW'.
  
CALL  SCREEN 9001.
  
ENDCASE.
endmodule.                 " USER_COMMAND_9000  INPUT

module STATUS_9001 output.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
N2 
N1.
endmodule.                 " STATUS_9001  OUTPUT

module USER_COMMAND_9001 input.
CASE OK_CODE.
  
WHEN 'BACK'.
    
CALL SCREEN 9000.
  
ENDCASE.
endmodule.                 " USER_COMMAND_9001  INPUT

module CHECK_N1 input.
N1 
= N1 + 20.
endmodule.                 " CKECK_N1  INPUT

FLOW LOGIC OF SCREEN 9000
PROCESS BEFORE OUTPUT.
 
MODULE STATUS_9000.
*
PROCESS AFTER 
INPUT.
field N1 MODULE CHECK_N1 on REQUEST.
 
MODULE USER_COMMAND_9000.
FLOW LOGIC OF SCREEN 9001
PROCESS BEFORE OUTPUT.
 
MODULE STATUS_9001.
*
PROCESS AFTER 
INPUT.
 
MODULE USER_COMMAND_9001.

  Run the program and if you give any value to the input field (n1) then only    CHECK_N1  module will execute . press SHOW & BACK button many times to see the change.

PROGRAM DEMONSTRATING (ON CHAIN-INPUT)

DATA : N1 TYPE i.
DATA : N2 TYPE i.
DATA : N3 TYPE i.
DATA res TYPE i.
DATA ok_code TYPE sy-ucomm.

MODULE status_9000 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_9000  OUTPUT

MODULE user_command_9000 INPUT.
  
CASE ok_code.
    
WHEN 'ADD'.
      
CALL  SCREEN 9001.
  
ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT

MODULE status_9001 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
  res 
= N1 + N2 + N3.
ENDMODULE.                 " STATUS_9001  OUTPUT

MODULE user_command_9001 INPUT.
  
CASE ok_code.
    
WHEN 'BACK'.
      
CALL SCREEN 9000.
  
ENDCASE.
ENDMODULE.                 " USER_COMMAND_9001  INPUT

module CHECK_TWO_NUMBER input.
N1 
= N1 + 10.
N2 
= N2 + 10.

endmodule.                 " CKECK_THREE_NUMBER  INPUT

FLOW LOGIC OF SCREEN 9000

PROCESS BEFORE OUTPUT.
  MODULE status_9000.
PROCESS AFTER INPUT.
  CHAIN.
    FIELD : N1,N2.
    MODULE CHECK_TWO_NUMBER ON CHAIN-INPUT.
  ENDCHAIN.
  MODULE user_command_9000.















FLOW LOGIC OF SCREEN 9001
PROCESS BEFORE OUTPUT.
 
MODULE STATUS_9001.

PROCESS AFTER 
INPUT.
 
MODULE USER_COMMAND_9001.






  Run the program and if you provide any value to either n1 or n2  or both  then only  CHECK_TWO_NUMBER  module will execute . press ADD & BACK button many times to see the change.

PROGRAM DEMONSTRATING (ON CHAIN-REQUEST)

DATA : N1 TYPE i.
DATA : N2 TYPE i.
DATA : N3 TYPE i.
DATA res TYPE i.
DATA ok_code TYPE sy-ucomm.

MODULE status_9000 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_9000  OUTPUT

MODULE user_command_9000 INPUT.
  
CASE ok_code.
    
WHEN 'ADD'.
      
CALL  SCREEN 9001.
  
ENDCASE.
ENDMODULE.                 " USER_COMMAND_9000  INPUT

MODULE status_9001 OUTPUT.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
  res 
= N1 + N2 + N3.
ENDMODULE.                 " STATUS_9001  OUTPUT

MODULE user_command_9001 INPUT.
  
CASE ok_code.
    
WHEN 'BACK'.
      
CALL SCREEN 9000.
  
ENDCASE.
ENDMODULE.                 " USER_COMMAND_9001  INPUT


module CHECK_TWO_NUMBER input.
N1 
= N1 + 10.
N2 
= N2 + 10.
endmodule.                 " CKECK_TWO_NUMBER  INPUT
FLOW LOGIC OF SCREEN 9000
PROCESS BEFORE OUTPUT.
  
MODULE status_9000.

PROCESS AFTER 
INPUT.
  CHAIN
.
    
FIELD : N1,N2.
    
MODULE CHECK_TWO_NUMBER ON CHAIN-REQUEST.
  ENDCHAIN
.
  
MODULE user_command_9000.
FLOW LOGIC OF SCREEN 9001
PROCESS BEFORE OUTPUT.
 
MODULE STATUS_9001.

PROCESS AFTER 
INPUT.
 
MODULE USER_COMMAND_9001.

  Run the program and if you provide any value to either n1 or n2  or both  then only  CHECK_TWO_NUMBER  module will execute . press ADD & BACK button many times to see the change.

PROGRAM DEMONSTRATING (AT EXIT-COMMAND)

Scenario : Generally if a screen contains any obligatory(Required) input field & we execute the MP program , the screen appears & if we want to come out of the program it will not allow us . We have to fill the mandatory field on the screen and then we can come out of the program by clicking on the application tool bar buttons. To overcome this problem , generally we use AT EXIT-COMMAND at PAI of the screen to force exit from the screen that contains a required field without filling any value to it.

Here we have two screens 9000 and 9001. In the 9000 screen we have an required i/p field & a single record is displayed on 9001 screen based on the i/p.


******** program on at exit-command *************

data : p_carr type spfli-carrid,
       wa_spfli 
type spfli,
       ok_code 
type sy-ucomm.

module STATUS_9000 output.
  
SET PF-STATUS 'STATUS'. " DOUBLE CLICK ON 'STATUS' TO CREATE IT
*  SET TITLEBAR 'xxx'.

endmodule.                 
" STATUS_9000  OUTPUT

module FORCE_EXIT input.
CASE OK_CODE.
  
WHEN 'EXIT' OR 'CANCEL'.
    
LEAVE PROGRAM.
  ENDCASE.
endmodule.                 
" FORCE_EXIT  INPUT

module USER_COMMAND_9000 input.
case ok_code.
  
WHEN 'DISP'.
    
CALL SCREEN 9001.
    
WHEN 'BACK'.
      
LEAVE PROGRAM.
  endcase.
endmodule.                 
" USER_COMMAND_9000  INPUT

module STATUS_9001 output.
*  SET PF-STATUS 'xxxxxxxx'.
*  SET TITLEBAR 'xxx'.
  
SELECT SINGLE FROM SPFLI INTO WA_SPFLI WHERE CARRID = P_CARR.

endmodule.                 
" STATUS_9001  OUTPUT

module USER_COMMAND_9001 input.
case ok_code.
  
when 'BACK'.
    
LEAVE TO SCREEN 0.
  endcase.
endmodule.                 
" USER_COMMAND_9001  INPUT


TO CREATE PF STATUS 
STEP-1 : Double click on 'STATUS' to create pf status and click on yes button.







STEP-2:  Give a short description.



 STEP-3: Click on the '+' button of the Function key & fill values 'BACK',  'EXIT' & 'CANCEL'.



 STEP-4: Double click on 'EXIT' & the following screen will appear. Click of the value help of theFunction Type field and choose the first entry. 'E' type.
  


STEP-5  : Click yes to set 'E' for the EXIT and also set 'E' type also for 'CANCEL'




 FLOW LOGIC OF SCREEN 9000
PROCESS BEFORE OUTPUT.
  MODULE status_9000.

PROCESS AFTER INPUT.
  MODULE force_exit AT EXIT-COMMAND.
  MODULE user_command_9000.
























FLOW LOGIC OF SCREEN 9001
PROCESS BEFORE OUTPUT.
 MODULE STATUS_9001.
PROCESS AFTER INPUT.
 MODULE USER_COMMAND_9001.




 


















OUTPUT:



Comments system

Disqus Shortname