Use a pop-up to populate a mandatory parameter
Using parameters is a great way to get last-minute data that does not necessarily need to be in the source data. Sometimes, clients forget to populate the parameter or will populate it with invalid data.
A pop-up window is a great way to get the required value. The values presented to the client can be validated in advance based on any condition that can be represented in ABAP.
In this example, a parameter called pLIFNR
is left initial and a pop-up provides the client with a list of available vendors filtered only on the condition that the name contains an upper case "X". This condition is only used as an example; the vendor (or customer or material or any other object or value) can be filtered on company code (or type or date or any value in any table).
The first step is defining a parameter to be filled. Making the field like
an existing type allows the client to choose from a list of available options.
parameters: pLIFNR like LFA1-LIFNR.
The second step is to set up two nearly identical data types: one an internal table and one a structure with the same field names. The flat structure will be used to populate the headers of the list in the pop-up.
data: begin of l_LIFNRS occurs 10, LIFNR type LIFNR, NAME1 like LFA1-NAME1, STRAS like LFA1-STRAS, end of l_LIFNRS. data: begin of l_HEADER, LIFNR type LIFNR, NAME1 like LFA1-NAME1, STRAS like LFA1-STRAS, end of l_HEADER. data: l_TITLE like RGSE1-SEL_LINE.
Finally, validation occurs. Ultimately, this should be a check against a table in SAP to ensure that the value entered is valid, but for this demonstration, the only validation is to check if the value is initial
.
if pLIFNR is initial. select LIFNR NAME1 STRAS from LFA1 into corresponding fields of l_LIFNRs. if l_LIFNRs-NAME1 cs 'X'. append l_LIFNRS. endif. endselect. L_TITLE = 'Vendors'. L_HEADER-LIFNR = 'Vendor'. L_HEADER-NAME1 = 'Name'. L_HEADER-STRAS = 'Street'. CALL FUNCTION 'G_DISPLAY_SELECTION_DYNPRO' EXPORTING DYNP_TITLE = L_TITLE KEY_COLUMNS = 1 NUMBER_OF_ROWS = 10 SEL_TITLE1 = L_HEADER WIDTH_OF_TITLES = 'X' IMPORTING SEL_INDEX = SY-INDEX TABLES SEL_TABLE = L_LIFNRs EXCEPTIONS NO_LINES = 4 NO_LINE_PICKED = 8. CASE SY-SUBRC. WHEN 0. READ TABLE L_LIFNRs INDEX SY-INDEX. pLIFNR = L_LIFNRs-LIFNR. WHEN 4. RAISE NO_VALUES_FOUND. WHEN 8. RAISE CANCELED_BY_USER. ENDCASE. endif.
The exceptions here are handled with sophomoric RAISE
statements. With a little effort, these can be changed to custom error messages that explain to the client the exact nature of the problem in the greatest possible detail.
Optionally, the parameter can be made mandatory by adding obligatory
to the parameter line. This prevents the LSMW object from performing the conversion until the parameter has been populated.
parameters: pLIFNR like LFA1-LIFNR obligatory.