Determine the number of lines on a screen for programming BDC 




Is there a way to determine the number of lines on a screen for programming BDC? 

Many users have different size fonts and resolutions on each screen. The number of lines vary. 
Many ABAPERS have this problem, if a batch input has a table control, then the font size changes from machine to machine as a result the no of entries keeps changing, so how to determine the number of available lines depending on the font size. 

Here is the solution code for this :-
************************************************************************
* data for controlling paging on screen 0102 
DATA: W_MAXLINES(2) TYPE N, 
W_NEXT_LINE(3) TYPE N, 
W_PAGE(1), "y = page forward, n otherwise 
W_SCRLEN(2) TYPE I, 
W_SCRLINE(2) TYPE I. 
DATA: BEGIN OF W_HDR. 
INCLUDE STRUCTURE D020S. 
DATA: END OF W_HDR. 
DATA: BEGIN OF W_FLD OCCURS 100. 
INCLUDE STRUCTURE D021S. 
DATA: END OF W_FLD. 
DATA: BEGIN OF W_LOG OCCURS 20. 
INCLUDE STRUCTURE D022S. 
DATA: END OF W_LOG. 
DATA: BEGIN OF W_MC OCCURS 20. 
INCLUDE STRUCTURE D023S. 
DATA: END OF W_MC. 
DATA: BEGIN OF W_DYNPRONAME, 
PROGRAM(8) VALUE 'SAPMM60X', 
DYNPRO(4) VALUE '0102', 
END OF W_DYNPRONAME. 

************************************************************************ 
FORM GET_MAX_LINES. 
* set w_maxlines to the number of var-loop occurrences on the screen so 
* that we know when to page forward on screen 0102 
* also initialise w_next_line to zero for GET_NEXT_LINE 
* this subroutine caters for all cases - including screens without loops 
CLEAR: W_MAXLINES, 
W_NEXT_LINE. 
IMPORT DYNPRO W_HDR 
W_FLD 
W_LOG 
W_MC 
ID W_DYNPRONAME. 
LOOP AT W_FLD WHERE LTYP EQ 'L'. 
MOVE W_FLD-LINE TO W_SCRLINE. "first var-loop line 
MOVE W_FLD-LBLK TO W_SCRLEN. "depth of loop block 
EXIT. 
ENDLOOP. 
IF SY-SUBRC EQ 0 
AND W_SCRLEN NE 0. 
* sy-srows = total no of lines on screen 
* w_scrline = actual first line of loop so that 
* w_scrline - 1 = number of heading lines (before loop) 
* 4 = no of lines at top of screen - command line, pushbuttons, 2 ulines 
* 3 = no of lines after loop - uline & Page count 
* w_scrlen = no of lines in loop block 
* w_maxlines = sy-srows - ( wscrline - 1 ) - 4 - 3 
* and then 1 less but not sure why! 
W_MAXLINES = SY-SROWS - W_SCRLINE - 1 - 4 - 3. 
W_MAXLINES = W_MAXLINES - 1.
W_MAXLINES = W_MAXLINES DIV W_SCRLEN. 
ELSE. 
MOVE 99 TO W_MAXLINES. "this required if no screen loop 
ENDIF. 
ENDFORM. 

************************************************************************ 
FORM GET_NEXT_LINE. 
* set w_page if page forward is required 
W_NEXT_LINE = W_NEXT_LINE + 1. 
IF W_NEXT_LINE GT W_MAXLINES. 
W_NEXT_LINE = 1. 
W_PAGE = 'Y'. 
ELSE. 
W_PAGE = 'N'. 
ENDIF. 
ENDFORM. 

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

Questions
Do you have a ABAP Question?

Best regards,
SAP Basis, ABAP Programming and Other IMG Stuff
http://www.erpgreat.com

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.