Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Can we call functional module in a subroutine? Any example?

Former Member
0 Kudos
84

Can we call functional module in a subroutine? Any example?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
47

Hi,

U can call a func. Module inside form. Please check below.

PERFORM error_log.

&----


*& Form error_log

&----


----


  • --> p1 text

  • <-- p2 text

----


FORM error_log .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = w_download_filename

TABLES

data_tab = it_log

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " error_log

Reward if helpful.

Regards,

Karthick.

5 REPLIES 5

Former Member
0 Kudos
47

yes we can call FM in a subroutine.

perform display tables it_data .

form display tables it_data .

call function reuse_alv_list display.

.....

......

.........

endform.

Message was edited by:

Premalatha G

former_member2382
Active Participant
0 Kudos
47

Yes, you can call funtion modules in Subroutines.

For ex.

Form.

call FM REUSE_ALV_...

...................

.................

...............

Endform.

Regards,

parvez.

Former Member
0 Kudos
47

sample code....

REPORT ZPL_BDC_PA30.

TABLES : PA0022.

DATA : V_PERNR LIKE PA0022-PERNR,

V_SLABS LIKE PA0022-SLABS.

DATA : FILENAME TYPE STRING.

DATA : BEGIN OF IT_DATA OCCURS 0,

PERNR LIKE PA0022-PERNR, "Personnel Number

SLABS LIKE PA0022-SLABS, "Certificate code

SLABS1 LIKE PA0022-SLABS, "Certificate code new

END OF IT_DATA.

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 1 WITH HEADER LINE.

DATA : BEGIN OF IT_ERROR OCCURS 0,

POS LIKE SY-TABIX,

TEXT(40),

END OF IT_ERROR.

PARAMETERS : P_FNAME TYPE DXFIELDS-LONGPATH.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAME.

CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'

  • EXPORTING

  • I_LOCATION_FLAG = ' '

  • I_SERVER = '?'

  • I_PATH = I_PATH

  • FILEMASK = '.'

  • FILEOPERATION = 'R'

IMPORTING

  • O_LOCATION_FLAG = O_LOCATION_FLAG

  • O_SERVER = O_SERVER

O_PATH = P_FNAME

  • ABEND_FLAG = ABEND_FLAG

EXCEPTIONS

RFC_ERROR = 1

ERROR_WITH_GUI = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

START-OF-SELECTION.

FILENAME = P_FNAME.

PERFORM UPLOAD. "Uploading inputfile to internal table.

PERFORM VALIDATE. "validating the values

PERFORM POPULATE_BDC. "Populating bdc internal table

PERFORM ERROR_RECORDS

TABLES IT_ERROR. "Error records

&----


*& Form bdc_fdata

&----


FORM BDC_FDATA USING FNAM FVAL.

CLEAR IT_BDCDATA.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

ENDFORM. " bdc_fdata

&----


*& Form bdc_hdata

&----


FORM BDC_HDATA USING PROGRAM SCRNO DYNBEGIN.

CLEAR IT_BDCDATA.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = SCRNO.

IT_BDCDATA-DYNBEGIN = DYNBEGIN.

APPEND IT_BDCDATA.

ENDFORM. " bdc_hdata

&----


*& Form upload

&----


FORM UPLOAD .

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = FILENAME

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE = VIRUS_SCAN_PROFILE

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH = FILELENGTH

  • HEADER = HEADER

TABLES

DATA_TAB = IT_DATA

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17

.

IF SY-SUBRC <> 0.

MESSAGE I000(BCTRAIN) WITH 'FILE NOT UPLOADED'.

ELSE.

  • MESSAGE I000(BCTRAIN) WITH 'FILE UPLOADED'.

ENDIF.

ENDFORM. " upload

&----


*& Form populate_bdc

&----


FORM POPULATE_BDC .

LOOP AT IT_DATA .

PERFORM BDC_HDATA USING 'SAPMP50A'

'1000'

'X'.

PERFORM BDC_FDATA USING 'RP50G-PERNR'

IT_DATA-PERNR.

PERFORM BDC_FDATA USING 'RP50G-CHOIC'

'0022'.

PERFORM BDC_FDATA USING 'BDC_OKCODE'

'=MOD'.

PERFORM BDC_HDATA USING 'MP002200'

'2000'

'X'.

PERFORM BDC_FDATA USING 'P0022-SLABS'

IT_DATA-SLABS1.

PERFORM BDC_FDATA USING 'BDC_OKCODE'

'=UPD'.

CALL TRANSACTION 'PA30' USING IT_BDCDATA.

REFRESH IT_BDCDATA.

ENDLOOP.

ENDFORM. " populate_bdc

&----


*& Form validate

&----


FORM VALIDATE .

data : num like sy-tabix,

num1 like sy-tabix.

LOOP AT IT_DATA.

num = num + 1.

num1 = sy-tabix.

SELECT PERNR

FROM PA0022

INTO V_PERNR WHERE

PERNR EQ IT_DATA-PERNR.

ENDSELECT.

IF SY-SUBRC <> 0.

MOVE num TO IT_ERROR-POS.

MOVE 'Invalid Pernr' TO IT_ERROR-TEXT.

APPEND IT_ERROR.

DELETE IT_DATA .

ELSE.

IF IT_DATA-SLABS IS INITIAL.

MOVE num TO IT_ERROR-POS.

MOVE 'Certificate code is initial' TO IT_ERROR-TEXT.

APPEND IT_ERROR.

DELETE IT_DATA.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " validate

&----


*& Form error_records

&----


FORM ERROR_RECORDS TABLES IT_ERRORS.

FORMAT COLOR COL_GROUP.

WRITE : / 'Error in the following records : ' .

FORMAT COLOR COL_NEGATIVE.

LOOP AT IT_ERROR.

WRITE : / IT_ERROR-POS,

IT_ERROR-TEXT.

ENDLOOP.

ENDFORM. " error_records

Former Member
0 Kudos
47

Hi,

yes you can definately call function module from the subrutine.

rgds

Deepak.

Former Member
0 Kudos
48

Hi,

U can call a func. Module inside form. Please check below.

PERFORM error_log.

&----


*& Form error_log

&----


----


  • --> p1 text

  • <-- p2 text

----


FORM error_log .

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = w_download_filename

TABLES

data_tab = it_log

EXCEPTIONS

file_write_error = 1

no_batch = 2

gui_refuse_filetransfer = 3

invalid_type = 4

no_authority = 5

unknown_error = 6

header_not_allowed = 7

separator_not_allowed = 8

filesize_not_allowed = 9

header_too_long = 10

dp_error_create = 11

dp_error_send = 12

dp_error_write = 13

unknown_dp_error = 14

access_denied = 15

dp_out_of_memory = 16

disk_full = 17

dp_timeout = 18

file_not_found = 19

dataprovider_exception = 20

control_flush_error = 21

OTHERS = 22.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " error_log

Reward if helpful.

Regards,

Karthick.