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: 

Subroutine

Former Member
0 Kudos

Hi,

In this program i want to use subroutine .i want to use subroutine instead of defining each field individually.

how to do that .

TYPE-POOLS SLIS.

TYPES:

BEGIN OF TY_VBAK,

VBELN TYPE VBAK-VBELN,

AUDAT TYPE VBAK-AUDAT,

AUART TYPE VBAK-AUART,

NETWR TYPE VBAK-NETWR,

KUNNR TYPE VBAK-KUNNR,

END OF TY_VBAK.

DATA:

ST_VBAK TYPE TY_VBAK,

IT_VBAK TYPE TABLE OF TY_VBAK.

DATA:

IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

ST_FIELDCAT TYPE LINE OF SLIS_T_FIELDCAT_ALV.

SELECT-OPTIONS:

SKUNNR FOR ST_VBAK-KUNNR.

START-OF-SELECTION.

ST_FIELDCAT-COL_POS = '1'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'VBELN'.

ST_FIELDCAT-KEY = 'X'.

ST_FIELDCAT-HOTSPOT = 'X'.

ST_FIELDCAT-SELTEXT_L = 'SALES DOCUMENT NUMBER'.

ST_FIELDCAT-SELTEXT_M = 'SALES DOC NO'.

ST_FIELDCAT-SELTEXT_S = 'ORDER NO'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '2'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'AUDAT'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'SALES DOCUMENT DATE'.

ST_FIELDCAT-SELTEXT_M = 'SALES DOC DT'.

ST_FIELDCAT-SELTEXT_S = 'DATE'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '3'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'AUART'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'SALES DOCUMENT DATE'.

ST_FIELDCAT-SELTEXT_M = 'SALES DOC DT'.

ST_FIELDCAT-SELTEXT_S = 'DATE'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '4'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'NETWR'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'NET WORTH'.

ST_FIELDCAT-SELTEXT_M = 'NET WOR'.

ST_FIELDCAT-SELTEXT_S = 'NW'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '5'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'KUNNR'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'CUSTOMER NUMBER'.

ST_FIELDCAT-SELTEXT_M = 'CUST NUM'.

ST_FIELDCAT-SELTEXT_S = 'CUST'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'ZAC_TAB31'

IT_FIELDCAT = 'SLIS_T_FIELDCAT_ALV'

TABLES

T_OUTTAB = IT_VBAK

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

SELECT VBELN AUDAT AUART NETWR KUNNR

FROM VBAK INTO TABLE IT_VBAK

WHERE KUNNR IN SKUNNR.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

Try this,

FORM FCAT USING POS TABNAME FNAME KEY HOTSPOT SEL_L SEL_M SEL_S .

ST_FIELDCAT-COL_POS = POS.

ST_FIELDCAT-TABNAME = TABNAME.

ST_FIELDCAT-FIELDNAME = FNAME.

ST_FIELDCAT-KEY = KEY.

ST_FIELDCAT-HOTSPOT = HOTSPOT.

ST_FIELDCAT-SELTEXT_L = SEL_L.

ST_FIELDCAT-SELTEXT_M = SEL_M.

ST_FIELDCAT-SELTEXT_S = SEL_S.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ENDFORM.

.........

.........

.........

PERFORM FCAT USING '1' 'ST_VBAK' 'VBELN' 'X' 'X' 'SALES DOCUMENT NUMBER' 'SALES DOC NO' 'ORDER NO' .

PERFORM FCAT USING '2' 'ST_VBAK' 'AUDAT' '' '' 'SALES DOCUMENT DATE' 'SALES DOC DT' 'DATE' .

PERFORM FCAT USING '3' 'ST_VBAK' 'AUART' '' '' 'SALES DOCUMENT TYPE' 'SALES DOC TYP' 'STYPE' .

PERFORM FCAT USING '4' 'ST_VBAK' 'NETWR' '' '' 'NET WORTH' 'NET WOR' 'NW'.

PERFORM FCAT USING '5' 'ST_VBAK' 'KUNNR' '' '' 'CUSTOMER NUMBER' 'CUST NUM' 'CUST'.

Likewise u have to write all Perform's.

Regards,

Padmam.

5 REPLIES 5

former_member189059
Active Contributor
0 Kudos
form fill_me using one two three four five six seven eight.

ST_FIELDCAT-COL_POS = one.
ST_FIELDCAT-TABNAME = two.
ST_FIELDCAT-FIELDNAME = three.
ST_FIELDCAT-KEY = four.
ST_FIELDCAT-HOTSPOT = five.
ST_FIELDCAT-SELTEXT_L = six.
ST_FIELDCAT-SELTEXT_M = seven.
ST_FIELDCAT-SELTEXT_S = eight.
APPEND ST_FIELDCAT TO IT_FIELDCAT.
CLEAR ST_FIELDCAT.

endform.

and accordingly pass the correct parameters to the perform fill_me statement

Former Member
0 Kudos

Hi

TYPE-POOLS SLIS.

TYPES:

BEGIN OF TY_VBAK,

VBELN TYPE VBAK-VBELN,

AUDAT TYPE VBAK-AUDAT,

AUART TYPE VBAK-AUART,

NETWR TYPE VBAK-NETWR,

KUNNR TYPE VBAK-KUNNR,

END OF TY_VBAK.

DATA:

ST_VBAK TYPE TY_VBAK,

IT_VBAK TYPE TABLE OF TY_VBAK.

DATA:

IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,

ST_FIELDCAT TYPE LINE OF SLIS_T_FIELDCAT_ALV.

SELECT-OPTIONS:

SKUNNR FOR ST_VBAK-KUNNR.

START-OF-SELECTION.

perofrm get_data.

perform prepare_fieldcatalog.

perform display_output.

Form prepare_fieldcatalog.

ST_FIELDCAT-COL_POS = '1'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'VBELN'.

ST_FIELDCAT-KEY = 'X'.

ST_FIELDCAT-HOTSPOT = 'X'.

ST_FIELDCAT-SELTEXT_L = 'SALES DOCUMENT NUMBER'.

ST_FIELDCAT-SELTEXT_M = 'SALES DOC NO'.

ST_FIELDCAT-SELTEXT_S = 'ORDER NO'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '2'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'AUDAT'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'SALES DOCUMENT DATE'.

ST_FIELDCAT-SELTEXT_M = 'SALES DOC DT'.

ST_FIELDCAT-SELTEXT_S = 'DATE'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '3'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'AUART'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'SALES DOCUMENT DATE'.

ST_FIELDCAT-SELTEXT_M = 'SALES DOC DT'.

ST_FIELDCAT-SELTEXT_S = 'DATE'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '4'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'NETWR'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'NET WORTH'.

ST_FIELDCAT-SELTEXT_M = 'NET WOR'.

ST_FIELDCAT-SELTEXT_S = 'NW'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ST_FIELDCAT-COL_POS = '5'.

ST_FIELDCAT-TABNAME = 'ST_VBAK'.

ST_FIELDCAT-FIELDNAME = 'KUNNR'.

ST_FIELDCAT-KEY = ''.

ST_FIELDCAT-HOTSPOT = ''.

ST_FIELDCAT-SELTEXT_L = 'CUSTOMER NUMBER'.

ST_FIELDCAT-SELTEXT_M = 'CUST NUM'.

ST_FIELDCAT-SELTEXT_S = 'CUST'.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

endform.

form display_output.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'ZAC_TAB31'

IT_FIELDCAT = 'SLIS_T_FIELDCAT_ALV'

TABLES

T_OUTTAB = IT_VBAK

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

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.

form get_data.

SELECT VBELN AUDAT AUART NETWR KUNNR

FROM VBAK INTO TABLE IT_VBAK

WHERE KUNNR IN SKUNNR.

endform.

<b>Reward points for useful Answers</b>

Regards

Anji

Former Member
0 Kudos

Hi,

Use FM REUSE_ALV_FIELDCATALOG_MERGE

Also through SE37 check its documentation, to how to use it.

Reward if useful!

Former Member
0 Kudos

HI,

Try this,

FORM FCAT USING POS TABNAME FNAME KEY HOTSPOT SEL_L SEL_M SEL_S .

ST_FIELDCAT-COL_POS = POS.

ST_FIELDCAT-TABNAME = TABNAME.

ST_FIELDCAT-FIELDNAME = FNAME.

ST_FIELDCAT-KEY = KEY.

ST_FIELDCAT-HOTSPOT = HOTSPOT.

ST_FIELDCAT-SELTEXT_L = SEL_L.

ST_FIELDCAT-SELTEXT_M = SEL_M.

ST_FIELDCAT-SELTEXT_S = SEL_S.

APPEND ST_FIELDCAT TO IT_FIELDCAT.

CLEAR ST_FIELDCAT.

ENDFORM.

.........

.........

.........

PERFORM FCAT USING '1' 'ST_VBAK' 'VBELN' 'X' 'X' 'SALES DOCUMENT NUMBER' 'SALES DOC NO' 'ORDER NO' .

PERFORM FCAT USING '2' 'ST_VBAK' 'AUDAT' '' '' 'SALES DOCUMENT DATE' 'SALES DOC DT' 'DATE' .

PERFORM FCAT USING '3' 'ST_VBAK' 'AUART' '' '' 'SALES DOCUMENT TYPE' 'SALES DOC TYP' 'STYPE' .

PERFORM FCAT USING '4' 'ST_VBAK' 'NETWR' '' '' 'NET WORTH' 'NET WOR' 'NW'.

PERFORM FCAT USING '5' 'ST_VBAK' 'KUNNR' '' '' 'CUSTOMER NUMBER' 'CUST NUM' 'CUST'.

Likewise u have to write all Perform's.

Regards,

Padmam.

dev_parbutteea
Active Contributor
0 Kudos

Hi,

Use FM REUSE_ALV_FIELDCATALOG_MERGE

e.g

data w_fieldcat type slis_fieldcat_alv.

type-pools : slis.

tables : sflight.

data : i_fieldcat type slis_T_fieldcat_alv.

data v_repid like sy-repid.

data : begin of i_sflight occurs 0,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

end of i_sflight.

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = sy-repid

i_internal_tabname = 'I_SFLIGHT'

i_inclname = sy-repid

changing

ct_fieldcat = I_fieldcatalog_TYPE.