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: 

Populate Function Module Parameter Depending on a condition.

Former Member
0 Kudos

Hi Guys,

I need to call function module WS_DELIVERY_UPDATE_2 with some export parameters and tables. (This is done in a loop. Program reads data from a file in the server and loop them). If the data set has a value for serial number field (sernr) (there are several fields) I need to populate the exporting parameter IT_SERNR_UPDATE with relevant data. If no value in the file for sernr then this parameter should not be populated. Can I do this without calling the function module twice.

Thanks and Regards,

2 REPLIES 2

former_member188827
Active Contributor
0 Kudos

You can check if passing blank parameter "IT_SERNR_UPDATE" throws any error or not. In case, the FM does not give any error, you can simply use IF statement to check if the serial number field is populated or not and depending on its value update "IT_SERNR_UPDATE" or leave it blank.

Regards

JerryWang
Advisor
Advisor
0 Kudos

Hi man,

for sure this is possible. You could just use CALL FUNCTION - parameter_tables and populate your parameter to the parameter tables dynamically. The following example is just directly copied from ABAP help ( just search with keyword CALL FUNCTION in your F1 help 😞


DATA: line     TYPE c LENGTH 80,
      text_tab LIKE STANDARD TABLE OF line,
      filename TYPE string,
       filetype TYPE c LENGTH 10,
      fleng    TYPE i.

DATA: func TYPE string,
      ptab TYPE abap_func_parmbind_tab,
      ptab_line TYPE abap_func_parmbind,
      etab TYPE abap_func_excpbind_tab,
      etab_line TYPE abap_func_excpbind.

func = 'GUI_DOWNLOAD'.
filename = 'c:\temp\text.txt'.
filetype = 'ASC'.

ptab_line-name = 'FILENAME'.
ptab_line-kind = abap_func_exporting.
GET REFERENCE OF filename INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

ptab_line-name = 'FILETYPE'.
ptab_line-kind = abap_func_exporting.
GET REFERENCE OF filetype INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

ptab_line-name = 'DATA_TAB'.
ptab_line-kind = abap_func_tables.
GET REFERENCE OF text_tab INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

ptab_line-name = 'FILELENGTH'.
ptab_line-kind = abap_func_importing.
GET REFERENCE OF fleng INTO ptab_line-value.
INSERT ptab_line INTO TABLE ptab.

...

etab_line-name = 'OTHERS'.
etab_line-value = 10.
INSERT etab_line INTO TABLE etab.

CALL FUNCTION func
  PARAMETER-TABLE
    ptab
  EXCEPTION-TABLE
    etab.

CASE sy-subrc.
  WHEN 1.
    ...
  ...
ENDCASE.


Best regards,

Jerry